Timers

Non-platform specific questions.

Timers

Postby boomblaster3 » Mon Jun 04, 2007 10:50 pm

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
boomblaster3
 
Posts: 1
Joined: Thu May 31, 2007 9:50 pm
Score: 0 Give a positive score

Re: Timers

Postby Sgt. Sparky » Tue Jun 05, 2007 4:58 am

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
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby pixelpoop » Tue Jun 05, 2007 7:22 am

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?
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby DilloDude » Tue Jun 05, 2007 9:40 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby Sgt. Sparky » Tue Jun 05, 2007 2:47 pm

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
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby makslane » Tue Jun 05, 2007 3:50 pm

Is better use the Timer event to track the seconds.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby DilloDude » Tue Jun 05, 2007 10:59 pm

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest