I have a little project I am trying to do with Blender that is going to require some scripting.
I understand how you can attach python scripts to get executed when something happens with the sensor of an object.
My question is can I have a python script that runs when the game is started and has a loop that loops during the entire game(game loop). This way there can be variables that are maintained throughout the game.
I think this would probably be easy but I can’t seem to find it.
I don’t think that is what I am looking for. This would run the entire script over again. I want to have variables in the script that persist through the loop.
Variables are only accessible by the script that is using them, and only until the script is finished- because no other game logic can be running while a script is. Everything must be run one at a time.
What you want to use is properties- they will always be persistent unless you explicitly delete them, and they can either be assigned to any object, or GameLogic itself (for an object you use object[‘propertyname’], for GameLogic you use GameLogic.propertyname) On objects you can either initialize your propertied before runtime (via the properties pane in the game logic panel) or during any script.
Properties function pretty much exactly like variables except they need an object or GameLogic to contain them, and they will not get removed at the end of the script.
My bad… didn’t know that. :o Also, couldn’t he just run the script like in my example but have the properties created in blender itself so that they stay forever?
I was just wondering about that. Or would running the script over and over again be rather bad for the whole game? Like does it take up memory or any other negative effects?