Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

ParameterMandatoryTypeDescription
functionName(tick)String

A string containing the name of the function to call.

The function must be defined on the global scope - it cannot be a method of an object or anything like that.

If you pass in a function, or the name of a function not on the global scope, the timer will break.

delay(tick)Number

The amount of time, in milliseconds, to wait before the function is called.

Avoid setting delays less than 100ms.

gameObject(error)Game object

An optional game object that will be passed in to your function when it gets called. The object will automatically be refreshed with the latest game data.

If the object gets destroyed, the associated timer will be cancelled automatically.

Return value

...

ValueTypeDescription
undefinedUndefinedThe timer was set.
<error>ErrorDid you forget to specify functionName as a string?

Example

Code Block
themeEclipse
languagejavascript
titleCall function "foo" every second
linenumberstrue
function foo(gameObj) {
  // do stuff
}

setTimer("foo",1000,someGameObject); // after 1000ms, global["foo"](someGameObject) will be called.

...