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

Lazy Loading Diagnostics

By lazy loading diagnostic routines, your script will start faster and use less RAM if diagnostics are not required.

 

Step 1

First, create a new script for your diagnostic routines. It's customary to put this in the /multiplay/skirmish/Diag/ folder with a filename in the form Diag.yourScript.js.

Diag.yourScript.js
// UTIL API DIAGNOSTICS
//
// Diagnostics:
// * cache = list key effectiveness
//
// License:
// * CC-BY-SA 3.0: http://creativecommons.org/licenses/by-sa/3.0/
// * URL: https://warzone.atlassian.net/wiki/display/EGG/Cache+API+Diagnostics
// /////////////////////////////////////////////////////////////////
 
void (function CacheDiagnostics() {
	var self = {
		file: "Diag.cache.js",
		ver : 1.0
	};
	var dependencies = {
		"Cache.js": 1.0,
		"Diag.js" : Check.ANY_VERSION
	}
	
	Check.required(dependencies, self);
 
	// /////////////////////////////////////////////////////////////////
	// DIAG: CACHE EFFECTIVENESS
	// diag cache
 
	Diag.add("cache", function DiagCache() {
		var keys = Cache();
		var list = [];
		keys.forEach(function(key) {
			list.push(key+":"+keys[key]);
		});
		return "Cache effectiveness: "+list.join(", ");
	});
	
	// /////////////////////////////////////////////////////////////////
	// INTERNAL: CONFIRM API AVAILABILITY
 
	Check.provide(self);
})();

Step 2

In your main script, instruct the dependency checker to lazy load the diagnostic routines. It is customary to put the diagnostic loader near the top of your script, just after any Dependency Checks:

yourScript.js
// /////////////////////////////////////////////////////////////////
// DIANOSTIC ROUTINES
// https://warzone.atlassian.net/wiki/display/EGG/Cache+API+Diagnostics

Check.doWhen(
	{"Diag.js": true}, // require Diag API
	self,
	"Diag.Cache.js", // Diag script to load when available
	Check.LAZY_LOAD // don't force Diag API to be loaded
);

(warning) The 'self' variable is a Self Descriptor Object that must be defined earlier in your script.

If and when the Diag API becomes available, "Diag.Cache.js" will automatically be loaded.

Step 3

You can load the Diag API at any time, however perhaps the easiest way is to use the "loaddiag" chat command if you have the Chat API installed.