Page 1 of 1

Timers

PostPosted: Mon Jun 04, 2007 10:50 pm
by boomblaster3
I am making a game of survival and i would like to make a timer showing how long you have lasted in seconds how would i do this

Re: Timers

PostPosted: Tue Jun 05, 2007 4:58 am
by Sgt. Sparky
boomblaster3 wrote:I am making a game of survival and i would like to make a timer showing how long you have lasted in seconds how would i do this

make a variable(integer) called Time(make it global as well),
on the create Actor event of your Actor Create a timer that repeats with the duration of 1000 MS,
on this timer event use this Code,
Code: Select all
Time++;

and on the draw actor event of a text actor(to display your Time),
Code: Select all
textNumber = Time;

:D
if you still need help let me know. :D

PostPosted: Tue Jun 05, 2007 7:22 am
by pixelpoop
hey,
do timers in GE work off the system clock or by frames per second? if their is slow down in the fps do the timers go off later or on time?

PostPosted: Tue Jun 05, 2007 9:40 am
by DilloDude
They go off actual time. So if the framerate slows down, the number of frames in the time-limit will be fewer. This can be a major draw-back, so I usually prefer to use variable counters...
Code: Select all
//time is an int (or a real)
time ++;
if (time >= 50)
{
    //some action
}

...or something similar.

PostPosted: Tue Jun 05, 2007 2:47 pm
by Sgt. Sparky
DilloDude wrote:They go off actual time. So if the framerate slows down, the number of frames in the time-limit will be fewer. This can be a major draw-back, so I usually prefer to use variable counters...
Code: Select all
//time is an int (or a real)
time ++;
if (time >= 50)
{
    //some action
}

...or something similar.

but that is a 30 second/frame Timer,
you must use set the timer to the fps rate(you could accually set it to the current FPS rate[real_fps]) to make it a 1 second (or somewhere around there because of Changes.)
but you are right,
variable timers come in handy alot,
I use 3 or 4 in my Card Game(Skip-Jo) that I made and one normal Timer. :D
1+ for Dillo Dude. :D

PostPosted: Tue Jun 05, 2007 3:50 pm
by makslane
Is better use the Timer event to track the seconds.

PostPosted: Tue Jun 05, 2007 10:59 pm
by DilloDude
It really depends. If you want to actually know how long you've been playing, use a timer. If you want to have a record for the shortest time, a counter is better. Otherwise, someone with a faster computer can always beat your score if your computer keeps dropping in fps to like 15. The other scenario is a dorr and a switch. When the switch is switched, the door opens and stays open for a certain time. You have to get to the door before the time runs out. If using a timer, and the fps lags, this can maki it impossible. GE does have a motion compensation to help when you get low framerates, but I haven't tried it and I'm not sure how well it works (although it obviously does some god or it wouldn't be there).

The other reason I prefer variable counters is that they sit nicely in a draw-actor script, and you can see easily where they go.=, and what they do, rather than having it hidden in a separate event. You can also vary the flow of time easily, or the speed at which you go. And then you have a variable that you can use in other cases, so although the time keeps counting, you can have if its less than a certain amount, do one thing, but otherwise, do another. But using actual timers is good when you want actual time.