Manual:UI Functions

From Mudlet
Revision as of 05:15, 13 August 2012 by Vadi (talk | contribs) (→‎replaceAll)
Jump to navigation Jump to search

UI Functions

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(colorName)
Changes the background color of the text. Useful for highlighting text.
See Also: fg(), setBgColor()
Parameters
  • 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") </lua>

calcFontSize

calcFontSize(fontSize)
Used to calculate the number of pixels wide and high a character would be on a mini console at fontSize.
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 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> 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>

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(name)
Clears the window or miniconsole with the name given as argument. If you don't give it a name, it will clear the main window (since 2.0-test3+)
See also: clearUserWindow()
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")

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

copy

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.
See Also: selectString(), selectCurrentLine()
Parameters
None
Example

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

createConsole

createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)
Makes a new miniconsole. 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>

createGauge

createGauge(name, width, Xpos, Ypos, gaugeText, r, g, b)
createGauge(name, width, Xpos, Ypos, gaugeText, colorName)
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.
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

<lua> --If you want to put text on the back of the gauge when it's low, use an echo with the gaugeName_back. echo("gaugeName_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(), setMiniConsoleFontSize(), 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 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", [[

You are under attack!

]] );

showWindow("messageBox"); tempTimer(2.3, hideWindow("messageBox") ) -- close the warning message box after 2.3 seconds </lua>

createMiniConsole

createMiniConsole(name, posX, posY, 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.
Returns true or false.
See also: createLabel(), hideWindow(), showWindow(), resizeWindow(), setTextFormat(), moveWindow(), setMiniConsoleFontSize(), handleWindowResizeEvent(), setBorderTop(), setWindowWrap(), getMainWindowSize(), calcFontSize()
Parameters
  • name:
The name of the miniconsole. Must be unique, you can not have two or more miniconsoles with the same name. Passed as a string.
  • Xpos:
X position of the miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.
  • Ypos:
Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.
  • width:
The width of the miniconsole, in pixels. Passed as an integer number.
  • height:
The height of the miniconsole, in pixels. Passed as an integer number.
Example

<lua> --This script would create a mini text console called "sys" and write with yellow foreground color and blue background color --"Hello World".


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

decho

decho (text[, foreground color] [, background color] [, true/false] [, name of console])
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("test", "255,0,0", "0,255,0")
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.
  • foreground color:
Optional string containing value for foreground color as a named color.
  • background color:"
Optional string containing value for background color as a named color.
  • true/false
Optional boolean that tells the function to use insertText() rather than echo().

Note Note: If sending to miniConsole, this has to be false.

  • name of console
Optional name of the console to echo to. Defaults to main.
Example

Need example

deleteLine

deleteLine()
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. For replacing text, replace() is the proper option - doing selectCurrentLine(); replace(""); cecho("new line!\n") is better.
See Also: replace(), wrapLine()

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

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(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
  • 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() </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()
Gets the absolute column number of the current user cursor.
Parameters
None
Example

Need example

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

Need example

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>

getLineCount

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

Need example

getLineNumber

Need information about this here!!!

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 Lua_table[relative_linenumber,content]
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()
Gets the absolute line number of the current user cursor.
Parameters
None
Example

Need example

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>

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

getStopWatchTimer(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>

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

Need example

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(windowName, text)
Inserts text at cursor postion in window.
Parameters
  • window:
The window to insert the text to.
  • text:
The text you will insert into the current cursor position.
Example

Need example

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.

moveCursor

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.
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
  • y:
The vertical axis in the window
Example

<lua> -- 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<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, dock them, 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
Examples

<lua> openUserWindow("My floatig window") cecho("My floatig 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>

replace

replace([windowName,] newtext)
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().

Note Note: This won't preserve existing colours by default - however it's easy to make it, see example below.

Parameters
  • windowName: optional name of window (a miniconsole)
  • with: the new text to display.
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!")

-- if you'd like to keep the original colouring instead of applying your own, you can do this: if selectString("There", 1) ~= -1 then

 setBgColor(getBgColor())
 setFgColor(getFgColor())
 replace("Here")

end </lua>

replaceAll

replaceAll( what, with )
Replaces all occurrences of what in the current line with with.
Example

<lua> -- replace all occurrences of the word "south" in the line with "north" replaceAll("south", "north") </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
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( 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().

Returns position in line or -1 on error (text not found in line)

Note Note: To prevent selection of random data use the error return if not found like this:

<lua>if selectString( "big monster", 1 ) > -1 then setFgColor( 255,0,0) 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, 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.

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>

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)
Shows user window name.

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()
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
None
Example

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

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 - 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 255 (full) to 0 (none).
  • green:
Amount of green to use, from 255 (full) to 0 (none).
  • blue:
Amount of red to use, from 255 (full) to 0 (none).
  • transparency:
Amount of transparency to use, from 255 (fully opaque) to 0 (fully transparent).
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.
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:
Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.
Example

<lua> function onClickGoNorth()

 echo("the north button was clicked!")

end

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

setLink

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.
Parameters
  • 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() </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://doc.qt.nokia.com/4.7/stylesheet-reference.html#list-of-properties
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>

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>