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

Function Manipulation

Create new functions based on existing functions...

 

Overview

These features allow you to create new functions based on existing functions:

An example of using both in relation to Warzone scripting is shown below:

Example

// create isMyAlly() function by pre-specifying 'me' as a param
// on JS API's allaianceExistsBetween() function...
var isMyAlly = allianceExistsBetween.curry(me);
 
// create a wrapper function...
var NOT = function(bool) {
	return !bool;
}
 
// create isMyEnemy() by wrapping isMyAlly() with the NOT() function...
var isMyEnemy = NOT.wraps(isMyAlly);
 
for (player = 0; player < maxPlayers; player++) {
	if (player == me) continue; // ignore me
 
	if (isMyAlly(player)) {
		// do nice stuff to ally
	}
 
	if (isMyEnemy(player)) {
		// do nasty stuff to enemy
    }
}
Availability STABLE

Requires:

Contents

Jump to:

Function Manipulation

Topics:

  • function.wraps() — Create a new function by wrapping an existing function in another existing function...
  • function.curry() — Create a new function based on an existing function but with some parameters pre-defined.
  • n.times() — Invoke a function n times...

See also

Related articles:

  • Hook API – create input/output hooks on any function
  • Inheritance Model – proper OOP inheritance model implementation

Â