This AI is still in early stages of development.
Check.paths[]
- Aubergine
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!
Value | Type | Notes | Util.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 | 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 |
| 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:
- Check.has() – unless the "lazy" parameter is used.
- Check.doWhen() – unless the "lazy" parameter is used.
- Check.required()
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
...
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.
// 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 }
Contents
Jump to:
Dependency Checking
Topics:
- Tricks for including files — Some tricks with the include() function...
- Dependency Descriptor Object — Define one or more dependencies for your script...
- Check() — Perform a soft-check to see if a dependency is available...
- Check.basePath — The base path to the folder that contains the APIs folder...
- Check.paths[] — Define one or more folder paths to enable autoloading...
- Check.doWhen() — Perform a task when dependencies become available.
- Check.has() — Check if a dependency is available, try and load it if not, return availability state...
- Check.LAZY_LOAD — Disable autoloading during a dependency check...
- Check.required() — Thrown a descriptive error if dependency check fails...
- Check.NOT_LOADED — Indicates a script is not yet loaded, or must not be loaded, depending on the Check function being used...
- Check.ANY_VERSION — Skip version checking for a dependency check...
- Check.provide() — Indicate a file is now available.
- Check.versionOf() — Check the version of a dependency.
- Self Descriptor Object — Define the filename and version of your script...