Script includes

From StealthBot Wiki
(Redirected from Script include)
Jump to: navigation, search

The StealthBot Scripting system provides the ability to use a C-like #include directive in order to include code from another file in the final loaded script.

The #include directive is a way to reduce duplicate code among scripts by putting commonly used functions of a certain type in it and packaging it with the script.

History

For StealthBot version 2.4, Stealth added the ability to #include files in the script.txt file. This system was used by the Plugin system to accomplish moving the Plugin system code to the pluginsystem.dat file. In 2.7, with the introduction of multiple script modules and the deprecation of the Plugin system, StealthBot staff encouraged the use of the #include directive.

How to use

To use, place the line at the top of your script in this format:

#include "<PathToFile>"

This code is not interpreted by the VBScript interpreter, but by the bot itself, so a string constant referring to a file relative to the current BotPath\Scripts\ location must be used.

No lines of code (not even blank ones or commented ones) can be above the #include lines. StealthBot will stop looking for them after the first line that doesn't contain them and any further ones will be errors in the VBScript code.

Conventions of use

FiftyToo's script updater and repository for version 2.7 and above stores and distributes dependency files such as #included files as "libraries" and requires that they be placed in the <BotPath>\scripts\lib\ directory. By convention, scripters should place libraries that their scripts use in <BotPath>\scripts\lib\<scripter's name>\.

For example, an #included file used by multiple scripts containing useful functions dealing with strings for a scripter who called himself BobScripter would be in:

<BotPath>\Scripts\lib\bobscripter\strings.txt

He would use the following line at the top of his scripts to #include the functions defined in that file:

#include "\lib\bobscripter\strings.txt"

See also