TIMER

From HEWIKI
(Difference between revisions)
Jump to: navigation, search
(initializeDefault())
(Functions)
Line 87: Line 87:
 
* Returns a [[Technical:Time Interval|Time Interval]] until the next call to tick() will occur.
 
* Returns a [[Technical:Time Interval|Time Interval]] until the next call to tick() will occur.
 
* Calling timeRemaining() when timerState is equal to OFF throws a runtime error.
 
* Calling timeRemaining() when timerState is equal to OFF throws a runtime error.
 +
=== setTimeSource(string)===
 +
''This is an upcoming feature for a future HeroEngine release''
 +
* Set the time source the timer uses for its time calculations
 +
* Can not be changed if the timer state is not OFF
 +
* correct values are "COORDINATED" or "LOCAL" (improper values passed to this function will cause the timer to default to "COORDINATED")
 
=== initializeDefault() ===
 
=== initializeDefault() ===
 
* Sets timerState to OFF.
 
* Sets timerState to OFF.

Revision as of 21:34, 31 January 2014

Contents

This page discusses how to get HSL calls at regular intervals via the TIMER datatype.

TIMER is a complex data type that causes a call to an HSL script after a specified interval of time.

Overview

Managing the concept of time, intervals and timers is important in MMOs. In particular, MMOs have various unusual needs for keeping track of time. For example, some game systems might work on real time (called "wall time", as in what time the "clock on the wall" says it is), vs. time that only elapses while logged on. Many common MMO game-play features, such as enhancements / buffs /etc. can be implemented using a Timer. HeroEngine timers contain important features such as the ability to be paused (for example, if a player is talking to the game-staff for customer service, a script can pause timers that might otherwise go off when it isn't appropraite, such as bleeding to death, etc.).

A timer is implemented as a field data type that causes a script call after a specified interval of time. HSL timers are like .NET timers in that they automatically repeat. If a scripter wants a 1-shot timer, they build removal or stopping of the timer into the tick() functionality.

When the timer's timespan has elapsed, a call is made to either a function or method with the format of <timer_field_name>_tick(). If the script subfield is set to a valid script, the function in that script is called; otherwise, the method is called on the node containing this timer field.

Related datatypes

Subfields

TIMER is a complex data type with member subfields.

timerState

realTime

startTime

stopTime

lastFired

fireRate

elapsedTime

pausedTime

script


timerTimeSource

(timerTimeSource is an upcoming feature in a future HeroEngine update)

Functions

The TIMER data type also has member functions that can be called.

start()

stop()

pause()

unpause()

forceTick()

timeRemaining()

setTimeSource(string)

This is an upcoming feature for a future HeroEngine release

initializeDefault()

Examples

Create field "custom_timer"

: cfd "custom_timer" timer;

Define "candle" class, with the above field.

: ccd "candle", asset, custom_timer;
  --> Node 4  (for example)

The following example assumes that a class GenericTimer has already been created, which has a timer field named myTimer

function foo()
  n as NodeRef of Class GenericTimer = CreateNodeFromClass("GenericTimer")
  n.myTimer.script = SYSTEM.EXEC.THISSCRIPT
  n.myTimer.fireRate = 0:05:45
  n.myTimer.realTime = true
  n.myTimer.start()
.
 
function myTimer_tick()
  where me is kindof GenericTimer
    if (me.myTimer.elapsedTime.inMilliseconds > 100) 
      println( me.myTimer.lastFired.hour )
      println( me.myTimer.startTime.monthString )
    .
    me.myTimer.stop()
  .
.

See also

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox