This AI is still in early stages of development.
n.times()
- Aubergine
Owned by Aubergine
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 / Value | Type | Mandatory | Description | API Version |
---|---|---|---|---|
<n> | Number | 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 | |
fn | Function | 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 | |
context | Object | The context in which the fn function should run. Default: The global object. | 1.1 |
Return value
Value | Type | Notes | API Version |
---|---|---|---|
<n> | Number | The number object, eg. so you can chain additional function iterations like so:
| 1.1 |
<error> | Error | An 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); });
Contents
Jump to:
Globals
Topics:
- Native — Allows 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...
- now — Return current universal time expressed as milliseconds since midnight, January 1, 1970.
- out() — Message output handler.
- out.HOST — Outputs the message to the game host via in-game chat .
- out.DEFAULT — Outputs the message via out.HOST or out.CONSOLE depending on Warzone version.
- out.ERROR — Outputs the message as an exception.
- out.DEBUG — Output message to debug().
- out.CONSOLE — Output message to console().
- out.ASSERT — Asserts whether config is truthy, and if not throws a game assert and a Javascript error...
- out.CHAT — Outputs the message to allies of the script player via in-game chat.
- out.RETURN — Returns the message to the calling script.
- difficultyScale() — Select a value based on difficulty level...
- global — A global reference to the global object...