Beginner question about python

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.

Thanks

See my attached picture for that. It seems to run all the time but I have no idea how good that would be for your game or the PC running it.

Attachments


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.

What I want would be like this script that runs on start

running = True
while running:
  do stuff

The problem with this is that it doesn’t allow blender to do anything since I have taken over the game 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.

Blender already has an game engine.
The script is just part of it.
With ShadowX’s configuration the script runs once at each frame (= logic tick).

here is a scheme how the BGEGameloop works. Just a scheme the order might be different, steps might be missing.

if you do endless loop within your script you will hold the whole game loop and have to kill the process.

I hope it helps

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?

So I would want to use GameLogic properties to store stuff. Thanks for your help.

One more question. Could someone explain to me the difference between using script or module at the type.