GetSetTimer??? [solved]

Started by DrewCCU, Sat 26/06/2010 23:05:15

Previous topic - Next topic

DrewCCU

I was wondering if there was a way to get what "tick" a timer is at?

Like you have SetTimer where you can set say:
SetTimer(1,80);

And then you have IsTimerExpired?

But i would like to have a way to be able to have some piece of code where you can see where the timer is ... like:

X = GetSetTimer;

where the result may be something like:

x = 40  (which would mean the timer isn't expired at 0 but only 40 cycles have expired ... and it still has 40 to go ...

if this makes sense? if not let me know what i should explain better.
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

Khris

You can always use a global variable instead of a timer.
Decrease it in rep_ex_always and check if it's X or 0.

tzachs

You can do it (to a degree) by saving the time when you set the timer.
Something in the lines of:

Code: ags

int lastTimerExpiredTime; //Here we will save the time we last set the timer.
int timerTimeout = 100; //How many ticks for the timer (100 just an example)?
int timerId = 1; //Select the timer id (1 just an example)

//Use that instead of the regular SetTimer
function MySetTimer()
{
   DateTime *dt = DateTime.Now;
   lastTimerExpiredTime = dt.RawTime;
   SetTimer(timerId, timerTimeout);
}

//And then, the function you want will be:
int GetNumberOfTicksLeft()
{
   DateTime *dt = DateTime.Now;
   int currentTime = dt.RawTime;
   int timeFromPreviousExpiredInTicks = (currentTime - lastTimerExpiredTime) 
                                                 * GetGameSpeed();
   
   return (timerTimeout - timeFromPreviousExpiredInTicks);
}

DrewCCU

Quote from: tzachs on Sun 27/06/2010 19:13:05
You can do it (to a degree) by saving the time when you set the timer.
Something in the lines of:

Code: ags

int lastTimerExpiredTime; //Here we will save the time we last set the timer.
int timerTimeout = 100; //How many ticks for the timer (100 just an example)?
int timerId = 1; //Select the timer id (1 just an example)

//Use that instead of the regular SetTimer
function MySetTimer()
{
   DateTime *dt = DateTime.Now;
   lastTimerExpiredTime = dt.RawTime;
   SetTimer(timerId, timerTimeout);
}

//And then, the function you want will be:
int GetNumberOfTicksLeft()
{
   DateTime *dt = DateTime.Now;
   int currentTime = dt.RawTime;
   int timeFromPreviousExpiredInTicks = (currentTime - lastTimerExpiredTime) 
                                                 * GetGameSpeed();
   
   return (timerTimeout - timeFromPreviousExpiredInTicks);
}


Thanks guys.  That's using your noggin right there tzachs.  But i think it may be easier to do it the what Khris was talking about.  Anway, thanks you guys.
"So much of what we do is ephemeral and quickly forgotten, even by ourselves, so it's gratifying to have something you have done linger in people's memories."
-John Williams

SMF spam blocked by CleanTalk