Time

Overview

In OpenBOR, there is no conventional clock. This is partially due to lack of clock support on some platforms, and also because of the need to tie time directly to frame updates. Instead, a global elapsed timer runs during game-play (accessible by openborvariant("elapsed_time")). Time is measured in centiseconds (0.01 second) and resets at the start of each level.

Note that by design, the timer is controlled through engine update cycles. It is in no way tied directly to real world time. In almost all cases the timer is real world accurate anyway, but just be aware it’s not a requirement.

Timer Properties

Most timer properties in OpenBOR work the same way.

  1. The time property (always an integer) is populated by adding elapsed time to whatever the desired length of time is. So if a delay of 1 second was wanted, the time property would be set to 100 + elapsed time.
  2. At intervals (usually every engine cycle), the time variable is compared to elapsed time.
  3. If elapsed time >= the timer variable, then the time has expired, and appropriate action is taken.

You can build custom timers of your own using the same principal.

Timer example

Set up a timer

void timer_set(int interval) 
{

     int elapsed_current;
     int expire;
 
     expire = interval + elapsed_current;
   
     setlocalvar("my_timer", expire);
}

Run a timer

int timer_check() 
{
     int elapsed_current;
     int my_timer;

     elapsed_current = openborvariant("elapsed_time");
     my_timer = getlocalvar("my_timer");
 
     if(difference >= interval)
     {
          result = 1;
          setlocalvar("my_timer", elapsed_current);
     }

     return 0;
}

Related Post