The contents of the message are probably better to be mentioned to the community, so I’ve posted it here:
I still do have few questions regarding the timer, IDE and one file script though.
How can I code it with timer? I’m still getting into coding and I’m still not that familiar with those complicated stuff.
with Geany. I just reload the script by ALT+R everytime I do changes. Is that how you do it?
lastly, I know it’s really complicated but can you give me just the main concept behind one file scripting? if that’s even possible. lol
Let’s say we want to know the time between two events. One frame we can do:
start_time = time.time() #Alternatively datetime.now() depending on what time module you are working with
And then later we can do:
end_time = time.time()
duration = end_time - start_time
So to have something that runs every second, you may do:
start_time = time.time() # Run this at some point in the past
....
...
current_time = time.time()
if end_time - start_time > time_in_seconds:
do_something()
Why are you reloading things frow within geany? What is changing them? In my setup, Geany is making the changes, and the BGE has to read those changes. So what’s doing the modification of the files?
***Ho boy, this is a biggie. Have you ever worked with embedded systems? Ever worked with a RTOS? If you have, some things here may be a little easier.
Pretty much, if we have a single python script running every frame, we have to have the script do everything. Except that is madness, so we split it into parts. Modules that handle subsections. These can be imported using the python import statement.
But what goes into this one file? In the case of my latest project CaveX16, it is the file you see here. Pretty much there are three things it does:
- Initialize the game
- Update the load sequence
- Update the actual game
So by initialize the game, I mean things that are major subsystems: Adding the scheduling system, adding the sound management system etc.
By “loading the system” I mean loading models, loading the sounds themselves, generating the level etc. Some things in the load sequence add themselves to the scheduler to be run at regular intervals at a later time.
Then in running the game, it goes through the items in the scheduler and runs thost when they need it.
So for instance, a game unit:
- Has the model loaded in part 2
- Adds itself to the scheduler in part 2
- Updates it’s AI every frame by being run from the scheduler run in part 3
The core part of such a system is the scheduler, which for CaveX16 can be seen here. If you aren’t familiar with object oriented programming it may look a little strange. The instalce of the scheudler created in Game.py I linked to earlier.
So there you go, there’s an overview of how this was set up in one of my recent projects.