(lightbulb) Looking for info on the NEXUS faction in the game? It's in the Warzone Encyclopaedia

Fn Subroutines

Shared helper functions.

 

Purpose

There are many common coding tasks when writing AIs or other scripts for Warzone. It would be good if there was a way to share and re-use common code...

Fn subroutines are basically small helper functions, that perform some common task (such as finding a free truck, or building an oil derrick).

A selection of ready-made Fn subroutines can be seen to the right.

Build your own

A Fn subroutine defines a new function on the NEXUS.fn object.

The NEXUS.fn object is just a shortcut to the prototype of NEXUS, meaning that anything you add there will be accessible from all NEXUS instances.

Your Fn subroutine should be structured like this:

NEXUS.fn.myFunc = (function() {
 
  // /////////////////////////////////////////////////////////////////
  // PRIVATE VARS

  var chimp = "hairy"; // just an example :p
 
  // /////////////////////////////////////////////////////////////////
  // PUBLIC HELPER FUNCTION

  var myFunc = function(params) {
    // your function code goes here
    return whatever; // return some meaningful value
  }
 
  // /////////////////////////////////////////////////////////////////
  // PRIVATE FUNCTIONS
 
  var isFoo = function(foo) { // just an example :p
    return (foo != "bar");
  }
 
  // return your helper function
  return myFunc;
 
})(); 

If you want to be super-helpful to other people looking at your code:

  1. Make it easy to understand!
  2. Document your functions, with examples

File name convention

Fn subroutines use the following naming convention: "NEXUS.fn_Whatever.js", where "whatever" is the name of your helper function or something that describes your bundle of helper functions.

See .fn for guidelines on using helper functions.

Subroutines

Absorb:

Memory Banks

Observe: