Scripting
Scripting lets you extend the behaviour of MUSHclient to do almost anything you want.

You can script in one of (currently) eight script languages: VBscript, JScript, PerlScript, Tcl, Python, Lua, TCL and PHPscript. If you use plugins you can also have multiple script languages per session (a different one per plugin).

We recommend using Lua as the preferred scripting language nowadays. Lua ships with MUSHclient, so scripts written in Lua will be more easily exchanged with other MUSHclient users. Also Lua can be used if running under Wine on Linux PCs. The Lua script DLL is shipped with MUSHclient. With the exception of Lua, VBscript and JScript, you will need to download and install the other script engines before using scripts written in those languages.


How do scripts get called?

MUSHclient will call a function (or subroutine) in your script at various places you can specify. For instance, each trigger, timer or alias can call a script. Information about the trigger, alias and timer (such as its name, and the matching line) is passed to the script routine so it can react appropriately.

For example, you might make a trigger script that kept count of the number of times you levelled when playing a MUD.

You can also specify that scripts get called when other events happen, like "world open", "world connect", "new chat user" and so on.

How do scripts communicate with MUSHclient?

Scripts use the COM (Component Object Model) technology to send requests to MUSHclient or ask for information (except for Lua, see below). For example, you can use "Note" to tell MUSHclient to put a note in the output window, or "GetInfo" to find out information about the current world (like when it was connected).

Scripts use the "world" COM object to do this - this is available in all script languages. For example:

world.Note "Hello, there"

Lua scripting

Lua scripting does not use COM, and can thus be used in situations (like running under Wine on Linux) where COM is not working reliably.

Lua scripts are called directly from MUSHclient, generally with the same arguments as the COM scripts. There are some minor exceptions, these are noted under the relevant entries for each script function.


Where do scripts go?

You have a number of options for placing script routines -

1. In a script file which is used by the world (these can be shared between worlds).

2. Each plugin you install can have scripts in it.

3. Triggers, aliases and timers can call a script functions directly from inside them, without needing a separate script file. This is called "send to script".

Script functions

There is extensive documentation about the script functions, including a list of all of them, at the web page:

http://www.gammon.com.au/mushclient/functions.htm

Lua

Commencing with version 3.52, the Lua language is supported. You can read more about Lua at:

http://www.lua.org/

Unlike the other languages, support for Lua is "hard-coded" into MUSHclient, it does not use the COM (Component Object Model) interface. This allows Lua to be supported in a consistent way, even on platforms that do not support other languages (eg. Linux).

Forum posting about scripting

There is a lengthy post on the MUSHclient forum about using scripting, see this:

http://www.gammon.com.au/forum/?id=6030


Functions ...



Scripting functions list


See Also ...

Topics

DOC_Arrays Arrays
DOC_lua_base Lua base functions
DOC_lua_bc Lua bc (big number) functions
DOC_lua_bit Lua bit manipulation functions
DOC_lua_coroutines Lua coroutine functions
DOC_lua_debug Lua debug functions
DOC_lua_io Lua io functions
DOC_lua_math Lua math functions
DOC_lua_os Lua os functions
DOC_lua_package Lua package functions
DOC_lua_rex Lua PCRE regular expression functions
DOC_lua Lua script extensions
DOC_lua_string Lua string functions
DOC_lua_tables Lua table functions
DOC_lua_utils Lua utilities
DOC_plugins Plugins
DOC_mxp_callbacks Scripting callbacks - MXP
DOC_plugin_callbacks Scripting callbacks - plugins
DOC_data_types Scripting data types
DOC_function_list Scripting functions list
DOC_errors Scripting return codes
DOC_utils Utilities
DOC_variables Variables
DOC_world World functions

Commands

CMD_ID_GAME_CONFIGURE_SCRIPTING ConfigureScripting (Sets scripting options)
CMD_ID_GAME_EDITSCRIPTFILE EditScriptFile (Edits the current script file)
CMD_ID_GAME_IMMEDIATE Immediate (Allows testing of scripts)
CMD_ID_EDIT_SENDTOIMMEDIATE SendToScript (Sends the selection to the script engine of the related world)

Dialogs

DLG_IDD_LUA_DEBUG Debug
DLG_IDD_GLOBAL_PREFSP13 Global preferences - Lua
DLG_IDD_IMMEDIATE Immediate
DLG_IDD_MISSING_ENTRY_POINTS Missing script procedure names
DLG_IDD_MXP_SCRIPTS MXP script routines
DLG_IDD_SCRIPT_ERROR Scripting Error
DLG_IDD_PREFS_P17 Scripts

(Help topic: general=scripting)

DOC_contents Documentation contents page