Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

Availability

...

Excerpt

...

Enables additional javascript files to be included in your script.

Include library scripts in to your main script...

 

Syntax

Code Block
theme

...

RDark
languagejavascript
linenumberstrue
var returnValue = include(

...

file);

Parameters

ParameterTypeMandatoryDescriptionGame verison

...

fileString(tick)

The path (relative to your mods folder), file name and extension of the file that should be included.

The path starts at your mod folder.

For example, if you're writing an AI script and want to include a "whatever.js" script that's stored in the same folder as your AI script, you'd specify:

include("multiplay/skirmish/whatever.js");

...

If you were loading a file from the 'challenges/' folder as part of a Challenge Game, it would be something like:

include("challenges/whatever.js");

3.1 Beta 1

Return value

In version 3.1 Beta 2 and earlier, this function would return undefined if the file was successfully loaded, however undefined is treated as false in an if statement, and false is the return value used to indicate the file failing to load!

As of 3.1 Beta 4 and above, the function will return true if the file was included, which is far easier to work with. However, if your script supports older versions of the game, then you need to be careful with earlier versions returning undefined instead of true.

ValueTypeDescriptionGame version
undefinedUndefined

The file was successfully included.

Note: undefined type-coerces to false in an if statement.

3.1 Betas 1 & 2 only
trueBooleanThe file was successfully included.3.1 Beta 4 and above
falseBooleanThere was a problem including the file (most likely path or file not found).3.1 Beta 1

...

(info) The include() function traps any uncaught errors and writes them to the log files, then returns false. So you don't need to wrap this function in a "try ... catch" clause.

...

Example

Code Block
themeRDark
languagejavascript
titleIncluding a file
linenumberstrue
if (include("multiplay/skirmish/foo.js") !== false) {
  // foo.js was loaded successfully
}
Code Block
theme

...

RDark
languagejavascript
title

...

Using a variable to define the path...
linenumberstrue
var path = "multiplay/skirmish/";
 
include(path+"foo.js");

...

include(path+"bar.js");
include(path+"moo.js");
Div
classbox
Availability
Status
colourGreen
titleStable

Requires:

  • Warzone 3.1 Beta 1 and above.
  • Return value improved in 3.1 Beta 4
Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5