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 3 Next »

Some tricks with the include() function...

 

Including a file if some other file not loaded

You can use this trick to create mods for your mods. A basic approach can be done using just the include() function and nothing else...

Basic approach to loading defaults if alternate not found...
if (include("path/to/mymod.custom.js") === false) { // not found
  include("path/to/mymod.default.js"); // load default settings
}

But, assuming you're starting to use dependencies, you might want a more robust approach...

Use dependency checking to load file and check it initialised...
include("path/to/util.js");
 
Check.paths = ["path/to/"]; // enable autoloading
 
if (!Check.has("mymod.custom.js")) {
	Check.load("mymod.default.js");
}

The obvious problem here is that you might have dependencies that rely on "mymod.default.js", but if "mymod.custom.js" gets loaded instead those dependencies will break.

The solution to this is to provide a fake file in both "mymod.default.js" and "mymod.extend.js" and then use that for dependency checks:

Fake provide in mymod.default.js and mymod.extend.js
// use this if you want to check which settings were loaded...
Check.provide(self);
 
// use this for general dependency checks...
Check.provide({
	file: "settings.loaded",
	ver : self.ver
});
Availability STABLE

Requires:

Dependency Checking

Topics:

 

  • No labels