Gah - a solution with more questions. – EntropicLqd

Timing

From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 12:56, 31 August 2011 by 00zX (Talk | contribs)

Jump to: navigation, search


Timing is a family of functions using which you can schedule other functions to be called asynchronously at a interval. Only SetTimer exists in UT2004. Like in JavaScript, despite asynchronous nature of SetTimer, UnrealScript is still single-threaded. It means that you don't have to worry about thread-safety. Race conditions are still possible though.

Functions

SetTimer

native final function SetTimer(
    float inRate, 
    optional bool inbLoop, // not optional in UT2004
    optional Name inTimerFunc='Timer', // doesn't exist in UT2004
    optional Object inObj // doesn't exist in UT2004
);

Sets a timer to call the given function at a set interval. Defaults to calling the 'Timer' event if no function is specified. If inRate is set to 0.f it will effectively disable the previous timer.

  • inRate - time interval, in gameplay seconds. If inRate <= 0.0, it'll reset the timer.
  • inbLoop - if false, it'll fire only once. Default to false.
  • inTimerFunc - function name.
  • inObj - object whose function will called. Defaults to self. Note that timer is still registered on self object, not on inObj. Which means, for instance, it's pointless to write something like
    SetTimer(1.0,,, OtherObj);
    Destroy();
    because timer will be destroyed.

ClearTimer

native final function ClearTimer(
    optional Name inTimerFunc='Timer', 
    optional Object inObj 
);

Clears a previously set timer.

  • inTimerFunc - function name.
  • inObj - object whose function will be called.

ClearAllTimers

native final function ClearAllTimers(
    optional Object inObj
);
  • inObj - object whose function will be called.

PauseTimer

native final function PauseTimer(
    bool bPause, 
    optional Name inTimerFunc='Timer', 
    optional Object inObj
);
  • param
  • inTimerFunc - function name.
  • inObj - object whose function will be called.

IsTimerActive

native final function bool IsTimerActive(
    optional Name inTimerFunc='Timer', 
    optional Object inObj
);

Checks is specified timer is active.

  • inTimerFunc - function name.
  • inObj - object whose function will be called.

GetTimerCount

native final function float GetTimerCount(
    optional Name inTimerFunc='Timer',
    optional Object inObj
);

Gets the current count for the specified timer, defaults to 'Timer' if no function is specified. Returns -1.f if the timer is not currently active. See GetTimerRate below for explanation.

  • inTimerFunc - function name.
  • inObj - object whose function will be called.

GetTimerRate

native final function float GetTimerRate(
    optional name TimerFuncName = 'Timer', 
    optional Object inObj
);

Gets the current rate for the specified timer. GetTimerRate('SomeTimer') - GetTimerCount('SomeTimer') is the time remaining before 'SomeTimer' is called. In other words, "count" starts at 0, increases, and when it reaches "rate", timer is fired.

  • inTimerFunc - function name.
  • inObj - object whose function will be called.

ModifyTimerTimeDilation

native final function ModifyTimerTimeDilation(
   const name TimerName, 
   const float InTimerTimeDilation,
   optional Object inObj
);

This will search the Timers on this actor and set the passed in TimerTimeDilation

  • inTimerFunc - function name.
  • InTimerTimeDilation - new time dilation for this timer function.
  • inObj - object whose function will be called.

ResetTimerTimeDilation

native final function ResetTimerTimeDilation(
    const name TimerName,
    optional Object inObj
);

This will search the Timers on this actor and reset the TimerTimeDilation to 1.0f

  • inTimerFunc - function name.
  • inObj - object whose function will be called.

How to make seconds real

Multiply rate by WorldInfo.TimeDilation. Of course, this method isn't absolutely reliable, as TimeDilation may change before timer fires.

See also