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.
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.
You can do it (to a degree) by saving the time when you set the timer.
Something in the lines of:
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);
}
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:
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.