Link to an overlay scene?

Is there a way to link logic blocks from one scene to another? I want to put a “speedometer” in my GUI scene and have it link to my vehicle in my main scene.

Is this possible? How do I do this?

THANKS!

Sure!
Use the great Message brick

Ex:move object in overlayed scene

MAin scene-Empty object- Keyb Sensor -> AND -> Message Actuator-Subject: foo
Overlayed scene-whatever object - Message Sensor-Subject: foo -> AND -> Motion Actuator

Bye

Thanks OTO,

I think I understand, the “message” bricks allow you to “talk” from one scene to another. What I don’t understand is how to get a variable’s value to another scene. Here’s a sample .blend:

http://www.pmudesign.com/downloads/text_test.zip

I want to display the object’s speed in the overlayed scene, but I can’t figure out how to do this?

Using a python global variable seems like your best choice.

Here’s the code (not mine) from the .blend:

import GameLogic
import math
cont4=GameLogic.getCurrentController()
owner=cont4.getOwner()

speed=owner.getVelocity()
speedt=math.pow(speed[0],2)+math.pow(speed[1],2)+math.pow(speed[2],2)
speedtot=(math.sqrt(speedt))*2


vel=cont4.getActuator("vel")
vel.setProperty("Text")
vel.setValue(str(abs(int(speedtot))))
GameLogic.addActiveActuator(vel,1)

… argh… I may “pretend” to know python, but I really don’t :frowning: I’m guessing I want to make “vel” a -global- variable then read it in the other scene, right? How do I do this?


import GameLogic
GameLogic.ABCDE = ABCDE

Then in the overlay scene, another scipt.


import GameLogic
ABCDE = GameLogic.ABCDE

Where ABCDE is whatever you`d like it to be.

-Daz.

Thanks for the replies. I think I see what’s supposed to be happening, but I guess I’m just not “getting it”.

I searched for threads on “global variables” and tried your hints, but nothing seems to be working.

Are the two code clips above supposed to be new python files or part of the existing python code? I don’t understand how the value in variable “vel” is supposed to get passed… ( I really should have studied computer science instead of biology in college :frowning: ).

Ok, I’m studing past posts trying to get an idea how to do this. Here’s the code of the sample blend I’ve created (and a link is above):

import GameLogic 
import math 
cont4=GameLogic.getCurrentController() 
owner=cont4.getOwner() 

speed=owner.getVelocity() 
speedt=math.pow(speed[0],2)+math.pow(speed[1],2)+math.pow(speed[2],2) 
speedtot=(math.sqrt(speedt))*2 


vel=cont4.getActuator("vel") 
vel.setProperty("Text") 
vel.setValue(str(abs(int(speedtot)))) 
GameLogic.addActiveActuator(vel,1)

This python code is attached to a block with is moved with a keystroke. There is also a “text” plane in the same scenewith a “text” property. This displays the object’s “vel” properly.

What I want to do is have “vel” display in another scene. In this 2nd scene, there is a plane with a “text” property. I understand that I need to pass a global variable to the 2nd scene.

Looking at the code above, isn’t " GameLogic.addActiveActuator(vel,1) " a global variable? Isn’t that what’s being passed to the “text” plane?

… argh… I’m getting a headache…

Hi,

When you have the speedtot value from the script above, place a GameLogic. before it.


GameLogic.speedtot = sqrt(speedt)

Then on your overlay speedo dial/needle. Have an Always -> And -> Ipo(propertytype) prop speedtot
and an
Always(pulsed) -> pythonscript


import GameLogic
c = GameLogic.getCurrentController()
o = c.getOwner()

o.speedtot = GameLogic.speedtot

Soz, I wasn`t sure how much python you knew earlier. :slight_smile:

No, doesn’t work.

Please download the .blend file that’s further up this thread so you’ll understand what’s going on.

I don’t think the “ipo” property works because it’s not using a dial/needle speedometer, it’s using a -digital- speedometer.

I’m also getting a value of 0 for speedtot while “vel” seems to display the correct value in the debug display.

Sorry to be so dense, but I think I understand what needs to be done, I just can’t see how to do it…

Ah, digital eh. :slight_smile: Missed that.

Chnange the,


o.speedtot = GameLogic.speedtot

to


o.text = GameLogic.speedtot

This should put the speed value straight into the text value to be displayed.

v-lil explination -v

You don`t need any messages, just the two scripts running. One sending the value you want, in this case, speedtot.(just make sure you have speedtot equaling the value you want to make global.) Then make it global.


GameLogic.speedtot = speedtot

Now, when the other script runs, for your digital read out. Just link the Text value for the string prop on your ‘digital’ face.


o.Text = GameLogic.speedtot

You may need a,


import GameLogic
c = GameLogic.getCurrentController()
o = c.getOwner()

Remember you need to have the scripts running on the objects conserned.
From above, c is the same as cont4, just how i like to write it. Lazy see. :wink:
Same for o, it`s the same as owner.

This is worth persisting with, is pretty cool and easy(ish) when ya know how. :slight_smile:

Thanks Iconjunky, but it’s still not working for me. Here’s a link to a small sample I’m working with to learn how to do this:

http://www.pmudesign.com/downloads/text_test.zip

This was created in 2.41. While running the game, press the up arrow (cursor key) to move the block. The text plane shows the object’s speed.

The text sample that is working is in the same scene as the object. The text sample that stays at “0” is in the scene “GUI”.

What am I doing wrong?

Hi,

A few little things, but your pretty much there. :slight_smile:

The main wrong one is:


GameLogic.speedtot = speedtot

This is prob my fault, :expressionless: But speedtot is a totally diferent variable to,


GameLogic.speedtot = owner.speedtot

Note the owner before speedtot. Make sure all the variables you want to move around ARE actually the variables you want. (I do this ALL the time. So does everyone else, apart from z3r0 d. :slight_smile: )

You dont need the 3rd paragraph in the speedometer script. (That is getting and changing the Text value through an Actuator. Not through aglobal`.)

You don`t need the Actuator named ‘speedtot’.

Remember the variable,(or name/word) you want to assign a value to is case sensitive. So, val is different to Val or vaL, which is different from owner.val

At the top of the scripts after the import GameLogic bit. Normally the words,


cont = GameLogic.getCurrentController()

are seen. This is not absolutely necessary to do, because you could just keep writting the GameLogic.getCurrentController bit. But its easier to assign these words to a shorter word, in this case, you got it, cont. My point is, make sure to check the other small blender console window and that there are no errors.

You dont need the pulsed sensor when adding the overlay scene, it was printing out a long list ofno need to add` msgs.

Umm, thats all really. You may benifit from re doing from the start. It shouldnt take you long really. Co`s you only need two small scripts being pulsed every time/frame, nothing else.

Oh, if there is a prop on an object, in one case, you have the Text prop for your Objects face to display the speedtot, this is accessed with the owner. before it. So,


owner.Text = "ABCDE"

I missed the fact that you may need a,


owner.Text = str(GameLogic.speedtot)

The above just converts the GameLogic.speedtot val into a STRing. Think it should display without it though.

Err, there are no textures with the text_test file i downloaded. Im not sure if you intended to see a display or something. You need toPack Data` in the File menu/options. (TopLeft of screen)

Keep trying, :slight_smile: An epiphany is near for ya. :wink:

Thanks Iconjunky, I know you’re trying to teach me how to do this but now I’m totally confused, I’m trying to follow your instructions and nothing makes sense at all.

Could you please just edit the file and post so I can study what you did? This is totally frustrating and making no sense whatsoever. I tried to plough though a book I have on Python programming and it’s not making much sense either…

Sorry to be such a slow learner…

Try this one. I wanted a camera in a background scene to move exactly as the camera in the main scene. I stored the main camera in the gamelogic and access it from the other camera. You can use the same method to access your object.

First script applied to the slave camera( slave.py ):

cont = GameLogic.getCurrentController()
own = cont.getOwner()

GameLogic.CamCtrl = own

You need this to run only once as it tells the gamelogic to store the camera object (use always with no pulse).

The second script must be applied to the master camera (master.py):

cont = GameLogic.getCurrentController()
own = cont.getOwner()

if hasattr( GameLogic, "CamCtrl" ):
	GameLogic.CamCtrl.setOrientation( own.getOrientation() )
	GameLogic.CamCtrl.setPosition( own.getPosition() )

You see the “CamCtrl”? This is the name from the slave script. If you do something like that you should always use hasattr(). Otherwise if the master script runs first you will get error messages on the console and the script will not run.

The disadvantage is that you can only react on things on frame later. If the mastercamera changes the position, the second will change it in the next frame. This leads to a “slow parent” effect. For your speedometer I don’ think you will notice this.

Thanks for trying, but I think I need to give up. :frowning: I know you both are trying to teach me over the forum, but that’s not working for me. What I need is a completed project so I can see everything together.

Thanks for trying.

Thanks for trying, but I think I need to give up. I know you both are trying to teach me over the forum, but that’s not working for me. What I need is a completed project so I can see everything together.

Thanks for trying.

Nah ya dont. :D Youve almost got it from what i can tell. Making your own small test file would be easier and more benificial for you imo.

Try the stuff in brackets.

You know how to make an object move with a keypress?
( KeyboardSensor -> AndController -> MotionActuator )

And, you know how to run a python script continually?
( AlwaysPulsedSensor -> PythonscriptController )

You know how to Add Property to objects and name them?
( speed )

You know what/where the console window is?

Try this just to start.


import GameLogic 
c = GameLogic.getCurrentController() 
o = c.getOwner() 

o.speed = o.getVelocity()[1]

print o.getVelocity()

This should give the speed prop on your object the value of Velocity in the Y direction. The velocity is stored as x,y and z coords. So telling o.speed to = o.getVelocity() will make o.speed = a list of x,y,z. When you place a [1] after the () o.speed will = the Y Velocity. (You could have 0 - x, 1 - y, or 2 - z) inside the .

When you check the console window you should get 3 sets of numbers seperated with a , or something.

All you need for the above is, 1 object, 5 scats(3 for the motion of the object, 2 to run the python script) and the Python script. Should take 2mins to set up and test. :slight_smile:

If you give up though, thats up to you. :frowning:

I wont post anymore unless you or anyone else is interested.

Hope I helped a little. :smiley:

… argh … I thought my sample file was a test app. Oh, well here we go again. New test app created. One cube on the screen.

( KeyboardSensor -> AndController -> MotionActuator )

Did that, used the up key to move the cube 0.1 in Y direction with dLoc

( AlwaysPulsedSensor -> PythonscriptController )

Did that.

( speed )

Did that, also ticked “D” to display the value in debug.

You know what/where the console window is?

Yup.

Try this just to start.


import GameLogic 
c = GameLogic.getCurrentController() 
o = c.getOwner() 

o.speed = o.getVelocity()[1]

print o.getVelocity()

Did that, called script “speedometer” and called it with the Python controller.

This should give the speed prop on your object the value of Velocity in the Y direction.

Nope. Nada. Zip. I get a long string of zeros in the console window and 0,0,0 in the debug.

Hehe. :smiley:

I`ve just taken a look myself and it does appear to be something awry with the velocty thing possibly.

So here is some code that i would use to get the velocity of something.


import GameLogic as g
from math import *

c = g.getCurrentController()
o = c.getOwner()
p = o.getPositon()

o.speed = sqrt(((p[0]-o.px)**2)+((p[1]-o.py])**2)+((p[2]-o.pz)**2))

o.px = p[0]
o.py = p[1]
o.pz = p[2]

Youll need props on the object ofspeed,px,pyandpz`

Px,y and z just store the old position of the object. Then Pythagorean theory it.

If you put the above onto your text_test file it should help a bit.

Almost there! I can feel it. :slight_smile:

Ok, I’ll work on that.

Question: When I create a new scene I get options for:

  • Empty
  • Link Objects
  • Link ObData
  • Full Copy

I’ve been creating a new “Empty” scene. What happens if I choose “link objects” or “link obdata”?