schedule() time variation
by N.K. · in Torque Game Engine · 05/18/2009 (12:02 pm) · 3 replies
Hi,
I'm using schedule() to schedule a function after every hour (3600000 ms). The problem is the scheduled function is not executed after exactly one hour. On one occasion it took as much as an hour and forty minutes to schedule again. On another it executed after 35 minutes. Any idea what the problem might be?
Cheers,
N.K.
I'm using schedule() to schedule a function after every hour (3600000 ms). The problem is the scheduled function is not executed after exactly one hour. On one occasion it took as much as an hour and forty minutes to schedule again. On another it executed after 35 minutes. Any idea what the problem might be?
Cheers,
N.K.
About the author
#2
it doesn't really say much other than i was noticing that elapsedSimTime was about 0.96 times elapsedRealTime over the course of three minutes.
05/18/2009 (12:33 pm)
woops, that thread is in the private forums, sorry.it doesn't really say much other than i was noticing that elapsedSimTime was about 0.96 times elapsedRealTime over the course of three minutes.
#3
05/19/2009 (7:28 am)
If Orion has indeed diagnosed the problem (sim time differing from real time), then that could be your issue. However, why not try repeating the schedule every minute, and counting up to 60? This would avoid any potential problems with large numbers.
Associate Orion Elenzil
Real Life Plus
schedule works by getting the current simulation time (milliseconds since the application began) and adding your offset to it, then registering an event to take place at that simulation time.
but as a U32, the current simulation time only wraps every 1,193 hours or so, which implies that you would only see that problem once every 1,192 hours or so. hm..
it might be drift in Simulation Time versus wall time,
which i was noticing a while back but never really pursued.
check out this thread. not much in the way of answers, i'm afraid, but might give you some experimentation ideas.
it looks like you don't have a license,
so one moderately-ugly-but-definitely-workable workaround might be to keep track in script of the reatime when you want this event to occur (eg, "$gEventRealTimeMS = getRealTime() + 60 * 60 * 1000;") and then have a repeating schedule() which fires every twenty seconds or so and checks if getRealTime() is bigger than $gEventRealTimeMS. if it's important that the event fire exactly in one hour instead of one hour plus-or-minus twenty seconds, you detect when the event is coming up in the next minute or so, and then issue a schedule() for it to occur on-the-dot.