Manual:UI Functions

From Mudlet
Jump to navigation Jump to search

UI Functions

ansi2decho

ansi2decho(text)
Converts ANSI colour sequences in text to colour tags that can be processed by the decho() function. Bold, italics, underline not currently supported since decho doesn't support them.
See also: decho()
Parameters
  • text:
String that contains ANSI colour sequences that should be replaced.
Example

<lua> local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m') -- 'replaced' should now contain <r><0,255,255:0,0,0>You say in a baritone voice, "Test."<r><192,192,192:0,0,0> decho(replaced) </lua>

Note Note: Available in Mudlet 3.0 and later.

appendBuffer

appendBuffer(name)
Pastes the previously copied rich text (including text formats like color etc.) into user window name.
See also: paste()
Parameters
  • name:
The name of the user window to paste into. Passed as a string.
Example

<lua> --selects and copies an entire line to user window named "Chat" selectCurrentLine() copy() appendBuffer("Chat") </lua>

bg

bg([window, ]colorName)
Changes the background color of the text. Useful for highlighting text.
See Also: fg(), setBgColor()
Parameters
  • window:
The miniconsole to operate on - optional. If you'd like it to work on the main window, don't specify anything, or use main (since Mudlet 3.0).
  • colorName:
The name of the color to set the background to. Color Table
Example

<lua> --This would change the background color of the text on the current line to magenta selectCurrentLine() bg("magenta")

-- or echo text with a green background to a miniconsole bg("my window", "green") echo("my window", "some green text\n") </lua>

calcFontSize

calcFontSize(fontSize)
Used to calculate the number of pixels wide a 'W' character would be and the extreme top and bottom pixels that any character in the font would be on a mini console at fontSize. 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 monospaced font for the sake of portability.
Returns two numbers, width/height
See Also: setMiniConsoleFontSize(), getMainWindowSize()
Parameters
  • fontSize:
The font size you are wanting to calculate pixel sizes for. Passed as an integer number.
Example

<lua> --this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide --would need to be at 9 point font, and then changes miniconsole Chat to be that size local width,height = calcFontSize(9) width = width * 20 height = height * 4 resizeWindow("Chat", width, height) </lua>

cecho

cecho(window, text)
Echoes text that can be easily formatted with colour tags.
See also: decho(), hecho()
Parameters
  • window:
Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.
  • text:
The text to display, with color names inside angle brackets <>, ie <red>. If you'd like to use a background color, put it after a colon : - <:red>. You can use the <reset> tag to reset to the default color. You can select any from this list: Color Table
Example

<lua> cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")

cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")

cecho("<blue:yellow>Blue on yellow text!")

cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.") </lua>

cechoLink

cechoLink([windowName], text, command, hint, true)
Echos a piece of text as a clickable link, at the end of the current selected line - similar to cecho(). This version allows you to use colours within your link text.
Parameters
  • windowName:
optional parameter, allows selection between sending the link to a miniconsole or the main window.
  • text:
text to display in the echo. Same as a normal cecho().
  • 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.
  • true:
requires argument for the colouring to work.
Example

<lua> -- echo a link named 'press me!' that'll send the 'hi' command to the game cechoLink("<red>press <brown:white>me!", send("hi"), "This is a tooltip", true) </lua>

cinsertText

cinsertText(window, text)
inserts text at the current cursor position, with the possibility for color tags.
See Also: cecho()
Parameters
  • window:
Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.
  • text:
The text to display, with color names inside angle brackets <>, ie <red>. If you'd like to use a background color, put it after a double colon : - <:red>. You can use the <reset> tag to reset to the default color. You can select any from this list: Color Table
Example

<lua> cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")

cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")

cinsertText("<blue:yellow>Blue on yellow text!")

cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.") </lua>

clearUserWindow

clearUserWindow(name)
Clears the window or miniconsole with the name given as argument.
Parameters
  • name:
The name of the user window to clear. Passed as a string.
Example

<lua> --This would clear a user window, or miniconsole with the name "Chat" clearUserWindow("Chat") </lua>

clearWindow

clearWindow([optional name])
This is (now) identical to clearUserWindow() which clears the window or miniconsole with the name given as argument (removes all text from it). If you don't give it a name, it will clear the main window.
Parameters
  • name:
The name of the user window to clear. Passed as a string.
Example

<lua> --This would clear a label, user window, or miniconsole with the name "Chat" clearWindow("Chat") </lua>

<lua> -- this can clear your whole main window - needs 2.0-test3+ clearWindow() </lua>

copy

copy([windowName])
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.
See Also: selectString(), selectCurrentLine()
Parameters
  • windowName:
Optional parameter to set the window from which to copy text.
Example

<lua> -- 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. selectString( line ) copy() appendBuffer("chat") replace("This line has been moved to the chat window!") </lua>

createBuffer

createBuffer(name)
Creates a named buffer for formatted text, much like a miniconsole, but the buffer is not intended to be shown on the screen - use it for formatting text or storing formatted text.
Parameters
  • name:
The name of the buffer to create.
Example

<lua> --This creates a named buffer called "scratchpad" createBuffer("scratchpad") </lua>

createButton

A similar function to createLabel() that is old and outdated - use createLabel() instead.

createConsole

createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)
Makes a new miniconsole which can be sized based upon the width of a 'W' character and the extreme top and bottom positions any character of the font should use. The background will be black, and the text color white.
Parameters
  • consoleName:
The name of your new miniconsole. Passed as a string.
  • fontSize:
The font size to use for the miniconsole. Passed as an integer number.
  • charsPerLine:
How many characters wide to make the miniconsole. Passed as an integer number.
  • numberOfLines:
How many lines high to make the miniconsole. Passed as an integer number.
  • Xpos:
X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.
  • Ypos:
Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.
Example

<lua> -- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide, -- 20 lines high, at coordinates 300x,400y createConsole("myConsoleWindow", 8, 80, 20, 200, 400) </lua>

Note Note: (For Mudlet Makers) This function is implemented outside the application's core via the GUIUtils.lua file of the Mudlet supporting Lua code using createMiniConsole() and other functions to position and size the mini-console and configure the font.

createGauge

createGauge(name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)
createGauge(name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)
Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.
See also: moveGauge(), setGauge(), setGaugeText()
Parameters
  • name:
The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.
  • width:
The width of the gauge, in pixels. Passed as an integer number.
  • height:
The height of the gauge, in pixels. Passed as an integer number.
  • Xpos:
X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.
  • Ypos:
Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.
  • gaugeText:
Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil
  • r:
The red component of the gauge color. Passed as an integer number from 0 to 255
  • g:
The green component of the gauge color. Passed as an integer number from 0 to 255
  • b:
The blue component of the gauge color. Passed as an integer number from 0 to 255
  • colorName:
the name of color for the gauge. Passed as a string.
  • orientation:
the gauge orientation. Can be horizontal, vertical, goofy, or batty.
Example

<lua> -- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green. -- The second example is using the same names you'd use for something like fg() or bg(). createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0) createGauge("healthBar", 300, 20, 30, 300, nil, "green")


-- If you wish to have some text on your label, you'll change the nil part and make it look like this: createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0) -- or createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green") </lua>

Note Note: If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back. <lua> echo("healthBar_back", "This is a test of putting text on the back of the gauge!") </lua>

createLabel

createLabel(name, Xpos, Ypos, width, height, fillBackground)
Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.
Returns true or false.
See also: hideWindow(), showWindow(), resizeWindow(), setLabelClickCallback(), setTextFormat(), setTextFormat(), setBackgroundColor(), getMainWindowSize(), calcFontSize()
Parameters
  • name:
The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.
  • Xpos:
X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.
  • Ypos:
Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.
  • width:
The width of the label, in pixels. Passed as an integer number.
  • height:
The height of the label, in pixels. Passed as an integer number.
  • fillBackground:
Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.
Example

<lua> --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 opaque) the background text can still be read through. 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", 255, 204, 0, 200)

echo("messageBox", [[

You are under attack!

]])

-- you can also make it react to clicks! mynamespace = {

 messageBoxClicked = function()
   echo("hey you've clicked the box!\n")
 end

}

setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")


-- uncomment code below to make it also hide after a short while -- tempTimer(2.3, hideWindow("messageBox") ) -- close the warning message box after 2.3 seconds </lua>

createMiniConsole

createMiniConsole(name, x, y, width, height)
Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc. Unlike labels, you cannot have transparency in them.
You can use clearWindow() / moveCursor() and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. setWindowWrap() will allow you to set word wrapping, and 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() functions.
Returns true or false.
See also: createLabel(), hideWindow(), showWindow(), resizeWindow(), setTextFormat(), moveWindow(), setMiniConsoleFontSize(), handleWindowResizeEvent(), setBorderTop(), setWindowWrap(), getMainWindowSize(), calcFontSize(), calcFontSize()
Parameters
  • name:
The name of the miniconsole. Must be unique. Passed as a string.
  • x, y, width, height
Parameters to set set the window size and location - in 2.1 and below it's best to set them via moveWindow() and resizeWindow(), as createMiniConsole() will only set them once. Starting with 3.0, however, that is fine and calling createMiniConsole() will re-position your miniconsole appropriately.
Example

<lua> -- first, determine the size of your screen local windowWidth, windowHeight = getMainWindowSize()

-- create the miniconsole createMiniConsole("sys", windowWidth-650,0,650,300) setBackgroundColor("sys",255,69,0,255) setMiniConsoleFontSize("sys", 8) -- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example setWindowWrap("sys", 40)

echo("sys","Hello world!\n") cecho("sys", "<:OrangeRed>This is random spam with the same background\n") cecho("sys", "<blue:OrangeRed>and this is with a blue foreground. ") cecho("sys", "<bisque:BlueViolet>Lastly, this is with both a foreground and a background.\n") </lua>

Note Note: (For Mudlet Makers) As mentioned above for version 3.0 this function is overridden outside the application's core via the LuaGlobal.lua file of the Mudlet supporting Lua code to repeat the setting of position and size of the mini-console in the case of the internal version failing to do so for a mini-console that already exists.

decho

decho ([name of console,] text)
Color changes can be made using the format <FR,FG,FB:BR,BG,BB> where each field is a number from 0 to 255. The background portion can be omitted using <FR,FG,FB> or the foreground portion can be omitted using <:BR,BG,BB>. Arguments 2 and 3 set the default fore and background colors for the string using the same format as is used within the string, sans angle brackets, e.g. decho("<50,50,0:0,255,0>test").
Parameters
  • text:
The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.
  • name of console
Optional name of the console to echo to. Defaults to main.
Example

<lua> decho("<50,50,0:0,255,0>test")

decho("miniconsolename", "<50,50,0:0,255,0>test") </lua>

dechoLink

dechoLink([windowName], text, command, hint, true)
Echos a piece of text as a clickable link, at the end of the current selected line - similar to decho(). This version allows you to use colours within your link text.
Parameters
  • windowName:
optional parameter, allows selection between sending the link to a miniconsole or the main window.
  • text:
text to display in the echo. Same as a normal decho().
  • 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.
  • true:
requires argument for the colouring to work.
Example

<lua> -- echo a link named 'press me!' that'll send the 'hi' command to the game dechoLink("<50,50,0:0,255,0>press me!", send("hi"), "This is a tooltip", true) </lua>

deleteLine

deleteLine([optional windowName])
Deletes the current line under the user cursor. This is a high speed gagging tool and is very good at this task, but is only meant to be use when a line should be omitted entirely in the output. If you echo() to that line it will not be shown, and lines deleted with deleteLine() are simply no longer rendered.
See Also: replace(), wrapLine()

Note Note: you do not need to put anything between () - it just deletes the line it is used on.

Note Note: for replacing text, replace() is the proper option; doing the following: selectCurrentLine(); replace(""); cecho("new line!\n") is better.

Example

<lua> -- deletes the line - just put this command into the big script box. Keep the case the same - -- it has to be deleteLine(), not Deleteline(), deleteline() or anything else deleteLine()

--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely. --This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window --Note: isPrompt() only works on servers which send a GA signal with their prompt. tempLineTrigger(1, 1, if isPrompt() then deleteLine() end)

-- example of deleting multiple lines: deleteLine() -- delete the current line moveCursor(0,getLineNumber()-1) -- move the cursor back one line deleteLine() -- delete the previous line now </lua>

deselect

deselect([optional window name])
This is used to clear the current selection (to no longer have anything selected). Should be used after changing the formatting of text, to keep from accidentally changing the text again later with another formatting call.
Parameters
  • name:
The name of the buffer/miniConsole to stop having anything selected in. This is an optional argument, if name is not provided the main window will have its selection cleared.
Example

<lua> --This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further --changes from effecting this line as well. selectCurrentLine() bg("red") deselect() </lua>

echoLink

echoLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])
Echos a piece of text as a clickable link, at the end of the current selected line - similar to echo().
Parameters
  • text:
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.
  • window:
if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.
Example

<lua> -- echo a link named 'press me!' that'll send the 'hi' command to the game echoLink("press me!", send("hi"), "This is a tooltip")

-- do the same, but send this link to a miniConsole echoLink("my miniConsole", "press me!", send("hi"), "This is a tooltip") </lua>

echoUserWindow

echoUserWindow(windowName)
This function will print text to both mini console windows, dock windows and labels. It is outdated however - echo() instead.

echoPopup

echoPopup([window], text, {commands}, {hints}, [current or default format])
Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like echo. The added 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.
Parameters
  • window:
Optional - the window to echo to - use either main or omit for the main window, or the miniconsoles name otherwise.
  • name:
the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.
  • {lua code}:
a table of lua code strings to do. ie, <lua>{send("hello"), echo("hi!"}</lua>
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, <lua>{"send the hi command", "echo hi to yourself"}</lua>
  • current or default format:
a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example

<lua> -- Create some text as a clickable with a popup menu: echoPopup("activities to do", {send "sleep", send "sit", send "stand"}, {"sleep", "sit", "stand"}) </lua>

fg

fg([window, ]colorName)
If used on a selection, sets the foreground color to colorName - otherwise, it will set the color of the next text-inserting calls (echo(), insertText, echoLink(), and others)
See Also: bg(), setBgColor()
Parameters
  • window:
The MiniConsole to operate on - optional. If you'd like it to work on the main window, don't specify anything or use main (since Mudlet 3.0).
  • colorName:
The name of the color to set the foreground to - list of possible names: Color Table
Example

<lua> --This would change the color of the text on the current line to green selectCurrentLine() fg("green") resetFormat()

--This will echo red, green, blue in their respective colors fg("red") echo("red ") fg("green") echo("green ") fg("blue") echo("blue ") resetFormat()

-- example of working on a miniconsole fg("my console", "red") echo("my console", "red text") </lua>

getBgColor

getBgColor(windowName)
This function returns the rgb values of the background color of the first character of the current selection on mini console (window) windowName. If windowName is omitted Mudlet will use the main screen.
Parameters
  • windowName:
A window to operate on - either a miniconsole or the main window.
Example

<lua> local r,g,b; selectString("troll",1) r,g,b = getBgColor() if r == 255 and g == 0 and b == 0 then

   echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");

end </lua>

getColorWildcard

getColorWildcard(ansi color number)
This function, given an ANSI color number (list), will return all strings on the current line that match it.
Parameters
  • ansi color number:
A color number (list) to match.
Example

<lua> -- we can run this script on a line that has the players name coloured differently to easily capture it from -- anywhere on the line local match = getColorWildcard(14)

if match then

 echo("\nFound "..match.."!")

else

 echo("\nDidn't find anyone.")

end </lua>

getColumnNumber

getColumnNumber([window])
Gets the absolute column number of the current user cursor.
Parameters
  • window:
The minoconsole to operate on - optional. If you'd like it to work on the main window, don't specify anything.

Note Note: the window argument is available in Mudlet 3.0.

Example

<lua> HelloWorld = Geyser.MiniConsole:new({

 name="HelloWorld",
 x="70%", y="50%",
 width="30%", height="50%",

})

HelloWorld:echo("hello!\n") HelloWorld:echo("hello!\n") HelloWorld:echo("hello!\n")

moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld")) -- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))

moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld")) -- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld"))) </lua>

getCurrentLine

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.
Example

<lua> print("Currently selected line: "..getCurrentLine()) </lua>

getFgColor

getFgColor(windowName)
This function returns the rgb values of the color of the first character of the current selection on mini console (window) windowName. If windowName is omitted Mudlet will use the main screen.
Parameters
  • windowName:
A window to operate on - either a miniconsole or the main window.
Example

<lua> 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 </lua>

getLastLineNumber

getLastLineNumber(window)
Returns the latest line's number in the main window or the miniconsole. This could be different from getLineNumber() if the cursor was moved around.
Parameters
  • window:
The window to use - either use main for the main window, or the miniconsoles name.
Example

<lua> -- get the latest line's # in the buffer local latestline = getLastLineNumber("main") </lua>


getLineCount

getLineCount()
Gets the absolute amount of lines in the current console buffer
Parameters
None
Example

Need example

getLines

getLines(from_line_number, to_line_number)
Returns a section of the content of the screen text buffer. Returns a Lua table with the content of the lines on a per line basis. The form value is result = {relative_linenumber = line}.
Absolute line numbers are used.
Parameters
  • from_line_number:
First line number
  • to_line_number:
End line number
Example

<lua> -- retrieve & echo the last line: echo(getLines(getLineNumber()-1, getLineNumber())[1]) </lua>

<lua> -- find out which server and port you are connected to (as per Mudlet settings dialog): local t = getLines(0, getLineNumber())

local server, port

for i = 1, #t do

 local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")
 if s then server, port = s, p break end

end

display(server) display(port) </lua>

getLineNumber

getLineNumber([window])
Returns the absolute line number of the current user cursor (the y position). The cursor by default is on the current line the triggers are processing - which you can move around with moveCursor() and moveCursorEnd(). This function can come in handy in combination when using with moveCursor() and getLines().
Parameters
  • window:
The miniconsole to operate on - optional. If you'd like it to work on the main window, don't specify anything.

Note Note: the window argument is available in Mudlet 3.0.

Example

<lua> -- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end

-- check how many lines you've got in your miniconsole after echoing some text. -- Note the use of moveCursorEnd() to update getLineNumber()'s output HelloWorld = Geyser.MiniConsole:new({

 name="HelloWorld",
 x="70%", y="50%",
 width="30%", height="50%",

})

print(getLineNumber("HelloWorld"))

HelloWorld:echo("hello!\n") HelloWorld:echo("hello!\n") HelloWorld:echo("hello!\n")

-- update the cursors position, as it seems to be necessary to do moveCursorEnd("HelloWorld") print(getLineNumber("HelloWorld")) </lua>

getMainConsoleWidth

getMainConsoleWidth()
Returns a single number; the width of the main console (MUD output) in pixels.
Parameters
None
Example

<lua> -- Save width of the main console to a variable for future use. consoleWidth = getMainConsoleWidth() </lua>

getMousePosition

getMousePosition()
Returns the x and y coordinates of the mouse's position, relative to the Mudlet window itself.
Parameters
None

Note Note: This command is present in the development code branch at GitHub repository and is to be included sometime after the release of 3.0.0.

Example

<lua> -- Retrieve x and y position of the mouse to determine where to create a new label, then use that position to create a new label local x, y = getMousePosition() createLabel("clickGeneratedLabel", x, y, 100, 100, 1) </lua>

hasFocus

hasFocus()
Returns true or false depending if Mudlet's main window is currently in focus (ie, the user isn't focused on another window, like a browser). This can be useful for determining whenever your script should call for attention or not, for example.
Parameters
None
Example

<lua> if attacked and not hasFocus() then

 runaway()

else

 fight()

end </lua>

getMainWindowSize

getMainWindowSize()
Returns two numbers, the width and height in pixels.
Parameters
None
Example

<lua> --this will get the size of your main mudlet window and save them --into the variables mainHeight and mainWidth mainWidth, mainHeight = getMainWindowSize() </lua>

getStopWatchTime

getStopWatchTime(watchID)
Returns the time (milliseconds based) in form of 0.058 (= clock ran for 58 milliseconds before it was stopped). Please note that after the stopwatch is stopped, retrieving the time will not work - it's only valid while it is running.
See also: createStopWatch()
Returns a number
Parameters
  • watchID
The ID number of the watch.
Example

<lua> -- an example of showing the time left on the stopwatch teststopwatch = teststopwatch or createStopWatch() startStopWatch(teststopwatch) echo("Time on stopwatch: "..getStopWatchTime(teststopwatch)) tempTimer(1, echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))) tempTimer(2, echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))) stopStopWatch(teststopwatch) </lua>

handleWindowResizeEvent

handleWindowResizeEvent()
(depreciated) This function is depreciated and should not be used; it's only documented here for historical reference - use the sysWindowResizeEvent event instead.

The standard implementation of this function does nothing. However, this function gets called whenever the main window is being manually resized. You can overwrite this function in your own scripts to handle window resize events yourself and e. g. adjust the screen position and size of your mini console windows, labels or other relevant GUI elements in your scripts that depend on the size of the main Window. To override this function you can simply put a function with the same name in one of your scripts thus overwriting the original empty implementation of this.

Parameters
None
Example

<lua> function handleWindowResizeEvent()

  -- determine the size of your screen
  WindowWidth=0;
  WindowHeight=0;
  WindowWidth, WindowHeight = getMainWindowSize();
  -- move mini console "sys" to the far right side of the screen whenever the screen gets resized
  moveWindow("sys",WindowWidth-300,0)

end </lua>

hasFocus

hasFocus()
Returns true or false depending on if the main Mudlet window is in focus. By focus, it means that the window is selected and you can type in the input line and etc. Not in focus means that the window isn’t selected, some other window is currently in focus.
Parameters
None
Example

Need example

hecho

hecho(window, text)
Echoes text that can be easily formatted with colour tags in the hexadecimal format.
See Also: decho(), cecho()
Parameters
  • window:
Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.
  • text:
The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB where FR is the foreground red value, FG is the foreground green value, FB is the foreground blue value, BR is the background red value, etc., BRBGBB is optional. |r can be used within the string to reset the colors to default.
Example

<lua> hecho("|ca00040black!") </lua>

hechoLink

hechoLink([windowName], text, command, hint, true)
Echos a piece of text as a clickable link, at the end of the current selected line - similar to hecho(). This version allows you to use colours within your link text.
Parameters
  • windowName:
optional parameter, allows selection between sending the link to a miniconsole or the main window.
  • text:
text to display in the echo. Same as a normal hecho().
  • 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.
  • true:
requires argument for the colouring to work.
Example

<lua> -- echo a link named 'press me!' that'll send the 'hi' command to the game hechoLink("|ca00040black!", send("hi"), "This is a tooltip", true) </lua>

hideToolBar

hideToolBar(name)
Hides the toolbar with the given name name and makes it disappear. If all toolbars of a tool bar area (top, left, right) are hidden, the entire tool bar area disappears automatically.
Parameters
  • name:
name of the button group to display
Example

<lua> hideToolBar("my offensive buttons") </lua>

hideWindow

hideWindow(name)
This function hides a mini console label. To show it again, use showWindow().
See also: createMiniConsole(), createLabel()
Parameters
None
Example

Need example

insertLink

insertLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])
Inserts a piece of text as a clickable link at the current cursor position - similar to insertText().
Parameters
  • text:
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.
  • window:
if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.
Example

<lua> -- link with the default blue on white colors insertLink("hey, click me!", echo("you clicked me!\n"), "Click me popup")

-- use current cursor colors by adding true at the end fg("red") insertLink("hey, click me!", echo("you clicked me!\n"), "Click me popup", true) resetFormat() </lua>

insertPopup

insertPopup([windowName], text, {commands}, {hints}, [current or default format])
Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to insertText(). The inserted 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.
Parameters
  • window:
Optional - the window to echo to - use either main or omit for the main window, or the miniconsoles name otherwise.
  • name:
the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.
  • {lua code}:
a table of lua code strings to do. ie, <lua>{send("hello"), echo("hi!"}</lua>.
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, <lua>{"send the hi command", "echo hi to yourself"}</lua>.
  • current or default format:
a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example

<lua> -- Create some text as a clickable with a popup menu: insertPopup("activities to do", {send "sleep", send "sit", send "stand"}, {"sleep", "sit", "stand"}) </lua>

insertText

insertText([optional windowName], text)
Inserts text at cursor postion in window - unlike echo(), which inserts the text at the end of the last line in the buffer (typically the one being processed by the triggers). You can use moveCursor() to move the cursor into position first.
insertHTML() also does the same thing as insertText, if you ever come across it.
See also: cinsertText()
Parameters
  • window:
The window to insert the text to.
  • text:
The text you will insert into the current cursor position.
Example

<lua> -- move the cursor to the end of the previous line and insert some text

-- move to the previous line moveCursor(0, getLineNumber()-1) -- move the end the of the previous line moveCursor(#getCurrentLine(), getLineNumber())

fg("dark_slate_gray") insertText(' <- that looks nice.')

deselect() resetFormat() moveCursorEnd() </lua>

ioprint

ioprint(text, some more text, ...)
Prints text to the to the stdout. This is only available if you launched Mudlet from cmd.exe on Windows, from the terminal on Mac, or from the terminal on a Linux OS (launch the terminal program, type mudlet and press enter).

Similar to echo(), but does not require a "\n" at the end for a newline and can print several items given to it. It cannot print whole tables. This function works similarly to the print() you will see in guides for Lua.

This function is useful in working out potential crashing problems with Mudlet due to your scripts - as you will still see whatever it printed when Mudlet crashes.

Parameters
  • text:
The information you want to display.
Example

<lua> ioprint("hi!") ioprint(1,2,3) ioprint(myvariable, someothervariable, yetanothervariable) </lua>

isAnsiBgColor

isAnsiBgColor(ansiBgColorCode)
This function tests if the first character of the current selection has the background color specified by ansiBgColorCode.
Parameters
  • ansiBgColorCode:
A color code to test for, possible codes are:

<lua> 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 </lua>

Example

<lua> selectString( matches[1], 1 ) if isAnsiBgColor( 5 ) then

   bg("red");
   resetFormat();
   echo("yes, the background of the text is light green")

else

   echo( "no sorry, some other backgroundground color" )

end </lua>

Note Note: 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.

isAnsiFgColor

isAnsiFgColor(ansiFgColorCode)
This function tests if the first character of the current selection has the foreground color specified by ansiFgColorCode.
Parameters
  • ansiFgColorCode:
A color code to test for, possible codes are:

<lua> 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 </lua>

Example

<lua> 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 </lua>

Note Note: 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.

lowerWindow

lowerWindow(labelName)
Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: raiseWindow().
Parameters
  • labelName: the name of the label/console you wish to move below the rest.

Note Note: This command is present in the development code branch at GitHub repository and is to be included sometime after the release of 3.0.0.

Example

<lua> createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label setBackgroundColor("blueLabel", 50, 50, 250, 255)

createLabel("redLabel", 350, 350, 100, 100, 1) --creates a red label which is placed on TOP of the blue label, as the last made label will sit at the top of the rest setBackgroundColor("redLabel", 250, 50, 50, 255)

lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top </lua>

moveCursor

moveCursor([optional windowName], x, y)
Moves the user cursor of the window windowName, or the main window, 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.
Returns true or false depending on if the cursor was moved to a valid position. Check this before doing further cursor operations - because things like deleteLine() might invalidate this.
Parameters
  • windowName:
The window you are going to move the cursor in.
  • x:
The horizontal axis in the window - that is, the letter position within the line.
  • y:
The vertical axis in the window - that is, the line number.
Example

<lua> -- move cursor to the start of the previous line and insert -<( -- the first 0 means we want the cursor right at the start of the line, -- and getLineNumber()-1 means we want the cursor on the current line# - 1 which -- equals to the previous line moveCursor(0, getLineNumber()-1) insertText("-<(")

-- now we move the cursor at the end of the previous line. Because the -- cursor is on the previous line already, we can use #getCurrentLine() -- to see how long it is. We also just do getLineNumber() because getLineNumber() -- returns the current line # the cursor is on moveCursor(#getCurrentLine(), getLineNumber()) insertText(")>-")

-- finally, reset it to the end where it was after our shenaningans - other scripts -- could expect the cursor to be at the end moveCursorEnd() </lua>

<lua> -- a more complicated example showing how to work with Mudlet functions

-- set up the small system message window in the top right corner -- determine the size of your screen local 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<this line is to be deleted>\n<this line is to be deleted also>\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") </lua>

moveCursorEnd

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.
See Also: moveCursor()
Returns true or false
Parameters
  • windowName:
The name of your user window.
Example

Need example

moveGauge

moveGauge(gaugeName, newX, newY)
Moves a gauge created with createGauge to the new x,y coordinates. Remember the coordinates are relative to the top-left corner of the output window.
Parameters
  • gaugeName:
The name of your gauge
  • newX:
The horizontal pixel location
  • newY:
The vertical pixel location
Example

<lua> -- This would move the health bar gauge to the location 1200, 400 moveGauge("healthBar", 1200, 400) </lua>

moveWindow

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 → 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.
See Also: createMiniConsole(), createLabel(), handleWindowResizeEvent(), resizeWindow(), setBorderTop()
Parameters
  • name:
The name of your winow
  • newX:
The horizontal pixel location
  • newY:
The vertical pixel location

openUserWindow

openUserWindow(name)
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 (even to a different screen on a system with a multi-screen display), dock them on any of the four sides of the main application window, make them into notebook tabs or float them. Note that they do currently have a bug in a sense that they will inherit your main windows borders. The windows position cannot be adjusting via scripting yet at the moment, and the layout won't be remembered next time Mudlet is open.
Parameters
  • name: The name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).
Examples

<lua> openUserWindow("My floating window") cecho("My floating window", "<red>hello <blue>bob!") </lua>

paste

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:
The name of your window

pasteUserWindow

pasteUserWindow(windowName)
Need description here
Parameters
  • windowName:
The name of your window

prefix

prefix(text)
Prefixes text at the beginning of the current line when used in a trigger.
Parameters
  • text:
The information you want to prefix
Example

<lua> -- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that prefix(os.date("%H:%M:%S ")) </lua>

print

print(text, some more text, ...)
Prints text to the main window. Similar to echo(), but does not require a "\n" at the end for a newline and can print several items given to it. It cannot print whole tables - use display() for those. This function works similarly to the print() you will see in guides for Lua.
Parameters
  • text:
The information you want to display.
Example

<lua> print("hi!") print(1,2,3) print(myvariable, someothervariable, yetanothervariable) </lua>

print

print(text, some more text, ...)
Prints text to the main window. Similar to echo(), but does not require a "\n" at the end for a newline and can print several items given to it. It cannot print whole tables - use display() for those. This function works similarly to the print() you will see in guides for Lua.
Parameters
  • text:
The information you want to display.
Example

<lua> print("hi!") print(1,2,3) print(myvariable, someothervariable, yetanothervariable) </lua>

raiseWindow

raiseWindow([labelName])
Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: lowerWindow().
Parameters
  • labelName: the name of the label/console you wish to bring to the top of the rest.

Note Note: This command is present in the development code branch at GitHub repository and is to be included sometime after the release of 3.0.0.

Example

<lua> createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label setBackgroundColor("blueLabel", 50, 50, 250, 255)

createLabel("redLabel", 350, 350, 100, 100, 1) --creates a red label which is placed on TOP of the bluewindow, as the last made label will sit at the top of the rest setBackgroundColor("redLabel", 250, 50, 50, 255)

raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel </lua>

replace

replace([windowName,] with[, keepcolor])
Replaces the currently selected text with the new text. To select text, use selectString(), selectSection() or a similar function.

Note Note: If you’d like to delete/gag the whole line, use deleteLine() instead.

Note Note: when used outside of a trigger context (for example, in a timer instead of a trigger), replace() won't trigger the screen to refresh. Instead, use replace("") and insertText("new text") as insertText() does.

Parameters
  • windowName: optional name of window (a miniconsole)
  • with: the new text to display.
  • keepcolor: available in 3.0, setting this to true will keep the existing colors.
Example

<lua> -- replace word "troll" with "cute trolly" selectString("troll",1) replace("cute trolly")

-- replace the whole line selectCurrentLine() replace("Out with the old, in with the new!") </lua>

replaceAll

replaceAll( what, with )
Replaces all occurrences of what in the current line with with.
Parameters
  • what: the text to replace
  • with: the new text to have in place
Examples

<lua> -- replace all occurrences of the word "south" in the line with "north" replaceAll("south", "north") </lua>

<lua> -- replace all occurrences of the text that the variable "target" has replaceAll(target, "The Bad Guy") </lua>

resizeWindow

resizeWindow(name,width,height)
Resizes a mini console or label
See also: createMiniConsole(), createLabel(), handleWindowResizeEvent(), resizeWindow(), setBorderTop()

selectCaptureGroup

selectCaptureGroup(groupNumber)
Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.
Example
Perl Reqular expression e.g. "you have (\d+) Euro".

<lua> --If you want to color the amount of money you have green you do:

selectCaptureGroup(1) setFgColor(0,255,0) </lua>

selectSection

selectSection(from, how long)
Selects the specified parts of the line starting from the left and extending to the right for however how long. The line starts from 0.
Returns true if the selection was successful, and false if the line wasn't actually long enough or the selection couldn't be done in general.
Example

<lua> -- select and colour the first character in the line red if selectSection(0,1) then fg("red") end

-- select and colour the second character green (start selecting from the first character, and select 1 character) if selectSection(1,1) then fg("green") end

-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long) if selectSection(2,3) then fg("grey") end </lua>

selectString

selectString( [windowName], text, number_of_match )
Selects a substring from the line where the user cursor is currently positioned - allowing you to edit selected text (apply colour, make it be a link, copy to other windows or other things).

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
  • windowName:
Optional parameter to set the window in which to select text.
  • text:
The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).
  • number_of_match:
The occurrence of text on the line that you'd like to select. For example, if the line was "Bob and Bob", 1 would select the first Bob, and 2 would select the second Bob.
Returns position in line or -1 on error (text not found in line)

Note Note: To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:

<lua>if selectString( "big monster", 1 ) > -1 then fg("red") end</lua>

setBgColor

setBgColor([windowName], r,g,b )
Sets the current text background color in the main window unless windowName parameter given. If you have selected text prior to this call, the selection will be highlighted 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.

See also: cecho()

Parameters
  • windowName:
Optional parameter set the current text background color in windowname given.
  • r:
The red component of the gauge color. Passed as an integer number from 0 to 255
  • g:
The green component of the gauge color. Passed as an integer number from 0 to 255
  • b:
The blue component of the gauge color. Passed as an integer number from 0 to 255
Example

<lua> --highlights the first occurrence of the string "Tom" in the current line with a red background color. selectString( "Tom", 1 ) setBgColor( 255,0,0 ) </lua> <lua> --prints "Hello" on red background and "You" on blue. setBgColor(255,0,0) echo("Hello") setBgColor(0,0,255) echo(" You!") resetFormat() </lua>

setBold

setBold(windowName, boolean)
Sets the current text font to bold (true) or non-bold (false) mode. If the windowName parameters omitted, the main screen will be used. If you've got text currently selected in the Mudlet buffer, then the selection will be bolded. Any text you add after with echo() or insertText() will be bolded until you use resetFormat().
  • windowName:
Optional parameter set the current text background color in windowname given.
  • boolean:
A true or false that enables or disables bolding of text
Example

<lua> -- enable bold formatting setBold(true) -- the following echo will be bolded echo("hi") -- turns off bolding, italics, underlines and colouring. It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes. resetFormat() </lua>

setFgColor

setFgColor([windowName],r, g, b)
Sets the current text foreground color in the main window unless windowName parameter given.
  • windowName:
Optional parameter set the current text background color in windowname given.
  • r:
The red component of the gauge color. Passed as an integer number from 0 to 255
  • g:
The green component of the gauge color. Passed as an integer number from 0 to 255
  • b:
The blue component of the gauge color. Passed as an integer number from 0 to 255
Example

<lua> --highlights the first occurrence of the string "Tom" in the current line with a red foreground color. selectString( "Tom", 1 ) setFgColor( 255,0,0 ) </lua>

setGauge

setGauge(gaugeName, currentValue, maxValue, gaugeText)
Use this function when you want to change the gauges look according to your values. Typical usage would be in a prompt with your current health or whatever value, and throw in some variables instead of the numbers.
Example

<lua> --Change the looks of the gauge named healthBar and make it --fill to half of its capacity. The height is always remembered. setGauge("healthBar", 200, 400) </lua>

<lua> --If you wish to change the text on your gauge, you’d do the following: setGauge("healthBar", 200, 400, "some text") </lua>

setGaugeStyleSheet

setGaugeStyleSheet(gaugeName, css, cssback, csstext)
Sets the CSS stylesheets on a gauge - one on the front (the part that resizes accoding to the values on the gauge) and one in the back.
Example

<lua> setGaugeStyleSheet("hp_bar", [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f04141, stop: 0.1 #ef2929, stop: 0.49 #cc0000, stop: 0.5 #a40000, stop: 1 #cc0000); border-top: 1px black solid; border-left: 1px black solid; border-bottom: 1px black solid; border-radius: 7; padding: 3px;]], [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #bd3333, stop: 0.1 #bd2020, stop: 0.49 #990000, stop: 0.5 #700000, stop: 1 #990000); border-width: 1px; border-color: black; border-style: solid; border-radius: 7; padding: 3px;]]) </lua>

setItalics

setItalics(windowName, bool)
Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.

setMiniConsoleFontSize

setMiniConsoleFontSize(name, fontSize)

Sets the font size of the mini console. see also: createMiniConsole(), createLabel()

setTextFormat

setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics)
Sets current text format of window windowName: foreground color(r1,g1,b1), background color(r2,g2,b2), bold(1/0), underline(1/0), italics(1/0) A more convenient way to control the text format in a mini console is to use setFgColor( windowName, r,g,b ), setBold( windowName, true ), setItalics( windowName, true ), setUnderline( windowName, true ) etc. → createMiniConsole, setBold, setBgColor, setFgColor, setItalics, setUnderline
Example

<lua> --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") </lua>

setUnderline

setUnderline(windowName, bool)
Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.

setWindowWrap

setWindowWrap(windowName, wrapAt)
sets at what position in the line the console or miniconsole will start word wrap

showCaptureGroups

showCaptureGroups()
Lua debug function that highlights in random coolors all capture groups in your trigger regex on the screen. This is very handy if you make complex regex and want to see what really matches in the text. This function is defined in LuaGlobal.lua.
Example
Make a trigger with the regex (\w+) and call this function in a trigger. All words in the text will be highlighted in random colors.

showMultimatches

showMultimatches()
Lua helper function to show you what the table multimatches[n][m] contains. This is very useful when debugging multiline triggers - just doing showMultimatches() in your script will make it give the info.

showWindow

showWindow(name)
Makes a hidden window (label or miniconsole) be shown again.
See also: hideWindow()

suffix

suffix(text)
Suffixes text at the end of the current line. This is similar to echo(), which also suffixes text at the end of the line, but different - echo() makes sure to do it on the last line in the buffer, while suffix does it on the line the cursor is currently on.
See also: prefix(), echo()

replaceWildcard

replaceWildcard(which, replacement)
Replaces the given wildcard (as a number) with the given text. Equivalent to doing:

<lua> selectString(matches[2], 1) replace("text") </lua>

Parameters
  • which:
Wildcard to replace.
  • replacement:
Text to replace the wildcard with.
Example

<lua> replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello </lua>

resetFormat

resetFormat()
Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.
Parameters
None
Example

<lua> -- select and set the 'Tommy' to red in the line if selectString("Tommy", 1) ~= -1 then fg("red") end

-- now reset the formatting, so our echo isn't red resetFormat() echo(" Hi Tommy!")

-- another example: just highlighting some words for _, word in ipairs{"he", "she", "her", "their"} do

 if selectString(word, 1) ~= -1 then
   bg("blue")
 end

end resetFormat() </lua>

selectCurrentLine

selectCurrentLine([windowName])
Selects the content of the current line that the cursor at. By default, the cursor is at the start of the current line that the triggers are processing, but you can move it with the moveCursor() function. Note Note: This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower selectString(line, 1) selection method.
See Also: selectString(), getCurrentLine()
Parameters
  • windowName:
Optional parameter to set the window in which to select text.
Example

<lua> -- color the whole line green! selectCurrentLine() fg("green") deselect() resetFormat() </lua>

setAppStyleSheet

setAppStyleSheet(stylesheet)
Sets a stylesheet for the entire Mudlet application - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on).
Parameters
  • stylesheet:
The entire stylesheet you'd like to use.
References
See Qt Style Sheets Reference for the list of widgets you can style and CSS properties you can apply on them.
See also QDarkStyleSheet, a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an mpackage here.

Note Note: Available since Mudlet 3.0.

Example

<lua> -- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770 local background_color = "#26192f" local border_color = "#b8731b"

setAppStyleSheet([[

 QMainWindow {
    background: ]]..background_color..[[;
 }
 QToolBar {
    background: ]]..background_color..[[;
 }
 QToolButton {
    background: ]]..background_color..[[;
    border-style: solid;
    border-width: 2px;
    border-color: ]]..border_color..[[;
    border-radius: 5px;
    font-family: BigNoodleTitling;
    color: white;
    margin: 2px;
    font-size: 12pt;
 }
 QToolButton:hover { background-color: grey;}
 QToolButton:focus { background-color: grey;}
 QTreeView {
    background: ]]..background_color..[[;
    color: white;
 }
 QMenuBar{ background-color: ]]..background_color..[[;}
 QMenuBar::item{ background-color: ]]..background_color..[[;}
 QDockWidget::title {
    background: ]]..border_color..[[;
 }
 QStatusBar {
    background: ]]..border_color..[[;
 }
 QScrollBar:vertical {
    background: ]]..background_color..[[;
    width: 15px;
    margin: 22px 0 22px 0;
 }
 QScrollBar::handle:vertical {
    background-color: ]]..background_color..[[;
    min-height: 20px;
    border-width: 2px;
    border-style: solid;
    border-color: ]]..border_color..[[;
    border-radius: 7px;
 }
 QScrollBar::add-line:vertical {
  background-color: ]]..background_color..[[;
  border-width: 2px;
  border-style: solid;
  border-color: ]]..border_color..[[;
  border-bottom-left-radius: 7px;
  border-bottom-right-radius: 7px;
       height: 15px;
       subcontrol-position: bottom;
       subcontrol-origin: margin;
 }
 QScrollBar::sub-line:vertical {
  background-color: ]]..background_color..[[;
  border-width: 2px;
  border-style: solid;
  border-color: ]]..border_color..[[;
  border-top-left-radius: 7px;
  border-top-right-radius: 7px;
       height: 15px;
       subcontrol-position: top;
       subcontrol-origin: margin;
 }
 QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
    background: white;
    width: 4px;
    height: 3px;
 }
 QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
    background: none;
 }

]])

-- if you'd like to reset it, use: setAppStyleSheet("") </lua>

Also available as a one-line install - copy/paste this into Mudlet:

lua function downloaded_package(a,b)if not b:find("dark",1,true)then return end installPackage(b)os.remove(b)end registerAnonymousEventHandler("sysDownloadDone","downloaded_package")downloadFile(getMudletHomeDir().."/dark.mpackage","http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip")

setBackgroundColor

setBackgroundColor(labelName, 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 0 to 255 (0 being completely transparent).

Note Note: Transparency only works on labels, not miniConsoles for efficiency reasons.

Parameters
  • labelName:
The name of the label to change it's background color.
  • red:
Amount of red to use, from 0 (none) to 255 (full).
  • green:
Amount of green to use, from 0 (none) to 255 (full).
  • blue:
Amount of red to use, from 0 (none) to 255 (full).
  • transparency:
Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).
Example

<lua> -- make a red label that's somewhat transparent setBackgroundColor("some label",255,0,0,200) </lua>

setBackgroundImage

setBackgroundImage(labelName, imageLocation)
Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with setLabelClickCallback() and such.
Note you can only do this for labels, not miniconsoles.
Note you can also load images via setLabelStyleSheet().
Parameters
  • labelName:
The name of the label to change it's background color.
  • imageLocation:
The full path to the image location. It's best to use [[ ]] instead of "" for it - because for Windows paths, backslashes need to be escaped.
Example

<lua> -- give the top border a nice look setBackgroundImage("top bar", /home/vadi/Games/Mudlet/games/top_bar.png) </lua>

setBorderBottom

setBorderBottom(size)
Sets the size of the bottom border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
See Also: setBorderColor()
Parameters
  • size:
Height of the border in pixels - with 0 indicating no border.
Example

<lua> setBorderLeft(100) </lua>

setBorderColor

setBorderColor(r,g,b)
Sets the color of the main windows border that you can create either with setBorderTop(), setBorderBottom(), setBorderLeft(), setBorderRight(), or via the main window settings.
See Also: setBorderTop(), setBorderBottom(), setBorderLeft(), setBorderRight()
Parameters
  • r:
Amount of red to use, from 0 to 255.
  • g:
Amount of green to use, from 0 to 255.
  • b:
Amount of blue to use, from 0 to 255.
Example

<lua> -- set the border to be completely blue setBorderColor(0, 0, 255)

-- or red, using a name setBorderColor( unpack(color_table.red) ) </lua>

setBorderLeft

setBorderLeft(size)
Sets the size of the left border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
See Also: setBorderColor()
Parameters
  • size:
Width of the border in pixels - with 0 indicating no border.
Example

<lua> setBorderLeft(100) </lua>

setBorderRight

setBorderRight(size)
Sets the size of the right border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
See Also: setBorderColor()
Parameters
  • size:
Width of the border in pixels - with 0 indicating no border.
Example

<lua> setBorderRight(100) </lua>

setBorderTop

setBorderTop(size)
Sets the size of the top border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
See Also: setBorderColor()
Parameters
  • size:
Height of the border in pixels - with 0 indicating no border.
Example

<lua> setBorderTop(100) </lua>

setLabelClickCallback

setLabelClickCallback(labelName, luaFunctionName, optional any amount of arguments)
Specifies a Lua function to be called if the user clicks on the label/image. This function can 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.
See Also: setLabelReleaseCallback(), setLabelOnEnter(), setLabelOnLeave()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string.
  • optional any amount of arguments:
Optional arguments you'd like to pass to the calling function.
Example

<lua> function onClickGoNorth()

 echo("the north button was clicked!")

end

setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )

-- you can also use them within tables now: mynamespace = {

 onClickGoNorth = function()
   echo("the north button was clicked!")
 end

}

setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" ) </lua>

setLabelReleaseCallback

setLabelReleaseCallback(labelName, luaFunctionName, optional any amount of arguments)
Specifies a Lua function to be called when a mouse click ends that originated on the specified label/console. This function is called even if you drag the mouse off of the label/console before releasing the click. This function can 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.
See Also: setLabelClickCallback(), setLabelOnEnter(), setLabelOnLeave()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string.
  • optional any amount of arguments:
Optional arguments you'd like to pass to the calling function.

Note Note: This command is present in the development code branch at GitHub repository and is to be included sometime after the release of 3.0.0.

Example

<lua> function onReleaseNorth()

 echo("the north button was released!")

end

setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )

-- you can also use them within tables: mynamespace = {

 onReleaseNorth = function()
   echo("the north button was released!")
 end

}

setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" ) </lua>

setLabelOnEnter

setLabelClickCallback(labelName, luaFunctionName, optional any amount of arguments)
Specifies a Lua function to be called when the mouse enters within the labels borders. This function can 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.
See Also: setLabelClickCallback(), setLabelOnLeave()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).
  • optional any amount of arguments:
Optional arguments you'd like to pass to the calling function.
Example

<lua> function onMouseOver()

 echo("The mouse is hovering over the label!\n")

end

setLabelOnEnter( "compassNorthImage", "onMouseOver" ) </lua>

setLabelOnLeave

setLabelClickCallback(labelName, luaFunctionName, optional any amount of arguments)
Specifies a Lua function to be called when the mouse leaves the labels borders. This function can 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.
See Also: setLabelClickCallback(), setLabelOnEnter()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).
  • optional any amount of arguments:
Optional arguments you'd like to pass to the calling function.
Example

<lua> function onMouseLeft(argument)

 echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)

end

setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" ) </lua>

setLink

setLink([window, ]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.
Parameters
  • window:
optional: a miniconsole or a userwindow in which to select the text in.
  • command:
command to do when the text is clicked.
  • tooltip:
tooltip to show when the mouse is over the text - explaining what would clicking do.
Example

<lua> -- you can clickify a lot of things to save yourself some time - for example, you can change -- the line where you receive a message to be clickable to read it! -- prel regex trigger: -- ^You just received message #(\w+) from \w+\.$ -- script: selectString(matches[2], 1) setUnderline(true) setLink(send("msg read ..matches[2].."), "Read #"..matches[2]) resetFormat()

-- an example of selecting text in a miniconsole and turning it into a link:

HelloWorld = Geyser.MiniConsole:new({

 name="HelloWorld",
 x="70%", y="50%",
 width="30%", height="50%",

}) HelloWorld:echo("hi") selectString("HelloWorld", "hi", 1) setLink("HelloWorld", "echo'you clicked hi!'", "click me!") </lua>

setLabelStyleSheet

setLabelStyleSheet(label, markup)
Applies Qt style formatting to a label via a special markup language.
Parameters
  • label:
The name of the label to be formatted (passed when calling createLabel).
  • markup:
The string instructions, as specified by the Qt Style Sheet reference.
References
http://qt-project.org/doc/qt-5/stylesheet-reference.html
Example

<lua> -- This creates a label with a white background and a green border, with the text "test" -- inside. createLabel("test", 50, 50, 100, 100, 0) setLabelStyleSheet("test", [[ background-color: white; border: 10px solid green; font-size: 12px; ]]) echo("test", "test")

-- This creates a label with a single image, that will tile or clip depending on the -- size of the label. To use this example, please supply your own image. createLabel("test5", 50, 353, 164, 55, 0) setLabelStyleSheet("test5", [[ background-image: url(C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png); ]])

-- This creates a label with a single image, that can be resized (such as during a -- sysWindowResizeEvent). To use this example, please supply your own image. createLabel("test9", 215, 353, 100, 100, 0) setLabelStyleSheet("test9", [[ border-image: url(C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png); ]]) </lua>

setPopup

setPopup(name, {lua code}, {hints})
Turns the selected() text into a left-clickable link, and a right-click menu for more options. 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.
Parameters
  • name:
the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.
  • {lua code}:
a table of lua code strings to do. ie, <lua>{send("hello"), echo("hi!"}</lua>
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, <lua>{"send the hi command", "echo hi to yourself"}</lua>.
Example

<lua> -- 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 right-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"}) </lua>

setStrikeOut

setStrikeOut(windowName, boolean)
Sets the current text font to be striken out (true) or not striken out (false) mode. If the windowName parameters omitted, the main screen will be used. If you've got text currently selected in the Mudlet buffer, then the selection will be bolded. Any text you add after with echo() or insertText() will be striken out until you use resetFormat().
  • windowName:
Optional parameter set the current text background color in windowname given.
  • boolean:
A true or false that enables or disables striking out of text
Example

<lua> -- enable striken-out text setStrikeOut(true) -- the following echo will be have a strikethrough echo("hi") -- turns off bolding, italics, underlines, colouring, and strikethrough. It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes. resetFormat() </lua>

showToolBar

showToolBar(name)
Makes a toolbar (a button group) appear on the screen.
Parameters
  • name:
name of the button group to display
Example

<lua> showToolBar("my offensive buttons") </lua>

wrapLine

wrapLine(windowName, lineNumber)
wraps the line specified by 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 your \n interpreted as newline characters properly. Using this function is no good programming practice and should be avoided. There are better ways of handling situations where you would call deleteLine() and echo afterwards e.g.:

<lua>selectString(line,1) replace("")</lua>

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.

See Also: replace(), deleteLine()
Parameters
  • windowName:
The miniconsole or the main window (use main for the main window)
  • lineNumber:
The line number which you'd like re-wrapped.
Example

<lua> -- re-wrap the last line in the main window wrapLine("main", getLineCount()) </lua>