ClosureTimers

Closures View source
ClosureTimers

Execute an action after a certain time. The callback object is automatically destroyed. Must be used on a timer acquired with getTimer()

Example use: ```wurst
someTimer.doAfter(10.0) ->
 print("10 seconds later") ```

Source on GitHub

📖 Read the detailed guide for hand-written examples and background.

Classes

CallbackSingle

public abstract class CallbackSingle

Members:

  • abstract function call()
  • getRemaining() returns real

CallbackPeriodic

public abstract class CallbackPeriodic

Members:

  • abstract function call(thistype cb)

CallbackCounted

public abstract class CallbackCounted

Members:

  • abstract function call(thistype cb)
  • isLast() returns boolean
  • getCount() returns int
  • progress() returns real Returns a value between 0 and 1.
  • stop()
  • callAndCount()

Interfaces

Callback

public interface Callback

Members:

  • call()

Functions

doAfter

public function doAfter(real timeToWait, CallbackSingle cb) returns CallbackSingle

Execute an action after a certain time. The callback object is automatically destroyed.

Example use: ```wurst
doAfter(10.0) ->
 print("10 seconds later") ```

doAfterWithDialogue

public function doAfterWithDialogue(real timeToWait, string titleText, Callback cb) returns CallbackSingle

Execute an action after a certain time. The timer is accompanied by a visible timerdialog with the title text provided. The callback object is automatically destroyed.

Example use: ```wurst
doAfterWithDialogue(10.0, "Respawn in") ->
 hero.revive()
 print("10 seconds later") ```

nullTimer

public function nullTimer(CallbackSingle cb) returns CallbackSingle

Execute an action with a 0-second timer delay. The callback object is destroyed afterwards.

doPeriodically

public function doPeriodically(real time, CallbackPeriodic cb) returns CallbackPeriodic

Execute an action periodically. The callback has to be destroyed manually.

Example use: ```wurst
doPeriodically(0.5) cb ->
 if i > 10
	destroy cb ```

doPeriodicallyCounted

public function doPeriodicallyCounted(real time, int callAmount, CallbackCounted cb) returns CallbackCounted

execute an action periodically, with a limited amount of calls The callback object is destroyed after the action has been executed callAmount times.

Example use: ```wurst
doPeriodicallyCounted(0.5, 100) cb ->
 doSomething() ```

doPeriodicallyTimed

public function doPeriodicallyTimed(real interval, real timerDuration, CallbackCounted cb) returns CallbackCounted

execute an action periodically, with a limited duration The callback object is destroyed afterwards.

Example use: ```wurst
doPeriodicallyCounted(0.5, 10.) ->
 doSomething() ```

Extension Functions

timer.doAfter

public function timer.doAfter(real timeToWait, CallbackSingle cb) returns CallbackSingle

timer.doPeriodically

public function timer.doPeriodically(real time, CallbackPeriodic cb) returns CallbackPeriodic

Execute an action periodically. The callback has to be destroyed manually. Must be used on a timer acquired with getTimer()

Example use: ```wurst
someTimer.doPeriodically(0.5) cb ->
 if i > 10
	destroy cb ```

timer.doPeriodicallyCounted

public function timer.doPeriodicallyCounted(real time, int callAmount, CallbackCounted cb) returns CallbackCounted

execute an action periodically, with a limited amount of calls The callback object is destroyed after the action has been executed callAmount times. Must be used on a timer acquired with getTimer()

Example use: ```wurst
someTimer.doPeriodicallyCounted(0.5, 100) cb ->
 doSomething() ```

timer.doPeriodicallyTimed

public function timer.doPeriodicallyTimed(real interval, real timerDuration, CallbackCounted cb) returns CallbackCounted

execute an action periodically, with a limited duration The callback object is destroyed afterwards. Must be used on a timer acquired with getTimer()

Example use: ```wurst
someTimer.doPeriodicallyCounted(0.5, 10.) ->
 doSomething() ```