Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Excerpt

Perform a task when dependencies become available.

 

Syntax

Code Block
themeRDark
languagejavascript
linenumberstrue
Check.doWhen(dependencies, selfsdo, task[, lazy]);

Parameters

ParameterTypeMandatoryNotesUtil.js version
dependenciesDependency Descriptor Object(tick)The dependencies for the task.1.0
selfsdo

Self Descriptor Object

(tick)

The SDO of the script submitting the task.

1.0
task

Function

String

(tick)

Either:

  • A function to run when the dependencies are met
  • A string containing a file name to autoload when dependencies are met.

Note: Autoloading must be enabled if you specify a file name to load. See Check.paths[] for more information.

1.0
lazyConstant(error)

By default, Check.doWhen() will attempt to autoload missing dependencies (except those marked as Check.NOT_LOADED).

If you want to prevent autoloading, specify Check.LAZY_LOAD

See Check.paths[] for more information on autoloading.

1.0

Return Values

ValueTypeNotesUtil.js version
trueBooleanThe dependencies were available and the task has been performed.1.0
falseBoolean

One or more of the dependency checks failed and the task has not yet been performed.

The task will be queued until missing dependencies become available.

If one of the dependencies is marked as Check.NOT_LOADED and that file gets loaded, the task will be blocked from running.

1.0
<error>Error

An error occurred, usually due to one of the following reasons:

  • Invalid parameters
  • A dependency specified Check.NOT_LOADED and the associated file was already loaded
  • The dependencies were all met and the task was processed, but the task generated an errror
1.0

Notes

The Check.doWhen() function is most commonly used for lazy loading diagnostic routines . Diagnostic routines and unit tests, neither of which are not required for normal gameplay, so they can be lazy loaded to reduce game start-up times and RAM consumption.

You can use the "loaddiag" or "loadtest" chat command commands (part of Chat API) to load Diag API at  or Test API, as applicable, at any time during a game, which in turn will cause all the associated lazy-loaded diagnostic routine load scripts to be loaded.

You can run the "blocked" diagnostic (requires Diag API) to get a list of tasks that are blocked due to errors or presence of dependencies marked as Check.NOT_LOADED. You can also run the "blocked" diagnostic routine via the "diag blocked" chat command (requires Chat API).

Example

Note: In these examples, it's assumed the 'self' variable is already defined. For more information on that variable, see Self Descriptor Object.

Code Block
themeRDark
languagejavascript
titleLazy load Diag.Cache.js when Diag.js becomes available.
linenumberstrue
Check.doWhen(
	{"Diag.js": true},
	self,
	"Diag.Cache.js",
	Check.LAZY_LOAD
);
Code Block
themeRDark
languagejavascript
titleSend chat message when Chat API becomes available...
linenumberstrue
Check.doWhen(
	{"Chat.js": true},
	self,
	function() {
		chat(0, "Let's chat...");
	},
	Check.LAZY_LOAD
);
Div
classbox
Availability
Status
colourYellow
titleBeta

Requires:

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

Dependency Checking

Topics:

Child pages (Children Display)
alltrue
depthall
pageDependency Checking
excerpttrue