Copying properties across scenes?


(Piraniac) #1

Hi all,

I know objects can be linked between scenes but can an object read the properties of another in a different scene?

What i would like to do is have a fancy HUD on an overlay scene and then change elements in the HUD according to the properties of the player character (eg. their life bar in the overlay goes down when they are shot in the main scene). If this can be accomplished using python then that would be better, but anything that works.

Forgive the waffle but i hope its clear!

cheers
Piran


(saluk) #2

You can use messages to do this if you like, but I would use global variables from python instead. If you know how to use python, you can store variables on GameLogic that will be able to be read from all objects from all scenes. As an example, for the health bar:

have a script hooked up to the character which looks like this:


c=GameLogic.getCurrentController()
ob=c.getOwner()
GameLogic.health=ob.health

This is assuming, that your health prop on the character is named health.

Then, on your health bar, you can have a script which does the reverse of the above:


c=GameLogic.getCurrentController()
ob=c.getOwner()
ob.health=GameLogic.health

Then the health bar’s health prop will be based on the characters health prop. You can add more lines to the aboves scripts for more properties if you like, or do whatever you want:)

Good luck.


(Piraniac) #3

Excellant!

Thats perfect, i wasn’t sure about global variables and python in the game engine but thats cool, neat an simple :wink:

Thanks again

Piran