advanced-scripting/Directives

Directives

Directives are lines that perform meta operations, ie, telling the scripting language what to do. They begin with a question mark (?) and take arguments.

Below is a list of currently supported directives:

Echo Directive

?echo on
?echo off

The echo directive takes the form "?echo <on|off>". This will turn off or on whether messages sent to the calling player by server commands are suppressed or not while executing the script (called "echo suppression"). By default, echo follows the config value "options.default-echo", which by default is true (echo is not suppressed).

Typically, scripts will start with "?echo off" to make sure that any commands called during script execution won't inundate the player with messages. A script might have "?echo on" right before a key command that shows the player output.

Commander's built-in "echo" command is designed to circumvent echo suppression, so that the script can give custom output to the player without having to call this directive.

Error Ignore Directive

?errorignore on
?errorignore off

The error ignore directive takes the form "?errorignore <on|off>". This will turn on or off whether Commander ignores errors thrown from commands. This defaults to off.

If an error occurs in a command that a script called and minecraft throws an exception, Commander will catch the exception. It will then check this directive and, if ignoreerror is off, will rethrow the exception, which will then be displayed to the player as "an error has occurred". If ignoreerror is on, however, it will log the error and continue on in the script.

Regardless of ignoreerror's value, you can check to see if the last command errored by checking the environment variable "command.error", which returns a boolean value. (Granted, if you don't ignore the error, you won't be able to check if there was an error because script execution will have ceased.)

Loop Limit Directive

?looplim x

The loop limit directive takes the form "?looplim <num>", and the num argument must be a constant number. This will set the loop iteration cap. By default, the cap is set to 200. If a while loop iterates past this cap, the script will throw an error.

Users should use this directive sparingly: there is a reason this is in place. Commands, and by extension Scripts, should not hold up the minecraft server via execution. If you have while loops running far past the default cap, perhaps you should a) examine to make sure the loop will actually complete or b) rethink your strategy.

Run Limit Directive

?runlim x

The run limit directive takes the form "?runlim <num>", and the num argument must be a constant number. This will set the recursive run call cap. By default, the cap is set to 10, and the cap cannot be set higher than 200. If there are more recursive calls than the cap, the script will throw an error.

Users should use this directive sparingly: there is a reason this is in place. There is a limit to the number of calls a program can make before either running out of memory or out of stack space. If you have scripts recursing past the default cap, perhaps you should a) examine to make sure that there is a structure to catch the bottom of your recursive calls (a "base case" in programmer parlance) or b) rethink your strategy. You shouldn't be trying to make a Fibonacci Sequence in Commander Script.


Comments

Posts Quoted:
Reply
Clear All Quotes