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

The Concept

Take some external input, classify it to get a Task ID, find an action associated with that task, and perform the action...

 

Take some external input...

Just like normal Warzone scripts, NEXUS is triggered by an external event or timer.

In the case of common events, everything is abstracted away by Infiltrate Subroutines – to hook in to common events, this is all you need to do:

NEXUS.infiltrate();

When a JS API event is triggered, NEXUS will know about it.

Classify it to get a Task ID...

Most JS API events have objects associated with them, for example eventDestroyed() tells you which of your objects was destroyed.

Classify Subroutine (optional) takes the object and determines it's "Object Key" – a sort of taxonomical description of the object.

For example, if you have a truck, it's Object Key could be ".droid.truck". If you have a sensor droid, it's key could be ".droid.tank.sensor".

The classification is usually done automatically by the Infiltrate Subroutine mentioned earlier. If there's no classify subroutine installed, the Object Key will be an empty string.

Once we've got the classification, a Task ID is determined based on the following formula:

taskID = taskName + objectKey;

The 'taskName' is usually a shortened version of the JS API event that was triggered, so the 'taskName' for eventObjectSeen() would be 'objectSeen'.

If you're using the standard classify subroutine, you can see a complete list of possible taskIDs here: NEXUS.classify.js.

Find an action associated with that task...

Knowing the Task ID, we now need to perform some action (if one is defined for the task).

But first, NEXUS will check for the presence of a Suffix Subroutine – if it finds one, the main object associated with the task, for exmaple the "seen" object in eventObjectSeen(), will be passed to the suffix routine to generate a suffix. If there's no suffix routine, the suffix will be an empty string.

If you're using the standard suffix subroutine, you can see a list of possible suffixes here: NEXUS.suffix.js. Usually, a suffix is something like ".Enemy" or ".Ally".

A search term is then defined using the following formula:

searchTerm = taskID + suffix;

Let's say that eventObjectSeen() was triggered when our sensors detected an enemy truck. The taskID would be something like "objectSeen.droid.truck" and the suffix would be ".Enemy".

This results in a search term of "objectSeen.droid.truck.Enemy".

NEXUS will look for that search term in it's lookup table (NEXUS.tasks) to get an associated action (see later)

If it finds a matching task, it will perform the action associated with it (see later).

If it doesn't find it, it will change the searchTerm to have a wildcard suffix ("objectSeen.droid.truck.*") and repeat the search.

If it still hasn't found a matching task, it will start "reducing" the objectKey to search for less specific matches.

Using our example of "objectSeen.droid.truck.Enemy" then the full set of searches, if no tasks were defined, would be:

  1. objectSeen.droid.truck.Enemy
  2. objectSeen.droid.truck.*
  3. objectSeen.droid.Enemy
  4. objectSeen.droid.*
  5. objectSeen.Enemy
  6. objectSeen.*

It will search for each of those until it finds a match in NEXUS.tasks.

Perform the action...

 Assuming we found something in the search above, NEXUS will now have an "Action Object" associated with the task it found.

An action object can contain just about anything, however there will be some special properties that your installed Process Subroutine will be looking for.

Common properties of the object include:

  • .fn – a function to run
  • .ogg – the name of an .ogg audio file to play
  • .throttle – how long to wait before allowing this action to be performed again?

All properties are optional, if the process subroutine doesn't find anything it expects, no action will be taken. This is useful as it lets you nullify a specific task, preventing the search routine from trying less specific matches.

Defining an action...

Defining actions is really easy. You just add a new entry to NEXUS.tasks that defines the task and what action to take, like this:

NEXUS.tasks["objectSeen.droid.truck.Enemy"] = { /* action properties */ };
If you haven't already done so, I recommend reading the Introduction first to understand the background of this project.