About Store Forum Documentation Contact



Post Reply 
[solved] Simple timer/alarm
Author Message
Azriel Offline
Member

Post: #1
[solved] Simple timer/alarm
Hi. It's me again pfft I have a very simple alarm that counts down and once it hits 0 it executes a piece of code. The problem is that I don't really know what value to substract from it on update(), so that it measures actual time.
(This post was last modified: 11-05-2015 12:11 PM by Azriel.)
11-02-2015 03:42 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
RE: Simple timer/alarm
Hi there,

Create a member variable of type flt (float) and set it to a value that is the length of your timer before the alarm goes off.

Then, in the update function do value -= Time.d();

When value <= 0, execute your stuff.

Hope that helps!
(This post was last modified: 11-02-2015 03:48 PM by Tottel.)
11-02-2015 03:48 PM
Find all posts by this user Quote this message in a reply
Azriel Offline
Member

Post: #3
RE: Simple timer/alarm
Well, that's exactly what I have at the moment, but if I want it to count for example 1 second, what value should I set?

Edit: Now that I've read my first post again I think I might have been imprecise. My timer works fine - I just don't know how to set it to count actual seconds/milliseconds wink
(This post was last modified: 11-02-2015 04:15 PM by Azriel.)
11-02-2015 04:10 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #4
RE: Simple timer/alarm
Time.time()? i believe that's what youre looking for
11-02-2015 05:45 PM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #5
RE: Simple timer/alarm
Hey Azriel the Time.d() is actually the time it took in seconds for the engine to process the last frame. That number is usually quite small something like 1/60 sec or 0.017 sec if your fps are at 60 fps.

So for example to measure 5 seconds you can do something like:
Code:
flt myTimer = 0.0f;
bool Update()
{
   myTimer += Time.d();

   if(myTimer >= 5.0f)
   {
   ...
   }

   if(Kb.bp(KB_ESC))return false;
   return true;
}
(This post was last modified: 11-02-2015 07:30 PM by georgatos7.)
11-02-2015 07:27 PM
Find all posts by this user Quote this message in a reply
Azriel Offline
Member

Post: #6
RE: Simple timer/alarm
Can't check the project atm, cause I'm at home already, but as far as I know that's how I did it and it didn't work as supposed. I'll double check my code tomorrow, probably some silly mistake, cause I've just made a new timer here and everything's fine.
Speaking about timing - is Time.d() what I should use in my whole game to get timing right? I've seen there were a couple other delta counters.
11-02-2015 09:21 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #7
RE: Simple timer/alarm
well you can check Time fonctions,

Flt d ()C {return _d ;} // game time delta (frame time duration, modified by game 'speed', affected by 'smooth' 'skipUpdate' and application pauses)

Flt time ()C {return _t ;} // game time in current frame ( seconds since application started, modified by game 'speed', affected by 'smooth' 'skipUpdate' and application pauses)

dont forget to use flt not int
(This post was last modified: 11-02-2015 11:09 PM by RedcrowProd.)
11-02-2015 11:08 PM
Find all posts by this user Quote this message in a reply
Azriel Offline
Member

Post: #8
RE: Simple timer/alarm
Ok, I had a little mistake in my code and that's why the timer was innacurate wink
11-05-2015 12:08 PM
Find all posts by this user Quote this message in a reply
Post Reply