Chatbox - Better living through scripting


***Scripting is now enabled as of version 0.99.57***

The concept behind a script is simple: type in one command and it performs one or more steps that save the user the time and effort of typing all those commands manually. Scripts are contained in a text file and may be edited via a button on the "Misc." tab of the Settings window. Let's examine the format:

   COMMAND [/]scriptcommand [#params [User menu text]]
   command(1)
   command(2)
   ...
   command(n)

The first line is known as the command definition line. It must start with the word "COMMAND" (not case-sensitive), then at least one space, followed by the command the user wishes to use (also case-insensitive). The command may not start with an underscore ("_"). I'll illustrate by creating a script command like so:

   COMMAND laugh

A script command is accessed in a chat room by placing a forward slash before the command name, in this case "/laugh". The command definition does not require the use of the forward slash, but the line below will work:

   COMMAND /laugh

If the command needs to take parameters, another space must follow the line above and the number of parameters expected must be specified. The allowable range is between 0 and 9 parameters. If no number is supplied, then zero is assumed.

   COMMAND laugh 2

The script loader will take every non-blank line after the COMMAND line until another COMMAND is encountered or the end of the file is reached. When that command is executed, the program will run through each line one at a time for that command.

   COMMAND laugh 2
   :)) :)) :)) :))
   /me laughs at you all

...will look like...

   UserABC:
   *** UserABC laughs at you all

If a command is specified to take two parameters, then it will not execute unless two parameters are supplied, even if those parameters are not used. Parameters are separated with the pipe ("|") character. In the example below, the spaces between the parameters and the pipe are not required.

   /laugh param1 | param2

To make use of the parameters specified, on the lines following the COMMAND definition simply use the dollar sign ("$") and a number to access that parameter. If the "/laugh" commands are changed to use the two parameters like so:

   COMMAND laugh 2
   :)) :)) :)) :))
   /me laughs at $1 because $2

In this case, the first parameter should be someone's nickname, and the second parameter should be the reason. If the command is invoked like this:

   /laugh UserXYZ | he made a fool of himself

...then the resulting messages to the users would appear like this:

   UserABC:
   *** UserABC laughs at UserXYZ because he made a fool of himself

Also, with this schema, you may create the same command name with a different number of expected parameters, and give each one completely separate functionality.

   COMMAND laugh 1

...would be completely different from...

   COMMAND laugh 2

The program will interpret which command definition to use based on how many parameters are supplied.

The last part of the script definition is the menu option. If the command takes one parameter, a menu option may be specified that will appear when the user right-clicks someone's name in the user list under "User-defined commands"

If the example used so far was modified like this:

   COMMAND laugh 1 Laugh at him
   :)) :)) :)) :))
   /me laughs at $1 because he's dumb



Chatbox will take the user's nickname as the first and only parameter when executing that command.

A script validator ensures all script commands are valid and checks for a multitude of errors. All errors are reported to the user, and if possible suggestions are made for how to fix the error.

Back to main page...