Game Development Community

Simulate loop

by Bucko · in Torque Game Builder · 03/12/2005 (9:13 am) · 4 replies

Warning: I am entirely fresh to T2D having only recently.
Most game have a game loop where the updating takes place, preferably on a fixed timestep basis.
Is there a way to have a function called periodically for every object to handle "power expenditure" etc.

#1
03/12/2005 (9:33 am)
I was thinking the same thing, because this engine more establishes a set of rules that constantly get checked. I want to get a grasp on this too because eventually I want to make a game based on persistent time. One tool that might help you out until the really skilled guys reach this thread is the schedule function:

schedule(2000, 0, "");

this will call the function 2 seconds from now. If you put a similar line in the function itself, you have a loop.

Not sure that would be much better than actually doing an infinite loop in script.
#2
03/13/2005 (2:22 am)
Jeremy is quite correct, that's exactly how you should schedule a function. As he mentions, you need to reschedule the function to make it periodic.

There's also a "fxSceneGraph2D::onUpdateScene()" call that's called each frame although you really should be careful that you don't do too much here as you can easily hurt performance.

Just thought that I'd add that you can't (read that shouldn't) do an infinite loop in the scripts otherwise the engine will lock as it is called synchronously.

- Melv.
#3
03/13/2005 (8:06 am)
From what I can tell, it just takes a different mindset developing from an engine rather than from scratch. If you think of the script as just a part of the "infinite loop". The engine itself is always churning over and over to render your objects.

Melv, would the onUpdateScene function be a good place for setting the global time variable in a persistant time game?
#4
03/13/2005 (9:16 am)
The scene maintains its own time and you can simply use that e.g. "getSceneTime()". All T2D objects use it as does the collision/physics system. Note that if you halt the scene "setScenePause()", the scene-time pauses as well. When your game begins, simply note the time. If you want to save some stuff then just note the scene-time.

It'd be best to use that as a baseline time.

- Melv.