Python... Help?

Ok. Here’s my problem.

I have 2 scenes. The first scene is my actual game. The second is an overlay, with a meter on it. Now this meter has a property that keeps on changing.

I need an object from the first scene to copy THAT property. Now, i know you can’t copy properties via logic bricks in different scenes, SO… i wrote this.

scene = GameLogic.getCurrentScene()

activeScenes = GameLogic.getSceneList()

objList = activeScenes.objects

meter = objList["Power"]

c = GameLogic.getCurrentController()

owner = c.owner

power = meter['Power']

copy = owner['Power']

copy = power

The object i want to copy from is called Power. Plus, both the properties are called Power.

I get this message on my screen:

AttributeError: ‘list’ object has no attribute ‘objects’

(Its refering to this line:
objList = activeScenes.objects)

Any help would REALLY be appreciated.

Thx.

getSceneList() returns a list of scenes, not a scene.

You must first pick a scene out of it to access that scene’s own list of objects.

activeScenes = GameLogic.getSceneList()
results in activeScenes which is now a list of scenes.

objList = activeScenes.objects
makes no sense as activeScenes is a list not a scene, so you get an error.

If you know the name of the overly scene you can do this:
overlayScene = GameLogic.getSceneList()[“otherScene”]
or
meterObject = GameLogic.getSceneList()[“otherScene”][“OBPower”]
or
powerProperty = GameLogic.getSceneList()[“otherSceneName”][“OBPower”][“Power”]

finally you can write


import GameLogic
owner = GameLogic.getCurrentController()
owner["Power"] = GameLogic.getSceneList()["<i>otherScene</i>"]["OBPower"]["Power"]

Do not forget that object names start with “OB”.

I hope it helps

getSceneList() returns in 2.49a and 2.49b at least a standard list which cannot be accessed by scene name.

So to get scene by its name in this case:


import GameLogic

owner = GameLogic.getCurrentController().owner

for sce in GameLogic.getSceneList():
    if sce.name == "otherScene":
        owner["Power"] = sce.objects["OBPower"]["Power"]
        break

Unfortunetly, I tried the codes and it didn’t work…

It doesn’t tell me there is an error, so I don’t know what i did wrong…

Btw, the other scene is called Overlay.

Do globalDicts work between scenes? If so than you can use those.

Er… it should work. Exept i’m not too good with those. You wanna give me a hint on that?

Just type:

GameLogic.globalDict[“name”] = value

to store, and

value = GameLogic.globalDict[“name”]

to get your value back

You can put anyting in for values, numbers, lists (, I even used it to store a complete rigid body constraint :smiley:)

I just don’t know if I ever tried it between scenes.

@supersocks
You are right :slight_smile: I forgot it’s a standard list

Turkey-Killer have you replaced the “otherScene” with “Overlay”?