GameLogic properties

Hi, n00bs of python!

I just found out a cool trick, for saving properties while switching scenes.
Of course, all experienced programmers should know this.

Instead of using normal blender properties, you use GameLogic.Properties, ( Maybe they aren’t called like that… ) and make a script for making a “normal” property equal to it.

Scripts example:

Initialize GL.Var: ( init.py )

GameLogic.thing = 30

Men, that’s a VERY long script!

Every time you use a sensor, remove 1 from property:

cont = GameLogic.getCurrentController()

x = cont.getSensor("x")

if x.isPositive():
    GameLogic.thing = GameLogic.thing - 1

Sets property equal to GL.prop:

cont = GameLogic.getCurrentController()

own = cont.getOwner()

own.Text = GameLogic.thing

EDIT: As C-106 Delta says, the variable could stay forever, although I don’t care it stays until I close the game. To delete objects, just use del, like if quit_key.ispositive(): del GL.var.

EXAMPLE BLEND: http://uploader.polorix.net//files/1586/Mouse_Activator.blend
The blend includes a GL variable, social’s mouselook, and a activators demo.
I got the original blend from somebody who just did a quick setup for social’s mouselook… http://www.savefile.com/files/1536265 All the other things that appear on my example are made by me. (lol)

I hope that helps somebody

A little example .b file, maybe?!

yea, a Blender file would be nice to show and example :slight_smile:

A simple inventory system, or a simple save and load property to a text file script would be nice for new users too :slight_smile:

thanks for sharing!

Yea, this is standard code. The idea behind it is that you save a variable to GameLogic rather than an object because GameLogic isn’t cleared when you switch scenes.

Just be careful when using this method. If you don’t delete the variable it will stay in memory forever!!! (or until you close the game). If you use this method often, make sure you plan ahead and know what you are doing.

If you don’t plan ahead, you may get unwanted glitches. You have been warned.

Alright, I added a example blend, when you get thru the “door”, the GL var is deleted…

If anyone knows a good uploading website, in which the files last forever and the site doesn’t get bothering people to wait or sign up, please tell me.

If anyone knows a good uploading website, in which the files last forever and the site doesn’t get bothering people to wait or sign up, please tell me.

Uploader Polorix

Thanks alot, C-106 Delta!