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

Diag.add()

Register diagnostic routines with the Diag API...

 

Syntax

Diag.add(name, routine);

Parameters

ParameterTypeMandatoryNotesDiag Ver
nameString(tick)

Name of the diagnostic routine

(warning) Must not contain any spaces! Will always be converted to lowercase.

0.1
routineFunction(tick)The function that performs the diagnostic0.1

Return values

ValueTypeNotesDiag Ver
trueBooleanIndicates the diagnostic routine was successfully registered.0.1
<error>Error

Indicates there was an error adding the routine, for example:

  • Name not specified
  • Name contained spaces
  • No routine specified
  • Routine was not a function
0.1

Example

// define a diagnostic routine function
var myDiagFn = function bar(name, param1, param2) {
  // do stuff
  // return either a string or an array of strings
  return "my name is "+name;
}
 
registerDiag("foo", myDiagFn); // register myDiagFn under the name "foo"

diag("Foo", true, "bleh"); // my name is foo

Notes

When defining your diagnostic routine the first parameter will always be the name you used when registering the routine. You can use this, for example, to create a single function and then register it multiple times under different names and have it act differently depending on the name.

You can specify any number of additional parameters in your diagnostic routine function – whatever is passed in to Diag() will be passed through to your routine. See EggPlant Diagnostics for a list of currently defined diagnostic routines.

Assume string parameters – this is because the in-game chat interface will be able to trigger routines in Warzone 3.2 and above. So, if you want a parameter to be a number, you'll have to use parseInt() or similar inside your routine to make sure it's a number. If the routine is called directly from code then different data types can be passed in, but it's best to code routines with the assumption that all parameters will be a string.

Your diagnostic routine function should return either a string, or an array of strings, to relay the results back to the calling script (which will in many case be relaying them back to the end-user via in-game chat).

If your routine requires multiple parameters, assume the end-user might get them wrong when they call it via the chat interface. Errors should be relayed to the user via human-friendly strings and not exceptions if practical to do so.

Where possible, name the function (eg. "bar" in the example above) – if there's an error running the diagnostic, the function name will usually be shown making it easier to track down bugs.

Diagnostic routines are always run in the global scope. If you want your routine to run in a different scope, use a closure.

EggPlant follows a convention of defining diagnostic routines near the bottom of the API sandboxes. For more info on sandboxes, see Code Conventions.

Availability BETA

Requires:

  • Warzone 3.1 or above
  • Warzone 3.2 or above (for chat interface)
  • Diag API
Contents

Jump to:

Diag API

Topics:

  • Diag()Run a diagnostic routine...
  • Diag API DiagnosticsThe Diag API provides a few diagnostic routines of it's own...
  • Lazy Loading DiagnosticsBy lazy loading diagnostic routines, your script will start faster and use less RAM if diagnostics are not required.