Usually you set aside a variable, set it to zero initially, which you then add one to for every game loop (at the end of your room logic perhaps).
Then, when it reaches a certain value, you do something like start or stop an animation.
If you want timers that last for longer than 255 game loops, you can try having two variables, with one you increase when the other reaches it's limit. but then you have to check the value of two variables when you check for a certain time.
// two var example
if (newroom)
{
timer1_a = 0;
timer1_b = 0;
set(timer_started);
}
if (timer1_b == 0 && timer1_a=50)
{
// start animation
}
if (something happens)
{
// it's also possible to speed things along too.
// (say all the puzzles have been done so you don't need
// the extra time for your player
timer1_b = 2;
timer1_a = 0;
}
if (timer1_b == 2 && timer1_a=20)
{
// print msg, stop animation
// don't need timer anymore.
reset(timer_started);
}
if (timer_started)
{
if (timer1_a == 255)
{
timer1_a = 0;
timer1_b++;
}
// agi does not allow incrementation to overflow.
// so, unchecked, timer1_a could just stay at 255.
timer1_a++;
}
else
{
// set it to 0 here or at the end of your series of things
// (when you reset timer_started
timer1_a = 0;
timer1_b =0;
}
um.. I hope that helps. It's used in a lot of places. Police Quest uses it at the start to see if you miss the first meeting or not. V uses it for it's intro sequence. And I'm pretty sure lots of other games use it too.
- Nick