Blender Game Engine Properties, 2.48 --> 2.49.x
---This follows on from my previous writing.BLender 2.48, Blender 2.49.*
As some may have realised, any script that is linked to an always sensor (pulsed of course, so it runs more than once) is completely run. This means that any variables you define will get written back to to their default values. I can here you say "But that doesn't matter, we'll just define em every time, we're assigning GE values to them anyway.". However, if you want to += something, you need to define the variable first. However, if you only += something once per execution, you'll be defining it to some value, and then adding something. You won't ever get anywhere. Now, there is several ways to solve this problem. The simplest, and probably most useful for debugging, is storing the variable in a property. Properties remain between executions, as well as being able to be toggled visible during the playback of the GE.
import GameLogic cont = GameLogic.getCurrentController() own = cont.owner #guts of it here if own["initp"] != True: #do setup here own["prop"] += 1 own["initp"] = True
If you want your program to be based upon user values, such as entering a name or server address, one of the simplest ways is to use a property. It's probably not the best way to for a production game, but if you feel confidant in your users, or just for testing, it works well.
Properties also have limited use as a method of communicating values between different scripts. Really, the only reaons you would want to do it this way is if you're absolutely pedantic about the namespace, or want to temporarily debug your script.
You can access another objects property by first accessing the other object. Goes as follows (not actual code, dont' copy+paste):
import GameLogic
scene = GameLogic.getCurrentScene()
objlist = scene.objects
control = objlist["OBEmpty"]
speed = control["wheelspeed"]
A much superior way is to store things into the GameLogic (?class?;?module?;?dict?), as simply as:
import Gamelogic
GameLogic.varname = value
Another possible use for properties is that logic bricks can access them easily. One example is the Ipo actuator. In the drop down menu, there is an option for setting the frame to a property. This is ideal for turning an object a discrete number of degrees, or moving an object a discrete amount in a smooth line. You can also do tests based on property values (sensor).
A final word on the limitation of properties:
It is best to only asign strings, boolean values, ints or floats to properties.
There are artificial limitations on the maximum and minimum values that you can graphically set a property to. For ints and floats it's 10000
I write this in the hope that it will be useful. If it is wrong, feel free to contact me at simfake [.] mapping {@} gmail (.) com