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

Check.paths[]

Define one or more folder paths to enable autoloading...

 

Syntax

Check.paths.push(additionalPath); // add a path
 
Check.paths = somethingNew; // replace existing path(s) with new path(s)
 
var currentPaths = Check.paths; // get array of current paths

Possible values

The paths array is seeded with the value of Check.basePath.

When setting Check.paths, the current array of paths will be replaced with the new value.

Don't forget the "/" at the end of your paths!

ValueTypeNotesUtil.js version
<string>

String

When setting the path, you can provide a single path as a string.

When getting the path, it will always be an array even if you set paths to a single string.

1.0
<array>Array of String

Multiple paths can be defined using an array of strings.

Each path in turn will be checked when trying to autoload, only the first match will be loaded (it won't try and load the same file from multiple paths).

1.0

false

null

undefined

""

Falsey

When setting the path, anything that typecasts to false, or an empty string or empty array, will empty the paths array.

1.0
[]Empty Array

If no paths are defined, Check.paths will be an empty array (even if it was set to a falsey value).

Autoloading is disabled when no paths are defined.

1.1

Which functions support autoloading?

The following Dependency Check functions will automatically attempt to load missing dependencies:

If Check.NOT_LOADED is specified as a version in a dependency check, the associated file will obviously not be autoloaded.

When autoloading, files are loaded in to the global scope, not the scope of the function that caused them to be autoloaded.

If the autoloaded file defines additional dependencies that are not yet loaded, those too will be loaded if found on paths.

Examples

The return value will always be an array of strings or false...

Check.loadPath is always an array or false...
var path;
 
// how to get the current list of paths...
path = Check.paths; // ["multiplay/skirmish/"] (or whatever base path is)
 
// how to add a path to the list...
Check.paths.push("multiplay/skirmish/foo/");
path = Check.paths; // ["multiplay/skirmish/", "multiplay/skirmish/foo/"]
 
// how to replace the existing paths with a new path...
Check.paths = "multiplay/skirmish/bar/";
path = Check.paths; // ["multiplay/skirmish/bar/"]
 
// how to remove all paths (disables autoloading)...
Check.paths = null; // or "", or [], or false, etc.
path = Check.paths; // []

In the following example, if foo.js isn't already loaded the Check.has() function will try each of the paths in turn to see if it can find the file. If it finds the file, it will automatically load it. If it can't find a match, Check.has() will return false.

Defining several paths to try...
// root path
var root = Check.basePath; // get base path
 
Check.paths = [
	root,
	root+"stuff/",   // foo.js lives here, and this is found first = loaded
    root+"Defines/", // usual location of defines
	root+"Diags/",   // usual location of diag routines
	root+"Chats/",   // usual location of chat commands
	root+"foo2/"     // another foo.js lives here, but will not get loaded
];
 
// if foo.js wasn't already loaded, doing this...
if (Check.has("foo.js")) {
	// multiplay/skirmish/stuff/foo.js is loaded
	// and you can start using it right away
}
Availability BETA

Requires:

Contents

Jump to:

Dependency Checking

Topics: