Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Overview

Excerpt

Queue a call to a function until a later frame.

Unlike setTimer(), queue() does not repeat. It will make a single call to the named function at a later frame in the game.

Queued functions persist the save/load cycle. You can therefore look at Saved game files to see what queued functions were defined at the time the game was saved.

Excerpt

Invoke a function at some point in the future...

 

Syntax

Code Block
theme

...

RDark
languagejavascript
titleThis function has two syntax options...
linenumberstrue
// syntax #1: optional game object as third parameter (WZ 3.1 b1+)
queue(functionName, delay[, gameObject]);
 
// syntax #2: optional string as third parameter (WZ 3.2+)
queue(functionName, delay[, str]);

Parameters

SyntaxParameterTypeMandatoryDescriptionGame Version
AllfunctionNameString(tick)

A string containing the name of

...

a global function to

...

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

...

invoke.

3.1 Beta 1
AlldelayNumber(error)

You can optionally set a minimum amount of time (in milliseconds) before your function gets called. Delays should ideally be 500 or more

...

.

If you

...

specify a value lower than 1 game tick (100 milliseconds) the default value will be used.

Default: 100 milliseconds

3.1 Beta 1
#1gameObjectGame object(error)

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 queued call will be cancelled automatically.

3.1 Beta 1
#2strString(error)

An optional string that will be passed in to your function when it gets called.

3.2

Return value

ValueTypeDescriptionGame version
undefinedUndefinedThe function was successfully queued.3.1 Beta 1
<error>ErrorDid you forget to specify functionName as a string?

...

3.1 Beta 1

Notes

Unlike setTimer(), queue() does not repeat. It will make a single call to the named function at a later frame in the game.

You can cancel a queued call by calling removeTimer() (will also remove any timers associated with the function).

The function, when called, will be run in the context of the global scope ("this" will be the global scope).

Queued function calls persist the save/load cycle. You can therefore look at Saved game files to see what queued functions were defined at the time the game was saved.

Examples

Code Block
theme

...

RDark
languagejavascript
titleSyntax #1: Call

...

a function next game tick, passing in a game object
linenumberstrue
function foo(gameObj) {
  // 

...

gameObj == someGameObject
}

// this syntax works on WZ 3.1 and above
queue("foo", 0, someGameObject);
//

...

See also

 global function foo will be called next game tick (100ms)
// if someGameObject gets destroyed, the queued call will be cancelled
Code Block
themeRDark
languagejavascript
titleSyntax #1: Call a function after 1 second, passing in a string
linenumberstrue
function bar(str) {
	// str = "hello"
}

// this syntax requires WZ 3.2 or above
queue("bar", 1000, "hello");
// global function bar will be called after 1 second
Div
classbox
Availability
Status
colourGreen
title3.1 b1+

Requires:

  • Warzone 3.1 Beta 1 and above
  • Syntax #2 added in Warzone 3.2
Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

See also

Related functions:

  • setTimer() – similar to queue, but will repeatedly call the function at a defined interval
  • removeTimer() – cancels all timers associated with a function