File CoreMudlet.lua

Functions

appendBuffer (windowName) Pastes the previously copied rich text (including text formats like color) into user window name.
calcFontSize (fontSize) This returns you the height and the length of letters for the given font size.
channel102 () The channel102 table is used by Aardwolf mud for returning various information about you state.
clearUserWindow (windowName) Clears the user window or a mini console with the name given as argument.
clearWindow (windowName) TODO clearWindow - TLuaInterpreter::clearUserWindow
closeUserWindow (windowName) Clears the user window or a mini console with the name given as argument.
command () The command variable holds initial user command e.g.
copy () Copies the current selection to the clipboard.
createBuffer (name) Creates a named buffer for formatted text, much like a user terminal window, but the buffer cannot be shown on the screen; intended for temporary buffer work
createButton () TODO createButton - TLuaInterpreter::createButton
createLabel (name, posX, posY, width, height, fillBackground) Labels are intended for very small variable or prompt displays or images.
createMiniConsole (name, posX, posY, width, height) Opens a console window inside the main window of Mudlet.
createStopWatch () This function creates a stop watch.
cut () TODO cut - TLuaInterpreter::cut
deleteLine () Deletes the current Line under the user cursor.
disableAlias (name) Disables/deactivates an alias with the given name.
disableKey (name) Uses trigger name as id or the id returned by tempTrigger() TODO tempKey?
disableTimer (name) Disables a timer from running it's script when it fires - so the timer cycles will still be happening, just no action on them.
disableTrigger (name) Use trigger name or the id returned by tempTrigger() to identify the timer that you want to disable.
disconnect () Disconnect from current session without a proper logout.
echo (windowName, text) This function appends text at the end of the current line.
echoLink (windowName, text, command, hint, useCurrentFormat) Echos a piece of text as a clickable link.
echoPopup () Same as setPopup() except it doesn't require a selection.
echoUserWindow (windowName, text) This function will print text to both mini console windows, dock windows and labels.
enableAlias (name) Enables/activates the alias by it's name.
enableKey (name) Enable key or key group "name" (hot keys or action keys).
enableTimer (name) Enables or activates a timer that was previously disabled.
enableTrigger (name) Enables a Trigger.
exists (name, type) Tells you how many things of the given type exist.
expandAlias (command, print=1) Like send(), but without bypassing alias expansion.
feedTriggers (text) This function will have Mudlet parse the given text as if it came from the MUD - one great application is trigger testing.
getBgColor (windowName) Get the RGB values of the first character of the current selection.
getButtonState () This function can be used in checkbox button scripts (2-state buttons) to determine the current state of the checkbox.
getColumnNumber () Gets the absolute column number of the current user cursor.
getCurrentLine () Returns the content of the current line under the user cursor in the buffer.
getFgColor (windowName) This function returns the RGB values of the color of the first character of the current selection on mini console (window) windowName.
getLastLineNumber () Returns number of the last line in the text buffer.
getLineCount () Gets the absolute amount of lines in the current console buffer.
getLineNumber () Gets the absolute line number of the current user cursor.
getLines (from_line_number, to_line_number) Returns a Lua table with the content of the lines on a per line basis.
getMainWindowSize () Return window width and window height (function have two return values).
getMudletHomeDir () Returns the current home directory of the current profile.
getNetworkLatency () Returns the last measured response time between the sent command and the server reply.
getStopWatchTime (watchID) Returns the time without stoping stop watch (milliseconds based) in form of 0.058 (= clock ran for 58 milliseconds before it was stopped).
getTime (returnType, format) Return time information.
getTimestamp (console_name, lineNumber) Returns the timestamp string as it's seen when you enable the timestamps view (blue 'i' button bottom right of the Mudlet screen).
hasFocus () TODO hasFocus - TLuaInterpreter::hasFocus
hideToolBar (name) Hides tool bar name and makes it disappear.
hideWindow (name) This function hides a mini console label.
insertHTML () TODO insertHTML - TLuaInterpreter::insertHTML
insertLink (windowName, text, command, hint, useCurrentFormat) Same as echoLink() but inserts the text at the current cursor position, while echoLink inserts at the end of the current line.
insertPopup (windowName, text, commands, hints, useCurrentFormat) Same as echoPopup(), but inserts text at the current cursor position.
insertText (windowName, text) Inserts text at the current cursor position in the main window.
invokeFileDialog (selection, dialogTitle) Opens a file chooser dialog, allowing the user to select a file or a folder visually.
isActive (name, type) You can use this function to check if something, or somethings, are active.
isAnsiBgColor (ansiBgColorCode) This function tests if the first character of the current selection has the background color specified by ansiBgColorCode.
isAnsiFgColor (ansiFgColorCode) This function tests if the first character of the current selection has the foreground color specified by ansiFgColorCode.
isPrompt () Returns true or false depending on if the current line being processed is a prompt.
killAlias (name) Deletes an alias with the given name.
killTimer (id) Deletes a tempTimer.
killTrigger (id) Deletes a tempTrigger according to trigger ID.
line () The line variable holds the content of the current line as being processed by the trigger engine.
loadRawFile () TODO loadRawFile - TLuaInterpreter::loadRawFile
matches () The matches table contains captured group.
moveCursor (windowName, x, y) Moves the user cursor of the window windowName to the absolute point (x,y).
moveCursorEnd (windowName) Moves the cursor to the end of the buffer.
moveWindow (name, x, y) This function moves window name to the given x/y coordinate.
multimatches () The multimatches table is being used by Mudlet in the context of multiline triggers that use Perl regular expression.
openUserWindow (windowName) Opens a user dockable console window for user output e.g.
paste (windowName) Pastes the previously copied text including all format codes like color, font etc.
pasteWindow () TODO pasteWindow - TLuaInterpreter::pasteWindow
permAlias (name, parent, regex, luaCode) Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.
permBeginOfLineStringTrigger (name, parent, patternTable, luaCode) Creates a persistent trigger with a begin of line substring pattern that shows up in the Script Editor and stays after Mudlet is restarted.
permRegexTrigger (name, parent, pattern, luaCode, regex) Creates a persistent trigger with a regex pattern that stays after Mudlet is restarted and shows up in the Script Editor.
permSubstringTrigger (name, parent, pattern, luaCode, regex) Creates a persistent trigger with a substring pattern that stays after Mudlet is restarted and shows up in the Script Editor.
permTimer (name, parent, seconds, luaCode) Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.
playSoundFile (fileName) This function plays a sound file.
raiseEvent (eventName, ...) Raises the event event_name.
reconnect () Reconnect to currect session.
replace (with) Replaces the currently selected text with the new text.
resetFormat (windowName) Resets the character format to default.
resetStopWatch (watchID) This function resets the time to 0:0:0.0, but does not start the stop watch.
resizeWindow (name, width, height) Resizes a mini console or label.
selectCaptureGroup (groupNumber) Selects the content of the capture group number in your Perl regular expression e.g.
selectCurrentLine () Selects the content of the current buffer line.
selectSection (windowName, from, lengthOfString) Select text on the line under the current cursor position.
selectString (text, numberOfMatch) Selects a substring from the line where the user cursor is currently positioned.
send (command, echoTheValue) This sends "command" directly to the network layer, skipping the alias matching.
sendATCP () TODO sendATCP - TLuaInterpreter::sendATCP
sendTelnetChannel102 () Send telnet channel 102 commands to MUD.
setBackgroundColor (windowName, red, green, blue, transparency) Sets RGB color values and the transparency for the given window.
setBgColor (windowName, r, g, b) Sets the current text background color in window windowName (or in main windows if you haven't specified that).
setBold (windowName, bool) Sets the current text font to bold (true) or non-bold (false) mode.
setBorderBottom (size) Sets the height of the bottom border to size pixel and thus effectively moves down the main console window by size pixels to make room for e.g.
setBorderColor (red, green, blue) Sets the color of the border in RGB color.
setBorderLeft (size)
setBorderRight (size) Sets the width of the right border and thus effectively moves down the main console window by size pixels to make room for e.g.
setBorderTop (size) Sets the height of the top border to size pixel and thus effectively moves down the main console window by size pixels to make room for e.g.
setConsoleBufferSize (consoleName, linesLimit, sizeOfBatchDeletion) Set the scrollback buffer size to linesLimit and determine how many lines are deleted at once in case the lines limit is reached.
setFgColor (windowName, r, g, b) Sets the current text foreground color in the main window.
setItalics (windowName, bool) Sets the current text font to italics/non-italics mode.
setLabelClickCallback (labelName, luaFunctionName, ...) Specify a Lua function to be called if the user clicks on the label/image.
setLabelStyleSheet () TODO setLabelStyleSheet - TLuaInterpreter::setLabelStyleSheet
setLink (command, tooltip) Turns the selected text into a clickable link - upon being clicked, the link will do the command code.
setMiniConsoleFontSize (name, fontSize) Sets the font size of the mini console.
setPopup (name, commands, hints) Turns the selected text into a left-clickable link, and a right-click menu.
setTextFormat (windowName, fgR, fgG, fgB, bgR, bgG, bgB, bold, underline, italics) Sets current text format of window.
setTriggerStayOpen (name, number) Set for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched.
setUnderline (windowName, bool) Sets the current text font to underline/non-underline mode.
setWindowWrap (windowName, wrapAt) Sets at what position in the line the console or miniconsole will start word wrap.
setWindowWrapIndent () TODO setWindowWrapIndent - TLuaInterpreter::setWindowWrapIndent
showToolBar (name) Shows tool bar name on the screen.
showWindow (name) This function shows a mini console or label.
spawn () TODO spawn - TLuaInterpreter::spawn
startLogging () TODO startLogging - TLuaInterpreter::startLogging
startStopWatch (watchID) Starts the stop watch.
stopStopWatch () Stops the stop watch and returns the elapsed time in milliseconds in form of 0.001.
tempAlias (regex, luaCode) Creates a temporary (lasts only until the profile is closed) alias.
tempColorTrigger (foregroundColor, backgqroundColor, luaCode) Makes a color trigger that triggers on the specified foreground and background color.
tempLineTrigger (from, howMany, luaCode) TODO example with luaCode - Temporary trigger that will fire on n consecutive lines following the current line.
tempRegexTrigger (regex, luaCode) Temporary trigger using Perl regex pattern matching.
tempTimer (seconds, luaCode) Creates a temporary single shot timer and returns the timer ID for subsequent enableTimer(), disableTimer() and killTimer() calls.
tempTrigger (string, luaCode) This function creates a temporary trigger using substring matching.
wait (time) Wait for specified time in milliseconds.
wrapLine () Wrap line lineNumber of mini console (window) windowName.


Functions

appendBuffer (windowName)
Pastes the previously copied rich text (including text formats like color) into user window name.
Parameters
  • windowName:
Usage:
  •     selectString(line, 1)
        copy()
        appendBuffer("chat")
     
See also:
calcFontSize (fontSize)
This returns you the height and the length of letters for the given font size. As the primary intended usage is for calculating the needed dimensions of a miniConsole, it doesn't accept a font argument - as the miniConsoles currently only work with the default font for the sake of portability.
Parameters
  • fontSize:
Usage
  • Get font dimensions in pixes.
        x,y = calcFontSize(10)
     
  • Create a miniConsole that is 45 letters in length and 25 letters in height for font size 7
        font_size = 7
        local x, y = calcFontSize( font_size )
        createMiniConsole("map",0,0,0,0)
        setMiniConsoleFontSize("map", font_size)
        resizeWindow( "map", x*45, y*25 )
     
channel102 ()
The channel102 table is used by Aardwolf mud for returning various information about you state.
Read http://www.aardwolf.com/blog/2008/07/10/telnet-negotiation-control-mud-client-interaction/ page for details.
Usage
  • Display content of channel10 table.
        display(channel102)
     
  • Function for detecting AFK status on Aardwolf mud.
        function amIafk()
           for k,v in pairs(channel102) do
              if k==100 and v==4 then
                 return true
              end
           end
           return false
        end
     
See also:
clearUserWindow (windowName)
Clears the user window or a mini console with the name given as argument. TODO is this still working?
Parameters
  • windowName:
clearWindow (windowName)
TODO clearWindow - TLuaInterpreter::clearUserWindow
Parameters
  • windowName:
closeUserWindow (windowName)
Clears the user window or a mini console with the name given as argument.
Parameters
  • windowName: optinal
command ()
The command variable holds initial user command e.g. unchanged by any aliases or triggers. This is typically used in alias scripts.
See also:
copy ()
Copies the current selection to the clipboard. This function operates on rich text, i.e. the selected text including all its format codes like colors, fonts etc. in the clipboard until it gets overwritten by another copy operation. example: This script copies the current line on the main screen to a user window (mini console) named chat and gags the output on the main screen.
Usage:
  •     selectString(line);
        copy();
        appendBuffer("chat");
        replace("This line has been moved to the chat window!")
     
See also:
createBuffer (name)
Creates a named buffer for formatted text, much like a user terminal window, but the buffer cannot be shown on the screen; intended for temporary buffer work
Parameters
  • name:
createButton ()
TODO createButton - TLuaInterpreter::createButton
createLabel (name, posX, posY, width, height, fillBackground)
Labels are intended for very small variable or prompt displays or images. labels are clickable and if you specify a callback function with setLabelClickCallback( labelName, myLabelOnClickFunction ) your function will get called if the user clicks on the label with the mouse. If fillBackground = 0, the background will be hidden, if fillBackground = 1 the background will be shown i.e. you can see the background color. labels can be transparent. You can place labels anywhere within then main display, also als overlays over the main displays e.g. for on screen buttons, micro display, etc. DON'T use labels for larger text displays because they are a lot slower than the highspeed mini consoles.

Labels accept some HTML and CSS code for text formating.
Parameters
  • name:
  • posX:
  • posY:
  • width:
  • height:
  • fillBackground:
Usage
  • This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent and 255 non-transparent) the background text can still be read through. The message box will disappear after 2.3 seconds.
        local width, height = getMainWindowSize();
        createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1);
        resizeWindow("messageBox",500,70);
        moveWindow("messageBox", (width/2)-300,(height/2)-100 );
        setBackgroundColor("messageBox", 150,100,100,200);
        echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]] );
        showWindow("messageBox");
        -- close the warning message box after 2.3 seconds
        tempTimer(2.3, [[hideWindow("messageBox")]] )
     
  • see forum for more examples
       http://mudlet.sourceforge.net/phpBB3/viewtopic.php?f=6&t=95
       http://mudlet.sourceforge.net/phpBB3/viewtopic.php?f=6&t=865
     
Return value:
  • true or false
See also:
createMiniConsole (name, posX, posY, width, height)
Opens a console window inside the main window of Mudlet. MiniConsole is openes at position posX/posY with size according to width/height (values depend on your own screen resolution usually between 0-1600 for x and 0-1024 for y). This console is the ideal fast colored text display for everything that requires a bit more text e.g. status screens, log windows, chat windows etc.. You can use clearWindow/moveCursor etc. functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window or normal echoUserWindow(name, text) for normal printing. To set word wrap see setWindowWrap. To move the main window to make room for miniconsole windows on your screen (if you want to do this as you can also layer mini console and label windows) see setBorderTop, setBorderColor To have your screen layout adjusted after the window size of the main screen gets resized see handleWindowResizeEvent
Parameters
  • name:
  • posX:
  • posY:
  • width:
  • height:
Usage:
  • Set up the small system message window in the top right corner
        -- determine the size of your screen
        WindowWidth = 0;
        WindowHeight = 0;
        WindowWidth, WindowHeight = getMainWindowSize();
     
        createMiniConsole("sys",WindowWidth-650,0,650,300)
        setBackgroundColor("sys",85,55,0,255)
        setMiniConsoleFontSize("sys", 8)
        -- wrap lines in window "sys" at 65 characters per line
        setWindowWrap("sys", 40)
        -- set default font colors and font style for window "sys"
        setTextFormat("sys",0,35,255,50,50,50,0,0,0)
     
        echo("sys","Hello world!")
     
Return value:
  • true or false
See also:
createStopWatch ()
This function creates a stop watch. It is high resolution time measurement tool. Stop watches can be started, stopped, reset and asked how much time has passed since the stop watch has been started. Returns the ID of a high resolution clock with milliseconds to measure time more accurately than what is possible with std. Lua routines ? startStopWatch, stopStopWatch, resetStopWatch, getStopWatchTime example: In a global script you create all stop watches that you need in your system and store the respective stopWatch-IDs in global variables:
Usage:
  •     fightStopWatchID = createStopWatch();
        -- you store the watchID in a global variable to access it from anywhere
        startStopWatch(fightStopWatch);
        -- To stop the watch and measure its time in e.g. a trigger script you can write:
        fightTime = stopStopWatch(fightStopWatchID)
        echo("The fight lasted for " .. fightTime .. " seconds.")
        resetStopWatch(fightStopWatchID);
     
Return value:
  • stop watch ID
See also:
cut ()
TODO cut - TLuaInterpreter::cut
deleteLine ()
Deletes the current Line under the user cursor. Note: This is a high speed gagging tool and it is very good at this task. It is meant to be used when the line can be omitted entirely in the output. If you want to replace this line with something else have a look at the replace() functions below.

Note that scripts such as: deleteLine(); echo("this line is gone"); will not work because lines that have been gagged with deleteLine() will not be rendered even if there is text in the buffer. See wrapLine for details on how to force a re-render if this is necessary for some reason. This is not the recommended way of replacing text.
See also:
disableAlias (name)
Disables/deactivates an alias with the given name. This means that when you type in text that should match it's pattern, it won't match and will be sent to the MUD. If several aliases have this name, they'll all be disabled.
Parameters
  • name:
disableKey (name)
Uses trigger name as id or the id returned by tempTrigger() TODO tempKey?
Parameters
  • name:
disableTimer (name)
Disables a timer from running it's script when it fires - so the timer cycles will still be happening, just no action on them. If you'd like to permanently delete it, use killTimer() instead.

Use timer name or the id returned by tempTimer() to identify the timer that you want to disable.
Parameters
  • name:
See also:
disableTrigger (name)
Use trigger name or the id returned by tempTrigger() to identify the timer that you want to disable.
Parameters
  • name:
See also:
disconnect ()
Disconnect from current session without a proper logout.
See also:
echo (windowName, text)
This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.
If the first argument is omitted the main console is used, otherwise the mini console windowName.
Parameters
  • windowName: optional
  • text:
Usage
  • Writes text to main window.
        echo("Hello world\n")
     
  • Writes text to the mini console named "info" if such a window exists.
        echo("info", "Hello this is the info window\n")
     
See also:
echoLink (windowName, text, command, hint, useCurrentFormat)
Echos a piece of text as a clickable link.

Release: Mudlet 1.1.0-pre1
Parameters
  • windowName: optional window name
  • text: to display in the echo. Same as a normal echo().
  • command: lua code to do when the link is clicked.
  • hint: text for the tooltip to be displayed when the mouse is over the link.
  • useCurrentFormat: true/false - controls whenever the current text formatting (colors, underline, bold, etc) should be used, or the default link format.
Usage:
  • Following will create "click me now" link.
        echoLink("hi", [[echo("hey bub!")]], "click me now")
     
See also:
echoPopup ()
Same as setPopup() except it doesn't require a selection. Method echoPopup creates a link from the given text that it echos.
Release: Mudlet 1.1.0-pre1
Usage:
  •     echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})
     
See also:
echoUserWindow (windowName, text)
This function will print text to both mini console windows, dock windows and labels. This function is outdated. Use echo( windowName, text ) instead.
Parameters
  • windowName:
  • text:
See also:
enableAlias (name)
Enables/activates the alias by it's name. If several aliases have this name, they'll all be enabled.
Parameters
  • name:
enableKey (name)
Enable key or key group "name" (hot keys or action keys).
Parameters
  • name:
enableTimer (name)
Enables or activates a timer that was previously disabled. The parameter "name" expects the timer ID that was returned by tempTimer() on creation of the timer or the name of the timer in case of a GUI timer
Parameters
  • name:
enableTrigger (name)
Enables a Trigger. see enableTimer() for more details.
Parameters
  • name:
See also:
exists (name, type)
Tells you how many things of the given type exist.
Parameters
  • name:
  • type: can be "alias", "trigger", or "timer".
Usage
  •     echo("I have " .. exists("my trigger", "trigger") .. " triggers called 'my trigger'!")
     
  • You can also use this alias to avoid creating duplicate things, for example:
        -- this code doesn't check if an alias already exists and will keep creating new aliases
        permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])
     
        -- while this code will make sure that such an alias doesn't exist first
        -- we do == 0 instead of 'not exists' because 0 is considered true in Lua
        if exists("Attack", "alias") == 0 then
            permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])
        end
     
Return value:
  • number
See also:
expandAlias (command, print=1)
Like send(), but without bypassing alias expansion. This function may lead to infinite recursion if you are not careful!

Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it's faster, you can easily give your function values, and your function can return you values, too.

Note: The variable "command" contains what was entered in the command line or issued via the expandAlias() function. If you use expandAlias( command ) inside an alias script the command would be doubled. You have to use send( ) inside an alias script to prevent recursion. This will send the data directly and bypass the alias expansion.
Parameters
  • command:
  • print=1:
See also:
feedTriggers (text)
This function will have Mudlet parse the given text as if it came from the MUD - one great application is trigger testing. You can use \n to represent a new line. The function also accept ANSI color codes that are used in MUDs. A sample table can be found here.
Parameters
  • text:
Usage
  • Usage of new line characters.
        feedTriggers("\nYou sit yourself down.\n")
     
  • Demonstration of ANSI color.
        feedTriggers("\nThis is \27[1;32mgreen\27[0;37m, \27[1;31mred\27[0;37m, " ..
           "\27[46mcyan background\27[0;37m,\27[32;47mwhite background and green foreground\27[0;37m.\n")
     
getBgColor (windowName)
Get the RGB values of the first character of the current selection.
Parameters
  • windowName: optional
Usage:
  • Getting RGB component.
        r,g,b = getBgColor(windowName)
     
See also:
getButtonState ()
This function can be used in checkbox button scripts (2-state buttons) to determine the current state of the checkbox.
Usage:
  •     checked = getButtonStated();
        if checked == 1 then
            hideExits()
        else
            showExits()
        end;
     
Return value:
  • numneric state; state = 1 button is checked and state = 0, button is not checked
getColumnNumber ()
Gets the absolute column number of the current user cursor.
getCurrentLine ()
Returns the content of the current line under the user cursor in the buffer. The Lua variable line holds the content of getCurrentLine() before any triggers have been run on this line. When triggers change the content of the buffer, the variable line will not be adjusted and thus hold an outdated string. line = getCurrentLine() will update line to the real content of the current buffer. This is important if you want to copy the current line after it has been changed by some triggers. selectString( line,1 ) will return false and won't select anything because line no longer equals getCurrentLine(). Consequently, selectString( getCurrentLine(), 1 ) is what you need.
Usage:
  • Update line variable with content of current line.
        line = getCurrentLine()
     
See also:
getFgColor (windowName)
This function returns the RGB values of the color of the first character of the current selection on mini console (window) windowName.
Parameters
  • windowName: optional - if windowName is omitted Mudlet will use the main screen.
Usage
  •     r,g,b = getFgColor(windowName)
     
  •     local r,g,b;
        selectString("troll",1)
        r,g,b = getFgColor()
        if r == 255 and g == 0 and b == 0 then
            echo("HELP! troll is written in red letters, the monster is aggressive!\n");
        end
     
See also:
getLastLineNumber ()
Returns number of the last line in the text buffer.
getLineCount ()
Gets the absolute amount of lines in the current console buffer.
Return value:
  • number
getLineNumber ()
Gets the absolute line number of the current user cursor.
getLines (from_line_number, to_line_number)
Returns a Lua table with the content of the lines on a per line basis. Absolute line numbers are used.
Parameters
  • from_line_number:
  • to_line_number:
Return value:
  • section of the content of the screen text buffer. The form of the return value is: Lua_table[relative_linenumber, content]
getMainWindowSize ()
Return window width and window height (function have two return values). This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.
Usage:
  •     mainWindowWidth, mainWindowHeight = getMainWindowSize();
     
Return value:
  • 2 numbers, width and height in pixels
getMudletHomeDir ()
Returns the current home directory of the current profile. This can be used to store data, save statistical information or load resource files.
Usage:
  • Get directory to current profile.
        homedir = getMudletHomeDir()
     
getNetworkLatency ()
Returns the last measured response time between the sent command and the server reply.
Return value:
  • number of seconds (0.058 (=58 milliseconds lag) or 0.309 (=309 milliseconds))
getStopWatchTime (watchID)
Returns the time without stoping stop watch (milliseconds based) in form of 0.058 (= clock ran for 58 milliseconds before it was stopped).
Parameters
  • watchID:
See also:
getTime (returnType, format)
Return time information.
Release: Mudlet 1.0.6
Parameters
  • returnType: Takes a boolean value (in Lua anything but false or nil will translate to true). If true, the function will return a table in the following format:
    { hour = #, min = #, sec = #, msec = # }
    If false or nil, it will return the time as a string using a format passed to the second arg or the default of hh:mm:ss.zzz
  • format: Format expressions built from following elements:
        h               the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
        hh              the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
        H               the hour without a leading zero (0 to 23, even with AM/PM display)
        HH              the hour with a leading zero (00 to 23, even with AM/PM display)
        m               the minute without a leading zero (0 to 59)
        mm              the minute with a leading zero (00 to 59)
        s               the second without a leading zero (0 to 59)
        ss              the second with a leading zero (00 to 59)
        z               the milliseconds without leading zeroes (0 to 999)
        zzz             the milliseconds with leading zeroes (000 to 999)
        AP or A         use AM/PM display. AP will be replaced by either "AM" or "PM".
        ap or a         use am/pm display. ap will be replaced by either "am" or "pm".
     
        d               the day as number without a leading zero (1 to 31)
        dd              the day as number with a leading zero (01 to 31)
        ddd             the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName().
        dddd            the long localized day name (e.g. 'Monday' to 'Qt::Sunday'). Uses QDate::longDayName().
        M               the month as number without a leading zero (1-12)
        MM              the month as number with a leading zero (01-12)
        MMM             the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName().
        MMMM            the long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName().
        yy              the year as two digit number (00-99)
        yyyy            the year as four digit number
     
    All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression. Two consecutive singlequotes ("''") are replaced by a singlequote in the output.
Usage
  • Get time as a table.
        getTime()
     
  • Get time as a string (with default formatting).
        getTime(true)
     
  • Get time as a string with user defined formatting.
        getTime(true, "hh:mm")
     
getTimestamp (console_name, lineNumber)
Returns the timestamp string as it's seen when you enable the timestamps view (blue 'i' button bottom right of the Mudlet screen).
Release: Mudlet 1.1.0-pre1
Parameters
  • console_name: optional parameter
  • lineNumber:
Usage:
  • Echo the timestamp of the current line in a trigger.
        echo( getTimestamp(getLineCount()) )
     
hasFocus ()
TODO hasFocus - TLuaInterpreter::hasFocus
hideToolBar (name)
Hides tool bar name and makes it disappear. If all tool bars of a tool bar area (top, left, right) are hidden, the entire tool bar area disappears automatically.
Parameters
  • name:
hideWindow (name)
This function hides a mini console label. To show it again use showWindow.
Parameters
  • name:
See also:
insertHTML ()
TODO insertHTML - TLuaInterpreter::insertHTML
insertLink (windowName, text, command, hint, useCurrentFormat)
Same as echoLink() but inserts the text at the current cursor position, while echoLink inserts at the end of the current line.
Release: Mudlet 1.1.0-pre1
Parameters
  • windowName:
  • text:
  • command:
  • hint:
  • useCurrentFormat:
See also:
insertPopup (windowName, text, commands, hints, useCurrentFormat)
Same as echoPopup(), but inserts text at the current cursor position.
Release: Mudlet 1.1.0-pre1
Parameters
  • windowName:
  • text:
  • commands:
  • hints:
  • useCurrentFormat:
See also:
insertText (windowName, text)
Inserts text at the current cursor position in the main window. If the cursor has not been explicitly moved this function will always print at the beginning of the line whereas the echo() function will always print at the end of the line.
Parameters
  • windowName: optional
  • text:
See also:
invokeFileDialog (selection, dialogTitle)
Opens a file chooser dialog, allowing the user to select a file or a folder visually. The function returns the selected path or nil if there was none chosen.
Parameters
  • selection: true for file selection, false for folder selection.
  • dialogTitle: name that the dialog (file chooser window) will have
Usage:
  •     local path = invokeFileDialog(false, "Find me the gfx folder, please")
        if path then
           echo(path)
        end
     
isActive (name, type)
You can use this function to check if something, or somethings, are active. Type can be either "alias", "trigger", or "timer", and name is the name of the said item you'd like to check.
Parameters
  • name:
  • type: could be "alias", "trigger", or "timer"
Usage:
  • This will check is my "my trigger" is active.
        echo("I have " .. isActive("my trigger", "trigger") .. " currently active triggers called 'my trigger'!")
     
isAnsiBgColor (ansiBgColorCode)
This function tests if the first character of the current selection has the background color specified by ansiBgColorCode.
Parameters
  • ansiBgColorCode:
See also:
isAnsiFgColor (ansiFgColorCode)
This function tests if the first character of the current selection has the foreground color specified by ansiFgColorCode. Codes are:
    0 = default text color
    1 = light black
    2 = dark black
    3 = light red
    4 = dark red
    5 = light green
    6 = dark green
    7 = light yellow
    8 = dark yellow
    9 = light blue
    10 = dark blue
    11 = light magenta
    12 = dark magenta
    13 = light cyan
    14 = dark cyan
    15 = light white
    16 = dark white
 

Parameters
  • ansiFgColorCode:
Usage:
  •     selectString( matches[1], 1 )
        if isAnsiFgColor( 5 ) then
            bg("red");
            resetFormat();
            echo("yes, the text is light green")
        else
            echo( "no sorry, some other foreground color" )
        end
     
    Note that matches[1] holds the matched trigger pattern - even in substring, exact match, begin of line substring trigger patterns or even color triggers that do not know about the concept of capture groups. Consequently, you can always test if the text that has fired the trigger has a certain color and react accordingly. This function is faster than using getFgColor() and then handling the color comparison in Lua.
isPrompt ()
Returns true or false depending on if the current line being processed is a prompt. This infallible feature is available for MUDs that supply GA events (to check if yours is one, look to bottom-right of the main window - if it doesn't say <No GA>, then it supplies them).
Return value:
  • true/false
killAlias (name)
Deletes an alias with the given name. If several aliases have this name, they'll all be deleted.
Parameters
  • name:
See also:
killTimer (id)
Deletes a tempTimer. Use the Timer ID returned by tempTimer() as name parameter. ID is a string and not a number. This function returns true on success and false if the timer id doesn't exist anymore (=timer has already fired) or the timer is not a temp timer. Note that non-temporary timers that you have set up in the GUI cannot be deleted with this function. Use disableTimer() to turn them on or off.
Parameters
  • id:
Return value:
  • true or false
See also:
killTrigger (id)
Deletes a tempTrigger according to trigger ID. ID is a string value, not a number.
Parameters
  • id:
Return value:
  • true or false
See also:
line ()
The line variable holds the content of the current line as being processed by the trigger engine. The engine runs all triggers on each line as it arrives from the MUD.
See also:
loadRawFile ()
TODO loadRawFile - TLuaInterpreter::loadRawFile
matches ()
The matches table contains captured group. This available only within trigger context. First item of matches table (matches[1]) holds current line, all other contains capture groups defined by regular expression trigger.
Usage:
  • Let say that you defined following trigger to detect and get droped items.
        RegEx:
           ^The (.*) drops (.*)\.$
        Code:
           display(matches)
           send("get " .. matches[3])
     
    Now let's say that MUD will send you following text (which will invoke your trigger).
        The skeleton drops scimitar.
     
    This will send "get scimitar" to your MUD and also print following table:
        table {
          1: 'The skeleton drops scimitar.'
          2: 'skeleton'
          3: 'scimitar'
        }
     
See also:
moveCursor (windowName, x, y)
Moves the user cursor of the window windowName to the absolute point (x,y). This function returns false if such a move is impossible e.g. the coordinates don't exist. To determine the correct coordinates use getLineNumber(), getColumnNumber() and getLastLineNumber(). The trigger engine will always place the user cursor at the beginning of the current line before the script is run. If you omit the windowName argument, the main screen will be used.
Parameters
  • windowName:
  • x:
  • y:
Usage:
  • Set up the small system message window in the top right corner.
        -- determine the size of your screen
        WindowWidth=0;
        WindowHeight=0;
        WindowWidth, WindowHeight = getMainWindowSize();
     
        -- define a mini console named "sys" and set its background color
        createMiniConsole("sys",WindowWidth-650,0,650,300)
        setBackgroundColor("sys",85,55,0,255);
     
        -- you *must* set the font size, otherwise mini windows will not work properly
        setMiniConsoleFontSize("sys", 12);
        -- wrap lines in window "sys" at 65 characters per line
        setWindowWrap("sys", 60);
        -- set default font colors and font style for window "sys"
        setTextFormat("sys",0,35,255,50,50,50,0,0,0);
        -- clear the window
        clearUserWindow("sys")
     
        moveCursorEnd("sys")
        setFgColor("sys", 10,10,0)
        setBgColor("sys", 0,0,255)
        echo("sys", "test1---line1\n\n\n")
        echo("sys", "test1---line2\n")
        echo("sys", "test1---line3\n")
        setTextFormat("sys",158,0,255,255,0,255,0,0,0);
        --setFgColor("sys",255,0,0);
        echo("sys", "test1---line4\n")
        echo("sys", "test1---line5\n")
        moveCursor("sys", 1,1)
     
        -- deleting lines 2+3
        deleteLine("sys");
        deleteLine("sys");
     
        -- inserting a line at pos 5,2
        moveCursor("sys", 5,2);
        setFgColor("sys", 100,100,0)
        setBgColor("sys", 255,100,0)
        insertText("sys","############## line inserted at pos 5/2 ##############");
     
        -- inserting a line at pos 0,0
        moveCursor("sys", 0,0)
        selectCurrentLine("sys");
        setFgColor("sys", 255,155,255);
        setBold( "sys", true );
        setUnderline( "sys", true );
        setItalics( "sys", true );
        insertText("sys", "------- line inserted at: 0/0 -----\n");
     
        setBold( "sys", true )
        setUnderline( "sys", false )
        setItalics( "sys", false )
        setFgColor("sys", 255,100,0)
        setBgColor("sys", 155,155,0)
        echo("sys", "*** This is the end. ***\n");
     
Return value:
  • true or false
moveCursorEnd (windowName)
Moves the cursor to the end of the buffer. "main" is the name of the main window, otherwise use the name of your user window.
Parameters
  • windowName:
Return value:
  • true or false
See also:
moveWindow (name, x, y)
This function moves window name to the given x/y coordinate. The main screen cannot be moved. Instead you'll have to set appropriate border values in preferences to move the main screen e.g. to make room for chat or information mini consoles, or other GUI elements. In the future moveWindow() will set the border values automatically if the name parameter is omitted.
Parameters
  • name:
  • x:
  • y:
See also:
multimatches ()
The multimatches table is being used by Mudlet in the context of multiline triggers that use Perl regular expression. It holds the table matches[n] as described above for each Perl regular expression based condition of the multiline trigger. multimatches[5][4] may hold the 3rd capture group of the 5th regex in the multiline trigger. This way you can examine and process all relevant data within a single script.

What makes multiline triggers really shine is the ability to react to MUD output that is spread over multiple lines and only fire the action (=run the script) if all conditions have been fulfilled in the specified amount of lines.
Usage:
  • Have a look at this example (can be tested on the MUD batmud.bat.org).
    In the case of a multiline trigger with these 2 Perl regex as conditions:
        ^You have (\w+) (\w+) (\w+) (\w+)
        ^You are (\w+).*(\w+).*
     
    The command "score" generates the following output on batMUD:
        You have an almost non-existent ability for avoiding hits.
        You are irreproachably kind.
        You have not completed any quests.
        You are refreshed, hungry, very young and brave.
        Conquer leads the human race.
        Hp:295/295 Sp:132/132 Ep:182/181 Exp:269 >
     
    If you add this script to the trigger:
        showMultimatches()
     
    The script, i.e. the call to the function showMultimatches() generates this output:
        -------------------------------------------------------
        The table multimatches[n][m] contains:
        -------------------------------------------------------
        regex 1 captured: (multimatches[1][1-n])
                  key=1 value=You have not completed any quests
                  key=2 value=not
                  key=3 value=completed
                  key=4 value=any
                  key=5 value=quests
        regex 2 captured: (multimatches[2][1-n])
                  key=1 value=You are refreshed, hungry, very young and brave
                  key=2 value=refreshed
                  key=3 value=young
                  key=4 value=and
                  key=5 value=brave
        -------------------------------------------------------
     
    The function showMultimatches() prints out the content of the table multimatches[n][m]. You can now see what the table multimatches[][] contains in this case. The first trigger condition (=regex 1) got as the first full match "You have not completed any quests". This is stored in multimatches[1][1] as the value of key=1 in the sub-table matches[1] which, in turn, is the value of key=1 of the table multimatches[n][m].

    Following script would use matched values from previously defined regex in the multiline trigger:
        myGold = myGold + tonumber( multimatches[1][2] )
        mySilver = mySilver + tonumber( multimatches[1][3] )
     
See also:
openUserWindow (windowName)
Opens a user dockable console window for user output e.g. statistics, chat etc. If a window of such a name already exists, nothing happens. You can move these windows, dock them, make them into notebook tabs or float them.

Note: There isn't currently way how to set size and position of user windows at the moment, so you might consider to use mini console instead.
Parameters
  • windowName:
Usage:
  • This command will open new user windows with name "Chat".
        openUserWindow("Chat")
     
See also:
paste (windowName)
Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The copy() and paste() functions can be used to copy formated text from the main window to a user window without losing colors e. g. for chat windows, map windows etc.
Parameters
  • windowName:
See also:
pasteWindow ()
TODO pasteWindow - TLuaInterpreter::pasteWindow
permAlias (name, parent, regex, luaCode)
Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.

Note that Mudlet by design allows duplicate names - so calling permAlias with the same name will keep creating new aliases. You can check if an alias already exists with the exists() function.
Parameters
  • name: is the name you'd like the alias to have.
  • parent: is the name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn't exist, it won't do anything. Use "" to make it not go into any groups.
  • regex: is the pattern that you'd like the alias to use.
  • luaCode: is the script the alias will do when it matches.
Usage:
  • Creates an alias called "new alias" in a group called "my group".
        permAlias("new alias", "my group", "^test$", [[echo ("say it works! This alias will show up in the script editor too.")]])
     
See also:
permBeginOfLineStringTrigger (name, parent, patternTable, luaCode)
Creates a persistent trigger with a begin of line substring pattern that shows up in the Script Editor and stays after Mudlet is restarted.

Note that Mudlet by design allows duplicate names - so calling permBeginOfLineStringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the exists() function.
Parameters
  • name: is the name you'd like the trigger to have.
  • parent: is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn't exist, it won't do anything. Use "" to make it not go into any groups.
  • patternTable: is a table of patterns that you'd like the trigger to use - it can be one or many.
  • luaCode: is the script the trigger will do when it matches.
Usage
  • Create a trigger that will match on anything that starts with "You sit" and do "stand". It will not go into any groups, so it'll be on the top.
        permBeginOfLineStringTrigger("Stand up", "", {"You sit"}, [[send ("stand")]])
     
  • Another example - lets put our trigger into a "General" folder and give it several patterns.
        permBeginOfLineStringTrigger("Stand up", "General", {"You sit", "You fall", "You are knocked over by"}, [[send ("stand")]])
     
permRegexTrigger (name, parent, pattern, luaCode, regex)
Creates a persistent trigger with a regex pattern that stays after Mudlet is restarted and shows up in the Script Editor.

Note that Mudlet by design allows duplicate names - so calling permRegexTrigger with the same name will keep creating new aliases. You can check if an alias already exists with the exists() function.
Parameters
  • name: is the name you'd like the alias to have.
  • parent: is the name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn't exist, it won't do anything. Use "" to make it not go into any groups.
  • pattern:
  • luaCode: is the script the alias will do when it matches.
  • regex: is the pattern that you'd like the alias to use.
Usage:
  • Create a regex trigger that will match on the prompt to record your status.
        permRegexTrigger("Prompt", "", {"^(\d+)h, (\d+)m"}, [[health = tonumber(matches[2]; mana = tonumber(matches[3])]]
     
See also:
permSubstringTrigger (name, parent, pattern, luaCode, regex)
Creates a persistent trigger with a substring pattern that stays after Mudlet is restarted and shows up in the Script Editor.

Note that Mudlet by design allows duplicate names - so calling permSubstringTrigger with the same name will keep creating new aliases. You can check if an alias already exists with the exists() function.
Parameters
  • name: is the name you'd like the alias to have.
  • parent: is the name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn't exist, it won't do anything. Use "" to make it not go into any groups.
  • pattern:
  • luaCode: is the script the alias will do when it matches.
  • regex: is the pattern that you'd like the alias to use.
Usage
  • Create a trigger to highlight the word "pixie" for us.
        permSubstringTrigger("Highlight stuff", "General", {"pixie"}, [[selectString(line, 1) bg("yellow") resetFormat()]])
     
  • Another trigger to highlight several different things.
        permSubstringTrigger("Highlight stuff", "General", {"pixie", "cat", "dog", "rabbit"}, [[selectString(line, 1) fg ("blue") bg("yellow") resetFormat()]])
     
See also:
permTimer (name, parent, seconds, luaCode)
Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.

Note that Mudlet by design allows duplicate names - so calling permTimer with the same name will keep creating new timers. You can check if a timer already exists with the exists() function.
Parameters
  • name: timer name, parent is the name of the timer group you want the timer to go in.
  • parent:
  • seconds: number specifying a delay after which the timer will execute the lua code.
  • luaCode: code to execute
Usage:
  • Creates new time that will tick each 4.5s.
        permTimer("my timer", "first timer group", 4.5, [[send ("my timer that's in my first timer group fired!")]])
     
playSoundFile (fileName)
This function plays a sound file. To make sound work on your operating system you may need to install additional packages:
Microsoft Windows: The underlying multimedia system is used; only WAVE format sound files are supported. (works out of the box)
Mac OS X: NSSound is used. All formats that NSSound supports, including QuickTime formats, are supported by Qt for Mac OS X (should work out of the box).
X11: The Network Audio System is used if available, otherwise all operations work silently. NAS supports WAVE and AU files. Please use following workaround for Linux systems:
    if "linux" == getOS() then
 	     os.execute("aplay /usr/share/sounds/alsa/Front_Center.wav")
    end
 

Parameters
  • fileName:
raiseEvent (eventName, ...)
Raises the event event_name. The event system will call the main function (the one that is called exactly like the script name) of all such scripts that have registered event handlers. If an event is raised, but no event handler scripts have been registered with the event system, the event is ignored and nothing happens. This is convenient as you can raise events in your triggers, timers, scripts etc. without having to care if the actual event handling has been implemented yet - or more specifically how it is implemented. Your triggers raise an event to tell the system that they have detected a certain condition to be true or that a certain event has happened. How - and if - the system is going to respond to this event is up to the system and your trigger scripts don't have to care about such details. For small systems it will be more convenient to use regular function calls instead of events, however, the more complicated your system will get, the more important events will become because they help reduce complexity very much.

The corresponding event handlers that listen to the events raised with raiseEvent() need to use the script name as function name and take the correct number of arguments. NOTE: If you raise an event with 5 arguments but your event handlers functions only take 2,10 or 0 arguments, the functions will not be called. For example: raiseEvent("fight") a correct event handler function would be: myScript(event_name). In this example raiseEvent uses minimal arguments, name the event name. There can only be one event handler function per script, but a script can still handle multiple events as the first argument is always the event name. So you can call your own special handlers for individual events. The reason behind this is that you should rather use many individual scripts instead of one huge script that has all your function code etc. Scripts can be organized very well in trees and thus help reduce complexity on large systems.

As an example, your prompt trigger could raise an onPrompt event if you want to attach 2 functions to it. In your prompt trigger, all you'd need to do is raiseEvent("onPrompt") Now we go about creating functions that attach to the event. Lets say the first one is check_health_stuff() and the other is check_salve_stuff(). We would like these to be executed when the event is raised. So create a script and give it a name of check_health_stuff. In the Add user defined event handler, type onPrompt, and press enter to add it to the list. In the script box, create: function check_health_stuff()blah blah end. When the onPrompt event comes along, that script catches it, and does check_health_stuff() for you.

Default events raised by Mudlet
Mudlet itself also creates events for your scripts to hook on. The following events are generated currently:
sysWindowResizeEvent
Raised when the main window is resized, with the new height and width coordinates passed to the event. A common usecase for this event is to move/resize your UI elements according to the new dimensions. This sample code will echo whenever a resize happened with the new dimensions:
    function resizeEvent( event, x, y )
       echo("RESIZE EVENT: event="..event.." x="..x.." y="..y.."\n")
    end
 
sysWindowMousePressEvent
Raised when a mouse button is pressed down anywhere on the main window (note that a click is composed of a mouse press and mouse release). The button number and the x,y coordinates of the click are reported.
    function onClickHandler( event, button, x, y )
       echo("CLICK event:"..event.." button="..button.." x="..x.." y="..y.."\n")
    end
 
sysWindowMouseReleaseEvent
Raised when a mouse button is released after being pressed down anywhere on the main window (note that a click is composed of a mouse press and mouse release). See sysWindowMousePressEvent for example use. ATCP events

Mudlets ATCP implementation generates events for each message that comes, allowing you to trigger on them easily. Since ATCP messages vary in name, event names will vary as well. See the atcp section on how to use them.
Parameters
  • eventName:
  • ...:
reconnect ()
Reconnect to currect session.
See also:
replace (with)
Replaces the currently selected text with the new text. To select text, use selectString() and similar function.
Parameters
  • with:
Usage
  • Replace word "troll" with "cute trolly".
        selectString("troll",1)
        replace("cute trolly")
     
  • Lets replace the whole line. If you'd like to delete/gag the whole line, use deleteLine()!
        selectString(line, 1)
        replace("Out with the old, in with the new!")
     
See also:
resetFormat (windowName)
Resets the character format to default. This should be used after you have highlighted some text or changed the current foreground or background color, but you don't want to keep using these colors for further prints. If you set a foreground or background color, the color will be used until you call resetFormat() on all further print commands.
Parameters
  • windowName: optional
resetStopWatch (watchID)
This function resets the time to 0:0:0.0, but does not start the stop watch. You can start it with startStopWatch.
Parameters
  • watchID:
See also:
resizeWindow (name, width, height)
Resizes a mini console or label.
Parameters
  • name:
  • width:
  • height:
See also:
selectCaptureGroup (groupNumber)
Selects the content of the capture group number in your Perl regular expression e.g. "you have (\d+) Euro". If you want to color the amount of money you have green you do:
Parameters
  • groupNumber: with first group = 1
Usage:
  •     setFgColor(0,255,0)
        selectCaptureGroup(1);
     
selectCurrentLine ()
Selects the content of the current buffer line.
TODO It this valid? selectCurrentLine("sys");

selectSection (windowName, from, lengthOfString)
Select text on the line under the current cursor position. Use absolute column number for start of selection and length of selection The function returns true on success and false if the selection is not possible.
Parameters
  • windowName: is optional
  • from:
  • lengthOfString:
selectString (text, numberOfMatch)
Selects a substring from the line where the user cursor is currently positioned. You can move the user cursor with moveCursor(). When a new line arrives from the MUD, the user cursor is positioned at the beginning of the line. However, if one of your trigger scripts moves the cursor around you need to take care of the cursor position yourself and make sure that the cursor is in the correct line if you want to call one of the select functions. To deselect text, see deselect().
Parameters
  • text:
  • numberOfMatch:
Usage
  • Select "big monster" in the line.
        selectString("big monster", 1)
     
  • Note: To prevent selection of random data use the error return if not found like this.
        if selectString("big monster", 1) > -1 then
           setFgColor(255,0,0)
        end
     
  • In a trigger, lets color all words on the current line green.
        selectString(line, 1)
        fg("green")
        resetFormat()
     
Return value:
  • returns position in line or -1 on error (text not found in line)
See also:
send (command, echoTheValue)
This sends "command" directly to the network layer, skipping the alias matching. The optional second argument of type boolean (print) determines if the outgoing command is to be echoed on the screen. Send honours command separator defined within Mudlet settings. If you want your command to be checked if it's an alias, use expandAlias() instead.
Parameters
  • command:
  • echoTheValue: optional boolean flag (default value is true) which determine if value should be echoed back on client.
Usage
  • Echos the command on the screen.
        send("Hello Jane")
     
  • Echos the command on the screen.
        send("Hello Jane", true)
     
  • Does not echo the command on the screen.
        send("Hello Jane", false)
     
See also:
sendATCP ()
TODO sendATCP - TLuaInterpreter::sendATCP
See also:
sendTelnetChannel102 ()
Send telnet channel 102 commands to MUD. This is widely used on Aardwolf for setting up user tags.
Usage:
  • Following command will enable all Aardwolf channel tags. You need to have active session.
        sendTelnetChannel102("\5\1")
     
See also:
setBackgroundColor (windowName, red, green, blue, transparency)
Sets RGB color values and the transparency for the given window. Colors are from 0 to 255 (0 being black), and transparency is from - to 255 (0 being completely transparent).

Note that transparency only works on labels, not miniConsoles for efficiency reasons.
Parameters
  • windowName:
  • red:
  • green:
  • blue:
  • transparency:
setBgColor (windowName, r, g, b)
Sets the current text background color in window windowName (or in main windows if you haven't specified that). If you have selected text prior to this call, the selection will be highlightd otherwise the current text background color will be changed. If you set a foreground or background color, the color will be used until you call resetFormat() on all further print commands.
Parameters
  • windowName: optional
  • r:
  • g:
  • b:
Usage
  • Highlights the first occurrence of the string "Tom" in the current line with a red background color.
        selectString( "Tom", 1 )
        setBgColor( 255,0,0 )
     
  • Prints "Hello" on red background and "You" on blue.
        setBgColor(255,0,0)
        echo("Hello")
        setBgColor(0,0,255)
        echo(" You!")
        resetFormat()
     
See also:
setBold (windowName, bool)
Sets the current text font to bold (true) or non-bold (false) mode. If the windowName parameters omitted, the main screen will be used.
Parameters
  • windowName: optional
  • bool:
setBorderBottom (size)
Sets the height of the bottom border to size pixel and thus effectively moves down the main console window by size pixels to make room for e.g. mini console windows, buttons etc..
Parameters
  • size:
See also:
setBorderColor (red, green, blue)
Sets the color of the border in RGB color.
Parameters
  • red:
  • green:
  • blue:
Usage:
  • Sets the border to red.
        setBorderColor( 255, 0, 0 )
     
setBorderLeft (size)

Parameters
  • size:
See also:
setBorderRight (size)
Sets the width of the right border and thus effectively moves down the main console window by size pixels to make room for e.g. mini console windows, buttons etc..
Parameters
  • size:
See also:
setBorderTop (size)
Sets the height of the top border to size pixel and thus effectively moves down the main console window by size pixels to make room for e.g. mini console windows, buttons etc..
Parameters
  • size:
See also:
setConsoleBufferSize (consoleName, linesLimit, sizeOfBatchDeletion)
Set the scrollback buffer size to linesLimit and determine how many lines are deleted at once in case the lines limit is reached. The lower the limit the less memory being used. On machines with low RAM you should consider limiting the size of buffers that don't need a lot of scrollback e.g. system notification windows, chat windows etc..
Default values are linesLimit = 100000 lines with 10000 lines of batch deletion.
Minimum buffer size is 100 lines with 10 lines batch deletion.
Parameters
  • consoleName:
  • linesLimit:
  • sizeOfBatchDeletion:
setFgColor (windowName, r, g, b)
Sets the current text foreground color in the main window. Values are RGB: red, green, blue ranging from 0-255 e.g.
Parameters
  • windowName: optional @setBgColor
  • r:
  • g:
  • b:
Usage:
  • Set blue foreground.
        setBgColor(0,0,255)
     
setItalics (windowName, bool)
Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.
Parameters
  • windowName: optional
  • bool:
setLabelClickCallback (labelName, luaFunctionName, ...)
Specify a Lua function to be called if the user clicks on the label/image. E.g. setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )

UPDATE: this function can now pass any number of string or integer number values as additional parameters. These parameters are then used in the callback. Thus you can associate data with the label/button. Check the forum for more information on how to use this. FIXME
Parameters
  • labelName:
  • luaFunctionName:
  • ...:
setLabelStyleSheet ()
TODO setLabelStyleSheet - TLuaInterpreter::setLabelStyleSheet
setLink (command, tooltip)
Turns the selected text into a clickable link - upon being clicked, the link will do the command code. Tooltip is a string which will be displayed when the mouse is over the selected text.
Release: Mudlet 1.1.0-pre1
Parameters
  • command:
  • tooltip:
Usage:
  • In a sewer grate substring trigger, the following code will make clicking on the words do the send("enter grate") command:
        selectString(matches[1], 1)
        setLink([[send("enter grate")]], "Clicky to enter grate")
     
See also:
setMiniConsoleFontSize (name, fontSize)
Sets the font size of the mini console.
Parameters
  • name:
  • fontSize:
See also:
setPopup (name, commands, hints)
Turns the selected text into a left-clickable link, and a right-click menu. The selected text, upon being left-clicked, will do the first command in the list. Upon being right-clicked, it'll display a menu with all possible commands. The menu will be populated with hints, one for each line.
Release: Mudlet 1.1.0-pre1
Parameters
  • name: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.
  • commands: a table of lua code strings to do e.g. {[[send("hello")]], [[echo("hi!"]]}.
  • hints: a table of strings which will be shown on the popup and right-click menu e.g. {"send the hi command", "echo hi to yourself"}.
Usage:
  • In a Raising your hand in greeting, you say "Hello!" exact match trigger, the following code will make left-clicking on Hello show you an echo, while left-clicking will show some commands you can do.
        selectString("Hello", 1)
        setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})
     
setTextFormat (windowName, fgR, fgG, fgB, bgR, bgG, bgB, bold, underline, italics)
Sets current text format of window. A more convenient way to control the text format in a mini console is to use setFgColor, setBold, setItalics, setUnderline etc.
Parameters
  • windowName:
  • fgR: foreground color(r,g,b)
  • fgG: foreground color(r,g,b)
  • fgB: foreground color(r,g,b)
  • bgR: background color(r,g,b)
  • bgG: background color(r,g,b)
  • bgB: background color(r,g,b)
  • bold: bold flag (1/0)
  • underline: underline flag (1/0)
  • italics: italics flag (1/0)
Usage:
  • This script would create a mini text console and write with yellow foreground color and blue background color "This is a test".
        createMiniConsole( "con1", 0,0,300,100);
        setTextFormat("con1",0,0,255,255,255,0,1,1,1);
        echo("con1","This is a test")
     
See also:
setTriggerStayOpen (name, number)
Set for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched. The main use of this function is to close a chain when a certain condition has been met.
Parameters
  • name:
  • number: should be 0 to close the chain, or a positive number to keep the chain open that much longer.
setUnderline (windowName, bool)
Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.
Parameters
  • windowName: optional
  • bool:
setWindowWrap (windowName, wrapAt)
Sets at what position in the line the console or miniconsole will start word wrap.
Parameters
  • windowName:
  • wrapAt:
setWindowWrapIndent ()
TODO setWindowWrapIndent - TLuaInterpreter::setWindowWrapIndent
showToolBar (name)
Shows tool bar name on the screen.
Parameters
  • name:
showWindow (name)
This function shows a mini console or label. To hide it use hideWindow.
Parameters
  • name:
See also:
spawn ()
TODO spawn - TLuaInterpreter::spawn
startLogging ()
TODO startLogging - TLuaInterpreter::startLogging
startStopWatch (watchID)
Starts the stop watch.
Parameters
  • watchID:
See also:
stopStopWatch ()
Stops the stop watch and returns the elapsed time in milliseconds in form of 0.001.
Return value:
  • returns time as a number
See also:
tempAlias (regex, luaCode)
Creates a temporary (lasts only until the profile is closed) alias. This means that it won't exist anymore after Mudlet restarts.
Parameters
  • regex:
  • luaCode:
Usage:
  • This triggers waits for "hi" string.
        tempAlias("^hi$", [[send ("hi") echo ("we said hi!")]]
     
Return value:
  • id
tempColorTrigger (foregroundColor, backgqroundColor, luaCode)
Makes a color trigger that triggers on the specified foreground and background color. Both colors need to be supplied in form of these simplified ANSI 16 color mode codes:
    0 = default text color
    1 = light black
    2 = dark black
    3 = light red
    4 = dark red
    5 = light green
    6 = dark green
    7 = light yellow
    8 = dark yellow
    9 = light blue
    10 = dark blue
    11 = light magenta
    12 = dark magenta
    13 = light cyan
    14 = dark cyan
    15 = light white
    16 = dark white
 

Parameters
  • foregroundColor:
  • backgqroundColor:
  • luaCode:
Usage:
  • This script will re-highlight all text in blue foreground colors on a black background with a red foreground color on a blue background color until another color in the current line is being met. temporary color triggers do not offer match_all or filter options like the GUI color triggers because this is rarely necessary for scripting. A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.
        tempColorTrigger(9,2,[[selectString(matches[1],1); fg("red"); bg("blue");]] );
     
tempLineTrigger (from, howMany, luaCode)
TODO example with luaCode - Temporary trigger that will fire on n consecutive lines following the current line. This is useful to parse output that is known to arrive in a certain line margin or to delete unwanted output from the MUD.
Parameters
  • from:
  • howMany:
  • luaCode:
Usage
  • Following will fire 3 times starting with the line from the MUD.
        tempLineTrigger( 1, 3, [[send("shout Help")]])
     
  • This will fire 20 lines after the current line and fire twice on 2 consecutive lines.
        tempLineTrigger( 20, 2, [[send("shout Help")]])
     
Return value:
  • the string ID of the newly created temporary trigger. You can use this ID to enable/disable or kill this trigger later on.
tempRegexTrigger (regex, luaCode)
Temporary trigger using Perl regex pattern matching.
Parameters
  • regex:
  • luaCode:
Return value:
  • the string ID of the newly created temporary trigger. You can use this ID to enable/disable or kill this trigger later on.
See also:
tempTimer (seconds, luaCode)
Creates a temporary single shot timer and returns the timer ID for subsequent enableTimer(), disableTimer() and killTimer() calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed.

Note [[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don't have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote.
Parameters
  • seconds:
  • luaCode:
Usage
  • This script will send the command "kill rat" 0.3 seconds after this function has been called. Note that this function does not wait until 0.3 seconds have been passed, but it will start a timer that will run the Lua script that you have provided as a second argument after 0.3 seconds.
        tempTimer(0.3, [[send("kill rat")]] )
     
  • Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:
        tempTimer(3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )
     
Return value:
  • timer ID, ID is a string and not a number.
tempTrigger (string, luaCode)
This function creates a temporary trigger using substring matching. Contrary to tempTimers, tempTriggers lives throughout the entire session until it is explicitly disabled or killed. Disabled tempTimers can be re-enabled with enableTrigger(). This is much faster than killing the trigger and creating a new one. This is the second fastest trigger (with begin of line substring patterns being the fastest) and should be used instead of regex triggers whenever possible.
Parameters
  • string:
  • luaCode:
Usage:
  • You can put the following script into your targeting alias highlight your target.
    (Note: trigger will stay active unless you'll kill it.)
        target = "rat"
        if id then
           killTrigger(id)
        end
        id = tempTrigger(target, [[selectString("]] .. target .. [[", 1) fg("gold") resetFormat()]])
     
Return value:
  • trigger ID, ID is a string and not a number.
See also:
wait (time)
Wait for specified time in milliseconds. Use tempTimer instead! Don't use this function, because it freezes main thread.
Parameters
  • time:
Usage
  • Preferred use of tempTimer - wait for 2 seconds and than send "kill rat".
        tempTimer(2, [[send("kill rat")]] )
     
  • Discouraged use of wait function.
        -- This will freeze Mudlet for 2 seconds!!!
        wait(2000)
        send("kill rat")
     
  • This example is demonstrating transition from Nexus/Zmud wait. You can simply rewrote following nexus/zmud code bellow with tempTimers.
        #send jerk fish
        #wait 1500
        #send pull line
        #wait 500
        #send jump
     
    Since timers are created instantly, if you want two or more, or means the times for consecutive timers should be to the starting point, unlike relatives times you do with waits.
        -- Mudlet code
        send ("jerk fish")
        tempTimer (1.5, [[send ("pull line")]])
        tempTimer (2,   [[send ("jump")]])
     
See also:
wrapLine ()
Wrap line lineNumber of mini console (window) windowName. This function will interpret \n characters, apply word wrap and display the new lines on the screen. This function may be necessary if you use deleteLine() and thus erase the entire current line in the buffer, but you want to do some further echo() calls after calling deleteLine(). You will then need to re-wrap the last line of the buffer to actually see what you have echoed and get you \n interpreted as newline characters properly.

Using this function is not good programming practice and should be avoided. There are better ways of handling situations where you would call deleteLine() and echo afterwards e.g.:
    selectString(line,1);
    replace("");
 
This will effectively have the same result as a call to deleteLine() but the buffer line will not be entirely removed. Consequently, further calls to echo() etc. sort of functions are possible without using wrapLine() unnecessarily.

Valid XHTML 1.0!