(info) This AI is still in early stages of development.

n.times()

Invoke a function n times...

 

Syntax

(<n>).times(fn[, context]); // use with primitive number or number object
 
<n>..times(fn[, context]); // only use with primitive number
 
<n>.times(fn[, context]); // only use with number object

Parameters / Values

Parameter / ValueTypeMandatoryDescriptionAPI Version
<n>Number(tick)

The number of times the fn function should be invoked.

If the number is 0, negative or NaN, the function will not be invoked.

1.1
fnFunction(tick)

The function to invoke.

The function is passed a single numeric argument, starting at n-1 on the first iteration, and decrementing with each subsequent iteration, ending at 0 on the final iteration.

Note: You can use  function.curry() to set parameters for the function. You can also use Hook API to modify arguments or retrieve results when the function is called.

1.1
contextObject(error)

The context in which the fn function should run.

Default: The global object.

1.1

Return value

ValueTypeNotesAPI Version
<n>Number

The number object, eg. so you can chain additional function iterations like so:

5..times(fnA).times(fnB)

1.1
<error>ErrorAn error, most likely invalid parameters or invalid syntax (eg. not wrapping a primitive value in brackets or using 2 dots).1.1

Examples

// assuming 4 player game...
(maxPlayers).times( function(num) {
	console(num); // 3, 2, 1, 0
	// want incremental order?
	console(maxPlayers - num - 1); // 0, 1, 2, 3
} );
(playerData.length).times(... // wat?!
 
// always use .forEach on arrays, much better as it
// gives you the value as well as the array index.
playerData.forEach( function(obj, id) {
	console("Player "+id+" is in team "+obj.team);
});
Availability BETA

Requires:

Contents

Jump to:

Globals

Topics:

  • NativeAllows access to JS API natives that have been replaced or removed by the Define API...
  • toArray()Convert an array-like object in to an array...
  • nowReturn current universal time expressed as milliseconds since midnight, January 1, 1970.
  • out()Message output handler.
    • out.HOSTOutputs the message to the game host via in-game chat .
    • out.DEFAULTOutputs the message via out.HOST or out.CONSOLE depending on Warzone version.
    • out.ERROROutputs the message as an exception.
    • out.DEBUGOutput message to debug().
    • out.CONSOLEOutput message to console().
    • out.ASSERTAsserts whether config is truthy, and if not throws a game assert and a Javascript error...
    • out.CHATOutputs the message to allies of the script player via in-game chat.
    • out.RETURNReturns the message to the calling script.
  • difficultyScale()Select a value based on difficulty level...
  • globalA global reference to the global object...