global propertys?

I was going to follow Blendenzo’s save/load tutorial but I hit a sang how do I tell an object how many lives it has left if the lives are a global property and then subtract from it every time I die?(basically how do I use the global props after creation?)

Do you mean global properties being properties on GameLogic, so GameLogic.lives?

If you do you can just use GameLogic.lives -= 1, thats the same as saying GameLogic.lives = GameLogic.lives - 1

thank you but what sensor do I connect to the script to take away lives? Do global props service into the next scene or restart of the same scene?

Depends on how you lose a life, if you lose a life by touching an object with a ‘bounds’ property on it then you connect a collision sensor to it.

Properties in GameLogic stay there until the blend is exited.

OK Thanks! I could make a life meter and it hits zero then I’ll lose a life. One last (maybe) qeustion how do I transfer a global prop (life left from last level) to a local prop and back again? Do you have a tuts you could point me to?

I don’t know why you would want to convert it to a local property, and then when ready change it back to a GameLogic property, its just easier to always use GameLogic.lives.

Or do you want to change it to a local property for a logic brick set up? In that case add a property on the object called lives, set to int -2. Add an always actuator connected to a script controller. Make a new script and put this code in it:

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

if own.lives == -1:
    own.lives = GameLogic.lives
elif own.lives <> GameLogic.lives:
    GameLogic.lives = own.lives

So, what this if condition is doing is when the local property lives is equal to -1 it changes it to be the same as the global property lives, pretty much -2 is like an initialisation state because it will never ever be -2 again.
The elif condition; ‘elif own.lives <> GameLogic.lives:’, may be a bit different to you because you may have never see <> before, <> means not equal to. So when own.lives is not equal to GameLogic.lives, GameLogic.lives is set to own.lives, what this means is when you lose a life and it is subtracted from the local property it will also be subtracted from the global property.

OK, first of all, use !=, not <>. both are valid, but no one uses <> anymore :stuck_out_tongue:

Secondly, if someone doesn’t just add in a nice little ‘g = GameLogic’, instead of typing out GameLogic 500,000 times, i’m going to go crazy.

Other than that, I think you’re OK. Those just drive my OCD a smidge off the edge.


Haha, well I just this <> looks 500,000 times cooler then !=, but yea, I guess you should use != because its whats commonly used,

Well, as for g = gameLogic, I can type at 318 characters per minute, that 5.3 characters per second. GameLogic has 9 characters in it so it only takes me around 1.69 seconds to type it, I’m not fussed about it :slight_smile:
I don’t like using single letter variables unless its for use in a for loop or arguments in a method.

Thankyou Andrew! This will help be a lot for making a save system.

after using local props transfered to global oness I desided to try using global ones only but it always prints 2 like it keeps resetting the global prop, heres my script to take away a life.

GL = GameLogic

cont = GL.getCurrentController()

lost = cont.getSensor("down")
lives = GL.lives

if lost:
	lives = lives - 1
	print lives

and heres

GameLogic.lives = 3

no errors in the console or anything. is connected to a always with palse off.

BUMP anyone?

BUMP help me someone!

Here’s a modified script

import.GameLogic as GL
cont = GL.getCurrentController()
own = cont.getOwner()
lost = cont.getSensor("down")
own.lives = GL.lives
if lost:
      GL.lives -= 1
      print lives

Always use getOwner() first before dealing with scripts using properties. Also, if you want lives to go down in a global sense you’d subtract the gamelogic variable, your lives would equal the gamelogic’s so it should go down. Also, ‘-=’ is the common way to subtract a value.

CD did you see this post?