I need to know if there is anyway to copy properties between two scenes. (via the copy property logic brick). Is it possible in bricks? Python?
In-game, yes, it’s quite easy… You store the variables in a module, like bge.logic, and then load the variables when the game goes to the next scene. For example,
from bge import logic obj['hp'] = 100 logic.hp = obj['hp'] # Set module variable obj['hp'] = logic.hp # Get module variable
I’m talking about an overlay scene (HUD) and the main scene. Here’s my code so far…
from bge import logic
cont = bge.logic.getCurrentController()
obj = cont.owner
sce = logic.getCurrentScene(‘Scene’)
prop = sce.objects[‘character_physics’]
prop[‘health’] = obj[‘health’]
for some reason it isn’t working. Any ideas why?
Because getCurrentScene() is a function to get the current scene that the script is run in, not one of your choice. If you want a specific scene, you can do either:
sce = logic.getSceneList() # the function returns a list of scenes currently in-game, and it goes in order of drawing (i.e. overlay functions are last on the list, while background functions seems to be first)
sce = [sce for sce in logic.getSceneList() if sce.name == "NameOfScene"] # Returns a list of which scenes conform to your standard (that have their name set to "NameOfScene"), and gives the first value in that list
Thanks, SolarLune! I couldn’t seem to get that first code to work but the second one worked.