This AI is still in early stages of development.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Allows APIs to register their diagnostic routines with the Diag API...

 

Syntax

registerDiag(name, routine);

Parameters

ParameterTypeMandatoryNotesDiag Ver
nameString(tick)

Name of the diagnostic routine

(warning) Must not contain any spaces!

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. A good example of fairly complex parameters can be seen in the Process API Diagnostics (all handled via a single diagnostic routine defined at the bottom of Process.js).

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 normal return values, not exceptions. A simple approach is to relay a google search to the user if they get things wrong, for example: "Google 'Warzone Process API Diagnostics' for usage instructions" – much easier to do a google search than try and type in some long cumbersome URL to get the docs.

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

Requires:

  • Warzone 3.1 or above
  • Warzone 3.2 or above (for chat interface)
  • Util.js 0.8 or above

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.

 

  • No labels