https://wiki.mudlet.org/api.php?action=feedcontributions&user=Smurf&feedformat=atomMudlet - User contributions [en]2024-03-29T01:36:38ZUser contributionsMediaWiki 1.35.0https://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=16163Manual:UI Functions2021-01-16T14:13:18Z<p>Smurf: /* setPopup */ document current usage, clean up example</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Mudlet API documentation for functions to construct custom GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation as well as displaying or formatting information on the screen.}}<br />
= UI Functions =<br />
All functions that help you construct custom GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation as well as displaying or formatting information on the screen.<br />
<br />
==ansi2decho==<br />
;ansi2decho(text, default_colour)<br />
: Converts ANSI colour sequences in <code>text</code> to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.<br />
: See also: [[Manual:Lua_Functions#decho|decho()]]<br />
<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<br />
<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be replaced.<br />
* ''default_colour:''<br />
: Optional - ANSI default colour code (used when handling orphan bold tags).<br />
<br />
;Return values<br />
* ''string text:''<br />
: The decho-valid converted text.<br />
* ''string colour:''<br />
: The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- '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><br />
decho(replaced)<br />
</syntaxhighlight><br />
<br />
Or show a complete colourful squirrel! It's a lotta code to do all the colours, so click the '''Expand''' button on the right to show it:<br />
<div class="toccolours mw-collapsible mw-collapsed"><br />
<syntaxhighlight lang="lua"><br />
decho(ansi2decho([[<br />
�[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m �[0m<br />
╭───────────────────────╮ �[38;5;95m▄▄�[0m �[38;5;95m▄�[48;5;95;38;5;130m▄▄�[48;5;130m█�[38;5;137m▄�[48;5;137;38;5;95m▄�[49m▀�[0m �[0m<br />
│ │ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄▄▄�[48;5;95;38;5;137m▄▄▄�[49;38;5;95m▄▄�[48;5;95;38;5;130m▄�[48;5;130m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[0m �[0m<br />
│ Encrypt everything! │ �[38;5;95m▄�[48;5;187;38;5;16m▄�[48;5;16;38;5;187m▄�[38;5;16m█�[48;5;137;38;5;137m███�[38;5;187m▄�[38;5;16m▄▄�[38;5;137m██�[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[0m �[0m<br />
│ ├──── �[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;16m▄▄▄�[48;5;137m███�[48;5;16;38;5;16m█�[48;5;187m▄�[48;5;16m█�[48;5;137;38;5;137m█�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
╰───────────────────────╯ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;16m▄�[38;5;16m█�[38;5;137m▄�[48;5;137m██████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;95m▀�[48;5;137m▄�[38;5;137m███████�[38;5;95m▄�[49m▀�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[48;5;95;38;5;187m▄▄▄�[38;5;137m▄�[48;5;137m██�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[38;5;95m▀�[48;5;130m▄�[38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;187m████�[48;5;137;38;5;137m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m██�[38;5;95m▄�[38;5;137m█�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;187;38;5;187m████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95m██�[48;5;137m▄▄�[48;5;187;38;5;187m████�[48;5;137;38;5;95m▄▄�[48;5;95;38;5;137m▄�[48;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;187;38;5;187m███�[48;5;95m▄�[38;5;137m▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[49m▄�[48;5;95;38;5;130m▄�[48;5;130m██████�[48;5;137;38;5;137m███�[38;5;95m▄�[49m▀�[0m�[0m<br />
�[48;5;187;38;5;95m▄�[38;5;187m████�[48;5;137;38;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m█████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;137m▄�[38;5;187m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██████�[48;5;95m▄▄�[48;5;130m▄▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▄▄▄�[48;5;95;38;5;137m▄�[48;5;187m▄�[38;5;187m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m█████�[38;5;95m▄�[38;5;137m███████████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀�[48;5;187m▄▄▄�[48;5;95;38;5;137m▄�[48;5;137m██�[38;5;95m▄�[49m▀�[0m �[38;5;95m▀▀�[48;5;137m▄▄▄▄▄▄�[49m▀▀▀�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀▀�[0m �[0m<br />
]]))<br />
</syntaxhighlight><br />
</div><br />
<br />
[[File:Squirrel-in-Mudlet.png|frameless]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.0+<br />
<br />
<br />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be removed.<br />
<br />
;Return values<br />
* ''string text:''<br />
: The plain text without ANSI colour sequences.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10+<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2string('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- 'replaced' should now contain You say in a baritone voice, "Test."<br />
print(replaced)<br />
</syntaxhighlight><br />
<br />
<br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name.<br />
: See also: [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[Manual:Lua_Functions#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</syntaxhighlight><br />
<br />
==bg==<br />
;bg([window, ]colorName)<br />
: Changes the background color of the text. Useful for highlighting text.<br />
: See Also: [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: 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).<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
<br />
-- or echo text with a green background to a miniconsole<br />
bg("my window", "green")<br />
echo("my window", "some green text\n")<br />
</syntaxhighlight><br />
<br />
==calcFontSize==<br />
;calcFontSize(window_or_fontsize, [fontname])<br />
: Returns the average height and width of characters in a particular window, or a font name and size combination. Helpful if you want to size a miniconsole to specific dimensions.<br />
: Returns two numbers, width/height<br />
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
;Parameters<br />
* ''window_or_fontsize:''<br />
: The miniconsole or font size you are wanting to calculate pixel sizes for.<br />
* ''fontname:''<br />
: Specific font name (along with the size as the first argument) to calculate for.<br />
<br />
{{note}}<br />
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide<br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</syntaxhighlight><br />
<br />
==cecho==<br />
;cecho([window], text)<br />
: Echoes text that can be easily formatted with colour, italics, bold and underline tags. You can also include unicode art in it - try some examples from [http://1lineart.kulaone.com/#/ 1lineart].<br />
: See also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cecho("<blue:yellow>Blue on yellow text!")<br />
<br />
cecho("\n<red>Red text with <i>italics</i>, <u>underline</u> and <b>bold</b>.")<br />
<br />
-- \n adds a new line<br />
cecho("<red>one line\n<green>another line\n<blue>last line")<br />
<br />
cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
<br />
cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")<br />
<br />
cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")<br />
<br />
cecho([[<br />
██╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗ ████████╗<br />
███║ ██║ ██║████╗ ██║██╔════╝ ██╔══██╗██╔══██╗╚══██╔══╝<br />
╚██║ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝ ██║<br />
██║ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗ ██║<br />
██║ ███████╗██║██║ ╚████║███████╗ ██║ ██║██║ ██║ ██║<br />
╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝<br />
]])<br />
</syntaxhighlight><br />
<br />
==cechoLink==<br />
;cechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#cecho|cecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cechoPopup==<br />
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#cecho|cecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.1}}<br />
<br />
==cinsertLink==<br />
;cinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#cinsertText|cinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.1}}<br />
<br />
==cinsertPopup==<br />
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#cinsertText|cinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.1}}<br />
<br />
==cinsertText==<br />
;cinsertText([window], text)<br />
: inserts text at the current cursor position, with the possibility for color tags.<br />
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cinsertText("<blue:yellow>Blue on yellow text!")<br />
<br />
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
</syntaxhighlight><br />
<br />
==clearUserWindow==<br />
;clearUserWindow([name])<br />
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].<br />
<br />
==clearWindow==<br />
;clearWindow([windowName])<br />
: Clears the label, mini console, or user window 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this can clear your whole main window<br />
clearWindow()<br />
</syntaxhighlight><br />
<br />
==copy==<br />
; copy([windowName])<br />
: Copies the current selection to the lua virtual clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the lua virtual clipboard until it gets overwritten by another copy operation.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
; Parameters<br />
* ''windowName'' (optional):<br />
: the window from which to copy text - use the main console if not specified.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This script copies the current line on the main screen to a window (miniconsole or userwindow) called 'chat' and gags the output on the main screen.<br />
selectString(line, 1)<br />
copy()<br />
appendBuffer("chat")<br />
replace("This line has been moved to the chat window!")<br />
</syntaxhighlight><br />
<br />
==copy2decho==<br />
; copy2decho([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in decho format.<br />
{{MudletVersion|4.8}}<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line.<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and dechos it to a miniconsole named "test"<br />
decho("test", copy2decho())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and decho it to a Geyser miniconsole stored as the variable enemylist<br />
enemylist:decho(copy2decho(matches[2]))<br />
</syntaxhighlight><br />
<br />
==copy2html==<br />
; copy2html([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in html format for echoing to a label.<br />
{{MudletVersion|4.8}}<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main"<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and echos it to a label named "TestLabel"<br />
echo("TestLabel", copy2html())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and echo it to a Geyser label stored as the variable enemylist<br />
enemylist:echo(copy2html(matches[2]))<br />
</syntaxhighlight><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: 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.<br />
<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</syntaxhighlight><br />
<br />
==createCommandLine==<br />
;createCommandLine([name of userwindow], name, x, y, width, height)<br />
: Creates a new command line inside the main window of Mudlet. If only a command line inside a miniConsole/UserWindow is needed see [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]].<br />
: You can use [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]] / [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]] and other command line functions to customize the input.<br />
{{note}} [[Manual:UI_Functions#setCmdLineAction|setCmdLineAction]] allows you to attach an action to your command line input.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#disableCommandLine|disableCommandLine()]], [[Manual:Mudlet_Object_Functions#clearCmdLine|clearCmdLine()]], [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]], [[Manual:Mudlet_Object_Functions#printCmdLine|printCmdLine()]], [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the command line is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the command line. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the command line size and location - it is also possible to set them by using [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createCommandLine() will only set them once.<br />
<br />
{{MudletVersion|4.10}}<br />
<br />
==createConsole==<br />
;createConsole([name of userwindow], consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow your new miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,<br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
''(For Mudlet Makers)'' This function is implemented outside the application's core via the '''GUIUtils.lua''' file of the Mudlet supporting Lua code using [[Manual:UI_Functions#createMiniConsole|createMiniConsole()]] and other functions to position and size the mini-console and configure the font.<br />
<br />
==createGauge==<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the gauge is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: 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<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
* ''orientation:''<br />
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.<br />
<syntaxhighlight lang="lua"><br />
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")<br />
</syntaxhighlight><br />
<br />
==createLabel==<br />
;createLabel([name of userwindow], name, Xpos, Ypos, width, height, fillBackground, [enableClickthrough])<br />
: 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.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]], [[Manual:Lua_Functions#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will display the background color, 0 or false will not.<br />
* ''enableClickthrough:''<br />
: Whether or not enable clickthrough on this label. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will enable clickthrough, 0 or false will not. Optional, defaults to clickthrough not enabled if not provided.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label situated at x=300 y=400 with dimensions 100x200<br />
createLabel("a very basic label",300,400,100,200,1)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle<br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent<br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
<br />
-- you can also make it react to clicks!<br />
mynamespace = {<br />
messageBoxClicked = function()<br />
echo("hey you've clicked the box!\n")<br />
end<br />
}<br />
<br />
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")<br />
<br />
<br />
-- uncomment code below to make it also hide after a short while<br />
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</syntaxhighlight><br />
<br />
==createMiniConsole==<br />
;createMiniConsole([name of userwindow], name, x, y, width, height)<br />
: 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.<br />
: You can use [[Manual:Lua_Functions#clearWindow|clearWindow()]] / [[Manual:Lua_Functions#moveCursor|moveCursor()]] and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. [[Manual:Lua_Functions#setWindowWrap|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 [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent()]], [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:'' (available in Mudlet 4.6.1+)<br />
: (Optional) name of userwindow the miniconsole is created in. Defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location - in Mudlet version 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createMiniConsole() will only set them once. Starting with Mudlet version 3.0, however, that is fine and calling createMiniConsole() will re-position your miniconsole appropriately.<br />
<br />
;Example<br />
<br />
==creplace==<br />
;creplace([window, ]text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, with color names inside angle brackets as with [[Manual:Lua_Functions#cecho|cecho()]]. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
creplace("<magenta>[ALERT!]: <reset>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==creplaceLine==<br />
;creplaceLine (text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''text:''<br />
*: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)<br />
</syntaxhighlight><br />
<br />
==decho==<br />
;decho ([name of console,] text)<br />
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB,[BA]> 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,[BA]>. 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")''. You can also include italics, bold and underline tags.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]]<br />
<br />
;Parameters<br />
* ''name of console''<br />
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.<br />
* ''text:''<br />
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.<br />
<br />
<br />
{{note}}<br />
Optional background transparancy parameter (BA) available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
decho("<50,50,0:0,255,0>test")<br />
<br />
decho("miniconsolename", "<50,50,0:0,255,0>test")<br />
<br />
decho("\n<255,0,0>Red text with <i>italics</i>, <u>underline</u> and <b>bold</b> formatting.")<br />
</syntaxhighlight><br />
<br />
==dechoLink==<br />
;dechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#decho|decho()]]. This version allows you to use colours within your link text.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) allows selection between sending the link to a miniconsole or the "main" window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==dechoPopup==<br />
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#decho|decho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.1}}<br />
<br />
==dinsertLink==<br />
;dinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#dinsertText|dinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.1}}<br />
<br />
==dinsertPopup==<br />
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#dinsertText|dinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.1}}<br />
<br />
== deleteLabel ==<br />
; deleteLabel(labelName)<br />
<br />
: Deletes and removes a label from the screen. Note that if you'd like to show the label again, it is much more performant to hide/show it instead.<br />
<br />
: Note that you shouldn't use the Geyser label associated with the label you delete afterwards - that doesn't make sense and Geyser right now wouldn't know that it's been deleted, either.<br />
<br />
: See also: [[#hideWindow|hideWindow()]], [[#showWindow|showWindow()]], [[#createLabel|createLabel()]]<br />
<br />
; Parameters<br />
<br />
* ''labelName'': name of the label to delete.<br />
<br />
<syntaxhighlight lang="lua"><br />
createLabel("a very basic label",300,400,100,200,1)<br />
setBackgroundColor("a very basic label", 255, 204, 0, 200)<br />
<br />
-- delete the label after 3 seconds<br />
tempTimer(3, function()<br />
deleteLabel("a very basic label")<br />
end)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.5}}<br />
<br />
==deleteLine==<br />
;deleteLine([windowName])<br />
: 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. This is purely visual - triggers will still fire on the line as expected.<br />
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.<br />
<br />
{{note}} for replacing text, [[Manual:Lua_Functions#replace|replace()]] is the proper option; doing the following: <code>selectCurrentLine(); replace(""); cecho("new line!\n")</code> is better.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- deletes the line - just put this command into the big script box. Keep the case the same -<br />
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else<br />
deleteLine()<br />
<br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
<br />
-- example of deleting multiple lines:<br />
deleteLine() -- delete the current line<br />
moveCursor(0,getLineNumber()-1) -- move the cursor back one line<br />
deleteLine() -- delete the previous line now<br />
</syntaxhighlight><br />
<br />
==deselect==<br />
;deselect([window name])<br />
: 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.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''window name:''<br />
: (optional) The name of the window to stop having anything selected in. If name is not provided the main window will have its selection cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further<br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</syntaxhighlight><br />
<br />
==disableClickthrough==<br />
; disableClickthrough(label)<br />
: Disables clickthrough for a label - making it act 'normal' again and receive clicks, doubleclicks, onEnter, and onLeave events. This is the default behaviour for labels.<br />
: See also: [[#enableClickthrough|enableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name of the label to restore clickability on.<br />
<br />
{{MudletVersion|3.17}}<br />
<br />
==disableCommandLine==<br />
; disableCommandLine(windowName)<br />
: Disables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableCommandLine|enableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to disable the command line in.<br />
<br />
{{MudletVersion|4.10}}<br />
<br />
==disableHorizontalScrollBar==<br />
; disableHorizontalScrollBar([windowName])<br />
: Disables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableHorizontalScrollBar|enableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{MudletVersion|4.10}}<br />
<br />
==disableScrollBar==<br />
; disableScrollBar([windowName])<br />
: Disables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==dreplace==<br />
;dreplace([window, ]text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#decho|decho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
dreplace("<255,0,255>[ALERT!]: <r>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''text:''<br />
: Text to display in the echo. Same as a normal echo().<br />
* ''command:''<br />
: Lua code to do when the link is clicked.<br />
* ''hint:''<br />
: Text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentFormatElseDefault:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
echoLink("press me!", [[send("hi")]], "This is a tooltip")<br />
<br />
-- do the same, but send this link to a miniConsole<br />
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")<br />
</syntaxhighlight><br />
<br />
==echoUserWindow==<br />
;echoUserWindow(windowName, text)<br />
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.<br />
<br />
==echoPopup==<br />
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==enableClickthrough==<br />
; enableClickthrough(label)<br />
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.<br />
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.<br />
: See also: [[#disableClickthrough|disableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: The name of the label to enable clickthrough on.<br />
<br />
{{MudletVersion|3.17}}<br />
<br />
==enableCommandLine==<br />
; enableCommandLine(windowName)<br />
: Enables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#disableCommandLine|disableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to enable the command line in.<br />
<br />
{{note}} The command line name is the same as the miniConsole name<br />
<br />
{{MudletVersion|4.10}}<br />
<br />
==enableHorizontalScrollBar==<br />
; enableHorizontalScrollBar([windowName])<br />
: Enables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableHorizontalScrollBar|disableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{MudletVersion|4.10}}<br />
<br />
==enableScrollBar==<br />
; enableScrollBar([windowName])<br />
: Enables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==fg==<br />
; fg([window], colorName)<br />
: 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)<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything or use ''main'' (since Mudlet 3.0).<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
<br />
-- example of working on a miniconsole<br />
fg("my console", "red")<br />
echo("my console", "red text")<br />
</syntaxhighlight><br />
<br />
==getAvailableFonts==<br />
; getAvailableFonts()<br />
: This returns a "font - true" key-value list of available fonts which you can use to verify that Mudlet has access to a given font.<br />
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.<br />
<br />
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]<br />
<br />
{{MudletVersion|3.10}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if Ubuntu Mono is a font we can use<br />
if getAvailableFonts()["Ubuntu Mono"] then<br />
-- make the miniconsole use the font at size 16<br />
setFont("my miniconsole", "Ubuntu Mono")<br />
setFontSize("my miniconsole", 16)<br />
end<br />
</syntaxhighlight><br />
<br />
==getBgColor==<br />
; getBgColor(windowName)<br />
: 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.<br />
<br />
: See also: [[#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r,g,b;<br />
selectString("troll",1)<br />
r,g,b = getBgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getBorderBottom==<br />
;getBorderBottom()<br />
: Returns the size of the bottom border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]<br />
<br />
: {{MudletVersion|4.0}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
getBorderBottom()<br />
-- returns: 150<br />
</syntaxhighlight><br />
<br />
==getBorderLeft==<br />
;getBorderLeft()<br />
: Returns the size of the left border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]<br />
<br />
: {{MudletVersion|4.0}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
getBorderLeft()<br />
-- returns: 5<br />
</syntaxhighlight><br />
<br />
==getBorderRight==<br />
;getBorderRight()<br />
: Returns the size of the right border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]<br />
<br />
: {{MudletVersion|4.0}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
getBorderRight()<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderSizes==<br />
;getBorderSizes()<br />
: Returns the a named table with the sizes of all borders of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]],[[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
: {{MudletVersion|4.0}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0)<br />
getBorderSizes()<br />
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }<br />
getBorderSizes().right<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderTop==<br />
;getBorderTop()<br />
: Returns the size of the top border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]<br />
<br />
: {{MudletVersion|4.0}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
getBorderTop()<br />
-- returns: 100<br />
</syntaxhighlight><br />
<br />
==getClipboardText==<br />
;getClipboardText()<br />
: Returns any text that is currently present in the clipboard. <br />
: See also: [[#setClipboardText | setClipboardText()]]<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local clipboardContents = getClipboardText()<br />
echo("Clipboard: " .. clipboardContents)<br />
</syntaxhighlight><br />
<br />
==getColorWildcard==<br />
; getColorWildcard(ansi color number)<br />
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.<br />
<br />
: See also: [[#isAnsiFgColor|isAnsiFgColor()]], [[#isAnsiBgColor|isAnsiBgColor()]]<br />
<br />
;Parameters<br />
* ''ansi color number:''<br />
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- we can run this script on a line that has the players name coloured differently to easily capture it from<br />
-- anywhere on the line<br />
local match = getColorWildcard(14) -- this will be a table of every match<br />
<br />
if match then -- if there's a table, then we try and print it on the screen!<br />
echo("\nFound "..table.concat(match, ", ").."!") -- this will combine all captured strings and separate them with a comma so it's easy to read.<br />
else -- if there isn't something in match, then we haven't found anything to print on the screen!<br />
echo("\nDidn't find anyone.") <br />
end<br />
</syntaxhighlight><br />
<br />
==getColumnCount==<br />
;getColumnCount([windowName])<br />
: Gets the maximum number of columns (characters) that a given window can display on a single row, taking into consideration factors such as window width, font size, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.<br />
<br />
{{MudletVersion|3.7}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum number of columns on the main window "..getColumnCount())<br />
</syntaxhighlight><br />
<br />
==getColumnNumber==<br />
;getColumnNumber([windowName])<br />
: Gets the absolute column number of the current user cursor.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
<br />
{{note}} the argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
<br />
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
</syntaxhighlight><br />
<br />
==getCurrentLine==<br />
;getCurrentLine([windowName])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Currently selected line: "..getCurrentLine())<br />
</syntaxhighlight><br />
<br />
==getFgColor==<br />
; getFgColor(windowName)<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString("troll",1)<br />
local r,g,b = getFgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is written in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getFont==<br />
;getFont([windowName])<br />
: Gets the current font of the given window or console name. Can be used to get font of the main console, dockable userwindows and miniconsoles.<br />
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
display("Font in the main window: "..getFont())<br />
<br />
display("Font in the main window: "..getFont("main"))<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
display("Font size: " .. getFont("user window awesome"))<br />
</syntaxhighlight><br />
<br />
==getFontSize==<br />
;getFontSize([windowName])<br />
: Gets the current font size of the given window or console name. Can be used to get font size of the Main console as well as dockable UserWindows.<br />
: See also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
<br />
{{MudletVersion|3.4}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
local mainWindowFontSize = getFontSize()<br />
if mainWindowFontSize then<br />
display("Font size: " .. mainWindowFontSize)<br />
end<br />
<br />
local mainWindowFontSize = getFontSize("main")<br />
if mainWindowFontSize then<br />
display("Font size: " .. fs2)<br />
end<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
local awesomeWindowFontSize = getFontSize("user window awesome")<br />
if awesomeWindowFontSize then<br />
display("Font size: " .. awesomeWindowFontSize)<br />
end<br />
</syntaxhighlight><br />
<br />
==getImageSize==<br />
;getImageSize(imageLocation)<br />
: Returns the width and the height of the given image. If the image can't be found, loaded, or isn't a valid image file - nil+error message will be returned instead.<br />
: See also: [[#createLabel|createLabel()]]<br />
<br />
;Parameters<br />
* ''imageLocation:''<br />
: Path to the image.<br />
<br />
{{MudletVersion|4.5}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local path = getMudletHomeDir().."/my-image.png"<br />
<br />
cecho("Showing dimensions of the picture in: "..path.."\n")<br />
<br />
local width, height = getImageSize(path)<br />
<br />
if not width then<br />
-- in case of an problem, we don't get a height back - but the error message<br />
cecho("error: "..height.."\n")<br />
else<br />
cecho(string.format("They are: %sx%s", width, height))<br />
end<br />
</syntaxhighlight><br />
<br />
==getLastLineNumber==<br />
;getLastLineNumber(windowName)<br />
:Returns the latest line's number in the main window or the miniconsole. This could be different from [[Manual:UI_Functions#getLineNumber|getLineNumber()]] if the cursor was moved around.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the latest line's # in the buffer<br />
local latestline = getLastLineNumber("main")<br />
</syntaxhighlight><br />
<br />
==getLineCount==<br />
;getLineCount()<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
''Need example''<br />
<br />
==getLines==<br />
;getLines([windowName,] from_line_number, to_line_number)<br />
: 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}''.<br />
<br />
:Absolute line numbers are used.<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)<br />
* ''from_line_number:''<br />
: First line number<br />
* ''to_line_number:''<br />
: End line number<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- retrieve & echo the last line:<br />
echo(getLines(getLineNumber()-1, getLineNumber())[1])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- find out which server and port you are connected to (as per Mudlet settings dialog):<br />
local t = getLines(0, getLineNumber())<br />
<br />
local server, port<br />
<br />
for i = 1, #t do<br />
local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")<br />
if s then server, port = s, p break end<br />
end<br />
<br />
display(server)<br />
display(port)<br />
</syntaxhighlight><br />
<br />
==getLineNumber==<br />
;getLineNumber([windowName])<br />
: 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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#moveCursorEnd|moveCursorEnd()]]. This function can come in handy in combination when using with [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#getLines|getLines()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.<br />
<br />
{{note}}<br />
The argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word<br />
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end<br />
<br />
-- check how many lines you've got in your miniconsole after echoing some text.<br />
-- Note the use of moveCursorEnd() to update getLineNumber()'s output<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
print(getLineNumber("HelloWorld"))<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
-- update the cursors position, as it seems to be necessary to do<br />
moveCursorEnd("HelloWorld")<br />
print(getLineNumber("HelloWorld"))<br />
</syntaxhighlight><br />
<br />
==getMainConsoleWidth==<br />
;getMainConsoleWidth()<br />
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.<br />
<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Save width of the main console to a variable for future use.<br />
consoleWidth = getMainConsoleWidth()<br />
</syntaxhighlight><br />
<br />
==getMousePosition==<br />
;getMousePosition()<br />
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|3.1}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- 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<br />
local x, y = getMousePosition()<br />
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)<br />
-- if the label already exists, just move it<br />
moveWindow("clickGeneratedLabel", x, y)<br />
-- and make it easier to notice<br />
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)<br />
</syntaxhighlight><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getUserWindowSize|getUserWindowSize()]], [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your main mudlet window and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</syntaxhighlight><br />
<br />
==getRowCount==<br />
;getRowCount([windowName])<br />
: Gets the maximum number of rows that a given window can display at once, taking into consideration factors such as window height, font type, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.<br />
<br />
{{MudletVersion|3.7}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum of rows on the main window "..getRowCount())<br />
</syntaxhighlight><br />
<br />
==getSelection==<br />
;getSelection([windowName])<br />
: Returns the text currently selected with [[#selectString|selectString()]], [[#selectSection|selectSection()]], or [[#selectCurrentLine|selectCurrentLine()]]. Note that this isn't the text currently selected with the mouse.<br />
: Also returns the start offset and length of the selection as second and third value.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window to get the selection from. By default it operates on the main window.<br />
<br />
{{MudletVersion|3.16}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
print("Current line contains: "..getSelection())<br />
</syntaxhighlight><br />
<br />
;retrieving the selection<br />
<syntaxhighlight lang="lua"><br />
text,offset,len = getSelection()<br />
-- manipulate the selection, e.g. to discover the color of characters other than the first<br />
-- then restore it<br />
selectSection(offset, len)<br />
</syntaxhighlight><br />
<br />
==getTextFormat==<br />
;getTextFormat([windowName])<br />
: Gets the current text format of the currently selected text. May be used with other console windows. The returned values come in a table containing text attribute names and their values. The values given will be booleans for: bold, italics, underline, overline, strikeout, and reverse - followed by color triplet tables for the foreground and background colors.<br />
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.<br />
<br />
{{MudletVersion|3.20}}<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- A suitable test for getTextFormat()<br />
-- (copy it into an alias or a script)<br />
<br />
clearWindow()<br />
<br />
echo("\n")<br />
<br />
local SGR = string.char(27)..'['<br />
feedTriggers("Format attributes: '"..SGR.."1mBold"..SGR.."0m' '"..SGR.."3mItalic"..SGR.."0m' '"..SGR.."4mUnderline"..SGR.."0m' '"..SGR.."5mBlink"..SGR.."0m' '"..SGR.."6mF.Blink"..SGR.."0m' '"..SGR.."7mReverse"..SGR.."0m' '"..SGR.."9mStruckout"..SGR.."0m' '"..SGR.."53mOverline"..SGR.."0m'.\n")<br />
<br />
moveCursor(1,1)<br />
selectSection(1,1)<br />
<br />
local results = getTextFormat()<br />
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))<br />
echo("\nItalic detected: " .. tostring(results["italic"]))<br />
echo("\nUnderline detected: " .. tostring(results["underline"]))<br />
echo("\nReverse detected: " .. tostring(results["reverse"]))<br />
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))<br />
echo("\nOverline detected: " .. tostring(results["overline"]))<br />
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")<br />
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")<br />
<br />
selectSection(21,1)<br />
echo("\n\nFor individual parts of test text:")<br />
echo("\nBold detected (character 21): " .. tostring(results["bold"]))<br />
<br />
selectSection(28,1)<br />
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))<br />
<br />
selectSection(37,1)<br />
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))<br />
<br />
selectSection(67,1)<br />
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))<br />
<br />
selectSection(77,1)<br />
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))<br />
<br />
selectSection(89,1)<br />
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))<br />
echo("\n")<br />
</syntaxhighlight><br />
<br />
==getUserWindowSize==<br />
;getUserWindowSize(windowName)<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the given userwindow dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''windowName''<br />
:the name of the userwindow we will get the dimensions from<br />
<br />
{{MudletVersion|4.6.1}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your userwindow named "ChatWindow" and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getUserWindowSize("ChatWindow")<br />
</syntaxhighlight><br />
<br />
<br />
==getWindowWrap==<br />
;getWindowWrap(windowName)<br />
: gets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main" or leave empty.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display(getWindowWrap("main"))<br />
<br />
-- The following output will result in the main window console:<br />
-- 10<br />
</syntaxhighlight><br />
<br />
;Practical Example<br />
<syntaxhighlight lang="lua"><br />
-- display ======== line with maximum possible width without wrapping<br />
echo(string.rep("=", getWindowWrap("main")))<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11}}<br />
<br />
==handleWindowResizeEvent==<br />
;handleWindowResizeEvent()<br />
: (''depreciated'') This function is depreciated and should not be used; it's only documented here for historical reference - use the [[Manual:Technical_Manual#sysWindowResizeEvent|sysWindowResizeEvent]] event instead.<br />
<br />
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.<br />
<br />
; Parameters<br />
:None<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
function handleWindowResizeEvent()<br />
-- determine the size of your screen<br />
WindowWidth=0;<br />
WindowHeight=0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
-- move mini console "sys" to the far right side of the screen whenever the screen gets resized<br />
moveWindow("sys",WindowWidth-300,0)<br />
end<br />
</syntaxhighlight><br />
<br />
==hasFocus==<br />
;hasFocus()<br />
: 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). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if attacked and not hasFocus() then<br />
runaway()<br />
else<br />
fight()<br />
end<br />
</syntaxhighlight><br />
<br />
==hecho==<br />
;hecho([windowName], text)<br />
: Echoes text that can be easily formatted with colour tags in the hexadecimal format. You can also use italics, bold and underline tags.<br />
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.<br />
* ''text:''<br />
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #FRFGFB,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 or #r can be used within the string to reset the colors to default. Hexadecimal color codes can be found here: https://www.color-hex.com/<br />
<br />
{{note}}<br />
Transparency for background in hex-format available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hecho("\n#ffffff White text!")<br />
-- your text in white<br />
hecho("\n#ca0004 Red text! And now reset #rit to the default color")<br />
-- your text in red, then reset to default using #r<br />
hecho("\n#ffffff,ca0004 White text with a red background!")<br />
-- your text in white, against a red background<br />
hecho("\n|c0000ff Blue text, this time using |c instead of #")<br />
-- your text in blue, activated with |c vs #.<br />
hecho("\n#ff0000Red text with #iitalics#/i, |uunderline|/u and #bbold#/b formatting.")<br />
</syntaxhighlight><br />
<br />
==hechoLink==<br />
;hechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#hecho|hecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
-- # format also works<br />
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==hechoPopup==<br />
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#hecho|hecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.1}}<br />
<br />
==hinsertLink==<br />
;hinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#hinsertText|hinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.1}}<br />
<br />
==hinsertPopup==<br />
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#hinsertText|hinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.1}}<br />
<br />
==hreplace==<br />
;hreplace([window, ]text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#hecho|hecho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
hreplace("#EE00EE[ALERT!]: #r"..matches[2])<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.5}}<br />
<br />
==hideToolBar==<br />
;hideToolBar(name)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to hide<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hideToolBar("my offensive buttons")<br />
</syntaxhighlight><br />
<br />
==hideWindow==<br />
;hideWindow(name)<br />
: This function hides a '''mini console''', a '''user window''' or a '''label''' with the given name. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].<br />
<br />
: See also: [[#createMiniConsole|createMiniConsole()]], [[#createLabel|createLabel()]], [[#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name''<br />
: specifies the label or console you want to hide.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function miniconsoleTest()<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
print("created red window top-right")<br />
<br />
tempTimer(1, function()<br />
hideWindow("sys")<br />
print("hid red window top-right")<br />
end)<br />
<br />
tempTimer(3, function()<br />
showWindow("sys")<br />
print("showed red window top-right")<br />
end)<br />
end<br />
<br />
miniconsoleTest()<br />
</syntaxhighlight><br />
<br />
==insertLink==<br />
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])<br />
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) the window to insert the link in - use either "main" or omit for the main window.<br />
* ''text:''<br />
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) true or false. 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- link with the default blue on white colors<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")<br />
<br />
-- use current cursor colors by adding true at the end<br />
fg("red")<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==insertPopup==<br />
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])<br />
: Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to [[Manual:Lua_Functions#insertText|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''name:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.<br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==insertText==<br />
;insertText([windowName], text)<br />
: Inserts text at cursor postion in window - unlike [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] to move the cursor into position first.<br />
<br />
: insertHTML() also does the same thing as insertText, if you ever come across it.<br />
<br />
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) The window to insert the text to.<br />
* ''text:''<br />
: The text you will insert into the current cursor position.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the cursor to the end of the previous line and insert some text<br />
<br />
-- move to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
-- move the end the of the previous line<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
<br />
fg("dark_slate_gray")<br />
insertText(' <- that looks nice.')<br />
<br />
deselect()<br />
resetFormat()<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
==ioprint==<br />
;ioprint(text, some more text, ...)<br />
:Prints text to the to the stdout. This is only available if you [http://www.wikihow.com/Run-a-Program-on-Command-Prompt launched Mudlet from cmd.exe] on Windows, [http://www.wikihow.com/Open-Applications-Using-Terminal-on-Mac from the terminal] on Mac, or from the terminal on a Linux OS (launch the terminal program, type ''mudlet'' and press enter).<br />
<br />
Similar to [[Manual:Lua_Functions#echo|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.<br />
<br />
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.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
ioprint("hi!")<br />
ioprint(1,2,3)<br />
ioprint(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==isAnsiBgColor==<br />
; isAnsiBgColor(bgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the background color specified by bgColorCode.<br />
<br />
;Parameters<br />
* ''bgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiBgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the background of the text is light green" )<br />
else<br />
echo( "no sorry, some other background color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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 getBgColor() and then handling the color comparison in Lua.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default background color in the zeroth position.''<br />
<br />
==isAnsiFgColor==<br />
; isAnsiFgColor(fgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the foreground color specified by fgColorCode.<br />
<br />
;Parameters<br />
* ''fgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiFgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the text is light green" )<br />
else<br />
echo( "no sorry, some other foreground color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default foreground color in the zeroth position.''<br />
<br />
==lowerWindow==<br />
;lowerWindow(labelName)<br />
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to move below the rest.<br />
<br />
{{MudletVersion|3.1}}<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top<br />
</syntaxhighlight><br />
<br />
==moveCursor==<br />
;moveCursor([windowName], x, y)<br />
: 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 [[Manual:Lua_Functions#getLineNumber|getLineNumber()]], [[Manual:Lua_Functions#getColumnNumber|getColumnNumber()]] and [[Manual:Lua_Functions#getLastLineNumber|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.<br />
<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The window you are going to move the cursor in.<br />
* ''x:''<br />
: The horizontal axis in the window - that is, the letter position within the line.<br />
* ''y:''<br />
: The vertical axis in the window - that is, the line number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move cursor to the start of the previous line and insert -<(<br />
-- the first 0 means we want the cursor right at the start of the line,<br />
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which<br />
-- equals to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
insertText("-<(")<br />
<br />
-- now we move the cursor at the end of the previous line. Because the<br />
-- cursor is on the previous line already, we can use #getCurrentLine()<br />
-- to see how long it is. We also just do getLineNumber() because getLineNumber()<br />
-- returns the current line # the cursor is on<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
insertText(")>-")<br />
<br />
-- finally, reset it to the end where it was after our shenaningans - other scripts<br />
-- could expect the cursor to be at the end<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a more complicated example showing how to work with Mudlet functions<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
local WindowWidth, WindowHeight = getMainWindowSize()<br />
<br />
-- define a mini console named "sys" and set its background color<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
<br />
-- you *must* set the font size, otherwise mini windows will not work properly<br />
setMiniConsoleFontSize("sys", 12)<br />
-- wrap lines in window "sys" at 65 characters per line<br />
setWindowWrap("sys", 60)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
-- clear the window<br />
clearUserWindow("sys")<br />
<br />
moveCursorEnd("sys")<br />
setFgColor("sys", 10,10,0)<br />
setBgColor("sys", 0,0,255)<br />
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")<br />
echo("sys", "test1---line2\n")<br />
echo("sys", "test1---line3\n")<br />
setTextFormat("sys",158,0,255,255,0,255,0,0,0);<br />
--setFgColor("sys",255,0,0);<br />
echo("sys", "test1---line4\n")<br />
echo("sys", "test1---line5\n")<br />
moveCursor("sys", 1,1)<br />
<br />
-- deleting lines 2+3<br />
deleteLine("sys")<br />
deleteLine("sys")<br />
<br />
-- inserting a line at pos 5,2<br />
moveCursor("sys", 5,2)<br />
setFgColor("sys", 100,100,0)<br />
setBgColor("sys", 255,100,0)<br />
insertText("sys","############## line inserted at pos 5/2 ##############")<br />
<br />
-- inserting a line at pos 0,0<br />
moveCursor("sys", 0,0)<br />
selectCurrentLine("sys")<br />
setFgColor("sys", 255,155,255)<br />
setBold( "sys", true );<br />
setUnderline( "sys", true )<br />
setItalics( "sys", true )<br />
insertText("sys", "------- line inserted at: 0/0 -----\n")<br />
<br />
setBold( "sys", true )<br />
setUnderline( "sys", false )<br />
setItalics( "sys", false )<br />
setFgColor("sys", 255,100,0)<br />
setBgColor("sys", 155,155,0)<br />
echo("sys", "*** This is the end. ***\n")<br />
</syntaxhighlight><br />
<br />
==moveCursorDown==<br />
;moveCursorDown([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window down a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor down by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{MudletVersion|3.17}}<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorUp==<br />
;moveCursorUp([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window up a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor up by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{MudletVersion|3.17}}<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorEnd==<br />
;moveCursorEnd([windowName])<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
: Returns true or false<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveGauge==<br />
;moveGauge(gaugeName, newX, newY)<br />
: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.<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: The name of your gauge<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would move the health bar gauge to the location 1200, 400<br />
moveGauge("healthBar", 1200, 400)<br />
</syntaxhighlight><br />
<br />
==moveWindow==<br />
;moveWindow(name, x, y)<br />
: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.<br />
<br />
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of your window<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles.<br />
<br />
==openUserWindow==<br />
;openUserWindow(windowName, [restoreLayout], [autoDock], [dockingArea])<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).<br />
* ''restoreLayout:'' (available in Mudlet 3.2+)<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.<br />
* ''autoDock:'' (available in Mudlet 4.7+)<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't dock automatically at the corners.<br />
* ''dockingArea:'' (available in Mudlet 4.7+)<br />
: (optional) - the area your UserWindow will be docked at. possible docking areas your UserWindow will be created in (f" floating "t" top "b" bottom "r" right and "l" left). Docking area is "right" if not given any value.<br />
<br />
{{note}}<br />
Since Mudlet version 3.2, Mudlet will automatically remember the window's last position.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
openUserWindow("My floating window")<br />
cecho("My floating window", "<red>hello <blue>bob!")<br />
<br />
-- if you don't want Mudlet to remember its last position:<br />
openUserWindow("My floating window", false)<br />
</syntaxhighlight><br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]]<br />
<br />
==paste==<br />
;paste(windowName)<br />
: Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The [[#copy | copy()]] and [[#paste | 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
<br />
==prefix==<br />
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
:Prefixes text at the beginning of the current line when used in a trigger.<br />
<br />
;Parameters<br />
* ''text:''<br />
: the information you want to prefix<br />
* "writingFunction:"<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* "foregroundColor:"<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* "backgroundColor:"<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* "windowName:"<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that<br />
prefix(os.date("%H:%M:%S "))<br />
-- Prefix the time in red into a miniconsole named "my_console"<br />
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#suffix | suffix()]]<br />
<br />
==print==<br />
;print(text, some more text, ...)<br />
:Prints text to the main window. Similar to [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#display|display()]] for those. This function works similarly to the print() you will see in guides for Lua.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
print("hi!")<br />
print(1,2,3)<br />
print(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==raiseWindow==<br />
;raiseWindow(labelName)<br />
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to bring to the top of the rest.<br />
<br />
{{MudletVersion|3.1}}<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel<br />
</syntaxhighlight><br />
<br />
==replace==<br />
;replace([windowName], with, [keepcolor])<br />
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.<br />
<br />
{{note}}<br />
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.<br />
<br />
{{note}}<br />
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 | insertText()]] does.<br />
<br />
See also: [[#creplace|creplace]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of window (a miniconsole)<br />
* ''with:''<br />
: the new text to display.<br />
* ''keepcolor:''<br />
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
-- replace word "troll" with "cute trolly"<br />
selectString("troll",1)<br />
replace("cute trolly")<br />
<br />
-- replace the whole line<br />
selectCurrentLine()<br />
replace("Out with the old, in with the new!")<br />
</syntaxhighlight><br />
<br />
==replaceAll==<br />
;replaceAll(what, with, [keepcolor])<br />
: Replaces all occurrences of ''what'' in the current line with ''with''.<br />
<br />
;Parameters<br />
* ''what:''<br />
: the text to replace<br />
{{note}}<br />
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]<br />
* ''with:''<br />
: the new text to have in place<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors.<br />
{{note}} keepcolor is available in Mudlet 4.10+<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the word "south" in the line with "north"<br />
replaceAll("south", "north")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the text that the variable "target" has<br />
replaceAll(target, "The Bad Guy")<br />
</syntaxhighlight><br />
<br />
==replaceWildcard==<br />
;replaceWildcard(which, replacement, [keepcolor])<br />
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString(matches[2], 1)<br />
replace("text")<br />
</syntaxhighlight><br />
<br />
;Parameters<br />
* ''which:''<br />
: Wildcard to replace.<br />
* ''replacement:''<br />
: Text to replace the wildcard with.<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors<br />
{{note}} keepcolor available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello<br />
</syntaxhighlight><br />
<br />
==resetCmdLineAction==<br />
;resetCmdLineAction(commandLineName)<br />
: Resets the action on the command line so the it behaves like the main command line again.<br />
;Parameters<br />
<br />
* ''commandLineName''<br />
: The name of the command line the action will be resetet.<br />
: See also: [[#setCmdLineAction | setCmdLineAction()]]<br />
{{MudletVersion|4.10}}<br />
<br />
==resetBackgroundImage==<br />
;resetBackgroundImage([windowName])<br />
: Resets the console background-image<br />
;Parameters<br />
<br />
* ''windowName''<br />
: (optional) name of the console the image will be reset<br />
: See also: [[#setBackgroundImage | setBackgroundImage()]]<br />
{{MudletVersion|4.10}}<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: 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.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==resetLabelCursor==<br />
;resetLabelCursor(labelName)<br />
: Resets your mouse cursor to the default one.<br />
<br />
: See also: [[#setLabelCursor|setLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{MudletVersion|4.8}}<br />
<br />
;Parameters<br />
* ''labelName'': label for which to reset the cursor for.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetLabelCursor("myLabel")<br />
-- This will reset the mouse cursor over myLabel to the default one<br />
</syntaxhighlight><br />
<br />
==resetLabelToolTip==<br />
;resetLabelToolTip(labelName)<br />
: Resets the tooltip on the given label.<br />
{{MudletVersion|4.6.1}}<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label the tooltip will be reseted.<br />
: See also: [[#setLabelToolTip | setLabelToolTip()]]<br />
<br />
==resetMapWindowTitle==<br />
;resetMapWindowTitle()<br />
: resets the title of the popped out map window to default.<br />
<br />
{{MudletVersion|4.8}}<br />
<br />
: See also: [[#setMapWindowTitle|setMapWindowTitle()]]<br />
<br />
==resetUserWindowTitle==<br />
;resetUserWindowTitle(windowName)<br />
: resets the title of the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow for which the title will be resetet<br />
<br />
{{MudletVersion|4.8}}<br />
<br />
: See also: [[#setUserWindowTitle|setUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==resizeWindow==<br />
;resizeWindow(windowName, width, height)<br />
: Resizes a mini console, label, or floating User Windows.<br />
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
* ''width:''<br />
: The new width you want<br />
* ''height:''<br />
: The new height you want<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.<br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumber:''<br />
: number of the capture group you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".<br />
--If you want to color the amount of money you have green you do:<br />
<br />
selectCaptureGroup(1)<br />
setFgColor(0,255,0)<br />
</syntaxhighlight><br />
<br />
==selectCurrentLine==<br />
; selectCurrentLine([windowName])<br />
: 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.<br />
<br />
{{note}}<br />
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.<br />
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- color the whole line green!<br />
selectCurrentLine()<br />
fg("green")<br />
deselect()<br />
resetFormat()<br />
<br />
-- to select the previous line, you can do this:<br />
moveCursor(0, getLineNumber()-1)<br />
selectCurrentLine()<br />
<br />
-- to select two lines back, this:<br />
moveCursor(0, getLineNumber()-2)<br />
selectCurrentLine()<br />
<br />
</syntaxhighlight><br />
<br />
==selectSection==<br />
;selectSection( [windowName], fromPosition, length )<br />
: 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.<br />
: 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.<br />
<br />
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]<br />
<br />
;Parameters<br />
* "windowName:"<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.<br />
: Will not work if "main" is given as the windowName to try to select from the main window.<br />
* ''fromPosition:''<br />
: number to specify at which position in the line to begin selecting<br />
* ''length:''<br />
: number to specify the amount of characters you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and colour the first character in the line red<br />
if selectSection(0,1) then fg("red") end<br />
<br />
-- select and colour the second character green (start selecting from the first character, and select 1 character)<br />
if selectSection(1,1) then fg("green") end<br />
<br />
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)<br />
if selectSection(2,3) then fg("grey") end<br />
</syntaxhighlight><br />
<br />
==selectString==<br />
;selectString( [windowName], text, number_of_match )<br />
: 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).<br />
<br />
{{note}}<br />
You can move the user cursor with [[#moveCursor | moveCursor()]]. When a new line arrives from the game, 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 | deselect()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.<br />
* ''text:''<br />
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).<br />
* ''number_of_match:''<br />
: 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.<br />
<br />
: Returns position in line or -1 on error (text not found in line)<br />
<br />
{{note}}<br />
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if selectString( "big monster", 1 ) > -1 then fg("red") end<br />
</syntaxhighlight><br />
<br />
==setAppStyleSheet==<br />
;setAppStyleSheet(stylesheet [, tag])<br />
: Sets a stylesheet for the entire Mudlet application and every open profile. Because it affects other profiles that might not be related to yours, it's better to use [[#setProfileStyleSheet|setProfileStyleSheet()]] instead of this function.<br />
<br />
: Raises the sysAppStyleSheetChange event which comes with two arguments in addition to the event name. The first is the optional tag which was passed into the function, or "" if nothing was given. The second is the profile which made the stylesheet changes.<br />
<br />
: See also: [[#setProfileStyleSheet|setProfileStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use.<br />
<br />
* ''tag:'' (available in Mudlet 3.19+)<br />
: (optional) string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event<br />
<br />
;References<br />
: See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setAppStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
]])<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|3.0}}<br />
<br />
{{note}} Enhanced in Mudlet version 3.19.0 to generate an event that profiles/packages can utilise to redraw any parts of the UI that they themselves had previously styled so their effects can be re-applied to the new application style.<br />
<br />
It is anticipated that the Mudlet application itself will make further use of application styling effects and two strings are provisionally planned for the second parameter in the ''sysAppStyleSheetChange'' event: "''mudlet-theme-dark''" and "''mudlet-theme-light''"; it will also set the third parameter to "''system''".<br />
<br />
==setBackgroundColor==<br />
;setBackgroundColor([windowName], r, g, b, transparency)<br />
: Sets the background for the given label, miniconsole, or userwindow. Colors are from 0 to 255 (0 being black), and transparency is from 0 to 255 (0 being completely transparent).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.<br />
* ''r:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''g:''<br />
: Amount of green to use, from 0 (none) to 255 (full).<br />
* ''b:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).<br />
<br />
{{note}}<br />
Transparency also available for main/miniconsoles in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red label that's somewhat transparent<br />
setBackgroundColor("some label",255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setBackgroundImage==<br />
;setBackgroundImage(labelName, imageLocation)<br />
;setBackgroundImage([windowname], imageLocation, [mode])<br />
: Loads an image file (png) as a background image for a label or console. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.<br />
<br />
{{note}}<br />
You can also load images on labels via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].<br />
<br />
;Parameters (label)<br />
<br />
* ''labelName:''<br />
: The name of the label to change it's background color.<br />
* ''imageLocation:''<br />
: 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.<br />
<br />
;Parameters (consoles)<br />
<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow to change the background image on, or "main" for the main window.<br />
* ''imageLocation:''<br />
: 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.<br />
* ''mode:''<br />
: (optional) allows different modes for drawing the background image. Possible modes areː <br />
<br />
** border - the background image is stretched (1)<br />
** center - the background image is in the center (2), <br />
** tile - the background image is 'tiled' (3)<br />
** style - choose your own background image stylesheet, see example below (4)<br />
<br />
: See also: [[#resetBackgroundImage | resetBackgroundImage()]]<br />
<br />
;Example (label)<br />
<syntaxhighlight lang="lua"><br />
-- give the top border a nice look<br />
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])<br />
</syntaxhighlight><br />
<br />
;Example (main/miniconsole)<br />
<syntaxhighlight lang="lua"><br />
-- give the main window a background image<br />
setBackgroundImage("main", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- or use your own for the main window:<br />
setBackgroundImage("main", [[C:\Documents and Settings\bub\Desktop\mypicture.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image and put it in the center<br />
setBackgroundImage("my_miniconsole", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image with own stylesheet option<br />
setBackgroundImage("my_miniconsole", [[background-image: url(:/Mudlet_splashscreen_development.png); background-repeat: no-repeat; background-position: right;]], "style")<br />
</syntaxhighlight><br />
{{note}} setBackgroundImage for main/miniconsoles and userwindows available in Mudlet 4.10+<br />
<br />
==setBgColor==<br />
;setBgColor([windowName], r, g, b, transparency)<br />
: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.<br />
<br />
:If you'd like to change the background color of a window, see [[#setBackgroundColor|setBackgroundColor()]].<br />
<br />
: ''See also:'' [[#cecho|cecho()]], [[#setBackgroundColor|setBackgroundColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Optional, if not used color is fully opaque<br />
<br />
<br />
<br />
{{note}}<br />
Transparency parameter available in Mudlet 4.10+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red background color.<br />
selectString( "Tom", 1 )<br />
setBgColor( 255,0,0 )<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--prints "Hello" on red background and "You" on blue.<br />
setBgColor(255,0,0)<br />
echo("Hello")<br />
setBgColor(0,0,255)<br />
echo(" You!")<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBold==<br />
;setBold(windowName, boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
<br />
* ''boolean:''<br />
: A <code>true</code> or <code>false</code> that enables or disables bolding of text<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- enable bold formatting<br />
setBold(true)<br />
-- the following echo will be bolded<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBorderBottom==<br />
;setBorderBottom(size)<br />
: Sets the size of the bottom border of the main window in pixels. A border means that the game text won't go on it, so this gives you room to place your graphical elements there.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
</syntaxhighlight><br />
<br />
==setBorderColor==<br />
;setBorderColor(red, green, blue)<br />
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]<br />
<br />
;Parameters<br />
* ''red:''<br />
: Amount of red color to use, from 0 to 255.<br />
* ''green:''<br />
: Amount of green color to use, from 0 to 255.<br />
* ''blue:''<br />
: Amount of blue color to use, from 0 to 255.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set the border to be completely blue<br />
setBorderColor(0, 0, 255)<br />
<br />
-- or red, using a name<br />
setBorderColor( unpack(color_table.red) )<br />
</syntaxhighlight><br />
<br />
==setBorderLeft==<br />
;setBorderLeft(size)<br />
: Sets the size of the left border of the main window in pixels. A border means that the game text won't go on it, so this gives you room to place your graphical elements there.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
</syntaxhighlight><br />
<br />
==setBorderRight==<br />
;setBorderRight(size)<br />
: Sets the size of the right border of the main window in pixels. A border means that the game text won't go on it, so this gives you room to place your graphical elements there.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
</syntaxhighlight><br />
<br />
==setBorderSizes==<br />
;setBorderSizes(top, right, bottom, left)<br />
: Sets the size of all borders of the main window in pixels. A border means that the game text won't go on it, so this gives you room to place your graphical elements there.<br />
: The exact result of this function depends on how many numbers you give to it as arguments.<br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]<br />
<br />
: {{MudletVersion|4.0}}<br />
<br />
;Arguments<br />
* '''setBorderSizes(top, right, bottom, left)'''<br />
: ''4 arguments:'' All borders will be set to their new given size.<br />
* '''setBorderSizes(top, width, bottom)''' <br />
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width. <br />
* '''setBorderSizes(height, width)'''<br />
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width. <br />
* '''setBorderSizes(size)'''<br />
: ''1 argument:'' All borders will be set to the same size.<br />
* '''setBorderSizes()'''<br />
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0) <br />
-- big border at the top, bigger at the bottom, small at the right, none at the left<br />
<br />
setBorderSizes(100, 50, 150) <br />
-- big border at the top, bigger at the bottom, small at the right and the left<br />
<br />
setBorderSizes(100, 50) <br />
-- big border at the top and the bottom, small at the right and the left<br />
<br />
setBorderSizes(100) <br />
-- big borders at all four sides<br />
<br />
setBorderSizes() <br />
-- no borders at all four sides<br />
</syntaxhighlight><br />
<br />
==setBorderTop==<br />
;setBorderTop(size)<br />
: Sets the size of the top border of the main window in pixels. A border means that the game text won't go on it, so this gives you room to place your graphical elements there.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
</syntaxhighlight><br />
<br />
==setFgColor==<br />
;setFgColor([windowName], red, green, blue)<br />
:Sets the current text foreground color in the main window unless windowName parameter given.<br />
<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''red:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''green:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''blue:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]], [[#setHexBgColor | setHexBgColor()]], [[#resetFormat | resetFormat()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setFgColor( 255, 0, 0 )<br />
</syntaxhighlight><br />
<br />
==setButtonStyleSheet==<br />
;setButtonStyleSheet(button, markup)<br />
: Applies Qt style formatting to a button via a special markup language.<br />
<br />
; Parameters<br />
* ''button:''<br />
: The name of the button to be formatted.<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note: You can instead use QWidget { markup }. QWidget will reference 'button', allowing the use of pseudostates like QWidget:hover and QWidget:selected<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setButtonStyleSheet("my test button", [[<br />
QWidget {<br />
background-color: #999999;<br />
border: 3px #777777;<br />
}<br />
QWidget:hover {<br />
background-color: #bbbbbb;<br />
}<br />
QWidget:checked {<br />
background-color: #77bb77;<br />
border: 3px #559955;<br />
}<br />
QWidget:hover:checked {<br />
background-color: #99dd99;<br />
} ]])</syntaxhighlight><br />
<br />
==setClipboardText==<br />
;setClipboardText(textContent)<br />
: Sets the value of the computer's clipboard to the string data provided.<br />
: See also: [[#getClipboardText | getClipboardText()]]<br />
<br />
; Parameters<br />
* ''textContent:''<br />
: The text to be put into the clipboard.<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setClipboardText("New Clipboard Contents")<br />
echo("Clipboard: " .. getClipboardText()) -- should echo "Clipboard: New Clipboard Contents"<br />
</syntaxhighlight><br />
<br />
==setCmdLineAction==<br />
;setCmdLineAction(commandLineName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user sends text to the command line. 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 command line action. Additionally, this function passes the command line input text as the final argument.<br />
{{note}} If no action is set the command line behaves like the main command line and sends commands directly to the game or alias engine.<br />
<br />
The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, text)<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#resetCmdLineAction|resetCmdLineAction()]]<br />
<br />
;Parameters<br />
<br />
* ''commandLineName:''<br />
: The name of the command line to attach the action function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} You can also pass a function directly instead of using a string<br />
<br />
{{MudletVersion|4.10}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function sendTextToMiniConsole(miniConsoleName, cmdLineText)<br />
echo(miniConsoleName, cmdLineText.."\n")<br />
end<br />
<br />
setCmdLineAction("myCmdLine", "sendTextToMiniConsole", "myMiniConsole")<br />
<br />
</syntaxhighlight><br />
<br />
==setCmdLineStyleSheet==<br />
;setCmdLineStyleSheet([commandLineName], markup)<br />
: Applies Qt style formatting to a command line via a special markup language.<br />
<br />
;Parameters<br />
* ''commandLineName:''<br />
: (optional) Name of the command line (or miniconsole the command line is in). If not given the stylesheet will be applied to the main command line.<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
<br />
{{MudletVersion|4.10}}<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#createCommandLine|createCommandLine()]]<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- move the main command line over to the right<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
padding-left: 100px; /* change 100 to your number */<br />
background-color: black; /* change it to your background color */<br />
}<br />
]])<br />
<br />
--only change font-size of your main command line<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
font-sizeː20pt; <br />
}<br />
]])<br />
<br />
--change bg/fg color of your miniconsole command line (name of the miniconsole is 'myMiniconsole'<br />
--the command line in the miniconsole has to be enabled<br />
setCmdLineStyleSheet("myMiniConsole", [[<br />
QPlainTextEdit {<br />
background: rgb(0,100,0);<br />
color: rgb(0,200,255);<br />
font-size: 10pt;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
==setFont==<br />
;setFont(name, font)<br />
: Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Prefer a monospaced font - those work best with text games. See here [https://doc.qt.io/qt-5/qfont.html#setFamily for more].<br />
: See also: [[#getFont|getFont()]], [[#setFontSize|setFontSize()]], [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''font:''<br />
: The font to use.<br />
<br />
{{MudletVersion|3.9}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.<br />
setFont("Ubuntu Mono")<br />
setFont("main", "Ubuntu Mono")<br />
<br />
-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.<br />
setFont("combat", "Ubuntu Mono")<br />
</syntaxhighlight><br />
<br />
==setFontSize==<br />
;setFontSize(name, size)<br />
: Sets a font size on the given window or console name. Can be used to change font size of the Main console as well as dockable UserWindows.<br />
: See Also: [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
* ''size:''<br />
: The font size to apply to the window.<br />
<br />
{{MudletVersion|3.4}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to 12-point font.<br />
setFontSize(12)<br />
setFontSize("main", 12)<br />
<br />
-- This will set the font size of a user window named "uw1" to 12-point font.<br />
setFontSize("uw1", 12)<br />
</syntaxhighlight><br />
<br />
==setGauge==<br />
;setGauge(gaugeName, currentValue, maxValue, gaugeText)<br />
: 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.<br />
<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#createGauge|createGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a gauge<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
--Change the looks of the gauge named healthBar and make it<br />
--fill to half of its capacity. The height is always remembered.<br />
setGauge("healthBar", 200, 400)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
--If you wish to change the text on your gauge, you’d do the following:<br />
setGauge("healthBar", 200, 400, "some text")<br />
</syntaxhighlight><br />
<br />
==setGaugeStyleSheet==<br />
;setGaugeStyleSheet(gaugeName, css, cssback, csstext)<br />
: 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. You can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create stylesheets.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]],<br />
[[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
</syntaxhighlight><br />
<br />
==setGaugeText==<br />
;setGaugeText(gaugename, css, ccstext )<br />
: Set the formatting of the text used inside the inserted gaugename.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
setGaugeText("healthBar", [[<p style="font-weight:bold;color:#C9C9C9;letter-spacing:1pt;word-spacing:2pt;font-size:12px;text-align:center;font-family:arial black, sans-serif;">]]..MY_NUMERIC_VARIABLE_HERE..[[</p>]])</syntaxhighlight><br />
<br />
;Useful resources:<br />
:http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.<br />
:https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!<br />
<br />
==setHexBgColor==<br />
;setHexBgColor([windowName], hexColorString)<br />
:Sets the current text nackground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.<br />
selectString( "Tom", 1 )<br />
setHexBgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setHexFgColor==<br />
;setHexFgColor([windowName], hexColorString)<br />
:Sets the current text foreground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text foreground color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setFgColor | setFgColor()]], [[#setHexBgColor | setHexBgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setHexFgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setItalics==<br />
;setItalics(windowName, bool)<br />
: Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setLabelToolTip==<br />
;setLabelToolTip(labelName, text, [duration])<br />
: Sets a tooltip on the given label.<br />
{{MudletVersion|4.6.1}}<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to set the tooltip to.<br />
* ''text:''<br />
: The text to be shown. Can contain Qt rich text formats.<br />
* ''duration:''<br />
: Duration of the tooltip timeout in seconds. Optional, if not set the default duration will be set.<br />
<br />
: See also: [[Manual:UI_Functions#resetLabelToolTip|resetLabelToolTip()]]<br />
<br />
==setLabelClickCallback==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument. This table contains information about the mouse button clicked, other buttons that were pressed at the time, and the mouse cursor's local (relative to the label) and global (relative to the Mudlet window) position. The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, event)<br />
</syntaxhighlight><br />
<br />
where '''event''' has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
button = "LeftButton",<br />
buttons = {"RightButton", "MidButton"},<br />
}<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]],[[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} Event argument is available in 3.6+, and in 4.8+ you can pass a function directly instead of a string.<br />
<br />
{{note}}<br />
While '''event.button''' may contain a single string of any listed below, '''event.buttons''' will only ever contain some combination of "LeftButton", "MidButton", and "RightButton"<br />
:The following mouse button strings are defined:<br />
<pre><br />
"LeftButton" "RightButton" "MidButton"<br />
"BackButton" "ForwardButton" "TaskButton"<br />
"ExtraButton4" "ExtraButton5" "ExtraButton6"<br />
"ExtraButton7" "ExtraButton8" "ExtraButton9"<br />
"ExtraButton10" "ExtraButton11" "ExtraButton12"<br />
"ExtraButton13" "ExtraButton14" "ExtraButton15"<br />
"ExtraButton16" "ExtraButton17" "ExtraButton18"<br />
"ExtraButton19" "ExtraButton20" "ExtraButton21"<br />
"ExtraButton22" "ExtraButton23" "ExtraButton24"<br />
</pre><br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
else if event.button == "RightButton" then<br />
send("swim north")<br />
else if event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )<br />
<br />
-- you can also use them within tables now:<br />
mynamespace = {<br />
onClickGoNorth = function()<br />
echo("the north button was clicked!")<br />
end<br />
}<br />
<br />
setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )<br />
<br />
</syntaxhighlight><br />
<br />
==setLabelDoubleClickCallback==<br />
;setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user double 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
{{MudletVersion|3.6}}<br />
<br />
: See also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
==setLabelMoveCallback==<br />
;setLabelMoveCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse moves while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{MudletVersion|3.6}}<br />
<br />
==setLabelOnEnter==<br />
;setLabelOnEnter(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the '''event''' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
}<br />
</syntaxhighlight><br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseOver()<br />
echo("The mouse is hovering over the label!\n")<br />
end<br />
<br />
setLabelOnEnter( "compassNorthImage", "onMouseOver" )<br />
</syntaxhighlight><br />
<br />
==setLabelOnLeave==<br />
;setLabelOnLeave(labelName, luaFunctionName, [any arguments])<br />
: 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.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseLeft(argument)<br />
echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)<br />
end<br />
<br />
setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )<br />
</syntaxhighlight><br />
<br />
==setLabelReleaseCallback==<br />
;setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
This command was added in version 3.0.0<br />
<br />
{{note}}<br />
The ''event'' argument only available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onReleaseNorth()<br />
echo("the north button was released!")<br />
end<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onReleaseNorth = function()<br />
echo("the north button was released!")<br />
end<br />
}<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )<br />
</syntaxhighlight><br />
<br />
==setLabelStyleSheet==<br />
;setLabelStyleSheet(label, markup)<br />
: Applies Qt style formatting to a label via a special markup language.<br />
<br />
; Parameters<br />
* ''label:''<br />
: The name of the label to be formatted (passed when calling createLabel).<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a white background and a green border, with the text "test"<br />
-- inside.<br />
createLabel("test", 50, 50, 100, 100, 0)<br />
setLabelStyleSheet("test", [[<br />
background-color: white;<br />
border: 10px solid green;<br />
font-size: 12px;<br />
]])<br />
echo("test", "test")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that will tile or clip depending on the<br />
-- size of the label. To use this example, please supply your own image.<br />
createLabel("test5", 50, 353, 164, 55, 0)<br />
setLabelStyleSheet("test5", [[<br />
background-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that can be resized (such as during a<br />
-- sysWindowResizeEvent). To use this example, please supply your own image.<br />
createLabel("test9", 215, 353, 100, 100, 0)<br />
setLabelStyleSheet("test9", [[<br />
border-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--This creates a label whose background changes when the users mouse hovers over it.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
local ourLabelStyle = [[<br />
QLabel{<br />
background-color: ]]..labelBackgroundColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
QLabel::hover{<br />
background-color: ]]..labelHoverColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--Using QLabel::hover mentioned above. Lets "trick" the label into changing it's text.<br />
--Please keep in mind that the setLabelMoveCallback allows for much more control over not just your label but your entire project.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
--Notice we are adding a string returned from a function. In this case, the users profile directory.<br />
local ourLabelStyle = [[<br />
QLabel{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithtext.png");<br />
}<br />
QLabel::hover{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithhovertext.png");<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
--This is just to example that echos draw on top of the label. You would not want to echo onto a label you were drawing text on with images, because echos would draw on top of them.<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<br />
==setLabelCursor==<br />
;setLabelCursor(labelName, cursorShape)<br />
: Changes how the mouse cursor looks like when over the label. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{MudletVersion|4.8}}<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''cursorShape''<br />
: Shape of the mouse cursor. List of possible cursor shapes is [[CursorShapes| available here]].<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCursor("myLabel", "Cross")<br />
-- This will change the mouse cursor to a cross if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelCustomCursor==<br />
;setLabelCustomCursor(labelName, custom cursor, [hotX, hotY])<br />
: Changes the mouse cursor shape over your label to a custom cursor. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCursor|setLabelCursor()]]<br />
<br />
{{MudletVersion|4.8}}<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''custom cursor''<br />
: Location of your custom cursor file. To be compatible with all systems it is recommended to use png files with size of 32x32.<br />
* ''hotX''<br />
: X-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
* ''hotY''<br />
: Y-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCustomCursor("myLabel", getMudletHomeDir().."/custom_cursor.png")<br />
-- This will change the mouse cursor to your custom cursor if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelWheelCallback==<br />
;setLabelWheelCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse wheel is scrolled while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the ''event'' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
buttons = {"RightButton", "MidButton"},<br />
angleDeltaX = 0,<br />
angleDeltaY = 120<br />
}<br />
</syntaxhighlight><br />
<br />
: Keys ''angleDeltaX'' and ''angleDeltaY'' correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{MudletVersion|3.6}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onWheelNorth(event)<br />
if event.angleDeltaY > 0 then<br />
echo("the north button was wheeled forwards over!")<br />
else<br />
echo("the north button was wheeled backwards over!")<br />
end<br />
end<br />
<br />
setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onWheelNorth = function()<br />
echo("the north button was wheeled over!")<br />
end<br />
}<br />
<br />
setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )<br />
</syntaxhighlight><br />
<br />
==setLink==<br />
;setLink([windowName], command, tooltip)<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of a miniconsole or a userwindow in which to select the text in.<br />
* ''command:''<br />
: command to do when the text is clicked.<br />
* ''tooltip:''<br />
: tooltip to show when the mouse is over the text - explaining what would clicking do.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can clickify a lot of things to save yourself some time - for example, you can change<br />
-- the line where you receive a message to be clickable to read it!<br />
-- prel regex trigger:<br />
-- ^You just received message #(\w+) from \w+\.$<br />
-- script:<br />
selectString(matches[2], 1)<br />
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])<br />
resetFormat()<br />
<br />
-- an example of selecting text in a miniconsole and turning it into a link:<br />
<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
HelloWorld:echo("hi")<br />
selectString("HelloWorld", "hi", 1)<br />
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")<br />
</syntaxhighlight><br />
<br />
==setMainWindowSize==<br />
;setMainWindowSize(mainWidth, mainHeight)<br />
: Changes the size of your main Mudlet window to the values given.<br />
: See Also: [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''mainWidth:''<br />
: The new width in pixels.<br />
* ''mainHeight:''<br />
: The new height in pixels.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will resize your main Mudlet window<br />
setMainWindowSize(1024, 768)<br />
</syntaxhighlight><br />
<br />
==setMapWindowTitle==<br />
;setMapWindowTitle(text)<br />
: Changes the title shown in the mapper window when it's popped out.<br />
: See also: [[#resetMapWindowTitle|resetMapWindowTitle()]]<br />
<br />
; Parameters<br />
* ''text:''<br />
: New window title to set.<br />
<br />
{{MudletVersion|4.8}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapWindowTitle("my cool game map")<br />
</syntaxhighlight><br />
<br />
==setMiniConsoleFontSize==<br />
;setMiniConsoleFontSize(name, fontSize)<br />
: Sets the font size of the mini console. see also: [[#setFontSize | setFontSize()]], [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]]<br />
<br />
==setOverline==<br />
;setOverline([windowName], boolean)<br />
: Sets the current text font to be overlined (true) or not overlined (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 overlined. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be overlined until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be overlined or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables overlining of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable overlined text<br />
setOverline(true)<br />
-- the following echo will be have an overline<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and reverse have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|3.17}}<br />
<br />
==setPopup==<br />
;setPopup([windowName,] unusedString, {lua code}, {hints})<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
: This argument was ignored before Mudlet 4.11.<br />
* ''unusedString:''<br />
: This argument is ignored, but must be present for compatibility with older releases.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,<br />
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking<br />
-- will show some commands you can do.<br />
<br />
selectString("Hello", 1)<br />
setPopup("main", "", {[[send("bye")]], [[echo("hi!")]]}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
</syntaxhighlight><br />
<br />
==setProfileStyleSheet==<br />
;setProfileStyleSheet(stylesheet)<br />
: Sets a stylesheet for the current Mudlet profile - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). This function is better than setAppStyleSheet() because it affects only the current profile and not every other one as well.<br />
<br />
: See also: [[#setAppStyleSheet|setAppStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use. See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setProfileStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
<br />
QTreeView {<br />
background: ]]..background_color..[[;<br />
color: white;<br />
}<br />
<br />
QMenuBar{ background-color: ]]..background_color..[[;}<br />
<br />
QMenuBar::item{ background-color: ]]..background_color..[[;}<br />
<br />
QDockWidget::title {<br />
background: ]]..border_color..[[;<br />
}<br />
QStatusBar {<br />
background: ]]..border_color..[[;<br />
}<br />
QScrollBar:vertical {<br />
background: ]]..background_color..[[;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background-color: ]]..background_color..[[;<br />
min-height: 20px;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 7px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-bottom-left-radius: 7px;<br />
border-bottom-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-top-left-radius: 7px;<br />
border-top-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
background: white;<br />
width: 4px;<br />
height: 3px;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]])<br />
<br />
-- if you'd like to reset it, use:<br />
setProfileStyleSheet("")<br />
<br />
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':<br />
setProfileStyleSheet[[<br />
TConsole QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
TConsole QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
TConsole QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.6}}<br />
<br />
==setReverse==<br />
;setReverse([windowName], boolean)<br />
: Sets the current text to swap foreground and background color settings (true) or not (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 have it's colors swapped. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will have their foreground and background colors swapped until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text colors to be reversed or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables reversing of the fore- and back-ground colors of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable fore/back-ground color reversal of text<br />
setReverse(true)<br />
-- the following echo will have the text colors reversed<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and overline have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|3.17}}<br />
<br />
{{note}} Although the visual effect on-screen is the same as that of text being selected if both apply to a piece of text they neutralise each other - however the effect of the reversal ''will'' be carried over in copies made by the "Copy to HTML" and in logs made in HTML format log file mode.<br />
<br />
==setStrikeOut==<br />
;setStrikeOut([windowName], boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be striken out until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be stricken out or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables striking out of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable striken-out text<br />
setStrikeOut(true)<br />
-- the following echo will be have a strikethrough<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setTextFormat==<br />
;setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])<br />
: Sets current text format of selected window. This is a more convenient means to set all the individual features at once compared to using [[#setFgColor|setFgColor]]( windowName, r,g,b ), [[#setBold|setBold]]( windowName, true ), [[#setItalics|setItalics]]( windowName, true ), [[#setUnderline|setUnderline]]( windowName, true ), [[#setStrikeOut|setStrikeOut]]( windowName, true ).<br />
: See Also: [[Manual:Lua_Functions#getTextFormat|getTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: Specify name of selected window. If empty string "" or "main" format will be applied to the main console<br />
* ''r1,g1,b1''<br />
: To color text background, give number values in RBG style<br />
* ''r2,g2,b2''<br />
: To color text foreground, give number values in RBG style<br />
* ''bold''<br />
: To format text bold, set to 1 or true, otherwise 0 or false<br />
* ''underline''<br />
: To underline text, set to 1 or true, otherwise 0 or false<br />
* ''italics''<br />
: To format text italic, set to 1 or true, otherwise 0 or false<br />
* ''strikeout<br />
: (optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''overline<br />
: (optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''reverse<br />
: (optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This script would create a mini text console and write with bold, struck-out, yellow foreground color and blue background color "This is a test".<br />
createMiniConsole( "con1", 0,0,300,100);<br />
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);<br />
echo("con1","This is a test")<br />
</syntaxhighlight><br />
<br />
{{note}} In versions prior to 3.7.0 the error messages ''and this wiki'' were wrong in that they had the foreground color parameters as r1, g1 and b1 and the background ones as r2, g2 and b2.<br />
<br />
==setUnderline==<br />
;setUnderline(windowName, bool)<br />
: Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setUserWindowTitle==<br />
;setUserWindowTitle(windowName, text)<br />
: sets a new title text for the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''text''<br />
: new title text<br />
<br />
{{MudletVersion|4.8}}<br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==setUserWindowStyleSheet==<br />
;setUserWindowStyleSheet(windowName, markup)<br />
: Applies Qt style formatting to the border/title area of a userwindow via a special markup language.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when you dock the userwindow the border style is not provided by this<br />
<br />
{{MudletVersion|4.10}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- changes the title area style of the UserWindow 'myUserWindow'<br />
setUserWindowStyleSheet("myUserWindow", [[QDockWidget::title{ <br />
background-color: rgb(0,255,150);<br />
border: 2px solid red;<br />
border-radius: 8px;<br />
text-align: center; <br />
}]])<br />
</syntaxhighlight><br />
<br />
: See also: [[#openUserWindow|openUserWindow()]]<br />
<br />
==setWindow==<br />
;setWindow(windowName, name, [Xpos, Ypos, show])<br />
: Changes the parent window of an element.<br />
{{MudletVersion|4.8}}<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow which you want the element put in. If you want to put the element into the main window, use windowName "main".<br />
* ''name''<br />
: Name of the element which you want to switch the parent from. Elements can be labels, miniconsoles and the embedded mapper. If you want to move the mapper use the name "mapper"<br />
* ''Xpos:''<br />
: X position of the element. Measured in pixels, with 0 being the very left. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''Ypos:''<br />
: Y position of the element. Measured in pixels, with 0 being the very top. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''show:''<br />
: true or false to decide if the element will be shown or not in the new parent window. Optional, if not given it will be true.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindow("myuserwindow", "mapper")<br />
-- This will put your embedded mapper in your userwindow "myuserwindow".<br />
</syntaxhighlight><br />
<br />
==setWindowWrap==<br />
;setWindowWrap(windowName, wrapAt)<br />
: sets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapAt:''<br />
: Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==setWindowWrapIndent==<br />
;setWindowWrapIndent(windowName, wrapTo)<br />
: sets how many spaces wrapped text will be indented with (after the first line of course).<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapTo:''<br />
: Number of spaces which wrapped lines are prefixed with.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
setWindowWrapIndent("main", 3)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==showCaptureGroups==<br />
;showCaptureGroups()<br />
:Lua debug function that highlights in random colors 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 DebugTools.lua.<br />
<br />
;Example:<br />
: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.<br />
<br />
==showMultimatches==<br />
;showMultimatches()<br />
: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. This function is defined in DebugTools.lua.<br />
<br />
;Example:<br />
See [[Manual:Advanced_Lua#How_to_use_multimatches.5Bn.5D.5Bm.5D|How to use multimatches[n][m]]] for a more thorough explanation including examples.<br />
<br />
==showWindow==<br />
;showWindow(name)<br />
: Makes a hidden window (label or miniconsole) be shown again.<br />
<br />
: See also: [[#hideWindow | hideWindow()]]<br />
<br />
==showColors==<br />
;showColors([columns], [filterColor], [sort])<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in '''color_table''', in table form. The format is ''color_table.colorName = {r, g, b}''.<br />
<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: (optional) number of columns to print the color table in.<br />
* ''filterColor:''<br />
: (optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.<br />
* ''sort:''<br />
: (optional) sort colors alphabetically.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- display as four columns:<br />
showColors(4)<br />
<br />
-- show only red colours:<br />
showColors("red")<br />
</syntaxhighlight><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)|thumb|center]]<br />
<br />
==showToolBar==<br />
;showToolBar(name)<br />
: Makes a toolbar (a button group) appear on the screen.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
showToolBar("my attack buttons")<br />
</syntaxhighlight><br />
<br />
==suffix==<br />
;suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
: Suffixes text at the end of the current line. This is similar to [[Manual:Lua_Functions#echo | echo()]], which also suffixes text at the end of the line, but different - [[Manual:Lua_Functions#echo | 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.<br />
<br />
;Parameters<br />
* ''text''<br />
: the information you want to prefix<br />
* ''writingFunction''<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* ''foregroundColor''<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* ''backgroundColor''<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* ''windowName''<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
<br />
: See also: [[#prefix | prefix()]], [[Manual:Lua_Functions#echo | echo()]]<br />
<br />
==wrapLine==<br />
;wrapLine(windowName, lineNumber)<br />
: 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.:<br />
<br />
<syntaxhighlight lang="lua">selectString(line,1)<br />
replace("")</syntaxhighlight><br />
<br />
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.<br />
<br />
: See Also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#deleteLine|deleteLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The miniconsole or the main window (use ''main'' for the main window)<br />
* ''lineNumber:''<br />
: The line number which you'd like re-wrapped.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- re-wrap the last line in the main window<br />
wrapLine("main", getLineCount())<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15990Manual:Mapper Functions2020-12-31T23:51:55Z<p>Smurf: /* getSpecialExits */ clarify explanation, drop "due to a coding error" (not relevant here)</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that upon clicking will raise an event with all the arguments.<br />
<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Room type")<br />
addMapEvent("markRoomsAsDeathTrap", "onMapMarkSelectedRooms", "Room type", "Mark selected rooms as Death Trap")<br />
addMapEvent("markRoomsAsOneRoom", "onMapMarkSelectedRooms", "Room type", "Mark selected rooms as single-pass")<br />
<br />
function onMapMarkSelectedRooms(event, MarkRoomType)<br />
local SelectedRooms = getMapSelection()["rooms"]<br />
for i, val in ipairs(SelectedRooms) do<br />
if MarkRoomType == "markRoomsAsDeathTrap" then<br />
local r, g, b = unpack(color_table.black)<br />
--death trap<br />
setRoomEnv(val, 300)<br />
--death traps Env<br />
setCustomEnvColor(300, r, g, b, 255)<br />
setRoomChar(val, "☠️")<br />
lockRoom(val, true)<br />
elseif MarkRoomType == "markRoomsAsOneRoom" then<br />
local r, g, b = unpack(color_table.LightCoral)<br />
--single-pass<br />
setRoomEnv(val, 301)<br />
--one room Env<br />
setCustomEnvColor(301, r, g, b, 255)<br />
setRoomChar(val, "🚹")<br />
end<br />
end<br />
updateMap()<br />
end<br />
<br />
registerAnonymousEventHandler("onMapMarkSelectedRooms", "onMapMarkSelectedRooms")<br />
</syntaxhighlight><br />
This create menu and two submenu options: "Mark selected rooms as Death Trap" and "Mark selected rooms as single-pass"<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This will create a menu named: Favorites.<br />
addMapMenu("Favorites")<br />
<br />
-- This will create a submenu with the unique id 'Favorites123' under 'Favorites' with the display name of 'More Favorites'.<br />
addMapMenu("Favorites1234343", "Favorites", "More Favorites") <br />
</syntaxhighlight><br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==auditAreas==<br />
;auditAreas()<br />
<br />
: Initiates a consistency check on the whole map: All rooms, areas, and their composition. This is also done automatically whenever you first open your map, so probably seldom necessary to do manually. Will output findings to screen and/or logfile for later review.<br />
<br />
: See also: [[#saveMap|saveMap()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original height of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', ''BgColor'', ''FgColor'', ''Pixmap'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
:''BgColor'' and ''FgColor'' are tables with ''r'',''g'',''b'' keys, each holding ''0-255'' color component value.<br />
<br />
:''Pixmap'' is base64 encoded image of label.<br />
<br />
{{note}} ''BgColor'', ''FgColor'', ''Pixmap'' are available since Mudlet 4.11<br />
<br />
;Parameters <br />
* ''areaID:'' areaID from which to retrieve label<br />
* ''labelID:'' labelID (''getMapLabels'' return table key) or labelText (exact match)<br />
<br />
See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(52)<br />
{<br />
"no text",<br />
[0] = "test"<br />
}<br />
<br />
lua getMapLabel(52, 0)<br />
{<br />
Y = -2,<br />
X = -8,<br />
Z = 11,<br />
Height = 3.9669418334961,<br />
Text = "test",<br />
Width = 8.6776866912842,<br />
BgColor = {<br />
b = 0,<br />
g = 0,<br />
r = 0<br />
},<br />
FgColor = {<br />
b = 50,<br />
g = 255,<br />
r = 255<br />
},<br />
Pixmap = "iVBORw0KG(...)lFTkSuQmCC" -- base64 encoded png image (shortened for brevity)<br />
}<br />
<br />
lua getMapLabel(52, "no text")<br />
{<br />
Y = 8,<br />
X = -15,<br />
Z = 11,<br />
Height = 7.2520666122437,<br />
Text = "no text"<br />
Width = 11.21900844574,<br />
BgColor = {<br />
b = 0,<br />
g = 0,<br />
r = 0<br />
},<br />
FgColor = {<br />
b = 50,<br />
g = 255,<br />
r = 255<br />
},<br />
Pixmap = "iVBORw0KG(...)lFTkSuQmCC" -- base64 encoded png image (shortened for brevity)<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
:If there are no labels in the area at all, will instead return the area number.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;x,y,z = getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID[, listAllSpecialExitsToSameExitRoom])<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the special exits of.<br />
* ''listAllSpecialExitsToSameExitRoom:''<br />
: (Since ''TBA'') In the case where there is more than one special exit to the same room ID list all of them.<br />
<br />
:Returns a roomid table of sub-tables containingg name/command and exit lock status, of the special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
:Before ''TBA'' (likely to be Mudlet version '''4.11.0'''), if more than one special exit goes to the ''same'' exit room id then one of those exits is returned at random. Since ''TBA'' this will be the best (i.e. lowest-weight) exit that is '''not''' locked; should none be unlocked then the lowest locked one will be listed. In case of a tie, one of the tying exits will be picked at random.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- There are three special exits from 1337 to the room 42:<br />
-- "climb down ladder" which is locked and has an exit weight of 10<br />
-- "step out window" which is unlocked and has an exit weight of 20<br />
-- "jump out window" which is unlocked and has an exit weight of 990<br />
getSpecialExits(1337)<br />
<br />
-- In 4.10.1 and before this could results in:<br />
table {<br />
42 = {"jump out window" = "0"},<br />
666 = {"dive into pit" = "1"}<br />
}<br />
-- OR<br />
table {<br />
42 = {"climb down ladder" = "1"},<br />
666 = {"dive into pit" = "1"}<br />
}<br />
-- OR<br />
table {<br />
42 = {"step out window" = "0"},<br />
666 = {"dive into pit" = "1"}<br />
}<br />
<br />
-- From TBA this will return:<br />
table {<br />
42 = {"step out window" = "0"},<br />
666 = {"dive into pit" = "1"}<br />
}<br />
<br />
-- From TBA, with the second argument as true, this gives:<br />
getSpecialExits(1337, true)<br />
table {<br />
42 = {"step out window" = "0",<br />
"climb down ladder" = "1",<br />
"jump out window" = "0"},<br />
666 = {"dive into pit" = "1"}<br />
}<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==mapSymbolFontInfo==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;returns<br />
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:<br />
:* ''fontName'' - a string of the family name of the font specified<br />
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.<br />
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).<br />
* or ''nil'' and an error message on failure.<br />
<br />
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==openMapWidget==<br />
;openMapWidget([dockingArea | Xpos, Ypos, width, height])<br />
means either of these are fine:<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeMapEvent==<br />
;removeMapEvent(event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#getMapEvents | getMapEvents()]], [[#removeMapMenu | removeMapMenu()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeMapMenu==<br />
;removeMapMenu(menu name)<br />
<br />
:Removes the given submenu from a mappers right-click menu. You can add custom ones with [[#addMapMenu | addMapMenu()]].<br />
: See also: [[#addMapMenu | addMapMenu()]], [[#getMapMenus | getMapMenus()]], [[#removeMapEvent | removeMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Test") -- add submenu to the general menu<br />
removeMapMenu("Test") -- removes that same menu again<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it coloured, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
:If the room was associated with a different hash, or vice versa, that association will be superseded.<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
:* - a string that is the family name of the font to use;<br />
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15976Manual:Mapper Functions2020-12-29T16:30:46Z<p>Smurf: /* setRoomIDbyHash */</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that upon clicking will raise an event with all the arguments.<br />
<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Room type")<br />
addMapEvent("markRoomsAsDeathTrap", "onMapMarkSelectedRooms", "Room type", "Mark selected rooms as Death Trap")<br />
addMapEvent("markRoomsAsOneRoom", "onMapMarkSelectedRooms", "Room type", "Mark selected rooms as single-pass")<br />
<br />
function onMapMarkSelectedRooms(event, MarkRoomType)<br />
local SelectedRooms = getMapSelection()["rooms"]<br />
for i, val in ipairs(SelectedRooms) do<br />
if MarkRoomType == "markRoomsAsDeathTrap" then<br />
local r, g, b = unpack(color_table.black)<br />
--death trap<br />
setRoomEnv(val, 300)<br />
--death traps Env<br />
setCustomEnvColor(300, r, g, b, 255)<br />
setRoomChar(val, "☠️")<br />
lockRoom(val, true)<br />
elseif MarkRoomType == "markRoomsAsOneRoom" then<br />
local r, g, b = unpack(color_table.LightCoral)<br />
--single-pass<br />
setRoomEnv(val, 301)<br />
--one room Env<br />
setCustomEnvColor(301, r, g, b, 255)<br />
setRoomChar(val, "🚹")<br />
end<br />
end<br />
updateMap()<br />
end<br />
<br />
registerAnonymousEventHandler("onMapMarkSelectedRooms", "onMapMarkSelectedRooms")<br />
</syntaxhighlight><br />
This create menu and two submenu options: "Mark selected rooms as Death Trap" and "Mark selected rooms as single-pass"<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This will create a menu named: Favorites.<br />
addMapMenu("Favorites")<br />
<br />
-- This will create a submenu with the unique id 'Favorites123' under 'Favorites' with the display name of 'More Favorites'.<br />
addMapMenu("Favorites1234343", "Favorites", "More Favorites") <br />
</syntaxhighlight><br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==auditAreas==<br />
;auditAreas()<br />
<br />
: Initiates a consistency check on the whole map: All rooms, areas, and their composition. This is also done automatically whenever you first open your map, so probably seldom necessary to do manually. Will output findings to screen and/or logfile for later review.<br />
<br />
: See also: [[#saveMap|saveMap()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original height of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
:If there are no labels in the area at all, will instead return the area number.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;x,y,z = getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==mapSymbolFontInfo==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;returns<br />
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:<br />
:* ''fontName'' - a string of the family name of the font specified<br />
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.<br />
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).<br />
* or ''nil'' and an error message on failure.<br />
<br />
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==openMapWidget==<br />
;openMapWidget([dockingArea | Xpos, Ypos, width, height])<br />
means either of these are fine:<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeMapEvent==<br />
;removeMapEvent(event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#getMapEvents | getMapEvents()]], [[#removeMapMenu | removeMapMenu()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeMapMenu==<br />
;removeMapMenu(menu name)<br />
<br />
:Removes the given submenu from a mappers right-click menu. You can add custom ones with [[#addMapMenu | addMapMenu()]].<br />
: See also: [[#addMapMenu | addMapMenu()]], [[#getMapMenus | getMapMenus()]], [[#removeMapEvent | removeMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Test") -- add submenu to the general menu<br />
removeMapMenu("Test") -- removes that same menu again<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it coloured, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
:If the room was associated with a different hash, or vice versa, that association will be superseded.<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
:* - a string that is the family name of the font to use;<br />
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15975Manual:Mapper Functions2020-12-29T16:30:29Z<p>Smurf: /* setRoomIDbyHash */</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that upon clicking will raise an event with all the arguments.<br />
<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Room type")<br />
addMapEvent("markRoomsAsDeathTrap", "onMapMarkSelectedRooms", "Room type", "Mark selected rooms as Death Trap")<br />
addMapEvent("markRoomsAsOneRoom", "onMapMarkSelectedRooms", "Room type", "Mark selected rooms as single-pass")<br />
<br />
function onMapMarkSelectedRooms(event, MarkRoomType)<br />
local SelectedRooms = getMapSelection()["rooms"]<br />
for i, val in ipairs(SelectedRooms) do<br />
if MarkRoomType == "markRoomsAsDeathTrap" then<br />
local r, g, b = unpack(color_table.black)<br />
--death trap<br />
setRoomEnv(val, 300)<br />
--death traps Env<br />
setCustomEnvColor(300, r, g, b, 255)<br />
setRoomChar(val, "☠️")<br />
lockRoom(val, true)<br />
elseif MarkRoomType == "markRoomsAsOneRoom" then<br />
local r, g, b = unpack(color_table.LightCoral)<br />
--single-pass<br />
setRoomEnv(val, 301)<br />
--one room Env<br />
setCustomEnvColor(301, r, g, b, 255)<br />
setRoomChar(val, "🚹")<br />
end<br />
end<br />
updateMap()<br />
end<br />
<br />
registerAnonymousEventHandler("onMapMarkSelectedRooms", "onMapMarkSelectedRooms")<br />
</syntaxhighlight><br />
This create menu and two submenu options: "Mark selected rooms as Death Trap" and "Mark selected rooms as single-pass"<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This will create a menu named: Favorites.<br />
addMapMenu("Favorites")<br />
<br />
-- This will create a submenu with the unique id 'Favorites123' under 'Favorites' with the display name of 'More Favorites'.<br />
addMapMenu("Favorites1234343", "Favorites", "More Favorites") <br />
</syntaxhighlight><br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==auditAreas==<br />
;auditAreas()<br />
<br />
: Initiates a consistency check on the whole map: All rooms, areas, and their composition. This is also done automatically whenever you first open your map, so probably seldom necessary to do manually. Will output findings to screen and/or logfile for later review.<br />
<br />
: See also: [[#saveMap|saveMap()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original height of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
:If there are no labels in the area at all, will instead return the area number.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;x,y,z = getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==mapSymbolFontInfo==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;returns<br />
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:<br />
:* ''fontName'' - a string of the family name of the font specified<br />
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.<br />
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).<br />
* or ''nil'' and an error message on failure.<br />
<br />
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==openMapWidget==<br />
;openMapWidget([dockingArea | Xpos, Ypos, width, height])<br />
means either of these are fine:<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeMapEvent==<br />
;removeMapEvent(event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#getMapEvents | getMapEvents()]], [[#removeMapMenu | removeMapMenu()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeMapMenu==<br />
;removeMapMenu(menu name)<br />
<br />
:Removes the given submenu from a mappers right-click menu. You can add custom ones with [[#addMapMenu | addMapMenu()]].<br />
: See also: [[#addMapMenu | addMapMenu()]], [[#getMapMenus | getMapMenus()]], [[#removeMapEvent | removeMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Test") -- add submenu to the general menu<br />
removeMapMenu("Test") -- removes that same menu again<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it coloured, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
If the room was associated with a different hash, or vice versa, that association will be superseded.<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
:* - a string that is the family name of the font to use;<br />
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=15849Manual:UI Functions2020-11-09T02:25:40Z<p>Smurf: /* getBgColor */ remove run-length extension</p>
<hr />
<div>{{TOC right}}<br />
= UI Functions =<br />
<br />
All functions that help you customize Mudlet's interface and the game's text.<br />
<br />
==ansi2decho==<br />
;ansi2decho(text, default_colour)<br />
: Converts ANSI colour sequences in <code>text</code> to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.<br />
: See also: [[Manual:Lua_Functions#decho|decho()]]<br />
{{note}}<br />
ANSI bold is available since Mudlet 3.7.1+.<br />
R<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be replaced.<br />
* ''default_colour:''<br />
: Optional - ANSI default colour code (used when handling orphan bold tags).<br />
<br />
;Return values<br />
* ''string text:''<br />
: The decho-valid converted text.<br />
* ''string colour:''<br />
: The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- '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><br />
decho(replaced)<br />
</syntaxhighlight><br />
<br />
Or show a complete colourful squirrel! It's a lotta code to do all the colours, so click the '''Expand''' button on the right to show it:<br />
<div class="toccolours mw-collapsible mw-collapsed"><br />
<syntaxhighlight lang="lua"><br />
decho(ansi2decho([[<br />
�[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m �[0m<br />
╭───────────────────────╮ �[38;5;95m▄▄�[0m �[38;5;95m▄�[48;5;95;38;5;130m▄▄�[48;5;130m█�[38;5;137m▄�[48;5;137;38;5;95m▄�[49m▀�[0m �[0m<br />
│ │ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄▄▄�[48;5;95;38;5;137m▄▄▄�[49;38;5;95m▄▄�[48;5;95;38;5;130m▄�[48;5;130m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[0m �[0m<br />
│ Encrypt everything! │ �[38;5;95m▄�[48;5;187;38;5;16m▄�[48;5;16;38;5;187m▄�[38;5;16m█�[48;5;137;38;5;137m███�[38;5;187m▄�[38;5;16m▄▄�[38;5;137m██�[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[0m �[0m<br />
│ ├──── �[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;16m▄▄▄�[48;5;137m███�[48;5;16;38;5;16m█�[48;5;187m▄�[48;5;16m█�[48;5;137;38;5;137m█�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
╰───────────────────────╯ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;16m▄�[38;5;16m█�[38;5;137m▄�[48;5;137m██████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;95m▀�[48;5;137m▄�[38;5;137m███████�[38;5;95m▄�[49m▀�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[48;5;95;38;5;187m▄▄▄�[38;5;137m▄�[48;5;137m██�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[38;5;95m▀�[48;5;130m▄�[38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;187m████�[48;5;137;38;5;137m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m██�[38;5;95m▄�[38;5;137m█�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;187;38;5;187m████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95m██�[48;5;137m▄▄�[48;5;187;38;5;187m████�[48;5;137;38;5;95m▄▄�[48;5;95;38;5;137m▄�[48;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;187;38;5;187m███�[48;5;95m▄�[38;5;137m▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[49m▄�[48;5;95;38;5;130m▄�[48;5;130m██████�[48;5;137;38;5;137m███�[38;5;95m▄�[49m▀�[0m�[0m<br />
�[48;5;187;38;5;95m▄�[38;5;187m████�[48;5;137;38;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m█████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;137m▄�[38;5;187m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██████�[48;5;95m▄▄�[48;5;130m▄▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▄▄▄�[48;5;95;38;5;137m▄�[48;5;187m▄�[38;5;187m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m█████�[38;5;95m▄�[38;5;137m███████████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀�[48;5;187m▄▄▄�[48;5;95;38;5;137m▄�[48;5;137m██�[38;5;95m▄�[49m▀�[0m �[38;5;95m▀▀�[48;5;137m▄▄▄▄▄▄�[49m▀▀▀�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀▀�[0m �[0m<br />
]]))<br />
</syntaxhighlight><br />
</div><br />
<br />
[[File:Squirrel-in-Mudlet.png|frameless]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.0+<br />
<br />
<br />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be removed.<br />
<br />
;Return values<br />
* ''string text:''<br />
: The plain text without ANSI colour sequences.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10+<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2string('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- 'replaced' should now contain You say in a baritone voice, "Test."<br />
print(replaced)<br />
</syntaxhighlight><br />
<br />
<br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name.<br />
: See also: [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[Manual:Lua_Functions#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</syntaxhighlight><br />
<br />
==bg==<br />
;bg([window, ]colorName)<br />
: Changes the background color of the text. Useful for highlighting text.<br />
: See Also: [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: 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).<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
<br />
-- or echo text with a green background to a miniconsole<br />
bg("my window", "green")<br />
echo("my window", "some green text\n")<br />
</syntaxhighlight><br />
<br />
==calcFontSize==<br />
;calcFontSize(window_or_fontsize, [fontname])<br />
: Returns the average height and width of characters in a particular window, or a font name and size combination. Helpful if you want to size a miniconsole to specific dimensions.<br />
: Returns two numbers, width/height<br />
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
;Parameters<br />
* ''window_or_fontsize:''<br />
: The miniconsole or font size you are wanting to calculate pixel sizes for.<br />
* ''fontname:''<br />
: Specific font name (along with the size as the first argument) to calculate for.<br />
<br />
{{note}}<br />
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide<br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</syntaxhighlight><br />
<br />
==cecho==<br />
;cecho([window], text)<br />
: Echoes text that can be easily formatted with colour, italics, bold and underline tags. You can also include unicode art in it - try some examples from [http://1lineart.kulaone.com/#/ 1lineart].<br />
: See also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cecho("<blue:yellow>Blue on yellow text!")<br />
<br />
cecho("\n<red>Red text with <i>italics</i>, <u>underline</u> and <b>bold</b>.")<br />
<br />
-- \n adds a new line<br />
cecho("<red>one line\n<green>another line\n<blue>last line")<br />
<br />
cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
<br />
cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")<br />
<br />
cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")<br />
<br />
cecho([[<br />
██╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗ ████████╗<br />
███║ ██║ ██║████╗ ██║██╔════╝ ██╔══██╗██╔══██╗╚══██╔══╝<br />
╚██║ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝ ██║<br />
██║ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗ ██║<br />
██║ ███████╗██║██║ ╚████║███████╗ ██║ ██║██║ ██║ ██║<br />
╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝<br />
]])<br />
</syntaxhighlight><br />
<br />
==cechoLink==<br />
;cechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#cecho|cecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cechoPopup==<br />
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#cecho|cecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertLink==<br />
;cinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#cinsertText|cinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertPopup==<br />
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#cinsertText|cinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertText==<br />
;cinsertText([window], text)<br />
: inserts text at the current cursor position, with the possibility for color tags.<br />
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cinsertText("<blue:yellow>Blue on yellow text!")<br />
<br />
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
</syntaxhighlight><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].<br />
<br />
==clearWindow==<br />
;clearWindow([windowName])<br />
: Clears the label, mini console, or user window 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 (starting with Mudlet 2.0-test3+)<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this can clear your whole main window - needs Mudlet version >= 2.0<br />
clearWindow()<br />
</syntaxhighlight><br />
<br />
==copy==<br />
; copy([windowName])<br />
: Copies the current selection to the lua virtual clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the lua virtual clipboard until it gets overwritten by another copy operation.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
; Parameters<br />
* ''windowName'' (optional):<br />
: the window from which to copy text - use the main console if not specified.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This script copies the current line on the main screen to a window (miniconsole or userwindow) called 'chat' and gags the output on the main screen.<br />
selectString(line, 1)<br />
copy()<br />
appendBuffer("chat")<br />
replace("This line has been moved to the chat window!")<br />
</syntaxhighlight><br />
<br />
==copy2decho==<br />
; copy2decho([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in decho format.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line.<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and dechos it to a miniconsole named "test"<br />
decho("test", copy2decho())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and decho it to a Geyser miniconsole stored as the variable enemylist<br />
enemylist:decho(copy2decho(matches[2]))<br />
</syntaxhighlight><br />
<br />
==copy2html==<br />
; copy2html([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in html format for echoing to a label.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main"<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and echos it to a label named "TestLabel"<br />
echo("TestLabel", copy2html())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and echo it to a Geyser label stored as the variable enemylist<br />
enemylist:echo(copy2html(matches[2]))<br />
</syntaxhighlight><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: 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.<br />
<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</syntaxhighlight><br />
<br />
==createCommandLine==<br />
;createCommandLine([name of userwindow], name, x, y, width, height)<br />
: Creates a new command line inside the main window of Mudlet. If only a command line inside a miniConsole/UserWindow is needed see [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]].<br />
: You can use [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]] / [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]] and other command line functions to customize the input.<br />
{{note}} [[Manual:UI_Functions#setCmdLineAction|setCmdLineAction]] allows you to attach an action to your command line input.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#disableCommandLine|disableCommandLine()]], [[Manual:Mudlet_Object_Functions#clearCmdLine|clearCmdLine()]], [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]], [[Manual:Mudlet_Object_Functions#printCmdLine|printCmdLine()]], [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the command line is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the command line. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the command line size and location - it is also possible to set them by using [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createCommandLine() will only set them once.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==createConsole==<br />
;createConsole([name of userwindow], consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow your new miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,<br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
''(For Mudlet Makers)'' This function is implemented outside the application's core via the '''GUIUtils.lua''' file of the Mudlet supporting Lua code using [[Manual:UI_Functions#createMiniConsole|createMiniConsole()]] and other functions to position and size the mini-console and configure the font.<br />
<br />
==createGauge==<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the gauge is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: 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<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
* ''orientation:''<br />
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.<br />
<syntaxhighlight lang="lua"><br />
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")<br />
</syntaxhighlight><br />
<br />
==createLabel==<br />
;createLabel([name of userwindow], name, Xpos, Ypos, width, height, fillBackground, [enableClickthrough])<br />
: 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.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]], [[Manual:Lua_Functions#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will display the background color, 0 or false will not.<br />
* ''enableClickthrough:''<br />
: Whether or not enable clickthrough on this label. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will enable clickthrough, 0 or false will not. Optional, defaults to clickthrough not enabled if not provided.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label situated at x=300 y=400 with dimensions 100x200<br />
createLabel("a very basic label",300,400,100,200,1)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle<br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent<br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
<br />
-- you can also make it react to clicks!<br />
mynamespace = {<br />
messageBoxClicked = function()<br />
echo("hey you've clicked the box!\n")<br />
end<br />
}<br />
<br />
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")<br />
<br />
<br />
-- uncomment code below to make it also hide after a short while<br />
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</syntaxhighlight><br />
<br />
==createMiniConsole==<br />
;createMiniConsole([name of userwindow], name, x, y, width, height)<br />
: 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.<br />
: You can use [[Manual:Lua_Functions#clearWindow|clearWindow()]] / [[Manual:Lua_Functions#moveCursor|moveCursor()]] and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. [[Manual:Lua_Functions#setWindowWrap|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 [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent()]], [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|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.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
==creplace==<br />
;creplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, with color names inside angle brackets as with [[Manual:Lua_Functions#cecho|cecho()]]. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
creplace("<magenta>[ALERT!]: <reset>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==creplaceLine==<br />
;creplaceLine (text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''text:''<br />
*: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)<br />
</syntaxhighlight><br />
<br />
==decho==<br />
;decho ([name of console,] text)<br />
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB,[BA]> 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,[BA]>. 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")''. You can also include italics, bold and underline tags.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]]<br />
<br />
;Parameters<br />
* ''name of console''<br />
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.<br />
* ''text:''<br />
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.<br />
<br />
<br />
{{note}}<br />
Optional background transparancy parameter (BA) available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
decho("<50,50,0:0,255,0>test")<br />
<br />
decho("miniconsolename", "<50,50,0:0,255,0>test")<br />
<br />
decho("\n<255,0,0>Red text with <i>italics</i>, <u>underline</u> and <b>bold</b> formatting.")<br />
</syntaxhighlight><br />
<br />
==dechoLink==<br />
;dechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#decho|decho()]]. This version allows you to use colours within your link text.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) allows selection between sending the link to a miniconsole or the "main" window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==dechoPopup==<br />
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#decho|decho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertLink==<br />
;dinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#dinsertText|dinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertPopup==<br />
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#dinsertText|dinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
== deleteLabel ==<br />
; deleteLabel(labelName)<br />
<br />
: Deletes and removes a label from the screen. Note that if you'd like to show the label again, it is much more performant to hide/show it instead.<br />
<br />
: Note that you shouldn't use the Geyser label associated with the label you delete afterwards - that doesn't make sense and Geyser right now wouldn't know that it's been deleted, either.<br />
<br />
: See also: [[#hideWindow|hideWindow()]], [[#showWindow|showWindow()]], [[#createLabel|createLabel()]]<br />
<br />
; Parameters<br />
<br />
* ''labelName'': name of the label to delete.<br />
<br />
<syntaxhighlight lang="lua"><br />
createLabel("a very basic label",300,400,100,200,1)<br />
setBackgroundColor("a very basic label", 255, 204, 0, 200)<br />
<br />
-- delete the label after 3 seconds<br />
tempTimer(3, function()<br />
deleteLabel("a very basic label")<br />
end)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 4.5+<br />
<br />
==deleteLine==<br />
;deleteLine([windowName])<br />
: 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. This is purely visual - triggers will still fire on the line as expected.<br />
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.<br />
<br />
{{note}} for replacing text, [[Manual:Lua_Functions#replace|replace()]] is the proper option; doing the following: <code>selectCurrentLine(); replace(""); cecho("new line!\n")</code> is better.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- deletes the line - just put this command into the big script box. Keep the case the same -<br />
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else<br />
deleteLine()<br />
<br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
<br />
-- example of deleting multiple lines:<br />
deleteLine() -- delete the current line<br />
moveCursor(0,getLineNumber()-1) -- move the cursor back one line<br />
deleteLine() -- delete the previous line now<br />
</syntaxhighlight><br />
<br />
==deselect==<br />
;deselect([window name])<br />
: 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.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''window name:''<br />
: (optional) The name of the window to stop having anything selected in. If name is not provided the main window will have its selection cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further<br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</syntaxhighlight><br />
<br />
==disableClickthrough==<br />
; disableClickthrough(label)<br />
: Disables clickthrough for a label - making it act 'normal' again and receive clicks, doubleclicks, onEnter, and onLeave events. This is the default behaviour for labels.<br />
: See also: [[#enableClickthrough|enableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name of the label to restore clickability on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==disableCommandLine==<br />
; disableCommandLine(windowName)<br />
: Disables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableCommandLine|enableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to disable the command line in.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10<br />
<br />
==disableHorizontalScrollBar==<br />
; disableHorizontalScrollBar([windowName])<br />
: Disables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableHorizontalScrollBar|enableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==disableScrollBar==<br />
; disableScrollBar([windowName])<br />
: Disables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==dreplace==<br />
;dreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#decho|decho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
dreplace("<255,0,255>[ALERT!]: <r>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''text:''<br />
: Text to display in the echo. Same as a normal echo().<br />
* ''command:''<br />
: Lua code to do when the link is clicked.<br />
* ''hint:''<br />
: Text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentFormatElseDefault:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
echoLink("press me!", [[send("hi")]], "This is a tooltip")<br />
<br />
-- do the same, but send this link to a miniConsole<br />
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")<br />
</syntaxhighlight><br />
<br />
==echoUserWindow==<br />
;echoUserWindow(windowName)<br />
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.<br />
<br />
==echoPopup==<br />
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==enableClickthrough==<br />
; enableClickthrough(label)<br />
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.<br />
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.<br />
: See also: [[#disableClickthrough|disableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: The name of the label to enable clickthrough on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==enableCommandLine==<br />
; enableCommandLine(windowName)<br />
: Enables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#disableCommandLine|disableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to enable the command line in.<br />
<br />
{{note}} The command line name is the same as the miniConsole name<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableHorizontalScrollBar==<br />
; enableHorizontalScrollBar([windowName])<br />
: Enables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableHorizontalScrollBar|disableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableScrollBar==<br />
; enableScrollBar([windowName])<br />
: Enables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==fg==<br />
; fg([window], colorName)<br />
: 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)<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything or use ''main'' (since Mudlet 3.0).<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
<br />
-- example of working on a miniconsole<br />
fg("my console", "red")<br />
echo("my console", "red text")<br />
</syntaxhighlight><br />
<br />
==getAvailableFonts==<br />
; getAvailableFonts()<br />
: This returns a "font - true" key-value list of available fonts which you can use to verify that Mudlet has access to a given font.<br />
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.<br />
<br />
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]<br />
<br />
{{note}}<br />
Available since Mudlet 3.10<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if Ubuntu Mono is a font we can use<br />
if getAvailableFonts()["Ubuntu Mono"] then<br />
-- make the miniconsole use the font at size 16<br />
setFont("my miniconsole", "Ubuntu Mono")<br />
setFontSize("my miniconsole", 16)<br />
end<br />
</syntaxhighlight><br />
<br />
==getBgColor==<br />
; getBgColor(windowName)<br />
: 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.<br />
<br />
: See also: [[#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r,g,b;<br />
selectString("troll",1)<br />
r,g,b = getBgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getBorderBottom==<br />
;getBorderBottom()<br />
: Returns the size of the bottom border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
getBorderBottom()<br />
-- returns: 150<br />
</syntaxhighlight><br />
<br />
==getBorderLeft==<br />
;getBorderLeft()<br />
: Returns the size of the left border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
getBorderLeft()<br />
-- returns: 5<br />
</syntaxhighlight><br />
<br />
==getBorderRight==<br />
;getBorderRight()<br />
: Returns the size of the right border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
getBorderRight()<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderSizes==<br />
;getBorderSizes()<br />
: Returns the a named table with the sizes of all borders of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]],[[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0)<br />
getBorderSizes()<br />
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }<br />
getBorderSizes().right<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderTop==<br />
;getBorderTop()<br />
: Returns the size of the top border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
getBorderTop()<br />
-- returns: 100<br />
</syntaxhighlight><br />
<br />
==getClipboardText==<br />
;getClipboardText()<br />
: Returns any text that is currently present in the clipboard. <br />
: See also: [[#setClipboardText | setClipboardText()]]<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local clipboardContents = getClipboardText()<br />
echo("Clipboard: " .. clipboardContents)<br />
</syntaxhighlight><br />
<br />
==getColorWildcard==<br />
; getColorWildcard(ansi color number)<br />
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.<br />
<br />
: See also: [[#isAnsiFgColor|isAnsiFgColor()]], [[#isAnsiBgColor|isAnsiBgColor()]]<br />
<br />
;Parameters<br />
* ''ansi color number:''<br />
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- we can run this script on a line that has the players name coloured differently to easily capture it from<br />
-- anywhere on the line<br />
local match = getColorWildcard(14)<br />
<br />
if match then<br />
echo("\nFound "..match.."!")<br />
else<br />
echo("\nDidn't find anyone.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getColumnCount==<br />
;getColumnCount([windowName])<br />
: Gets the maximum number of columns (characters) that a given window can display on a single row, taking into consideration factors such as window width, font size, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum number of columns on the main window "..getColumnCount())<br />
</syntaxhighlight><br />
<br />
==getColumnNumber==<br />
;getColumnNumber([windowName])<br />
: Gets the absolute column number of the current user cursor.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
<br />
{{note}} the argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
<br />
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
</syntaxhighlight><br />
<br />
==getCurrentLine==<br />
;getCurrentLine([windowName])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Currently selected line: "..getCurrentLine())<br />
</syntaxhighlight><br />
<br />
==getFgColor==<br />
; getFgColor(windowName)<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString("troll",1)<br />
local r,g,b = getFgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is written in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getFont==<br />
;getFont(windowName)<br />
: Gets the current font of the given window or console name. Can be used to get font of the main console, dockable userwindows and miniconsoles.<br />
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
display("Font in the main window: "..getFont())<br />
<br />
display("Font in the main window: "..getFont("main"))<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
display("Font size: " .. getFont("user window awesome"))<br />
</syntaxhighlight><br />
<br />
==getFontSize==<br />
;getFontSize(windowName)<br />
: Gets the current font size of the given window or console name. Can be used to get font size of the Main console as well as dockable UserWindows.<br />
: See also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
local mainWindowFontSize = getFontSize()<br />
if mainWindowFontSize then<br />
display("Font size: " .. mainWindowFontSize)<br />
end<br />
<br />
local mainWindowFontSize = getFontSize("main")<br />
if mainWindowFontSize then<br />
display("Font size: " .. fs2)<br />
end<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
local awesomeWindowFontSize = getFontSize("user window awesome")<br />
if awesomeWindowFontSize then<br />
display("Font size: " .. awesomeWindowFontSize)<br />
end<br />
</syntaxhighlight><br />
<br />
==getImageSize==<br />
;getImageSize(imageLocation)<br />
: Returns the width and the height of the given image. If the image can't be found, loaded, or isn't a valid image file - nil+error message will be returned instead.<br />
: See also: [[#createLabel|createLabel()]]<br />
<br />
;Parameters<br />
* ''imageLocation:''<br />
: Path to the image.<br />
<br />
{{note}}<br />
Available in Mudlet 4.5+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local path = getMudletHomeDir().."/my-image.png"<br />
<br />
cecho("Showing dimensions of the picture in: "..path.."\n")<br />
<br />
local width, height = getImageSize(path)<br />
<br />
if not width then<br />
-- in case of an problem, we don't get a height back - but the error message<br />
cecho("error: "..height.."\n")<br />
else<br />
cecho(string.format("They are: %sx%s", width, height))<br />
end<br />
</syntaxhighlight><br />
<br />
==getLastLineNumber==<br />
;getLastLineNumber(windowName)<br />
:Returns the latest line's number in the main window or the miniconsole. This could be different from [[Manual:UI_Functions#getLineNumber|getLineNumber()]] if the cursor was moved around.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the latest line's # in the buffer<br />
local latestline = getLastLineNumber("main")<br />
</syntaxhighlight><br />
<br />
==getLineCount==<br />
;getLineCount()<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
''Need example''<br />
<br />
==getLines==<br />
;getLines([windowName,] from_line_number, to_line_number)<br />
: 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}''.<br />
<br />
:Absolute line numbers are used.<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)<br />
* ''from_line_number:''<br />
: First line number<br />
* ''to_line_number:''<br />
: End line number<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- retrieve & echo the last line:<br />
echo(getLines(getLineNumber()-1, getLineNumber())[1])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- find out which server and port you are connected to (as per Mudlet settings dialog):<br />
local t = getLines(0, getLineNumber())<br />
<br />
local server, port<br />
<br />
for i = 1, #t do<br />
local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")<br />
if s then server, port = s, p break end<br />
end<br />
<br />
display(server)<br />
display(port)<br />
</syntaxhighlight><br />
<br />
==getLineNumber==<br />
;getLineNumber([windowName])<br />
: 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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#moveCursorEnd|moveCursorEnd()]]. This function can come in handy in combination when using with [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#getLines|getLines()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.<br />
<br />
{{note}}<br />
The argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word<br />
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end<br />
<br />
-- check how many lines you've got in your miniconsole after echoing some text.<br />
-- Note the use of moveCursorEnd() to update getLineNumber()'s output<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
print(getLineNumber("HelloWorld"))<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
-- update the cursors position, as it seems to be necessary to do<br />
moveCursorEnd("HelloWorld")<br />
print(getLineNumber("HelloWorld"))<br />
</syntaxhighlight><br />
<br />
==getMainConsoleWidth==<br />
;getMainConsoleWidth()<br />
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.<br />
<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Save width of the main console to a variable for future use.<br />
consoleWidth = getMainConsoleWidth()<br />
</syntaxhighlight><br />
<br />
==getMousePosition==<br />
;getMousePosition()<br />
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{note}} Available since Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- 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<br />
local x, y = getMousePosition()<br />
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)<br />
-- if the label already exists, just move it<br />
moveWindow("clickGeneratedLabel", x, y)<br />
-- and make it easier to notice<br />
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)<br />
</syntaxhighlight><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getUserWindowSize|getUserWindowSize()]], [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your main mudlet window and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</syntaxhighlight><br />
<br />
==getRowCount==<br />
;getRowCount([windowName])<br />
: Gets the maximum number of rows that a given window can display at once, taking into consideration factors such as window height, font type, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum of rows on the main window "..getRowCount())<br />
</syntaxhighlight><br />
<br />
==getSelection==<br />
;getSelection([windowName])<br />
: Returns the text currently selected with [[#selectString|selectString()]], [[#selectSection|selectSection()]], or [[#selectCurrentLine|selectCurrentLine()]]. Note that this isn't the text currently selected with the mouse.<br />
: Also returns the start offset and length of the selection as second and third value.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window to get the selection from. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.16.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
print("Current line contains: "..getSelection())<br />
</syntaxhighlight><br />
<br />
;retrieving the selection<br />
<syntaxhighlight lang="lua"><br />
text,offset,len = getSelection()<br />
-- manipulate the selection, e.g. to discover the color of characters other than the first<br />
-- then restore it<br />
selectSection(offset, len)<br />
</syntaxhighlight><br />
<br />
==getTextFormat==<br />
;getTextFormat([windowName])<br />
: Gets the current text format of the currently selected text. May be used with other console windows. The returned values come in a table containing text attribute names and their values. The values given will be booleans for: bold, italics, underline, overline, strikeout, and reverse - followed by color triplet tables for the foreground and background colors.<br />
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.<br />
<br />
{{note}} Available since Mudlet 3.20.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- A suitable test for getTextFormat()<br />
-- (copy it into an alias or a script)<br />
<br />
clearWindow()<br />
<br />
echo("\n")<br />
<br />
local SGR = string.char(27)..'['<br />
feedTriggers("Format attributes: '"..SGR.."1mBold"..SGR.."0m' '"..SGR.."3mItalic"..SGR.."0m' '"..SGR.."4mUnderline"..SGR.."0m' '"..SGR.."5mBlink"..SGR.."0m' '"..SGR.."6mF.Blink"..SGR.."0m' '"..SGR.."7mReverse"..SGR.."0m' '"..SGR.."9mStruckout"..SGR.."0m' '"..SGR.."53mOverline"..SGR.."0m'.\n")<br />
<br />
moveCursor(1,1)<br />
selectSection(1,1)<br />
<br />
local results = getTextFormat()<br />
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))<br />
echo("\nItalic detected: " .. tostring(results["italic"]))<br />
echo("\nUnderline detected: " .. tostring(results["underline"]))<br />
echo("\nReverse detected: " .. tostring(results["reverse"]))<br />
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))<br />
echo("\nOverline detected: " .. tostring(results["overline"]))<br />
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")<br />
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")<br />
<br />
selectSection(21,1)<br />
echo("\n\nFor individual parts of test text:")<br />
echo("\nBold detected (character 21): " .. tostring(results["bold"]))<br />
<br />
selectSection(28,1)<br />
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))<br />
<br />
selectSection(37,1)<br />
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))<br />
<br />
selectSection(67,1)<br />
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))<br />
<br />
selectSection(77,1)<br />
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))<br />
<br />
selectSection(89,1)<br />
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))<br />
echo("\n")<br />
</syntaxhighlight><br />
<br />
==getUserWindowSize==<br />
{{note}} available in Mudlet 4.6.1+<br />
;getUserWindowSize(windowName)<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the given userwindow dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''windowName''<br />
:the name of the userwindow we will get the dimensions from<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your userwindow named "ChatWindow" and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getUserWindowSize("ChatWindow")<br />
</syntaxhighlight><br />
<br />
==handleWindowResizeEvent==<br />
;handleWindowResizeEvent()<br />
: (''depreciated'') This function is depreciated and should not be used; it's only documented here for historical reference - use the [[Manual:Technical_Manual#sysWindowResizeEvent|sysWindowResizeEvent]] event instead.<br />
<br />
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.<br />
<br />
; Parameters<br />
:None<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
function handleWindowResizeEvent()<br />
-- determine the size of your screen<br />
WindowWidth=0;<br />
WindowHeight=0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
-- move mini console "sys" to the far right side of the screen whenever the screen gets resized<br />
moveWindow("sys",WindowWidth-300,0)<br />
end<br />
</syntaxhighlight><br />
<br />
==hasFocus==<br />
;hasFocus()<br />
: 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). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if attacked and not hasFocus() then<br />
runaway()<br />
else<br />
fight()<br />
end<br />
</syntaxhighlight><br />
<br />
==hecho==<br />
;hecho([windowName], text)<br />
: Echoes text that can be easily formatted with colour tags in the hexadecimal format. You can also use italics, bold and underline tags.<br />
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.<br />
* ''text:''<br />
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #FRFGFB,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 or #r can be used within the string to reset the colors to default. Hexadecimal color codes can be found here: https://www.color-hex.com/<br />
<br />
{{note}}<br />
Transparency for background in hex-format available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hecho("\n#ffffff White text!")<br />
-- your text in white<br />
hecho("\n#ca0004 Red text! And now reset #rit to the default color")<br />
-- your text in red, then reset to default using #r<br />
hecho("\n#ffffff,ca0004 White text with a red background!")<br />
-- your text in white, against a red background<br />
hecho("\n|c0000ff Blue text, this time using |c instead of #")<br />
-- your text in blue, activated with |c vs #.<br />
hecho("\n#ff0000Red text with #iitalics#/i, |uunderline|/u and #bbold#/b formatting.")<br />
</syntaxhighlight><br />
<br />
==hechoLink==<br />
;hechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#hecho|hecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
-- # format also works<br />
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==hechoPopup==<br />
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#hecho|hecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertLink==<br />
;hinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#hinsertText|hinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertPopup==<br />
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#hinsertText|hinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hreplace==<br />
;hreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#hecho|hecho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
hreplace("#EE00EE[ALERT!]: #r"..matches[2])<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.5+<br />
<br />
==hideToolBar==<br />
;hideToolBar(name)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to hide<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hideToolBar("my offensive buttons")<br />
</syntaxhighlight><br />
<br />
==hideWindow==<br />
;hideWindow(name)<br />
: This function hides a '''mini console''', a '''user window''' or a '''label''' with the given name. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].<br />
<br />
: See also: [[#createMiniConsole|createMiniConsole()]], [[#createLabel|createLabel()]], [[#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name''<br />
: specifies the label or console you want to hide.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function miniconsoleTest()<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
print("created red window top-right")<br />
<br />
tempTimer(1, function()<br />
hideWindow("sys")<br />
print("hid red window top-right")<br />
end)<br />
<br />
tempTimer(3, function()<br />
showWindow("sys")<br />
print("showed red window top-right")<br />
end)<br />
end<br />
<br />
miniconsoleTest()<br />
</syntaxhighlight><br />
<br />
==insertLink==<br />
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])<br />
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) the window to insert the link in - use either "main" or omit for the main window.<br />
* ''text:''<br />
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) true or false. 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- link with the default blue on white colors<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")<br />
<br />
-- use current cursor colors by adding true at the end<br />
fg("red")<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==insertPopup==<br />
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])<br />
: Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to [[Manual:Lua_Functions#insertText|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''name:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.<br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==insertText==<br />
;insertText([windowName], text)<br />
: Inserts text at cursor postion in window - unlike [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] to move the cursor into position first.<br />
<br />
: insertHTML() also does the same thing as insertText, if you ever come across it.<br />
<br />
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) The window to insert the text to.<br />
* ''text:''<br />
: The text you will insert into the current cursor position.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the cursor to the end of the previous line and insert some text<br />
<br />
-- move to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
-- move the end the of the previous line<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
<br />
fg("dark_slate_gray")<br />
insertText(' <- that looks nice.')<br />
<br />
deselect()<br />
resetFormat()<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
==ioprint==<br />
;ioprint(text, some more text, ...)<br />
:Prints text to the to the stdout. This is only available if you [http://www.wikihow.com/Run-a-Program-on-Command-Prompt launched Mudlet from cmd.exe] on Windows, [http://www.wikihow.com/Open-Applications-Using-Terminal-on-Mac from the terminal] on Mac, or from the terminal on a Linux OS (launch the terminal program, type ''mudlet'' and press enter).<br />
<br />
Similar to [[Manual:Lua_Functions#echo|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.<br />
<br />
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.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
ioprint("hi!")<br />
ioprint(1,2,3)<br />
ioprint(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==isAnsiBgColor==<br />
; isAnsiBgColor(bgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the background color specified by bgColorCode.<br />
<br />
;Parameters<br />
* ''bgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiBgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the background of the text is light green" )<br />
else<br />
echo( "no sorry, some other background color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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 getBgColor() and then handling the color comparison in Lua.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default background color in the zeroth position.''<br />
<br />
==isAnsiFgColor==<br />
; isAnsiFgColor(fgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the foreground color specified by fgColorCode.<br />
<br />
;Parameters<br />
* ''fgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiFgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the text is light green" )<br />
else<br />
echo( "no sorry, some other foreground color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default foreground color in the zeroth position.''<br />
<br />
==lowerWindow==<br />
;lowerWindow(labelName)<br />
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to move below the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top<br />
</syntaxhighlight><br />
<br />
==moveCursor==<br />
;moveCursor([windowName], x, y)<br />
: 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 [[Manual:Lua_Functions#getLineNumber|getLineNumber()]], [[Manual:Lua_Functions#getColumnNumber|getColumnNumber()]] and [[Manual:Lua_Functions#getLastLineNumber|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.<br />
<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The window you are going to move the cursor in.<br />
* ''x:''<br />
: The horizontal axis in the window - that is, the letter position within the line.<br />
* ''y:''<br />
: The vertical axis in the window - that is, the line number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move cursor to the start of the previous line and insert -<(<br />
-- the first 0 means we want the cursor right at the start of the line,<br />
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which<br />
-- equals to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
insertText("-<(")<br />
<br />
-- now we move the cursor at the end of the previous line. Because the<br />
-- cursor is on the previous line already, we can use #getCurrentLine()<br />
-- to see how long it is. We also just do getLineNumber() because getLineNumber()<br />
-- returns the current line # the cursor is on<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
insertText(")>-")<br />
<br />
-- finally, reset it to the end where it was after our shenaningans - other scripts<br />
-- could expect the cursor to be at the end<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a more complicated example showing how to work with Mudlet functions<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
local WindowWidth, WindowHeight = getMainWindowSize()<br />
<br />
-- define a mini console named "sys" and set its background color<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
<br />
-- you *must* set the font size, otherwise mini windows will not work properly<br />
setMiniConsoleFontSize("sys", 12)<br />
-- wrap lines in window "sys" at 65 characters per line<br />
setWindowWrap("sys", 60)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
-- clear the window<br />
clearUserWindow("sys")<br />
<br />
moveCursorEnd("sys")<br />
setFgColor("sys", 10,10,0)<br />
setBgColor("sys", 0,0,255)<br />
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")<br />
echo("sys", "test1---line2\n")<br />
echo("sys", "test1---line3\n")<br />
setTextFormat("sys",158,0,255,255,0,255,0,0,0);<br />
--setFgColor("sys",255,0,0);<br />
echo("sys", "test1---line4\n")<br />
echo("sys", "test1---line5\n")<br />
moveCursor("sys", 1,1)<br />
<br />
-- deleting lines 2+3<br />
deleteLine("sys")<br />
deleteLine("sys")<br />
<br />
-- inserting a line at pos 5,2<br />
moveCursor("sys", 5,2)<br />
setFgColor("sys", 100,100,0)<br />
setBgColor("sys", 255,100,0)<br />
insertText("sys","############## line inserted at pos 5/2 ##############")<br />
<br />
-- inserting a line at pos 0,0<br />
moveCursor("sys", 0,0)<br />
selectCurrentLine("sys")<br />
setFgColor("sys", 255,155,255)<br />
setBold( "sys", true );<br />
setUnderline( "sys", true )<br />
setItalics( "sys", true )<br />
insertText("sys", "------- line inserted at: 0/0 -----\n")<br />
<br />
setBold( "sys", true )<br />
setUnderline( "sys", false )<br />
setItalics( "sys", false )<br />
setFgColor("sys", 255,100,0)<br />
setBgColor("sys", 155,155,0)<br />
echo("sys", "*** This is the end. ***\n")<br />
</syntaxhighlight><br />
<br />
==moveCursorDown==<br />
;moveCursorDown([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window down a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor down by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorUp==<br />
;moveCursorUp([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window up a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor up by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorEnd==<br />
;moveCursorEnd([windowName])<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
: Returns true or false<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveGauge==<br />
;moveGauge(gaugeName, newX, newY)<br />
: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.<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: The name of your gauge<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would move the health bar gauge to the location 1200, 400<br />
moveGauge("healthBar", 1200, 400)<br />
</syntaxhighlight><br />
<br />
==moveWindow==<br />
;moveWindow(name, x, y)<br />
: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.<br />
<br />
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of your window<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles.<br />
<br />
==openUserWindow==<br />
;openUserWindow(windowName, [restoreLayout], [autoDock], [dockingArea])<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).<br />
* ''restoreLayout:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.<br />
* ''autoDock:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't dock automatically at the corners.<br />
* ''dockingArea:''<br />
: (optional) - the area your UserWindow will be docked at. possible docking areas your UserWindow will be created in (f" floating "t" top "b" bottom "r" right and "l" left). Docking area is "right" if not given any value.<br />
<br />
{{note}}<br />
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.<br />
<br />
{{note}}<br />
The parameters autoDock and dockingArea are available since Mudlet 4.7+ <br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
openUserWindow("My floating window")<br />
cecho("My floating window", "<red>hello <blue>bob!")<br />
<br />
-- if you don't want Mudlet to remember its last position:<br />
openUserWindow("My floating window", false)<br />
</syntaxhighlight><br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]]<br />
<br />
==paste==<br />
;paste(windowName)<br />
: Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The [[#copy | copy()]] and [[#paste | 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
<br />
==prefix==<br />
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
:Prefixes text at the beginning of the current line when used in a trigger.<br />
<br />
;Parameters<br />
* ''text:''<br />
: the information you want to prefix<br />
* "writingFunction:"<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* "foregroundColor:"<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* "backgroundColor:"<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* "windowName:"<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that<br />
prefix(os.date("%H:%M:%S "))<br />
-- Prefix the time in red into a miniconsole named "my_console"<br />
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#suffix | suffix()]]<br />
<br />
==print==<br />
;print(text, some more text, ...)<br />
:Prints text to the main window. Similar to [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#display|display()]] for those. This function works similarly to the print() you will see in guides for Lua.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
print("hi!")<br />
print(1,2,3)<br />
print(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==raiseWindow==<br />
;raiseWindow(labelName)<br />
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to bring to the top of the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel<br />
</syntaxhighlight><br />
<br />
==replace==<br />
;replace([windowName], with, [keepcolor])<br />
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.<br />
<br />
{{note}}<br />
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.<br />
<br />
{{note}}<br />
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 | insertText()]] does.<br />
<br />
See also: [[#creplace|creplace]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of window (a miniconsole)<br />
* ''with:''<br />
: the new text to display.<br />
* ''keepcolor:''<br />
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
-- replace word "troll" with "cute trolly"<br />
selectString("troll",1)<br />
replace("cute trolly")<br />
<br />
-- replace the whole line<br />
selectCurrentLine()<br />
replace("Out with the old, in with the new!")<br />
</syntaxhighlight><br />
<br />
==replaceAll==<br />
;replaceAll(what, with, [keepcolor])<br />
: Replaces all occurrences of ''what'' in the current line with ''with''.<br />
<br />
;Parameters<br />
* ''what:''<br />
: the text to replace<br />
{{note}}<br />
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]<br />
* ''with:''<br />
: the new text to have in place<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors.<br />
{{note}} keepcolor is available in Mudlet 4.10+<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the word "south" in the line with "north"<br />
replaceAll("south", "north")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the text that the variable "target" has<br />
replaceAll(target, "The Bad Guy")<br />
</syntaxhighlight><br />
<br />
==replaceWildcard==<br />
;replaceWildcard(which, replacement, [keepcolor])<br />
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString(matches[2], 1)<br />
replace("text")<br />
</syntaxhighlight><br />
<br />
;Parameters<br />
* ''which:''<br />
: Wildcard to replace.<br />
* ''replacement:''<br />
: Text to replace the wildcard with.<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors<br />
{{note}} keepcolor available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello<br />
</syntaxhighlight><br />
<br />
==resetCmdLineAction==<br />
;resetCmdLineAction(commandLineName)<br />
: Resets the action on the command line so the it behaves like the main command line again.<br />
;Parameters<br />
<br />
* ''commandLineName''<br />
: The name of the command line the action will be resetet.<br />
: See also: [[#setCmdLineAction | setCmdLineAction()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetBackgroundImage==<br />
;resetBackgroundImage([windowName])<br />
: Resets the console background-image<br />
;Parameters<br />
<br />
* ''windowName''<br />
: (optional) name of the console the image will be reset<br />
: See also: [[#setBackgroundImage | setBackgroundImage()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: 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.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==resetLabelCursor==<br />
;resetLabelCursor(labelName)<br />
: Resets your mouse cursor to the default one.<br />
<br />
: See also: [[#setLabelCursor|setLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName'': label for which to reset the cursor for.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetLabelCursor("myLabel")<br />
-- This will reset the mouse cursor over myLabel to the default one<br />
</syntaxhighlight><br />
<br />
==resetLabelToolTip==<br />
;resetLabelToolTip(labelName)<br />
: Resets the tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label the tooltip will be reseted.<br />
: See also: [[#setLabelToolTip | setLabelToolTip()]]<br />
<br />
==resetMapWindowTitle==<br />
;resetMapWindowTitle()<br />
: resets the title of the popped out map window to default.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setMapWindowTitle|setMapWindowTitle()]]<br />
<br />
==resetUserWindowTitle==<br />
;resetUserWindowTitle(windowName)<br />
: resets the title of the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow for which the title will be resetet<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setUserWindowTitle|setUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==resizeWindow==<br />
;resizeWindow(windowName, width, height)<br />
: Resizes a mini console, label, or floating User Windows.<br />
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
* ''width:''<br />
: The new width you want<br />
* ''height:''<br />
: The new height you want<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.<br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumber:''<br />
: number of the capture group you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".<br />
--If you want to color the amount of money you have green you do:<br />
<br />
selectCaptureGroup(1)<br />
setFgColor(0,255,0)<br />
</syntaxhighlight><br />
<br />
==selectCurrentLine==<br />
; selectCurrentLine([windowName])<br />
: 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.<br />
<br />
{{note}}<br />
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.<br />
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- color the whole line green!<br />
selectCurrentLine()<br />
fg("green")<br />
deselect()<br />
resetFormat()<br />
<br />
-- to select the previous line, you can do this:<br />
moveCursor(0, getLineNumber()-1)<br />
selectCurrentLine()<br />
<br />
-- to select two lines back, this:<br />
moveCursor(0, getLineNumber()-2)<br />
selectCurrentLine()<br />
<br />
</syntaxhighlight><br />
<br />
==selectSection==<br />
;selectSection( [windowName], fromPosition, length )<br />
: 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.<br />
: 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.<br />
<br />
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]<br />
<br />
;Parameters<br />
* "windowName:"<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.<br />
: Will not work if "main" is given as the windowName to try to select from the main window.<br />
* ''fromPosition:''<br />
: number to specify at which position in the line to begin selecting<br />
* ''length:''<br />
: number to specify the amount of characters you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and colour the first character in the line red<br />
if selectSection(0,1) then fg("red") end<br />
<br />
-- select and colour the second character green (start selecting from the first character, and select 1 character)<br />
if selectSection(1,1) then fg("green") end<br />
<br />
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)<br />
if selectSection(2,3) then fg("grey") end<br />
</syntaxhighlight><br />
<br />
==selectString==<br />
;selectString( [windowName], text, number_of_match )<br />
: 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).<br />
<br />
{{note}}<br />
You can move the user cursor with [[#moveCursor | 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 | deselect()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.<br />
* ''text:''<br />
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).<br />
* ''number_of_match:''<br />
: 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.<br />
<br />
: Returns position in line or -1 on error (text not found in line)<br />
<br />
{{note}}<br />
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if selectString( "big monster", 1 ) > -1 then fg("red") end<br />
</syntaxhighlight><br />
<br />
==setAppStyleSheet==<br />
;setAppStyleSheet(stylesheet [, tag])<br />
: Sets a stylesheet for the entire Mudlet application and every open profile. Because it affects other profiles that might not be related to yours, it's better to use [[#setProfileStyleSheet|setProfileStyleSheet()]] instead of this function.<br />
<br />
: Raises the sysAppStyleSheetChange event which comes with two arguments in addition to the event name. The first is the optional tag which was passed into the function, or "" if nothing was given. The second is the profile which made the stylesheet changes.<br />
<br />
: See also: [[#setProfileStyleSheet|setProfileStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use.<br />
<br />
* ''tag:'' (with Mudlet 3.19+)<br />
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.<br />
<br />
;References<br />
: See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setAppStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
]])<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 3.0.<br />
<br />
Enhanced in Mudlet version 3.19.0 to generate an event that profiles/packages can utilise to redraw any parts of the UI that they themselves had previously styled so their effects can be re-applied to the new application style.<br />
<br />
It is anticipated that the Mudlet application itself will make further use of application styling effects and two strings are provisionally planned for the second parameter in the ''sysAppStyleSheetChange'' event: "''mudlet-theme-dark''" and "''mudlet-theme-light''"; it will also set the third parameter to "''system''".<br />
<br />
==setBackgroundColor==<br />
;setBackgroundColor([windowName], r, g, b, transparency)<br />
: Sets the background for the given label, miniconsole, or userwindow. Colors are from 0 to 255 (0 being black), and transparency is from 0 to 255 (0 being completely transparent).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.<br />
* ''r:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''g:''<br />
: Amount of green to use, from 0 (none) to 255 (full).<br />
* ''b:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).<br />
<br />
{{note}}<br />
Transparency also available for main/miniconsoles in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red label that's somewhat transparent<br />
setBackgroundColor("some label",255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setBackgroundImage==<br />
;setBackgroundImage(labelName, imageLocation)<br />
;setBackgroundImage([windowname], imageLocation, [mode])<br />
: Loads an image file (png) as a background image for a label or console. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.<br />
<br />
{{note}}<br />
You can also load images on labels via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].<br />
<br />
;Parameters (label)<br />
<br />
* ''labelName:''<br />
: The name of the label to change it's background color.<br />
* ''imageLocation:''<br />
: 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.<br />
<br />
;Parameters (consoles)<br />
<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow to change the background image on, or "main" for the main window.<br />
* ''imageLocation:''<br />
: 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.<br />
* ''mode:''<br />
: (optional) allows different modes for drawing the background image. Possible modes areː <br />
<br />
** border - the background image is stretched (1)<br />
** center - the background image is in the center (2), <br />
** tile - the background image is 'tiled' (3)<br />
** style - choose your own background image stylesheet, see example below (4)<br />
<br />
: See also: [[#resetBackgroundImage | resetBackgroundImage()]]<br />
<br />
;Example (label)<br />
<syntaxhighlight lang="lua"><br />
-- give the top border a nice look<br />
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])<br />
</syntaxhighlight><br />
<br />
;Example (main/miniconsole)<br />
<syntaxhighlight lang="lua"><br />
-- give the main window a background image<br />
setBackgroundImage("main", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- or use your own for the main window:<br />
setBackgroundImage("main", [[C:\Documents and Settings\bub\Desktop\mypicture.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image and put it in the center<br />
setBackgroundImage("my_miniconsole", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image with own stylesheet option<br />
setBackgroundImage("my_miniconsole", [[background-image: url(:/Mudlet_splashscreen_development.png); background-repeat: no-repeat; background-position: right;]], "style")<br />
</syntaxhighlight><br />
{{note}} setBackgroundImage for main/miniconsoles and userwindows available in Mudlet 4.10+<br />
<br />
==setBgColor==<br />
;setBgColor([windowName], r, g, b, transparency)<br />
: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.<br />
<br />
:If you'd like to change the background color of a window, see [[#setBackgroundColor|setBackgroundColor()]].<br />
<br />
: ''See also:'' [[#cecho|cecho()]], [[#setBackgroundColor|setBackgroundColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Optional, if not used color is fully opaque<br />
<br />
<br />
<br />
{{note}}<br />
Transparency parameter available in Mudlet 4.10+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red background color.<br />
selectString( "Tom", 1 )<br />
setBgColor( 255,0,0 )<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--prints "Hello" on red background and "You" on blue.<br />
setBgColor(255,0,0)<br />
echo("Hello")<br />
setBgColor(0,0,255)<br />
echo(" You!")<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBold==<br />
;setBold(windowName, boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
<br />
* ''boolean:''<br />
: A <code>true</code> or <code>false</code> that enables or disables bolding of text<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- enable bold formatting<br />
setBold(true)<br />
-- the following echo will be bolded<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBorderBottom==<br />
;setBorderBottom(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
</syntaxhighlight><br />
<br />
==setBorderColor==<br />
;setBorderColor(red, green, blue)<br />
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]<br />
<br />
;Parameters<br />
* ''red:''<br />
: Amount of red color to use, from 0 to 255.<br />
* ''green:''<br />
: Amount of green color to use, from 0 to 255.<br />
* ''blue:''<br />
: Amount of blue color to use, from 0 to 255.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set the border to be completely blue<br />
setBorderColor(0, 0, 255)<br />
<br />
-- or red, using a name<br />
setBorderColor( unpack(color_table.red) )<br />
</syntaxhighlight><br />
<br />
==setBorderLeft==<br />
;setBorderLeft(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
</syntaxhighlight><br />
<br />
==setBorderRight==<br />
;setBorderRight(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
</syntaxhighlight><br />
<br />
==setBorderSizes==<br />
;setBorderSizes(top, right, bottom, left)<br />
: Sets the size of all borders 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.<br />
: The exact result of this function depends on how many numbers you give to it as arguments.<br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Arguments<br />
* '''setBorderSizes(top, right, bottom, left)'''<br />
: ''4 arguments:'' All borders will be set to their new given size.<br />
* '''setBorderSizes(top, width, bottom)''' <br />
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width. <br />
* '''setBorderSizes(height, width)'''<br />
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width. <br />
* '''setBorderSizes(size)'''<br />
: ''1 argument:'' All borders will be set to the same size.<br />
* '''setBorderSizes()'''<br />
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0) <br />
-- big border at the top, bigger at the bottom, small at the right, none at the left<br />
<br />
setBorderSizes(100, 50, 150) <br />
-- big border at the top, bigger at the bottom, small at the right and the left<br />
<br />
setBorderSizes(100, 50) <br />
-- big border at the top and the bottom, small at the right and the left<br />
<br />
setBorderSizes(100) <br />
-- big borders at all four sides<br />
<br />
setBorderSizes() <br />
-- no borders at all four sides<br />
</syntaxhighlight><br />
<br />
==setBorderTop==<br />
;setBorderTop(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
</syntaxhighlight><br />
<br />
==setFgColor==<br />
;setFgColor([windowName], red, green, blue)<br />
:Sets the current text foreground color in the main window unless windowName parameter given.<br />
<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''red:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''green:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''blue:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]], [[#setHexBgColor | setHexBgColor()]], [[#resetFormat | resetFormat()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setFgColor( 255, 0, 0 )<br />
</syntaxhighlight><br />
<br />
==setButtonStyleSheet==<br />
;setButtonStyleSheet(button, markup)<br />
: Applies Qt style formatting to a button via a special markup language.<br />
<br />
; Parameters<br />
* ''button:''<br />
: The name of the button to be formatted.<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note: You can instead use QWidget { markup }. QWidget will reference 'button', allowing the use of pseudostates like QWidget:hover and QWidget:selected<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setButtonStyleSheet("my test button", [[<br />
QWidget {<br />
background-color: #999999;<br />
border: 3px #777777;<br />
}<br />
QWidget:hover {<br />
background-color: #bbbbbb;<br />
}<br />
QWidget:checked {<br />
background-color: #77bb77;<br />
border: 3px #559955;<br />
}<br />
QWidget:hover:checked {<br />
background-color: #99dd99;<br />
} ]])</syntaxhighlight><br />
<br />
==setClipboardText==<br />
;setClipboardText(textContent)<br />
: Sets the value of the computer's clipboard to the string data provided.<br />
: See also: [[#getClipboardText | getClipboardText()]]<br />
<br />
; Parameters<br />
* ''textContent:''<br />
: The text to be put into the clipboard.<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setClipboardText("New Clipboard Contents")<br />
echo("Clipboard: " .. getClipboardText()) -- should echo "Clipboard: New Clipboard Contents"<br />
</syntaxhighlight><br />
<br />
==setCmdLineAction==<br />
;setCmdLineAction(commandLineName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user sends text to the command line. 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 command line action. Additionally, this function passes the command line input text as the final argument.<br />
{{note}} If no action is set the command line behaves like the main command line and sends commands directly to the game or alias engine.<br />
<br />
The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, text)<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#resetCmdLineAction|resetCmdLineAction()]]<br />
<br />
;Parameters<br />
<br />
* ''commandLineName:''<br />
: The name of the command line to attach the action function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} You can also pass a function directly instead of using a string<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function sendTextToMiniConsole(miniConsoleName, cmdLineText)<br />
echo(miniConsoleName, cmdLineText.."\n")<br />
end<br />
<br />
setCmdLineAction("myCmdLine", "sendTextToMiniConsole", "myMiniConsole")<br />
<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setCmdLineStyleSheet==<br />
;setCmdLineStyleSheet([commandLineName], markup)<br />
: Applies Qt style formatting to a command line via a special markup language.<br />
<br />
;Parameters<br />
* ''commandLineName:''<br />
: (optional) Name of the command line (or miniconsole the command line is in). If not given the stylesheet will be applied to the main command line.<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#createCommandLine|createCommandLine()]]<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- move the main command line over to the right<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
padding-left: 100px; /* change 100 to your number */<br />
background-color: black; /* change it to your background color */<br />
}<br />
]])<br />
<br />
--only change font-size of your main command line<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
font-sizeː20pt; <br />
}<br />
]])<br />
<br />
--change bg/fg color of your miniconsole command line (name of the miniconsole is 'myMiniconsole'<br />
--the command line in the miniconsole has to be enabled<br />
setCmdLineStyleSheet("myMiniConsole", [[<br />
QPlainTextEdit {<br />
background: rgb(0,100,0);<br />
color: rgb(0,200,255);<br />
font-size: 10pt;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
==setFont==<br />
;setFont(name, font)<br />
: Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Prefer a monospaced font - those work best with text games. See here [https://doc.qt.io/qt-5/qfont.html#setFamily for more].<br />
: See also: [[#getFont|getFont()]], [[#setFontSize|setFontSize()]], [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''font:''<br />
: The font to use.<br />
<br />
{{note}}<br />
Available in Mudlet 3.9+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.<br />
setFont("Ubuntu Mono")<br />
setFont("main", "Ubuntu Mono")<br />
<br />
-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.<br />
setFont("combat", "Ubuntu Mono")<br />
</syntaxhighlight><br />
<br />
==setFontSize==<br />
;setFontSize(name, size)<br />
: Sets a font size on the given window or console name. Can be used to change font size of the Main console as well as dockable UserWindows.<br />
: See Also: [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
* ''size:''<br />
: The font size to apply to the window.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to 12-point font.<br />
setFontSize(12)<br />
setFontSize("main", 12)<br />
<br />
-- This will set the font size of a user window named "uw1" to 12-point font.<br />
setFontSize("uw1", 12)<br />
</syntaxhighlight><br />
<br />
==setGauge==<br />
;setGauge(gaugeName, currentValue, maxValue, gaugeText)<br />
: 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.<br />
<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#createGauge|createGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a gauge<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
--Change the looks of the gauge named healthBar and make it<br />
--fill to half of its capacity. The height is always remembered.<br />
setGauge("healthBar", 200, 400)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
--If you wish to change the text on your gauge, you’d do the following:<br />
setGauge("healthBar", 200, 400, "some text")<br />
</syntaxhighlight><br />
<br />
==setGaugeStyleSheet==<br />
;setGaugeStyleSheet(gaugeName, css, cssback, csstext)<br />
: 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. You can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create stylesheets.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]],<br />
[[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
</syntaxhighlight><br />
<br />
==setGaugeText==<br />
;setGaugeText(gaugename, css, ccstext )<br />
: Set the formatting of the text used inside the inserted gaugename.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
setGaugeText("healthBar", [[<p style="font-weight:bold;color:#C9C9C9;letter-spacing:1pt;word-spacing:2pt;font-size:12px;text-align:center;font-family:arial black, sans-serif;">]]..MY_NUMERIC_VARIABLE_HERE..[[</p>]])</syntaxhighlight><br />
<br />
;Useful resources:<br />
:http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.<br />
:https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!<br />
<br />
==setHexBgColor==<br />
;setHexBgColor([windowName], hexColorString)<br />
:Sets the current text nackground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.<br />
selectString( "Tom", 1 )<br />
setHexBgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setHexFgColor==<br />
;setHexFgColor([windowName], hexColorString)<br />
:Sets the current text foreground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text foreground color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setFgColor | setFgColor()]], [[#setHexBgColor | setHexBgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setHexFgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setItalics==<br />
;setItalics(windowName, bool)<br />
: Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setLabelToolTip==<br />
;setLabelToolTip(labelName, [duration])<br />
: Sets a tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to set the tooltip to.<br />
* ''duration:''<br />
: Duration of the tooltip timeout in seconds. Optional, if not set the default duration will be set.<br />
<br />
: See also: [[Manual:UI_Functions#resetLabelToolTip|resetLabelToolTip()]]<br />
<br />
==setLabelClickCallback==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument. This table contains information about the mouse button clicked, other buttons that were pressed at the time, and the mouse cursor's local (relative to the label) and global (relative to the Mudlet window) position. The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, event)<br />
</syntaxhighlight><br />
<br />
where '''event''' has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
button = "LeftButton",<br />
buttons = {"RightButton", "MidButton"},<br />
}<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]],[[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} Event argument is available in 3.6+, and in 4.8+ you can pass a function directly instead of a string.<br />
<br />
{{note}}<br />
While '''event.button''' may contain a single string of any listed below, '''event.buttons''' will only ever contain some combination of "LeftButton", "MidButton", and "RightButton"<br />
:The following mouse button strings are defined:<br />
<pre><br />
"LeftButton" "RightButton" "MidButton"<br />
"BackButton" "ForwardButton" "TaskButton"<br />
"ExtraButton4" "ExtraButton5" "ExtraButton6"<br />
"ExtraButton7" "ExtraButton8" "ExtraButton9"<br />
"ExtraButton10" "ExtraButton11" "ExtraButton12"<br />
"ExtraButton13" "ExtraButton14" "ExtraButton15"<br />
"ExtraButton16" "ExtraButton17" "ExtraButton18"<br />
"ExtraButton19" "ExtraButton20" "ExtraButton21"<br />
"ExtraButton22" "ExtraButton23" "ExtraButton24"<br />
</pre><br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
else if event.button == "RightButton" then<br />
send("swim north")<br />
else if event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )<br />
<br />
-- you can also use them within tables now:<br />
mynamespace = {<br />
onClickGoNorth = function()<br />
echo("the north button was clicked!")<br />
end<br />
}<br />
<br />
setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )<br />
<br />
</syntaxhighlight><br />
<br />
==setLabelDoubleClickCallback==<br />
;setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user double 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.6+<br />
<br />
: See also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
==setLabelMoveCallback==<br />
;setLabelMoveCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse moves while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
==setLabelOnEnter==<br />
;setLabelOnEnter(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the '''event''' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
}<br />
</syntaxhighlight><br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseOver()<br />
echo("The mouse is hovering over the label!\n")<br />
end<br />
<br />
setLabelOnEnter( "compassNorthImage", "onMouseOver" )<br />
</syntaxhighlight><br />
<br />
==setLabelOnLeave==<br />
;setLabelOnLeave(labelName, luaFunctionName, [any arguments])<br />
: 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.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseLeft(argument)<br />
echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)<br />
end<br />
<br />
setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )<br />
</syntaxhighlight><br />
<br />
==setLabelReleaseCallback==<br />
;setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
This command was added in version 3.0.0<br />
<br />
{{note}}<br />
The ''event'' argument only available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onReleaseNorth()<br />
echo("the north button was released!")<br />
end<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onReleaseNorth = function()<br />
echo("the north button was released!")<br />
end<br />
}<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )<br />
</syntaxhighlight><br />
<br />
==setLabelStyleSheet==<br />
;setLabelStyleSheet(label, markup)<br />
: Applies Qt style formatting to a label via a special markup language.<br />
<br />
; Parameters<br />
* ''label:''<br />
: The name of the label to be formatted (passed when calling createLabel).<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a white background and a green border, with the text "test"<br />
-- inside.<br />
createLabel("test", 50, 50, 100, 100, 0)<br />
setLabelStyleSheet("test", [[<br />
background-color: white;<br />
border: 10px solid green;<br />
font-size: 12px;<br />
]])<br />
echo("test", "test")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that will tile or clip depending on the<br />
-- size of the label. To use this example, please supply your own image.<br />
createLabel("test5", 50, 353, 164, 55, 0)<br />
setLabelStyleSheet("test5", [[<br />
background-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that can be resized (such as during a<br />
-- sysWindowResizeEvent). To use this example, please supply your own image.<br />
createLabel("test9", 215, 353, 100, 100, 0)<br />
setLabelStyleSheet("test9", [[<br />
border-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--This creates a label whose background changes when the users mouse hovers over it.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
local ourLabelStyle = [[<br />
QLabel{<br />
background-color: ]]..labelBackgroundColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
QLabel::hover{<br />
background-color: ]]..labelHoverColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--Using QLabel::hover mentioned above. Lets "trick" the label into changing it's text.<br />
--Please keep in mind that the setLabelMoveCallback allows for much more control over not just your label but your entire project.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
--Notice we are adding a string returned from a function. In this case, the users profile directory.<br />
local ourLabelStyle = [[<br />
QLabel{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithtext.png");<br />
}<br />
QLabel::hover{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithhovertext.png");<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
--This is just to example that echos draw on top of the label. You would not want to echo onto a label you were drawing text on with images, because echos would draw on top of them.<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<br />
==setLabelCursor==<br />
;setLabelCursor(labelName, cursorShape)<br />
: Changes how the mouse cursor looks like when over the label. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''cursorShape''<br />
: Shape of the mouse cursor. List of possible cursor shapes is [[CursorShapes| available here]].<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCursor("myLabel", "Cross")<br />
-- This will change the mouse cursor to a cross if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelCustomCursor==<br />
;setLabelCustomCursor(labelName, custom cursor, [hotX, hotY])<br />
: Changes the mouse cursor shape over your label to a custom cursor. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCursor|setLabelCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''custom cursor''<br />
: Location of your custom cursor file. To be compatible with all systems it is recommended to use png files with size of 32x32.<br />
* ''hotX''<br />
: X-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
* ''hotY''<br />
: Y-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCustomCursor("myLabel", getMudletHomeDir().."/custom_cursor.png")<br />
-- This will change the mouse cursor to your custom cursor if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelWheelCallback==<br />
;setLabelWheelCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse wheel is scrolled while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the ''event'' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
buttons = {"RightButton", "MidButton"},<br />
angleDeltaX = 0,<br />
angleDeltaY = 120<br />
}<br />
</syntaxhighlight><br />
<br />
: Keys ''angleDeltaX'' and ''angleDeltaY'' correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onWheelNorth(event)<br />
if event.angleDeltaY > 0 then<br />
echo("the north button was wheeled forwards over!")<br />
else<br />
echo("the north button was wheeled backwards over!")<br />
end<br />
end<br />
<br />
setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onWheelNorth = function()<br />
echo("the north button was wheeled over!")<br />
end<br />
}<br />
<br />
setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )<br />
</syntaxhighlight><br />
<br />
==setLink==<br />
;setLink([windowName], command, tooltip)<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of a miniconsole or a userwindow in which to select the text in.<br />
* ''command:''<br />
: command to do when the text is clicked.<br />
* ''tooltip:''<br />
: tooltip to show when the mouse is over the text - explaining what would clicking do.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can clickify a lot of things to save yourself some time - for example, you can change<br />
-- the line where you receive a message to be clickable to read it!<br />
-- prel regex trigger:<br />
-- ^You just received message #(\w+) from \w+\.$<br />
-- script:<br />
selectString(matches[2], 1)<br />
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])<br />
resetFormat()<br />
<br />
-- an example of selecting text in a miniconsole and turning it into a link:<br />
<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
HelloWorld:echo("hi")<br />
selectString("HelloWorld", "hi", 1)<br />
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")<br />
</syntaxhighlight><br />
<br />
==setMainWindowSize==<br />
;setMainWindowSize(mainWidth, mainHeight)<br />
: Changes the size of your main Mudlet window to the values given.<br />
: See Also: [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''mainWidth:''<br />
: The new width in pixels.<br />
* ''mainHeight:''<br />
: The new height in pixels.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will resize your main Mudlet window<br />
setMainWindowSize(1024, 768)<br />
</syntaxhighlight><br />
<br />
==setMapWindowTitle==<br />
;setMapWindowTitle(text)<br />
: Changes the title shown in the mapper window when it's popped out.<br />
: See also: [[#resetMapWindowTitle|resetMapWindowTitle()]]<br />
<br />
; Parameters<br />
* ''text:''<br />
: New window title to set.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapWindowTitle("my cool game map")<br />
</syntaxhighlight><br />
<br />
==setMiniConsoleFontSize==<br />
;setMiniConsoleFontSize(name, fontSize)<br />
: Sets the font size of the mini console. see also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]]<br />
<br />
==setOverline==<br />
;setOverline([windowName], boolean)<br />
: Sets the current text font to be overlined (true) or not overlined (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 overlined. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be overlined until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be overlined or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables overlining of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable overlined text<br />
setOverline(true)<br />
-- the following echo will be have an overline<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and reverse have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==setPopup==<br />
;setPopup(windowName, {lua code}, {hints})<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,<br />
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking<br />
-- will show some commands you can do.<br />
<br />
selectString("Hello", 1)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})<br />
</syntaxhighlight><br />
<br />
==setProfileStyleSheet==<br />
;setProfileStyleSheet(stylesheet)<br />
: Sets a stylesheet for the current Mudlet profile - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). This function is better than setAppStyleSheet() because it affects only the current profile and not every other one as well.<br />
<br />
: See also: [[#setAppStyleSheet|setAppStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use. See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setProfileStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
<br />
QTreeView {<br />
background: ]]..background_color..[[;<br />
color: white;<br />
}<br />
<br />
QMenuBar{ background-color: ]]..background_color..[[;}<br />
<br />
QMenuBar::item{ background-color: ]]..background_color..[[;}<br />
<br />
QDockWidget::title {<br />
background: ]]..border_color..[[;<br />
}<br />
QStatusBar {<br />
background: ]]..border_color..[[;<br />
}<br />
QScrollBar:vertical {<br />
background: ]]..background_color..[[;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background-color: ]]..background_color..[[;<br />
min-height: 20px;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 7px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-bottom-left-radius: 7px;<br />
border-bottom-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-top-left-radius: 7px;<br />
border-top-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
background: white;<br />
width: 4px;<br />
height: 3px;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]])<br />
<br />
-- if you'd like to reset it, use:<br />
setProfileStyleSheet("")<br />
<br />
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':<br />
setProfileStyleSheet[[<br />
TConsole QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
TConsole QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
TConsole QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 4.6.<br />
<br />
==setReverse==<br />
;setReverse([windowName], boolean)<br />
: Sets the current text to swap foreground and background color settings (true) or not (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 have it's colors swapped. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will have their foreground and background colors swapped until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text colors to be reversed or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables reversing of the fore- and back-ground colors of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable fore/back-ground color reversal of text<br />
setReverse(true)<br />
-- the following echo will have the text colors reversed<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and overline have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
{{note}} Although the visual effect on-screen is the same as that of text being selected if both apply to a piece of text they neutralise each other - however the effect of the reversal ''will'' be carried over in copies made by the "Copy to HTML" and in logs made in HTML format log file mode.<br />
<br />
==setStrikeOut==<br />
;setStrikeOut([windowName], boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be striken out until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be stricken out or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables striking out of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable striken-out text<br />
setStrikeOut(true)<br />
-- the following echo will be have a strikethrough<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setTextFormat==<br />
;setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])<br />
: Sets current text format of selected window. This is a more convenient means to set all the individual features at once compared to using [[#setFgColor|setFgColor]]( windowName, r,g,b ), [[#setBold|setBold]]( windowName, true ), [[#setItalics|setItalics]]( windowName, true ), [[#setUnderline|setUnderline]]( windowName, true ), [[#setStrikeOut|setStrikeOut]]( windowName, true ).<br />
: See Also: [[Manual:Lua_Functions#getTextFormat|getTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: Specify name of selected window. If empty string "" or "main" format will be applied to the main console<br />
* ''r1,g1,b1''<br />
: To color text background, give number values in RBG style<br />
* ''r2,g2,b2''<br />
: To color text foreground, give number values in RBG style<br />
* ''bold''<br />
: To format text bold, set to 1 or true, otherwise 0 or false<br />
* ''underline''<br />
: To underline text, set to 1 or true, otherwise 0 or false<br />
* ''italics''<br />
: To format text italic, set to 1 or true, otherwise 0 or false<br />
* ''strikeout<br />
: (optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''overline<br />
: (optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''reverse<br />
: (optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This script would create a mini text console and write with bold, struck-out, yellow foreground color and blue background color "This is a test".<br />
createMiniConsole( "con1", 0,0,300,100);<br />
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);<br />
echo("con1","This is a test")<br />
</syntaxhighlight><br />
<br />
{{note}} In versions prior to 3.7.0 the error messages ''and this wiki'' were wrong in that they had the foreground color parameters as r1, g1 and b1 and the background ones as r2, g2 and b2.<br />
<br />
==setUnderline==<br />
;setUnderline(windowName, bool)<br />
: Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setUserWindowTitle==<br />
;setUserWindowTitle(windowName, text)<br />
: sets a new title text for the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''text''<br />
: new title text<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==setUserWindowStyleSheet==<br />
;setUserWindowStyleSheet(windowName, markup)<br />
: Applies Qt style formatting to the border/title area of a userwindow via a special markup language.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when you dock the userwindow the border style is not provided by this<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- changes the title area style of the UserWindow 'myUserWindow'<br />
setUserWindowStyleSheet("myUserWindow", [[QDockWidget::title{ <br />
background-color: rgb(0,255,150);<br />
border: 2px solid red;<br />
border-radius: 8px;<br />
text-align: center; <br />
}]])<br />
</syntaxhighlight><br />
<br />
: See also: [[#openUserWindow|openUserWindow()]]<br />
<br />
==setWindow==<br />
;setWindow(windowName, name, [Xpos, Ypos, show])<br />
: Changes the parent window of an element.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow which you want the element put in. If you want to put the element into the main window, use windowName "main".<br />
* ''name''<br />
: Name of the element which you want to switch the parent from. Elements can be labels, miniconsoles and the embedded mapper. If you want to move the mapper use the name "mapper"<br />
* ''Xpos:''<br />
: X position of the element. Measured in pixels, with 0 being the very left. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''Ypos:''<br />
: Y position of the element. Measured in pixels, with 0 being the very top. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''show:''<br />
: true or false to decide if the element will be shown or not in the new parent window. Optional, if not given it will be true.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindow("myuserwindow", "mapper")<br />
-- This will put your embedded mapper in your userwindow "myuserwindow".<br />
</syntaxhighlight><br />
<br />
==setWindowWrap==<br />
;setWindowWrap(windowName, wrapAt)<br />
: sets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapAt:''<br />
: Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==setWindowWrapIndent==<br />
;setWindowWrapIndent(windowName, wrapTo)<br />
: sets how many spaces wrapped text will be indented with (after the first line of course).<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapTo:''<br />
: Number of spaces which wrapped lines are prefixed with.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
setWindowWrapIndent("main", 3)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==showCaptureGroups==<br />
;showCaptureGroups()<br />
:Lua debug function that highlights in random colors 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.<br />
<br />
;Example:<br />
: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.<br />
<br />
==showMultimatches==<br />
;showMultimatches()<br />
: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.<br />
<br />
==showWindow==<br />
;showWindow(name)<br />
: Makes a hidden window (label or miniconsole) be shown again.<br />
<br />
: See also: [[#hideWindow | hideWindow()]]<br />
<br />
==showColors==<br />
;showColors([columns], [filterColor], [sort])<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in '''color_table''', in table form. The format is ''color_table.colorName = {r, g, b}''.<br />
<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: (optional) number of columns to print the color table in.<br />
* ''filterColor:''<br />
: (optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.<br />
* ''sort:''<br />
: (optional) sort colors alphabetically.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- display as four columns:<br />
showColors(4)<br />
<br />
-- show only red colours:<br />
showColors("red")<br />
</syntaxhighlight><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)|thumb|center]]<br />
<br />
==showToolBar==<br />
;showToolBar(name)<br />
: Makes a toolbar (a button group) appear on the screen.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
showToolBar("my attack buttons")<br />
</syntaxhighlight><br />
<br />
==suffix==<br />
;suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
: Suffixes text at the end of the current line. This is similar to [[Manual:Lua_Functions#echo | echo()]], which also suffixes text at the end of the line, but different - [[Manual:Lua_Functions#echo | 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.<br />
<br />
;Parameters<br />
* ''text''<br />
: the information you want to prefix<br />
* ''writingFunction''<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* ''foregroundColor''<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* ''backgroundColor''<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* ''windowName''<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
<br />
: See also: [[#prefix | prefix()]], [[Manual:Lua_Functions#echo | echo()]]<br />
<br />
==wrapLine==<br />
;wrapLine(windowName, lineNumber)<br />
: 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.:<br />
<br />
<syntaxhighlight lang="lua">selectString(line,1)<br />
replace("")</syntaxhighlight><br />
<br />
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.<br />
<br />
: See Also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#deleteLine|deleteLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The miniconsole or the main window (use ''main'' for the main window)<br />
* ''lineNumber:''<br />
: The line number which you'd like re-wrapped.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- re-wrap the last line in the main window<br />
wrapLine("main", getLineCount())<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=15848Manual:UI Functions2020-11-09T02:25:06Z<p>Smurf: /* getFgColor */ remove run-length extension</p>
<hr />
<div>{{TOC right}}<br />
= UI Functions =<br />
<br />
All functions that help you customize Mudlet's interface and the game's text.<br />
<br />
==ansi2decho==<br />
;ansi2decho(text, default_colour)<br />
: Converts ANSI colour sequences in <code>text</code> to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.<br />
: See also: [[Manual:Lua_Functions#decho|decho()]]<br />
{{note}}<br />
ANSI bold is available since Mudlet 3.7.1+.<br />
R<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be replaced.<br />
* ''default_colour:''<br />
: Optional - ANSI default colour code (used when handling orphan bold tags).<br />
<br />
;Return values<br />
* ''string text:''<br />
: The decho-valid converted text.<br />
* ''string colour:''<br />
: The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- '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><br />
decho(replaced)<br />
</syntaxhighlight><br />
<br />
Or show a complete colourful squirrel! It's a lotta code to do all the colours, so click the '''Expand''' button on the right to show it:<br />
<div class="toccolours mw-collapsible mw-collapsed"><br />
<syntaxhighlight lang="lua"><br />
decho(ansi2decho([[<br />
�[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m �[0m<br />
╭───────────────────────╮ �[38;5;95m▄▄�[0m �[38;5;95m▄�[48;5;95;38;5;130m▄▄�[48;5;130m█�[38;5;137m▄�[48;5;137;38;5;95m▄�[49m▀�[0m �[0m<br />
│ │ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄▄▄�[48;5;95;38;5;137m▄▄▄�[49;38;5;95m▄▄�[48;5;95;38;5;130m▄�[48;5;130m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[0m �[0m<br />
│ Encrypt everything! │ �[38;5;95m▄�[48;5;187;38;5;16m▄�[48;5;16;38;5;187m▄�[38;5;16m█�[48;5;137;38;5;137m███�[38;5;187m▄�[38;5;16m▄▄�[38;5;137m██�[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[0m �[0m<br />
│ ├──── �[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;16m▄▄▄�[48;5;137m███�[48;5;16;38;5;16m█�[48;5;187m▄�[48;5;16m█�[48;5;137;38;5;137m█�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
╰───────────────────────╯ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;16m▄�[38;5;16m█�[38;5;137m▄�[48;5;137m██████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;95m▀�[48;5;137m▄�[38;5;137m███████�[38;5;95m▄�[49m▀�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[48;5;95;38;5;187m▄▄▄�[38;5;137m▄�[48;5;137m██�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[38;5;95m▀�[48;5;130m▄�[38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;187m████�[48;5;137;38;5;137m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m██�[38;5;95m▄�[38;5;137m█�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;187;38;5;187m████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95m██�[48;5;137m▄▄�[48;5;187;38;5;187m████�[48;5;137;38;5;95m▄▄�[48;5;95;38;5;137m▄�[48;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;187;38;5;187m███�[48;5;95m▄�[38;5;137m▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[49m▄�[48;5;95;38;5;130m▄�[48;5;130m██████�[48;5;137;38;5;137m███�[38;5;95m▄�[49m▀�[0m�[0m<br />
�[48;5;187;38;5;95m▄�[38;5;187m████�[48;5;137;38;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m█████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;137m▄�[38;5;187m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██████�[48;5;95m▄▄�[48;5;130m▄▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▄▄▄�[48;5;95;38;5;137m▄�[48;5;187m▄�[38;5;187m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m█████�[38;5;95m▄�[38;5;137m███████████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀�[48;5;187m▄▄▄�[48;5;95;38;5;137m▄�[48;5;137m██�[38;5;95m▄�[49m▀�[0m �[38;5;95m▀▀�[48;5;137m▄▄▄▄▄▄�[49m▀▀▀�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀▀�[0m �[0m<br />
]]))<br />
</syntaxhighlight><br />
</div><br />
<br />
[[File:Squirrel-in-Mudlet.png|frameless]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.0+<br />
<br />
<br />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be removed.<br />
<br />
;Return values<br />
* ''string text:''<br />
: The plain text without ANSI colour sequences.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10+<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2string('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- 'replaced' should now contain You say in a baritone voice, "Test."<br />
print(replaced)<br />
</syntaxhighlight><br />
<br />
<br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name.<br />
: See also: [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[Manual:Lua_Functions#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</syntaxhighlight><br />
<br />
==bg==<br />
;bg([window, ]colorName)<br />
: Changes the background color of the text. Useful for highlighting text.<br />
: See Also: [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: 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).<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
<br />
-- or echo text with a green background to a miniconsole<br />
bg("my window", "green")<br />
echo("my window", "some green text\n")<br />
</syntaxhighlight><br />
<br />
==calcFontSize==<br />
;calcFontSize(window_or_fontsize, [fontname])<br />
: Returns the average height and width of characters in a particular window, or a font name and size combination. Helpful if you want to size a miniconsole to specific dimensions.<br />
: Returns two numbers, width/height<br />
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
;Parameters<br />
* ''window_or_fontsize:''<br />
: The miniconsole or font size you are wanting to calculate pixel sizes for.<br />
* ''fontname:''<br />
: Specific font name (along with the size as the first argument) to calculate for.<br />
<br />
{{note}}<br />
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide<br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</syntaxhighlight><br />
<br />
==cecho==<br />
;cecho([window], text)<br />
: Echoes text that can be easily formatted with colour, italics, bold and underline tags. You can also include unicode art in it - try some examples from [http://1lineart.kulaone.com/#/ 1lineart].<br />
: See also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cecho("<blue:yellow>Blue on yellow text!")<br />
<br />
cecho("\n<red>Red text with <i>italics</i>, <u>underline</u> and <b>bold</b>.")<br />
<br />
-- \n adds a new line<br />
cecho("<red>one line\n<green>another line\n<blue>last line")<br />
<br />
cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
<br />
cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")<br />
<br />
cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")<br />
<br />
cecho([[<br />
██╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗ ████████╗<br />
███║ ██║ ██║████╗ ██║██╔════╝ ██╔══██╗██╔══██╗╚══██╔══╝<br />
╚██║ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝ ██║<br />
██║ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗ ██║<br />
██║ ███████╗██║██║ ╚████║███████╗ ██║ ██║██║ ██║ ██║<br />
╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝<br />
]])<br />
</syntaxhighlight><br />
<br />
==cechoLink==<br />
;cechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#cecho|cecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cechoPopup==<br />
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#cecho|cecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertLink==<br />
;cinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#cinsertText|cinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertPopup==<br />
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#cinsertText|cinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertText==<br />
;cinsertText([window], text)<br />
: inserts text at the current cursor position, with the possibility for color tags.<br />
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cinsertText("<blue:yellow>Blue on yellow text!")<br />
<br />
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
</syntaxhighlight><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].<br />
<br />
==clearWindow==<br />
;clearWindow([windowName])<br />
: Clears the label, mini console, or user window 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 (starting with Mudlet 2.0-test3+)<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this can clear your whole main window - needs Mudlet version >= 2.0<br />
clearWindow()<br />
</syntaxhighlight><br />
<br />
==copy==<br />
; copy([windowName])<br />
: Copies the current selection to the lua virtual clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the lua virtual clipboard until it gets overwritten by another copy operation.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
; Parameters<br />
* ''windowName'' (optional):<br />
: the window from which to copy text - use the main console if not specified.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This script copies the current line on the main screen to a window (miniconsole or userwindow) called 'chat' and gags the output on the main screen.<br />
selectString(line, 1)<br />
copy()<br />
appendBuffer("chat")<br />
replace("This line has been moved to the chat window!")<br />
</syntaxhighlight><br />
<br />
==copy2decho==<br />
; copy2decho([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in decho format.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line.<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and dechos it to a miniconsole named "test"<br />
decho("test", copy2decho())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and decho it to a Geyser miniconsole stored as the variable enemylist<br />
enemylist:decho(copy2decho(matches[2]))<br />
</syntaxhighlight><br />
<br />
==copy2html==<br />
; copy2html([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in html format for echoing to a label.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main"<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and echos it to a label named "TestLabel"<br />
echo("TestLabel", copy2html())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and echo it to a Geyser label stored as the variable enemylist<br />
enemylist:echo(copy2html(matches[2]))<br />
</syntaxhighlight><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: 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.<br />
<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</syntaxhighlight><br />
<br />
==createCommandLine==<br />
;createCommandLine([name of userwindow], name, x, y, width, height)<br />
: Creates a new command line inside the main window of Mudlet. If only a command line inside a miniConsole/UserWindow is needed see [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]].<br />
: You can use [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]] / [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]] and other command line functions to customize the input.<br />
{{note}} [[Manual:UI_Functions#setCmdLineAction|setCmdLineAction]] allows you to attach an action to your command line input.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#disableCommandLine|disableCommandLine()]], [[Manual:Mudlet_Object_Functions#clearCmdLine|clearCmdLine()]], [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]], [[Manual:Mudlet_Object_Functions#printCmdLine|printCmdLine()]], [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the command line is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the command line. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the command line size and location - it is also possible to set them by using [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createCommandLine() will only set them once.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==createConsole==<br />
;createConsole([name of userwindow], consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow your new miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,<br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
''(For Mudlet Makers)'' This function is implemented outside the application's core via the '''GUIUtils.lua''' file of the Mudlet supporting Lua code using [[Manual:UI_Functions#createMiniConsole|createMiniConsole()]] and other functions to position and size the mini-console and configure the font.<br />
<br />
==createGauge==<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the gauge is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: 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<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
* ''orientation:''<br />
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.<br />
<syntaxhighlight lang="lua"><br />
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")<br />
</syntaxhighlight><br />
<br />
==createLabel==<br />
;createLabel([name of userwindow], name, Xpos, Ypos, width, height, fillBackground, [enableClickthrough])<br />
: 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.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]], [[Manual:Lua_Functions#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will display the background color, 0 or false will not.<br />
* ''enableClickthrough:''<br />
: Whether or not enable clickthrough on this label. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will enable clickthrough, 0 or false will not. Optional, defaults to clickthrough not enabled if not provided.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label situated at x=300 y=400 with dimensions 100x200<br />
createLabel("a very basic label",300,400,100,200,1)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle<br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent<br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
<br />
-- you can also make it react to clicks!<br />
mynamespace = {<br />
messageBoxClicked = function()<br />
echo("hey you've clicked the box!\n")<br />
end<br />
}<br />
<br />
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")<br />
<br />
<br />
-- uncomment code below to make it also hide after a short while<br />
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</syntaxhighlight><br />
<br />
==createMiniConsole==<br />
;createMiniConsole([name of userwindow], name, x, y, width, height)<br />
: 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.<br />
: You can use [[Manual:Lua_Functions#clearWindow|clearWindow()]] / [[Manual:Lua_Functions#moveCursor|moveCursor()]] and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. [[Manual:Lua_Functions#setWindowWrap|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 [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent()]], [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|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.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
==creplace==<br />
;creplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, with color names inside angle brackets as with [[Manual:Lua_Functions#cecho|cecho()]]. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
creplace("<magenta>[ALERT!]: <reset>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==creplaceLine==<br />
;creplaceLine (text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''text:''<br />
*: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)<br />
</syntaxhighlight><br />
<br />
==decho==<br />
;decho ([name of console,] text)<br />
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB,[BA]> 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,[BA]>. 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")''. You can also include italics, bold and underline tags.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]]<br />
<br />
;Parameters<br />
* ''name of console''<br />
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.<br />
* ''text:''<br />
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.<br />
<br />
<br />
{{note}}<br />
Optional background transparancy parameter (BA) available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
decho("<50,50,0:0,255,0>test")<br />
<br />
decho("miniconsolename", "<50,50,0:0,255,0>test")<br />
<br />
decho("\n<255,0,0>Red text with <i>italics</i>, <u>underline</u> and <b>bold</b> formatting.")<br />
</syntaxhighlight><br />
<br />
==dechoLink==<br />
;dechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#decho|decho()]]. This version allows you to use colours within your link text.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) allows selection between sending the link to a miniconsole or the "main" window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==dechoPopup==<br />
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#decho|decho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertLink==<br />
;dinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#dinsertText|dinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertPopup==<br />
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#dinsertText|dinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
== deleteLabel ==<br />
; deleteLabel(labelName)<br />
<br />
: Deletes and removes a label from the screen. Note that if you'd like to show the label again, it is much more performant to hide/show it instead.<br />
<br />
: Note that you shouldn't use the Geyser label associated with the label you delete afterwards - that doesn't make sense and Geyser right now wouldn't know that it's been deleted, either.<br />
<br />
: See also: [[#hideWindow|hideWindow()]], [[#showWindow|showWindow()]], [[#createLabel|createLabel()]]<br />
<br />
; Parameters<br />
<br />
* ''labelName'': name of the label to delete.<br />
<br />
<syntaxhighlight lang="lua"><br />
createLabel("a very basic label",300,400,100,200,1)<br />
setBackgroundColor("a very basic label", 255, 204, 0, 200)<br />
<br />
-- delete the label after 3 seconds<br />
tempTimer(3, function()<br />
deleteLabel("a very basic label")<br />
end)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 4.5+<br />
<br />
==deleteLine==<br />
;deleteLine([windowName])<br />
: 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. This is purely visual - triggers will still fire on the line as expected.<br />
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.<br />
<br />
{{note}} for replacing text, [[Manual:Lua_Functions#replace|replace()]] is the proper option; doing the following: <code>selectCurrentLine(); replace(""); cecho("new line!\n")</code> is better.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- deletes the line - just put this command into the big script box. Keep the case the same -<br />
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else<br />
deleteLine()<br />
<br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
<br />
-- example of deleting multiple lines:<br />
deleteLine() -- delete the current line<br />
moveCursor(0,getLineNumber()-1) -- move the cursor back one line<br />
deleteLine() -- delete the previous line now<br />
</syntaxhighlight><br />
<br />
==deselect==<br />
;deselect([window name])<br />
: 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.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''window name:''<br />
: (optional) The name of the window to stop having anything selected in. If name is not provided the main window will have its selection cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further<br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</syntaxhighlight><br />
<br />
==disableClickthrough==<br />
; disableClickthrough(label)<br />
: Disables clickthrough for a label - making it act 'normal' again and receive clicks, doubleclicks, onEnter, and onLeave events. This is the default behaviour for labels.<br />
: See also: [[#enableClickthrough|enableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name of the label to restore clickability on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==disableCommandLine==<br />
; disableCommandLine(windowName)<br />
: Disables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableCommandLine|enableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to disable the command line in.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10<br />
<br />
==disableHorizontalScrollBar==<br />
; disableHorizontalScrollBar([windowName])<br />
: Disables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableHorizontalScrollBar|enableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==disableScrollBar==<br />
; disableScrollBar([windowName])<br />
: Disables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==dreplace==<br />
;dreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#decho|decho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
dreplace("<255,0,255>[ALERT!]: <r>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''text:''<br />
: Text to display in the echo. Same as a normal echo().<br />
* ''command:''<br />
: Lua code to do when the link is clicked.<br />
* ''hint:''<br />
: Text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentFormatElseDefault:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
echoLink("press me!", [[send("hi")]], "This is a tooltip")<br />
<br />
-- do the same, but send this link to a miniConsole<br />
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")<br />
</syntaxhighlight><br />
<br />
==echoUserWindow==<br />
;echoUserWindow(windowName)<br />
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.<br />
<br />
==echoPopup==<br />
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==enableClickthrough==<br />
; enableClickthrough(label)<br />
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.<br />
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.<br />
: See also: [[#disableClickthrough|disableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: The name of the label to enable clickthrough on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==enableCommandLine==<br />
; enableCommandLine(windowName)<br />
: Enables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#disableCommandLine|disableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to enable the command line in.<br />
<br />
{{note}} The command line name is the same as the miniConsole name<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableHorizontalScrollBar==<br />
; enableHorizontalScrollBar([windowName])<br />
: Enables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableHorizontalScrollBar|disableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableScrollBar==<br />
; enableScrollBar([windowName])<br />
: Enables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==fg==<br />
; fg([window], colorName)<br />
: 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)<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything or use ''main'' (since Mudlet 3.0).<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
<br />
-- example of working on a miniconsole<br />
fg("my console", "red")<br />
echo("my console", "red text")<br />
</syntaxhighlight><br />
<br />
==getAvailableFonts==<br />
; getAvailableFonts()<br />
: This returns a "font - true" key-value list of available fonts which you can use to verify that Mudlet has access to a given font.<br />
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.<br />
<br />
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]<br />
<br />
{{note}}<br />
Available since Mudlet 3.10<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if Ubuntu Mono is a font we can use<br />
if getAvailableFonts()["Ubuntu Mono"] then<br />
-- make the miniconsole use the font at size 16<br />
setFont("my miniconsole", "Ubuntu Mono")<br />
setFontSize("my miniconsole", 16)<br />
end<br />
</syntaxhighlight><br />
<br />
==getBgColor==<br />
; getBgColor(windowName)<br />
: 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.<br />
<br />
: See also: [[#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r,g,b;<br />
selectString("troll",1)<br />
r,g,b = getBgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
With Mudlet 4.10, '''getBgColor''' returns a fourth integer: the number of (UTF-16) characters with the same color. You can use this length to efficiently split a line into same-color runs.<br />
<br />
==getBorderBottom==<br />
;getBorderBottom()<br />
: Returns the size of the bottom border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
getBorderBottom()<br />
-- returns: 150<br />
</syntaxhighlight><br />
<br />
==getBorderLeft==<br />
;getBorderLeft()<br />
: Returns the size of the left border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
getBorderLeft()<br />
-- returns: 5<br />
</syntaxhighlight><br />
<br />
==getBorderRight==<br />
;getBorderRight()<br />
: Returns the size of the right border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
getBorderRight()<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderSizes==<br />
;getBorderSizes()<br />
: Returns the a named table with the sizes of all borders of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]],[[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0)<br />
getBorderSizes()<br />
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }<br />
getBorderSizes().right<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderTop==<br />
;getBorderTop()<br />
: Returns the size of the top border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
getBorderTop()<br />
-- returns: 100<br />
</syntaxhighlight><br />
<br />
==getClipboardText==<br />
;getClipboardText()<br />
: Returns any text that is currently present in the clipboard. <br />
: See also: [[#setClipboardText | setClipboardText()]]<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local clipboardContents = getClipboardText()<br />
echo("Clipboard: " .. clipboardContents)<br />
</syntaxhighlight><br />
<br />
==getColorWildcard==<br />
; getColorWildcard(ansi color number)<br />
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.<br />
<br />
: See also: [[#isAnsiFgColor|isAnsiFgColor()]], [[#isAnsiBgColor|isAnsiBgColor()]]<br />
<br />
;Parameters<br />
* ''ansi color number:''<br />
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- we can run this script on a line that has the players name coloured differently to easily capture it from<br />
-- anywhere on the line<br />
local match = getColorWildcard(14)<br />
<br />
if match then<br />
echo("\nFound "..match.."!")<br />
else<br />
echo("\nDidn't find anyone.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getColumnCount==<br />
;getColumnCount([windowName])<br />
: Gets the maximum number of columns (characters) that a given window can display on a single row, taking into consideration factors such as window width, font size, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum number of columns on the main window "..getColumnCount())<br />
</syntaxhighlight><br />
<br />
==getColumnNumber==<br />
;getColumnNumber([windowName])<br />
: Gets the absolute column number of the current user cursor.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
<br />
{{note}} the argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
<br />
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
</syntaxhighlight><br />
<br />
==getCurrentLine==<br />
;getCurrentLine([windowName])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Currently selected line: "..getCurrentLine())<br />
</syntaxhighlight><br />
<br />
==getFgColor==<br />
; getFgColor(windowName)<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString("troll",1)<br />
local r,g,b = getFgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is written in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getFont==<br />
;getFont(windowName)<br />
: Gets the current font of the given window or console name. Can be used to get font of the main console, dockable userwindows and miniconsoles.<br />
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
display("Font in the main window: "..getFont())<br />
<br />
display("Font in the main window: "..getFont("main"))<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
display("Font size: " .. getFont("user window awesome"))<br />
</syntaxhighlight><br />
<br />
==getFontSize==<br />
;getFontSize(windowName)<br />
: Gets the current font size of the given window or console name. Can be used to get font size of the Main console as well as dockable UserWindows.<br />
: See also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
local mainWindowFontSize = getFontSize()<br />
if mainWindowFontSize then<br />
display("Font size: " .. mainWindowFontSize)<br />
end<br />
<br />
local mainWindowFontSize = getFontSize("main")<br />
if mainWindowFontSize then<br />
display("Font size: " .. fs2)<br />
end<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
local awesomeWindowFontSize = getFontSize("user window awesome")<br />
if awesomeWindowFontSize then<br />
display("Font size: " .. awesomeWindowFontSize)<br />
end<br />
</syntaxhighlight><br />
<br />
==getImageSize==<br />
;getImageSize(imageLocation)<br />
: Returns the width and the height of the given image. If the image can't be found, loaded, or isn't a valid image file - nil+error message will be returned instead.<br />
: See also: [[#createLabel|createLabel()]]<br />
<br />
;Parameters<br />
* ''imageLocation:''<br />
: Path to the image.<br />
<br />
{{note}}<br />
Available in Mudlet 4.5+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local path = getMudletHomeDir().."/my-image.png"<br />
<br />
cecho("Showing dimensions of the picture in: "..path.."\n")<br />
<br />
local width, height = getImageSize(path)<br />
<br />
if not width then<br />
-- in case of an problem, we don't get a height back - but the error message<br />
cecho("error: "..height.."\n")<br />
else<br />
cecho(string.format("They are: %sx%s", width, height))<br />
end<br />
</syntaxhighlight><br />
<br />
==getLastLineNumber==<br />
;getLastLineNumber(windowName)<br />
:Returns the latest line's number in the main window or the miniconsole. This could be different from [[Manual:UI_Functions#getLineNumber|getLineNumber()]] if the cursor was moved around.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the latest line's # in the buffer<br />
local latestline = getLastLineNumber("main")<br />
</syntaxhighlight><br />
<br />
==getLineCount==<br />
;getLineCount()<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
''Need example''<br />
<br />
==getLines==<br />
;getLines([windowName,] from_line_number, to_line_number)<br />
: 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}''.<br />
<br />
:Absolute line numbers are used.<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)<br />
* ''from_line_number:''<br />
: First line number<br />
* ''to_line_number:''<br />
: End line number<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- retrieve & echo the last line:<br />
echo(getLines(getLineNumber()-1, getLineNumber())[1])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- find out which server and port you are connected to (as per Mudlet settings dialog):<br />
local t = getLines(0, getLineNumber())<br />
<br />
local server, port<br />
<br />
for i = 1, #t do<br />
local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")<br />
if s then server, port = s, p break end<br />
end<br />
<br />
display(server)<br />
display(port)<br />
</syntaxhighlight><br />
<br />
==getLineNumber==<br />
;getLineNumber([windowName])<br />
: 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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#moveCursorEnd|moveCursorEnd()]]. This function can come in handy in combination when using with [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#getLines|getLines()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.<br />
<br />
{{note}}<br />
The argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word<br />
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end<br />
<br />
-- check how many lines you've got in your miniconsole after echoing some text.<br />
-- Note the use of moveCursorEnd() to update getLineNumber()'s output<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
print(getLineNumber("HelloWorld"))<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
-- update the cursors position, as it seems to be necessary to do<br />
moveCursorEnd("HelloWorld")<br />
print(getLineNumber("HelloWorld"))<br />
</syntaxhighlight><br />
<br />
==getMainConsoleWidth==<br />
;getMainConsoleWidth()<br />
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.<br />
<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Save width of the main console to a variable for future use.<br />
consoleWidth = getMainConsoleWidth()<br />
</syntaxhighlight><br />
<br />
==getMousePosition==<br />
;getMousePosition()<br />
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{note}} Available since Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- 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<br />
local x, y = getMousePosition()<br />
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)<br />
-- if the label already exists, just move it<br />
moveWindow("clickGeneratedLabel", x, y)<br />
-- and make it easier to notice<br />
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)<br />
</syntaxhighlight><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getUserWindowSize|getUserWindowSize()]], [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your main mudlet window and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</syntaxhighlight><br />
<br />
==getRowCount==<br />
;getRowCount([windowName])<br />
: Gets the maximum number of rows that a given window can display at once, taking into consideration factors such as window height, font type, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum of rows on the main window "..getRowCount())<br />
</syntaxhighlight><br />
<br />
==getSelection==<br />
;getSelection([windowName])<br />
: Returns the text currently selected with [[#selectString|selectString()]], [[#selectSection|selectSection()]], or [[#selectCurrentLine|selectCurrentLine()]]. Note that this isn't the text currently selected with the mouse.<br />
: Also returns the start offset and length of the selection as second and third value.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window to get the selection from. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.16.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
print("Current line contains: "..getSelection())<br />
</syntaxhighlight><br />
<br />
;retrieving the selection<br />
<syntaxhighlight lang="lua"><br />
text,offset,len = getSelection()<br />
-- manipulate the selection, e.g. to discover the color of characters other than the first<br />
-- then restore it<br />
selectSection(offset, len)<br />
</syntaxhighlight><br />
<br />
==getTextFormat==<br />
;getTextFormat([windowName])<br />
: Gets the current text format of the currently selected text. May be used with other console windows. The returned values come in a table containing text attribute names and their values. The values given will be booleans for: bold, italics, underline, overline, strikeout, and reverse - followed by color triplet tables for the foreground and background colors.<br />
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.<br />
<br />
{{note}} Available since Mudlet 3.20.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- A suitable test for getTextFormat()<br />
-- (copy it into an alias or a script)<br />
<br />
clearWindow()<br />
<br />
echo("\n")<br />
<br />
local SGR = string.char(27)..'['<br />
feedTriggers("Format attributes: '"..SGR.."1mBold"..SGR.."0m' '"..SGR.."3mItalic"..SGR.."0m' '"..SGR.."4mUnderline"..SGR.."0m' '"..SGR.."5mBlink"..SGR.."0m' '"..SGR.."6mF.Blink"..SGR.."0m' '"..SGR.."7mReverse"..SGR.."0m' '"..SGR.."9mStruckout"..SGR.."0m' '"..SGR.."53mOverline"..SGR.."0m'.\n")<br />
<br />
moveCursor(1,1)<br />
selectSection(1,1)<br />
<br />
local results = getTextFormat()<br />
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))<br />
echo("\nItalic detected: " .. tostring(results["italic"]))<br />
echo("\nUnderline detected: " .. tostring(results["underline"]))<br />
echo("\nReverse detected: " .. tostring(results["reverse"]))<br />
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))<br />
echo("\nOverline detected: " .. tostring(results["overline"]))<br />
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")<br />
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")<br />
<br />
selectSection(21,1)<br />
echo("\n\nFor individual parts of test text:")<br />
echo("\nBold detected (character 21): " .. tostring(results["bold"]))<br />
<br />
selectSection(28,1)<br />
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))<br />
<br />
selectSection(37,1)<br />
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))<br />
<br />
selectSection(67,1)<br />
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))<br />
<br />
selectSection(77,1)<br />
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))<br />
<br />
selectSection(89,1)<br />
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))<br />
echo("\n")<br />
</syntaxhighlight><br />
<br />
==getUserWindowSize==<br />
{{note}} available in Mudlet 4.6.1+<br />
;getUserWindowSize(windowName)<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the given userwindow dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''windowName''<br />
:the name of the userwindow we will get the dimensions from<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your userwindow named "ChatWindow" and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getUserWindowSize("ChatWindow")<br />
</syntaxhighlight><br />
<br />
==handleWindowResizeEvent==<br />
;handleWindowResizeEvent()<br />
: (''depreciated'') This function is depreciated and should not be used; it's only documented here for historical reference - use the [[Manual:Technical_Manual#sysWindowResizeEvent|sysWindowResizeEvent]] event instead.<br />
<br />
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.<br />
<br />
; Parameters<br />
:None<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
function handleWindowResizeEvent()<br />
-- determine the size of your screen<br />
WindowWidth=0;<br />
WindowHeight=0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
-- move mini console "sys" to the far right side of the screen whenever the screen gets resized<br />
moveWindow("sys",WindowWidth-300,0)<br />
end<br />
</syntaxhighlight><br />
<br />
==hasFocus==<br />
;hasFocus()<br />
: 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). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if attacked and not hasFocus() then<br />
runaway()<br />
else<br />
fight()<br />
end<br />
</syntaxhighlight><br />
<br />
==hecho==<br />
;hecho([windowName], text)<br />
: Echoes text that can be easily formatted with colour tags in the hexadecimal format. You can also use italics, bold and underline tags.<br />
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.<br />
* ''text:''<br />
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #FRFGFB,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 or #r can be used within the string to reset the colors to default. Hexadecimal color codes can be found here: https://www.color-hex.com/<br />
<br />
{{note}}<br />
Transparency for background in hex-format available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hecho("\n#ffffff White text!")<br />
-- your text in white<br />
hecho("\n#ca0004 Red text! And now reset #rit to the default color")<br />
-- your text in red, then reset to default using #r<br />
hecho("\n#ffffff,ca0004 White text with a red background!")<br />
-- your text in white, against a red background<br />
hecho("\n|c0000ff Blue text, this time using |c instead of #")<br />
-- your text in blue, activated with |c vs #.<br />
hecho("\n#ff0000Red text with #iitalics#/i, |uunderline|/u and #bbold#/b formatting.")<br />
</syntaxhighlight><br />
<br />
==hechoLink==<br />
;hechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#hecho|hecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
-- # format also works<br />
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==hechoPopup==<br />
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#hecho|hecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertLink==<br />
;hinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#hinsertText|hinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertPopup==<br />
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#hinsertText|hinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hreplace==<br />
;hreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#hecho|hecho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
hreplace("#EE00EE[ALERT!]: #r"..matches[2])<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.5+<br />
<br />
==hideToolBar==<br />
;hideToolBar(name)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to hide<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hideToolBar("my offensive buttons")<br />
</syntaxhighlight><br />
<br />
==hideWindow==<br />
;hideWindow(name)<br />
: This function hides a '''mini console''', a '''user window''' or a '''label''' with the given name. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].<br />
<br />
: See also: [[#createMiniConsole|createMiniConsole()]], [[#createLabel|createLabel()]], [[#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name''<br />
: specifies the label or console you want to hide.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function miniconsoleTest()<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
print("created red window top-right")<br />
<br />
tempTimer(1, function()<br />
hideWindow("sys")<br />
print("hid red window top-right")<br />
end)<br />
<br />
tempTimer(3, function()<br />
showWindow("sys")<br />
print("showed red window top-right")<br />
end)<br />
end<br />
<br />
miniconsoleTest()<br />
</syntaxhighlight><br />
<br />
==insertLink==<br />
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])<br />
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) the window to insert the link in - use either "main" or omit for the main window.<br />
* ''text:''<br />
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) true or false. 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- link with the default blue on white colors<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")<br />
<br />
-- use current cursor colors by adding true at the end<br />
fg("red")<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==insertPopup==<br />
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])<br />
: Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to [[Manual:Lua_Functions#insertText|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''name:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.<br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==insertText==<br />
;insertText([windowName], text)<br />
: Inserts text at cursor postion in window - unlike [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] to move the cursor into position first.<br />
<br />
: insertHTML() also does the same thing as insertText, if you ever come across it.<br />
<br />
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) The window to insert the text to.<br />
* ''text:''<br />
: The text you will insert into the current cursor position.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the cursor to the end of the previous line and insert some text<br />
<br />
-- move to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
-- move the end the of the previous line<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
<br />
fg("dark_slate_gray")<br />
insertText(' <- that looks nice.')<br />
<br />
deselect()<br />
resetFormat()<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
==ioprint==<br />
;ioprint(text, some more text, ...)<br />
:Prints text to the to the stdout. This is only available if you [http://www.wikihow.com/Run-a-Program-on-Command-Prompt launched Mudlet from cmd.exe] on Windows, [http://www.wikihow.com/Open-Applications-Using-Terminal-on-Mac from the terminal] on Mac, or from the terminal on a Linux OS (launch the terminal program, type ''mudlet'' and press enter).<br />
<br />
Similar to [[Manual:Lua_Functions#echo|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.<br />
<br />
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.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
ioprint("hi!")<br />
ioprint(1,2,3)<br />
ioprint(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==isAnsiBgColor==<br />
; isAnsiBgColor(bgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the background color specified by bgColorCode.<br />
<br />
;Parameters<br />
* ''bgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiBgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the background of the text is light green" )<br />
else<br />
echo( "no sorry, some other background color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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 getBgColor() and then handling the color comparison in Lua.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default background color in the zeroth position.''<br />
<br />
==isAnsiFgColor==<br />
; isAnsiFgColor(fgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the foreground color specified by fgColorCode.<br />
<br />
;Parameters<br />
* ''fgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiFgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the text is light green" )<br />
else<br />
echo( "no sorry, some other foreground color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default foreground color in the zeroth position.''<br />
<br />
==lowerWindow==<br />
;lowerWindow(labelName)<br />
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to move below the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top<br />
</syntaxhighlight><br />
<br />
==moveCursor==<br />
;moveCursor([windowName], x, y)<br />
: 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 [[Manual:Lua_Functions#getLineNumber|getLineNumber()]], [[Manual:Lua_Functions#getColumnNumber|getColumnNumber()]] and [[Manual:Lua_Functions#getLastLineNumber|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.<br />
<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The window you are going to move the cursor in.<br />
* ''x:''<br />
: The horizontal axis in the window - that is, the letter position within the line.<br />
* ''y:''<br />
: The vertical axis in the window - that is, the line number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move cursor to the start of the previous line and insert -<(<br />
-- the first 0 means we want the cursor right at the start of the line,<br />
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which<br />
-- equals to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
insertText("-<(")<br />
<br />
-- now we move the cursor at the end of the previous line. Because the<br />
-- cursor is on the previous line already, we can use #getCurrentLine()<br />
-- to see how long it is. We also just do getLineNumber() because getLineNumber()<br />
-- returns the current line # the cursor is on<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
insertText(")>-")<br />
<br />
-- finally, reset it to the end where it was after our shenaningans - other scripts<br />
-- could expect the cursor to be at the end<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a more complicated example showing how to work with Mudlet functions<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
local WindowWidth, WindowHeight = getMainWindowSize()<br />
<br />
-- define a mini console named "sys" and set its background color<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
<br />
-- you *must* set the font size, otherwise mini windows will not work properly<br />
setMiniConsoleFontSize("sys", 12)<br />
-- wrap lines in window "sys" at 65 characters per line<br />
setWindowWrap("sys", 60)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
-- clear the window<br />
clearUserWindow("sys")<br />
<br />
moveCursorEnd("sys")<br />
setFgColor("sys", 10,10,0)<br />
setBgColor("sys", 0,0,255)<br />
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")<br />
echo("sys", "test1---line2\n")<br />
echo("sys", "test1---line3\n")<br />
setTextFormat("sys",158,0,255,255,0,255,0,0,0);<br />
--setFgColor("sys",255,0,0);<br />
echo("sys", "test1---line4\n")<br />
echo("sys", "test1---line5\n")<br />
moveCursor("sys", 1,1)<br />
<br />
-- deleting lines 2+3<br />
deleteLine("sys")<br />
deleteLine("sys")<br />
<br />
-- inserting a line at pos 5,2<br />
moveCursor("sys", 5,2)<br />
setFgColor("sys", 100,100,0)<br />
setBgColor("sys", 255,100,0)<br />
insertText("sys","############## line inserted at pos 5/2 ##############")<br />
<br />
-- inserting a line at pos 0,0<br />
moveCursor("sys", 0,0)<br />
selectCurrentLine("sys")<br />
setFgColor("sys", 255,155,255)<br />
setBold( "sys", true );<br />
setUnderline( "sys", true )<br />
setItalics( "sys", true )<br />
insertText("sys", "------- line inserted at: 0/0 -----\n")<br />
<br />
setBold( "sys", true )<br />
setUnderline( "sys", false )<br />
setItalics( "sys", false )<br />
setFgColor("sys", 255,100,0)<br />
setBgColor("sys", 155,155,0)<br />
echo("sys", "*** This is the end. ***\n")<br />
</syntaxhighlight><br />
<br />
==moveCursorDown==<br />
;moveCursorDown([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window down a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor down by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorUp==<br />
;moveCursorUp([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window up a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor up by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorEnd==<br />
;moveCursorEnd([windowName])<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
: Returns true or false<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveGauge==<br />
;moveGauge(gaugeName, newX, newY)<br />
: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.<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: The name of your gauge<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would move the health bar gauge to the location 1200, 400<br />
moveGauge("healthBar", 1200, 400)<br />
</syntaxhighlight><br />
<br />
==moveWindow==<br />
;moveWindow(name, x, y)<br />
: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.<br />
<br />
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of your window<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles.<br />
<br />
==openUserWindow==<br />
;openUserWindow(windowName, [restoreLayout], [autoDock], [dockingArea])<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).<br />
* ''restoreLayout:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.<br />
* ''autoDock:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't dock automatically at the corners.<br />
* ''dockingArea:''<br />
: (optional) - the area your UserWindow will be docked at. possible docking areas your UserWindow will be created in (f" floating "t" top "b" bottom "r" right and "l" left). Docking area is "right" if not given any value.<br />
<br />
{{note}}<br />
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.<br />
<br />
{{note}}<br />
The parameters autoDock and dockingArea are available since Mudlet 4.7+ <br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
openUserWindow("My floating window")<br />
cecho("My floating window", "<red>hello <blue>bob!")<br />
<br />
-- if you don't want Mudlet to remember its last position:<br />
openUserWindow("My floating window", false)<br />
</syntaxhighlight><br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]]<br />
<br />
==paste==<br />
;paste(windowName)<br />
: Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The [[#copy | copy()]] and [[#paste | 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
<br />
==prefix==<br />
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
:Prefixes text at the beginning of the current line when used in a trigger.<br />
<br />
;Parameters<br />
* ''text:''<br />
: the information you want to prefix<br />
* "writingFunction:"<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* "foregroundColor:"<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* "backgroundColor:"<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* "windowName:"<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that<br />
prefix(os.date("%H:%M:%S "))<br />
-- Prefix the time in red into a miniconsole named "my_console"<br />
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#suffix | suffix()]]<br />
<br />
==print==<br />
;print(text, some more text, ...)<br />
:Prints text to the main window. Similar to [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#display|display()]] for those. This function works similarly to the print() you will see in guides for Lua.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
print("hi!")<br />
print(1,2,3)<br />
print(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==raiseWindow==<br />
;raiseWindow(labelName)<br />
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to bring to the top of the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel<br />
</syntaxhighlight><br />
<br />
==replace==<br />
;replace([windowName], with, [keepcolor])<br />
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.<br />
<br />
{{note}}<br />
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.<br />
<br />
{{note}}<br />
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 | insertText()]] does.<br />
<br />
See also: [[#creplace|creplace]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of window (a miniconsole)<br />
* ''with:''<br />
: the new text to display.<br />
* ''keepcolor:''<br />
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
-- replace word "troll" with "cute trolly"<br />
selectString("troll",1)<br />
replace("cute trolly")<br />
<br />
-- replace the whole line<br />
selectCurrentLine()<br />
replace("Out with the old, in with the new!")<br />
</syntaxhighlight><br />
<br />
==replaceAll==<br />
;replaceAll(what, with, [keepcolor])<br />
: Replaces all occurrences of ''what'' in the current line with ''with''.<br />
<br />
;Parameters<br />
* ''what:''<br />
: the text to replace<br />
{{note}}<br />
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]<br />
* ''with:''<br />
: the new text to have in place<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors.<br />
{{note}} keepcolor is available in Mudlet 4.10+<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the word "south" in the line with "north"<br />
replaceAll("south", "north")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the text that the variable "target" has<br />
replaceAll(target, "The Bad Guy")<br />
</syntaxhighlight><br />
<br />
==replaceWildcard==<br />
;replaceWildcard(which, replacement, [keepcolor])<br />
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString(matches[2], 1)<br />
replace("text")<br />
</syntaxhighlight><br />
<br />
;Parameters<br />
* ''which:''<br />
: Wildcard to replace.<br />
* ''replacement:''<br />
: Text to replace the wildcard with.<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors<br />
{{note}} keepcolor available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello<br />
</syntaxhighlight><br />
<br />
==resetCmdLineAction==<br />
;resetCmdLineAction(commandLineName)<br />
: Resets the action on the command line so the it behaves like the main command line again.<br />
;Parameters<br />
<br />
* ''commandLineName''<br />
: The name of the command line the action will be resetet.<br />
: See also: [[#setCmdLineAction | setCmdLineAction()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetBackgroundImage==<br />
;resetBackgroundImage([windowName])<br />
: Resets the console background-image<br />
;Parameters<br />
<br />
* ''windowName''<br />
: (optional) name of the console the image will be reset<br />
: See also: [[#setBackgroundImage | setBackgroundImage()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: 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.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==resetLabelCursor==<br />
;resetLabelCursor(labelName)<br />
: Resets your mouse cursor to the default one.<br />
<br />
: See also: [[#setLabelCursor|setLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName'': label for which to reset the cursor for.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetLabelCursor("myLabel")<br />
-- This will reset the mouse cursor over myLabel to the default one<br />
</syntaxhighlight><br />
<br />
==resetLabelToolTip==<br />
;resetLabelToolTip(labelName)<br />
: Resets the tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label the tooltip will be reseted.<br />
: See also: [[#setLabelToolTip | setLabelToolTip()]]<br />
<br />
==resetMapWindowTitle==<br />
;resetMapWindowTitle()<br />
: resets the title of the popped out map window to default.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setMapWindowTitle|setMapWindowTitle()]]<br />
<br />
==resetUserWindowTitle==<br />
;resetUserWindowTitle(windowName)<br />
: resets the title of the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow for which the title will be resetet<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setUserWindowTitle|setUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==resizeWindow==<br />
;resizeWindow(windowName, width, height)<br />
: Resizes a mini console, label, or floating User Windows.<br />
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
* ''width:''<br />
: The new width you want<br />
* ''height:''<br />
: The new height you want<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.<br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumber:''<br />
: number of the capture group you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".<br />
--If you want to color the amount of money you have green you do:<br />
<br />
selectCaptureGroup(1)<br />
setFgColor(0,255,0)<br />
</syntaxhighlight><br />
<br />
==selectCurrentLine==<br />
; selectCurrentLine([windowName])<br />
: 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.<br />
<br />
{{note}}<br />
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.<br />
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- color the whole line green!<br />
selectCurrentLine()<br />
fg("green")<br />
deselect()<br />
resetFormat()<br />
<br />
-- to select the previous line, you can do this:<br />
moveCursor(0, getLineNumber()-1)<br />
selectCurrentLine()<br />
<br />
-- to select two lines back, this:<br />
moveCursor(0, getLineNumber()-2)<br />
selectCurrentLine()<br />
<br />
</syntaxhighlight><br />
<br />
==selectSection==<br />
;selectSection( [windowName], fromPosition, length )<br />
: 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.<br />
: 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.<br />
<br />
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]<br />
<br />
;Parameters<br />
* "windowName:"<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.<br />
: Will not work if "main" is given as the windowName to try to select from the main window.<br />
* ''fromPosition:''<br />
: number to specify at which position in the line to begin selecting<br />
* ''length:''<br />
: number to specify the amount of characters you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and colour the first character in the line red<br />
if selectSection(0,1) then fg("red") end<br />
<br />
-- select and colour the second character green (start selecting from the first character, and select 1 character)<br />
if selectSection(1,1) then fg("green") end<br />
<br />
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)<br />
if selectSection(2,3) then fg("grey") end<br />
</syntaxhighlight><br />
<br />
==selectString==<br />
;selectString( [windowName], text, number_of_match )<br />
: 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).<br />
<br />
{{note}}<br />
You can move the user cursor with [[#moveCursor | 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 | deselect()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.<br />
* ''text:''<br />
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).<br />
* ''number_of_match:''<br />
: 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.<br />
<br />
: Returns position in line or -1 on error (text not found in line)<br />
<br />
{{note}}<br />
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if selectString( "big monster", 1 ) > -1 then fg("red") end<br />
</syntaxhighlight><br />
<br />
==setAppStyleSheet==<br />
;setAppStyleSheet(stylesheet [, tag])<br />
: Sets a stylesheet for the entire Mudlet application and every open profile. Because it affects other profiles that might not be related to yours, it's better to use [[#setProfileStyleSheet|setProfileStyleSheet()]] instead of this function.<br />
<br />
: Raises the sysAppStyleSheetChange event which comes with two arguments in addition to the event name. The first is the optional tag which was passed into the function, or "" if nothing was given. The second is the profile which made the stylesheet changes.<br />
<br />
: See also: [[#setProfileStyleSheet|setProfileStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use.<br />
<br />
* ''tag:'' (with Mudlet 3.19+)<br />
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.<br />
<br />
;References<br />
: See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setAppStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
]])<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 3.0.<br />
<br />
Enhanced in Mudlet version 3.19.0 to generate an event that profiles/packages can utilise to redraw any parts of the UI that they themselves had previously styled so their effects can be re-applied to the new application style.<br />
<br />
It is anticipated that the Mudlet application itself will make further use of application styling effects and two strings are provisionally planned for the second parameter in the ''sysAppStyleSheetChange'' event: "''mudlet-theme-dark''" and "''mudlet-theme-light''"; it will also set the third parameter to "''system''".<br />
<br />
==setBackgroundColor==<br />
;setBackgroundColor([windowName], r, g, b, transparency)<br />
: Sets the background for the given label, miniconsole, or userwindow. Colors are from 0 to 255 (0 being black), and transparency is from 0 to 255 (0 being completely transparent).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.<br />
* ''r:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''g:''<br />
: Amount of green to use, from 0 (none) to 255 (full).<br />
* ''b:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).<br />
<br />
{{note}}<br />
Transparency also available for main/miniconsoles in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red label that's somewhat transparent<br />
setBackgroundColor("some label",255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setBackgroundImage==<br />
;setBackgroundImage(labelName, imageLocation)<br />
;setBackgroundImage([windowname], imageLocation, [mode])<br />
: Loads an image file (png) as a background image for a label or console. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.<br />
<br />
{{note}}<br />
You can also load images on labels via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].<br />
<br />
;Parameters (label)<br />
<br />
* ''labelName:''<br />
: The name of the label to change it's background color.<br />
* ''imageLocation:''<br />
: 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.<br />
<br />
;Parameters (consoles)<br />
<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow to change the background image on, or "main" for the main window.<br />
* ''imageLocation:''<br />
: 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.<br />
* ''mode:''<br />
: (optional) allows different modes for drawing the background image. Possible modes areː <br />
<br />
** border - the background image is stretched (1)<br />
** center - the background image is in the center (2), <br />
** tile - the background image is 'tiled' (3)<br />
** style - choose your own background image stylesheet, see example below (4)<br />
<br />
: See also: [[#resetBackgroundImage | resetBackgroundImage()]]<br />
<br />
;Example (label)<br />
<syntaxhighlight lang="lua"><br />
-- give the top border a nice look<br />
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])<br />
</syntaxhighlight><br />
<br />
;Example (main/miniconsole)<br />
<syntaxhighlight lang="lua"><br />
-- give the main window a background image<br />
setBackgroundImage("main", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- or use your own for the main window:<br />
setBackgroundImage("main", [[C:\Documents and Settings\bub\Desktop\mypicture.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image and put it in the center<br />
setBackgroundImage("my_miniconsole", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image with own stylesheet option<br />
setBackgroundImage("my_miniconsole", [[background-image: url(:/Mudlet_splashscreen_development.png); background-repeat: no-repeat; background-position: right;]], "style")<br />
</syntaxhighlight><br />
{{note}} setBackgroundImage for main/miniconsoles and userwindows available in Mudlet 4.10+<br />
<br />
==setBgColor==<br />
;setBgColor([windowName], r, g, b, transparency)<br />
: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.<br />
<br />
:If you'd like to change the background color of a window, see [[#setBackgroundColor|setBackgroundColor()]].<br />
<br />
: ''See also:'' [[#cecho|cecho()]], [[#setBackgroundColor|setBackgroundColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Optional, if not used color is fully opaque<br />
<br />
<br />
<br />
{{note}}<br />
Transparency parameter available in Mudlet 4.10+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red background color.<br />
selectString( "Tom", 1 )<br />
setBgColor( 255,0,0 )<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--prints "Hello" on red background and "You" on blue.<br />
setBgColor(255,0,0)<br />
echo("Hello")<br />
setBgColor(0,0,255)<br />
echo(" You!")<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBold==<br />
;setBold(windowName, boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
<br />
* ''boolean:''<br />
: A <code>true</code> or <code>false</code> that enables or disables bolding of text<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- enable bold formatting<br />
setBold(true)<br />
-- the following echo will be bolded<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBorderBottom==<br />
;setBorderBottom(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
</syntaxhighlight><br />
<br />
==setBorderColor==<br />
;setBorderColor(red, green, blue)<br />
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]<br />
<br />
;Parameters<br />
* ''red:''<br />
: Amount of red color to use, from 0 to 255.<br />
* ''green:''<br />
: Amount of green color to use, from 0 to 255.<br />
* ''blue:''<br />
: Amount of blue color to use, from 0 to 255.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set the border to be completely blue<br />
setBorderColor(0, 0, 255)<br />
<br />
-- or red, using a name<br />
setBorderColor( unpack(color_table.red) )<br />
</syntaxhighlight><br />
<br />
==setBorderLeft==<br />
;setBorderLeft(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
</syntaxhighlight><br />
<br />
==setBorderRight==<br />
;setBorderRight(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
</syntaxhighlight><br />
<br />
==setBorderSizes==<br />
;setBorderSizes(top, right, bottom, left)<br />
: Sets the size of all borders 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.<br />
: The exact result of this function depends on how many numbers you give to it as arguments.<br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Arguments<br />
* '''setBorderSizes(top, right, bottom, left)'''<br />
: ''4 arguments:'' All borders will be set to their new given size.<br />
* '''setBorderSizes(top, width, bottom)''' <br />
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width. <br />
* '''setBorderSizes(height, width)'''<br />
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width. <br />
* '''setBorderSizes(size)'''<br />
: ''1 argument:'' All borders will be set to the same size.<br />
* '''setBorderSizes()'''<br />
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0) <br />
-- big border at the top, bigger at the bottom, small at the right, none at the left<br />
<br />
setBorderSizes(100, 50, 150) <br />
-- big border at the top, bigger at the bottom, small at the right and the left<br />
<br />
setBorderSizes(100, 50) <br />
-- big border at the top and the bottom, small at the right and the left<br />
<br />
setBorderSizes(100) <br />
-- big borders at all four sides<br />
<br />
setBorderSizes() <br />
-- no borders at all four sides<br />
</syntaxhighlight><br />
<br />
==setBorderTop==<br />
;setBorderTop(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
</syntaxhighlight><br />
<br />
==setFgColor==<br />
;setFgColor([windowName], red, green, blue)<br />
:Sets the current text foreground color in the main window unless windowName parameter given.<br />
<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''red:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''green:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''blue:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]], [[#setHexBgColor | setHexBgColor()]], [[#resetFormat | resetFormat()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setFgColor( 255, 0, 0 )<br />
</syntaxhighlight><br />
<br />
==setButtonStyleSheet==<br />
;setButtonStyleSheet(button, markup)<br />
: Applies Qt style formatting to a button via a special markup language.<br />
<br />
; Parameters<br />
* ''button:''<br />
: The name of the button to be formatted.<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note: You can instead use QWidget { markup }. QWidget will reference 'button', allowing the use of pseudostates like QWidget:hover and QWidget:selected<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setButtonStyleSheet("my test button", [[<br />
QWidget {<br />
background-color: #999999;<br />
border: 3px #777777;<br />
}<br />
QWidget:hover {<br />
background-color: #bbbbbb;<br />
}<br />
QWidget:checked {<br />
background-color: #77bb77;<br />
border: 3px #559955;<br />
}<br />
QWidget:hover:checked {<br />
background-color: #99dd99;<br />
} ]])</syntaxhighlight><br />
<br />
==setClipboardText==<br />
;setClipboardText(textContent)<br />
: Sets the value of the computer's clipboard to the string data provided.<br />
: See also: [[#getClipboardText | getClipboardText()]]<br />
<br />
; Parameters<br />
* ''textContent:''<br />
: The text to be put into the clipboard.<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setClipboardText("New Clipboard Contents")<br />
echo("Clipboard: " .. getClipboardText()) -- should echo "Clipboard: New Clipboard Contents"<br />
</syntaxhighlight><br />
<br />
==setCmdLineAction==<br />
;setCmdLineAction(commandLineName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user sends text to the command line. 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 command line action. Additionally, this function passes the command line input text as the final argument.<br />
{{note}} If no action is set the command line behaves like the main command line and sends commands directly to the game or alias engine.<br />
<br />
The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, text)<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#resetCmdLineAction|resetCmdLineAction()]]<br />
<br />
;Parameters<br />
<br />
* ''commandLineName:''<br />
: The name of the command line to attach the action function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} You can also pass a function directly instead of using a string<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function sendTextToMiniConsole(miniConsoleName, cmdLineText)<br />
echo(miniConsoleName, cmdLineText.."\n")<br />
end<br />
<br />
setCmdLineAction("myCmdLine", "sendTextToMiniConsole", "myMiniConsole")<br />
<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setCmdLineStyleSheet==<br />
;setCmdLineStyleSheet([commandLineName], markup)<br />
: Applies Qt style formatting to a command line via a special markup language.<br />
<br />
;Parameters<br />
* ''commandLineName:''<br />
: (optional) Name of the command line (or miniconsole the command line is in). If not given the stylesheet will be applied to the main command line.<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#createCommandLine|createCommandLine()]]<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- move the main command line over to the right<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
padding-left: 100px; /* change 100 to your number */<br />
background-color: black; /* change it to your background color */<br />
}<br />
]])<br />
<br />
--only change font-size of your main command line<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
font-sizeː20pt; <br />
}<br />
]])<br />
<br />
--change bg/fg color of your miniconsole command line (name of the miniconsole is 'myMiniconsole'<br />
--the command line in the miniconsole has to be enabled<br />
setCmdLineStyleSheet("myMiniConsole", [[<br />
QPlainTextEdit {<br />
background: rgb(0,100,0);<br />
color: rgb(0,200,255);<br />
font-size: 10pt;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
==setFont==<br />
;setFont(name, font)<br />
: Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Prefer a monospaced font - those work best with text games. See here [https://doc.qt.io/qt-5/qfont.html#setFamily for more].<br />
: See also: [[#getFont|getFont()]], [[#setFontSize|setFontSize()]], [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''font:''<br />
: The font to use.<br />
<br />
{{note}}<br />
Available in Mudlet 3.9+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.<br />
setFont("Ubuntu Mono")<br />
setFont("main", "Ubuntu Mono")<br />
<br />
-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.<br />
setFont("combat", "Ubuntu Mono")<br />
</syntaxhighlight><br />
<br />
==setFontSize==<br />
;setFontSize(name, size)<br />
: Sets a font size on the given window or console name. Can be used to change font size of the Main console as well as dockable UserWindows.<br />
: See Also: [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
* ''size:''<br />
: The font size to apply to the window.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to 12-point font.<br />
setFontSize(12)<br />
setFontSize("main", 12)<br />
<br />
-- This will set the font size of a user window named "uw1" to 12-point font.<br />
setFontSize("uw1", 12)<br />
</syntaxhighlight><br />
<br />
==setGauge==<br />
;setGauge(gaugeName, currentValue, maxValue, gaugeText)<br />
: 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.<br />
<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#createGauge|createGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a gauge<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
--Change the looks of the gauge named healthBar and make it<br />
--fill to half of its capacity. The height is always remembered.<br />
setGauge("healthBar", 200, 400)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
--If you wish to change the text on your gauge, you’d do the following:<br />
setGauge("healthBar", 200, 400, "some text")<br />
</syntaxhighlight><br />
<br />
==setGaugeStyleSheet==<br />
;setGaugeStyleSheet(gaugeName, css, cssback, csstext)<br />
: 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. You can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create stylesheets.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]],<br />
[[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
</syntaxhighlight><br />
<br />
==setGaugeText==<br />
;setGaugeText(gaugename, css, ccstext )<br />
: Set the formatting of the text used inside the inserted gaugename.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
setGaugeText("healthBar", [[<p style="font-weight:bold;color:#C9C9C9;letter-spacing:1pt;word-spacing:2pt;font-size:12px;text-align:center;font-family:arial black, sans-serif;">]]..MY_NUMERIC_VARIABLE_HERE..[[</p>]])</syntaxhighlight><br />
<br />
;Useful resources:<br />
:http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.<br />
:https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!<br />
<br />
==setHexBgColor==<br />
;setHexBgColor([windowName], hexColorString)<br />
:Sets the current text nackground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.<br />
selectString( "Tom", 1 )<br />
setHexBgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setHexFgColor==<br />
;setHexFgColor([windowName], hexColorString)<br />
:Sets the current text foreground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text foreground color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setFgColor | setFgColor()]], [[#setHexBgColor | setHexBgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setHexFgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setItalics==<br />
;setItalics(windowName, bool)<br />
: Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setLabelToolTip==<br />
;setLabelToolTip(labelName, [duration])<br />
: Sets a tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to set the tooltip to.<br />
* ''duration:''<br />
: Duration of the tooltip timeout in seconds. Optional, if not set the default duration will be set.<br />
<br />
: See also: [[Manual:UI_Functions#resetLabelToolTip|resetLabelToolTip()]]<br />
<br />
==setLabelClickCallback==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument. This table contains information about the mouse button clicked, other buttons that were pressed at the time, and the mouse cursor's local (relative to the label) and global (relative to the Mudlet window) position. The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, event)<br />
</syntaxhighlight><br />
<br />
where '''event''' has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
button = "LeftButton",<br />
buttons = {"RightButton", "MidButton"},<br />
}<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]],[[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} Event argument is available in 3.6+, and in 4.8+ you can pass a function directly instead of a string.<br />
<br />
{{note}}<br />
While '''event.button''' may contain a single string of any listed below, '''event.buttons''' will only ever contain some combination of "LeftButton", "MidButton", and "RightButton"<br />
:The following mouse button strings are defined:<br />
<pre><br />
"LeftButton" "RightButton" "MidButton"<br />
"BackButton" "ForwardButton" "TaskButton"<br />
"ExtraButton4" "ExtraButton5" "ExtraButton6"<br />
"ExtraButton7" "ExtraButton8" "ExtraButton9"<br />
"ExtraButton10" "ExtraButton11" "ExtraButton12"<br />
"ExtraButton13" "ExtraButton14" "ExtraButton15"<br />
"ExtraButton16" "ExtraButton17" "ExtraButton18"<br />
"ExtraButton19" "ExtraButton20" "ExtraButton21"<br />
"ExtraButton22" "ExtraButton23" "ExtraButton24"<br />
</pre><br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
else if event.button == "RightButton" then<br />
send("swim north")<br />
else if event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )<br />
<br />
-- you can also use them within tables now:<br />
mynamespace = {<br />
onClickGoNorth = function()<br />
echo("the north button was clicked!")<br />
end<br />
}<br />
<br />
setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )<br />
<br />
</syntaxhighlight><br />
<br />
==setLabelDoubleClickCallback==<br />
;setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user double 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.6+<br />
<br />
: See also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
==setLabelMoveCallback==<br />
;setLabelMoveCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse moves while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
==setLabelOnEnter==<br />
;setLabelOnEnter(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the '''event''' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
}<br />
</syntaxhighlight><br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseOver()<br />
echo("The mouse is hovering over the label!\n")<br />
end<br />
<br />
setLabelOnEnter( "compassNorthImage", "onMouseOver" )<br />
</syntaxhighlight><br />
<br />
==setLabelOnLeave==<br />
;setLabelOnLeave(labelName, luaFunctionName, [any arguments])<br />
: 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.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseLeft(argument)<br />
echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)<br />
end<br />
<br />
setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )<br />
</syntaxhighlight><br />
<br />
==setLabelReleaseCallback==<br />
;setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
This command was added in version 3.0.0<br />
<br />
{{note}}<br />
The ''event'' argument only available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onReleaseNorth()<br />
echo("the north button was released!")<br />
end<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onReleaseNorth = function()<br />
echo("the north button was released!")<br />
end<br />
}<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )<br />
</syntaxhighlight><br />
<br />
==setLabelStyleSheet==<br />
;setLabelStyleSheet(label, markup)<br />
: Applies Qt style formatting to a label via a special markup language.<br />
<br />
; Parameters<br />
* ''label:''<br />
: The name of the label to be formatted (passed when calling createLabel).<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a white background and a green border, with the text "test"<br />
-- inside.<br />
createLabel("test", 50, 50, 100, 100, 0)<br />
setLabelStyleSheet("test", [[<br />
background-color: white;<br />
border: 10px solid green;<br />
font-size: 12px;<br />
]])<br />
echo("test", "test")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that will tile or clip depending on the<br />
-- size of the label. To use this example, please supply your own image.<br />
createLabel("test5", 50, 353, 164, 55, 0)<br />
setLabelStyleSheet("test5", [[<br />
background-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that can be resized (such as during a<br />
-- sysWindowResizeEvent). To use this example, please supply your own image.<br />
createLabel("test9", 215, 353, 100, 100, 0)<br />
setLabelStyleSheet("test9", [[<br />
border-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--This creates a label whose background changes when the users mouse hovers over it.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
local ourLabelStyle = [[<br />
QLabel{<br />
background-color: ]]..labelBackgroundColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
QLabel::hover{<br />
background-color: ]]..labelHoverColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--Using QLabel::hover mentioned above. Lets "trick" the label into changing it's text.<br />
--Please keep in mind that the setLabelMoveCallback allows for much more control over not just your label but your entire project.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
--Notice we are adding a string returned from a function. In this case, the users profile directory.<br />
local ourLabelStyle = [[<br />
QLabel{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithtext.png");<br />
}<br />
QLabel::hover{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithhovertext.png");<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
--This is just to example that echos draw on top of the label. You would not want to echo onto a label you were drawing text on with images, because echos would draw on top of them.<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<br />
==setLabelCursor==<br />
;setLabelCursor(labelName, cursorShape)<br />
: Changes how the mouse cursor looks like when over the label. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''cursorShape''<br />
: Shape of the mouse cursor. List of possible cursor shapes is [[CursorShapes| available here]].<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCursor("myLabel", "Cross")<br />
-- This will change the mouse cursor to a cross if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelCustomCursor==<br />
;setLabelCustomCursor(labelName, custom cursor, [hotX, hotY])<br />
: Changes the mouse cursor shape over your label to a custom cursor. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCursor|setLabelCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''custom cursor''<br />
: Location of your custom cursor file. To be compatible with all systems it is recommended to use png files with size of 32x32.<br />
* ''hotX''<br />
: X-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
* ''hotY''<br />
: Y-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCustomCursor("myLabel", getMudletHomeDir().."/custom_cursor.png")<br />
-- This will change the mouse cursor to your custom cursor if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelWheelCallback==<br />
;setLabelWheelCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse wheel is scrolled while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the ''event'' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
buttons = {"RightButton", "MidButton"},<br />
angleDeltaX = 0,<br />
angleDeltaY = 120<br />
}<br />
</syntaxhighlight><br />
<br />
: Keys ''angleDeltaX'' and ''angleDeltaY'' correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onWheelNorth(event)<br />
if event.angleDeltaY > 0 then<br />
echo("the north button was wheeled forwards over!")<br />
else<br />
echo("the north button was wheeled backwards over!")<br />
end<br />
end<br />
<br />
setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onWheelNorth = function()<br />
echo("the north button was wheeled over!")<br />
end<br />
}<br />
<br />
setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )<br />
</syntaxhighlight><br />
<br />
==setLink==<br />
;setLink([windowName], command, tooltip)<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of a miniconsole or a userwindow in which to select the text in.<br />
* ''command:''<br />
: command to do when the text is clicked.<br />
* ''tooltip:''<br />
: tooltip to show when the mouse is over the text - explaining what would clicking do.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can clickify a lot of things to save yourself some time - for example, you can change<br />
-- the line where you receive a message to be clickable to read it!<br />
-- prel regex trigger:<br />
-- ^You just received message #(\w+) from \w+\.$<br />
-- script:<br />
selectString(matches[2], 1)<br />
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])<br />
resetFormat()<br />
<br />
-- an example of selecting text in a miniconsole and turning it into a link:<br />
<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
HelloWorld:echo("hi")<br />
selectString("HelloWorld", "hi", 1)<br />
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")<br />
</syntaxhighlight><br />
<br />
==setMainWindowSize==<br />
;setMainWindowSize(mainWidth, mainHeight)<br />
: Changes the size of your main Mudlet window to the values given.<br />
: See Also: [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''mainWidth:''<br />
: The new width in pixels.<br />
* ''mainHeight:''<br />
: The new height in pixels.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will resize your main Mudlet window<br />
setMainWindowSize(1024, 768)<br />
</syntaxhighlight><br />
<br />
==setMapWindowTitle==<br />
;setMapWindowTitle(text)<br />
: Changes the title shown in the mapper window when it's popped out.<br />
: See also: [[#resetMapWindowTitle|resetMapWindowTitle()]]<br />
<br />
; Parameters<br />
* ''text:''<br />
: New window title to set.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapWindowTitle("my cool game map")<br />
</syntaxhighlight><br />
<br />
==setMiniConsoleFontSize==<br />
;setMiniConsoleFontSize(name, fontSize)<br />
: Sets the font size of the mini console. see also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]]<br />
<br />
==setOverline==<br />
;setOverline([windowName], boolean)<br />
: Sets the current text font to be overlined (true) or not overlined (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 overlined. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be overlined until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be overlined or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables overlining of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable overlined text<br />
setOverline(true)<br />
-- the following echo will be have an overline<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and reverse have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==setPopup==<br />
;setPopup(windowName, {lua code}, {hints})<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,<br />
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking<br />
-- will show some commands you can do.<br />
<br />
selectString("Hello", 1)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})<br />
</syntaxhighlight><br />
<br />
==setProfileStyleSheet==<br />
;setProfileStyleSheet(stylesheet)<br />
: Sets a stylesheet for the current Mudlet profile - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). This function is better than setAppStyleSheet() because it affects only the current profile and not every other one as well.<br />
<br />
: See also: [[#setAppStyleSheet|setAppStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use. See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setProfileStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
<br />
QTreeView {<br />
background: ]]..background_color..[[;<br />
color: white;<br />
}<br />
<br />
QMenuBar{ background-color: ]]..background_color..[[;}<br />
<br />
QMenuBar::item{ background-color: ]]..background_color..[[;}<br />
<br />
QDockWidget::title {<br />
background: ]]..border_color..[[;<br />
}<br />
QStatusBar {<br />
background: ]]..border_color..[[;<br />
}<br />
QScrollBar:vertical {<br />
background: ]]..background_color..[[;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background-color: ]]..background_color..[[;<br />
min-height: 20px;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 7px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-bottom-left-radius: 7px;<br />
border-bottom-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-top-left-radius: 7px;<br />
border-top-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
background: white;<br />
width: 4px;<br />
height: 3px;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]])<br />
<br />
-- if you'd like to reset it, use:<br />
setProfileStyleSheet("")<br />
<br />
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':<br />
setProfileStyleSheet[[<br />
TConsole QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
TConsole QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
TConsole QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 4.6.<br />
<br />
==setReverse==<br />
;setReverse([windowName], boolean)<br />
: Sets the current text to swap foreground and background color settings (true) or not (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 have it's colors swapped. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will have their foreground and background colors swapped until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text colors to be reversed or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables reversing of the fore- and back-ground colors of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable fore/back-ground color reversal of text<br />
setReverse(true)<br />
-- the following echo will have the text colors reversed<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and overline have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
{{note}} Although the visual effect on-screen is the same as that of text being selected if both apply to a piece of text they neutralise each other - however the effect of the reversal ''will'' be carried over in copies made by the "Copy to HTML" and in logs made in HTML format log file mode.<br />
<br />
==setStrikeOut==<br />
;setStrikeOut([windowName], boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be striken out until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be stricken out or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables striking out of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable striken-out text<br />
setStrikeOut(true)<br />
-- the following echo will be have a strikethrough<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setTextFormat==<br />
;setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])<br />
: Sets current text format of selected window. This is a more convenient means to set all the individual features at once compared to using [[#setFgColor|setFgColor]]( windowName, r,g,b ), [[#setBold|setBold]]( windowName, true ), [[#setItalics|setItalics]]( windowName, true ), [[#setUnderline|setUnderline]]( windowName, true ), [[#setStrikeOut|setStrikeOut]]( windowName, true ).<br />
: See Also: [[Manual:Lua_Functions#getTextFormat|getTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: Specify name of selected window. If empty string "" or "main" format will be applied to the main console<br />
* ''r1,g1,b1''<br />
: To color text background, give number values in RBG style<br />
* ''r2,g2,b2''<br />
: To color text foreground, give number values in RBG style<br />
* ''bold''<br />
: To format text bold, set to 1 or true, otherwise 0 or false<br />
* ''underline''<br />
: To underline text, set to 1 or true, otherwise 0 or false<br />
* ''italics''<br />
: To format text italic, set to 1 or true, otherwise 0 or false<br />
* ''strikeout<br />
: (optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''overline<br />
: (optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''reverse<br />
: (optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This script would create a mini text console and write with bold, struck-out, yellow foreground color and blue background color "This is a test".<br />
createMiniConsole( "con1", 0,0,300,100);<br />
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);<br />
echo("con1","This is a test")<br />
</syntaxhighlight><br />
<br />
{{note}} In versions prior to 3.7.0 the error messages ''and this wiki'' were wrong in that they had the foreground color parameters as r1, g1 and b1 and the background ones as r2, g2 and b2.<br />
<br />
==setUnderline==<br />
;setUnderline(windowName, bool)<br />
: Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setUserWindowTitle==<br />
;setUserWindowTitle(windowName, text)<br />
: sets a new title text for the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''text''<br />
: new title text<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==setUserWindowStyleSheet==<br />
;setUserWindowStyleSheet(windowName, markup)<br />
: Applies Qt style formatting to the border/title area of a userwindow via a special markup language.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when you dock the userwindow the border style is not provided by this<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- changes the title area style of the UserWindow 'myUserWindow'<br />
setUserWindowStyleSheet("myUserWindow", [[QDockWidget::title{ <br />
background-color: rgb(0,255,150);<br />
border: 2px solid red;<br />
border-radius: 8px;<br />
text-align: center; <br />
}]])<br />
</syntaxhighlight><br />
<br />
: See also: [[#openUserWindow|openUserWindow()]]<br />
<br />
==setWindow==<br />
;setWindow(windowName, name, [Xpos, Ypos, show])<br />
: Changes the parent window of an element.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow which you want the element put in. If you want to put the element into the main window, use windowName "main".<br />
* ''name''<br />
: Name of the element which you want to switch the parent from. Elements can be labels, miniconsoles and the embedded mapper. If you want to move the mapper use the name "mapper"<br />
* ''Xpos:''<br />
: X position of the element. Measured in pixels, with 0 being the very left. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''Ypos:''<br />
: Y position of the element. Measured in pixels, with 0 being the very top. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''show:''<br />
: true or false to decide if the element will be shown or not in the new parent window. Optional, if not given it will be true.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindow("myuserwindow", "mapper")<br />
-- This will put your embedded mapper in your userwindow "myuserwindow".<br />
</syntaxhighlight><br />
<br />
==setWindowWrap==<br />
;setWindowWrap(windowName, wrapAt)<br />
: sets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapAt:''<br />
: Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==setWindowWrapIndent==<br />
;setWindowWrapIndent(windowName, wrapTo)<br />
: sets how many spaces wrapped text will be indented with (after the first line of course).<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapTo:''<br />
: Number of spaces which wrapped lines are prefixed with.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
setWindowWrapIndent("main", 3)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==showCaptureGroups==<br />
;showCaptureGroups()<br />
:Lua debug function that highlights in random colors 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.<br />
<br />
;Example:<br />
: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.<br />
<br />
==showMultimatches==<br />
;showMultimatches()<br />
: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.<br />
<br />
==showWindow==<br />
;showWindow(name)<br />
: Makes a hidden window (label or miniconsole) be shown again.<br />
<br />
: See also: [[#hideWindow | hideWindow()]]<br />
<br />
==showColors==<br />
;showColors([columns], [filterColor], [sort])<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in '''color_table''', in table form. The format is ''color_table.colorName = {r, g, b}''.<br />
<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: (optional) number of columns to print the color table in.<br />
* ''filterColor:''<br />
: (optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.<br />
* ''sort:''<br />
: (optional) sort colors alphabetically.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- display as four columns:<br />
showColors(4)<br />
<br />
-- show only red colours:<br />
showColors("red")<br />
</syntaxhighlight><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)|thumb|center]]<br />
<br />
==showToolBar==<br />
;showToolBar(name)<br />
: Makes a toolbar (a button group) appear on the screen.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
showToolBar("my attack buttons")<br />
</syntaxhighlight><br />
<br />
==suffix==<br />
;suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
: Suffixes text at the end of the current line. This is similar to [[Manual:Lua_Functions#echo | echo()]], which also suffixes text at the end of the line, but different - [[Manual:Lua_Functions#echo | 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.<br />
<br />
;Parameters<br />
* ''text''<br />
: the information you want to prefix<br />
* ''writingFunction''<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* ''foregroundColor''<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* ''backgroundColor''<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* ''windowName''<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
<br />
: See also: [[#prefix | prefix()]], [[Manual:Lua_Functions#echo | echo()]]<br />
<br />
==wrapLine==<br />
;wrapLine(windowName, lineNumber)<br />
: 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.:<br />
<br />
<syntaxhighlight lang="lua">selectString(line,1)<br />
replace("")</syntaxhighlight><br />
<br />
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.<br />
<br />
: See Also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#deleteLine|deleteLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The miniconsole or the main window (use ''main'' for the main window)<br />
* ''lineNumber:''<br />
: The line number which you'd like re-wrapped.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- re-wrap the last line in the main window<br />
wrapLine("main", getLineCount())<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15729Mapping script2020-11-04T11:12:09Z<p>Smurf: /* Labelling rooms */ simplify algorithm for staggered name placement</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
=== Labelling rooms ===<br />
<br />
Rooms have three attributes which you can show on the map:<br />
* an ID. You can't change it; the ID is shown in the room's box when you check "IDs" in the dialog below the map and you're zoomed in far enough.<br />
* a symbol, also displayed in the room's box. You set it with the [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomChar ''setRoomChar''] Lua function, or via the map's context menu.<br />
* a name, typically sent via GMCP. You add it to the map with [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomName ''setRoomName''].<br />
<br />
The room name can be displayed along with a room's box. Its position defaults to "centered below the room". It is not visible by default because many maps have rooms that are quite close to each other; showing the names by default would create an ugly visual mess.<br />
<br />
If you want to enable room names in your mapper, you need to<br />
* stagger rooms. Four or five units' distance instead of one works best if you want to show every label; less is OK if you only show labels when the user asks you to.<br />
* call ''setMapUserData("room.ui_showName","1")''. The existence of this entry controls whether the "Names" checkbox is shown next to "IDs", below the map. This value is zero if the user has unchecked the "Names" checkbox.<br />
* optionally call ''setMapUserData("room.ui_nameFont","FontName")'' to change the names' font. The default is the same monospaced font used for the room IDs and symbols.<br />
* call ''setRoomUserData(room_id, "room.ui_showName","1")'' to show a room's label. You might want to add an entry to the map's pop-up menu which toggles this.<br />
<br />
If the name is misplaced (collision with another room, label, or whatever), you can modify the room's "room.ui_nameOffset" attribute to move it around. The value of this attribute consists of two floating-point values, separated by a space, which offset the room's label (in units of the room box's size). You might want to bind functions that increase or decrease these values to keys like Shift-Control-Arrow and/or Control-Numpad-2468. A hotkey to toggle a room's label display from "on" to "off" and back (e.g. Control-Numpad-5?) is also a good idea.<br />
<br />
You also might default to staggering room names. One possible algorithm: '''if''' a new room's X coordinate, divided by your default room distance, is an odd number '''then''' position its label with an offset like "0 -1.6", which would place it above the room in question. The optimal value for the Y offset depends on the font.<br />
<br />
Changes are displayed only when the map is next redrawn.<br />
<br />
Font options are global. Overriding them for a single room can be be implemented if requested.<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
If you'd like to use a custom pathfinding algorithm instead of the built-in one, as of Mudlet 4.10 you can do that:<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example package that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15701Mapping script2020-10-24T12:02:37Z<p>Smurf: /* More complex speedwalking and pathfinding */</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
=== Labelling rooms ===<br />
<br />
Rooms have three attributes which you can show on the map:<br />
* an ID. You can't change it; the ID is shown in the room's box when you check "IDs" in the dialog below the map and you're zoomed in far enough.<br />
* a symbol, also displayed in the room's box. You set it with the [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomChar ''setRoomChar''] Lua function, or via the map's context menu.<br />
* a name, typically sent via GMCP. You add it to the map with [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomName ''setRoomName''].<br />
<br />
The room name can be displayed along with a room's box. Its position defaults to "centered below the room". It is not visible by default because many maps have rooms that are quite close to each other; showing the names by default would create an ugly visual mess.<br />
<br />
If you want to enable room names in your mapper, you need to<br />
* stagger rooms. Four or five units' distance instead of one works best if you want to show every label; less is OK if you only show labels when the user asks you to.<br />
* call ''setMapUserData("room.ui_showName","1")''. The existence of this entry controls whether the "Names" checkbox is shown next to "IDs", below the map. This value is zero if the user has unchecked the "Names" checkbox.<br />
* optionally call ''setMapUserData("room.ui_nameFont","FontName")'' to change the names' font. The default is the same monospaced font used for the room IDs and symbols.<br />
* call ''setRoomUserData(room_id, "room.ui_showName","1")'' to show a room's label. You might want to add an entry to the map's pop-up menu which toggles this.<br />
<br />
If the name is misplaced (collision with another room, label, or whatever), you can modify the room's "room.ui_nameOffset" attribute to move it around. The value of this attribute consists of two floating-point values, separated by a space, which offset the room's label (in units of the room box's size). You might want to bind functions that increase or decrease these values to keys like Shift-Control-Arrow and/or Control-Numpad-2468. A hotkey to toggle a room's label display from "on" to "off" and back (e.g. Control-Numpad-5?) is also a good idea.<br />
<br />
You also might default to staggering room names. One possible algorithm: whenever a new room's X coordinate, divided by twice your default room distance, would round up, position its label with an offset like "0 -1.6", which would place it above the room in question. The optimal value for the Y offset depends on the font.<br />
<br />
Changes are displayed only when the map is next redrawn.<br />
<br />
Font options are global. Overriding them for a single room can be be implemented if requested.<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This only applies to the part of the path that's in the same area as the destination.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own find-the-shortest-path algorithm. Fortunately, as of Mudlet 4.10 you can do that:<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example package that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15700Mapping script2020-10-24T12:00:58Z<p>Smurf: /* Labelling rooms */</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
=== Labelling rooms ===<br />
<br />
Rooms have three attributes which you can show on the map:<br />
* an ID. You can't change it; the ID is shown in the room's box when you check "IDs" in the dialog below the map and you're zoomed in far enough.<br />
* a symbol, also displayed in the room's box. You set it with the [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomChar ''setRoomChar''] Lua function, or via the map's context menu.<br />
* a name, typically sent via GMCP. You add it to the map with [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomName ''setRoomName''].<br />
<br />
The room name can be displayed along with a room's box. Its position defaults to "centered below the room". It is not visible by default because many maps have rooms that are quite close to each other; showing the names by default would create an ugly visual mess.<br />
<br />
If you want to enable room names in your mapper, you need to<br />
* stagger rooms. Four or five units' distance instead of one works best if you want to show every label; less is OK if you only show labels when the user asks you to.<br />
* call ''setMapUserData("room.ui_showName","1")''. The existence of this entry controls whether the "Names" checkbox is shown next to "IDs", below the map. This value is zero if the user has unchecked the "Names" checkbox.<br />
* optionally call ''setMapUserData("room.ui_nameFont","FontName")'' to change the names' font. The default is the same monospaced font used for the room IDs and symbols.<br />
* call ''setRoomUserData(room_id, "room.ui_showName","1")'' to show a room's label. You might want to add an entry to the map's pop-up menu which toggles this.<br />
<br />
If the name is misplaced (collision with another room, label, or whatever), you can modify the room's "room.ui_nameOffset" attribute to move it around. The value of this attribute consists of two floating-point values, separated by a space, which offset the room's label (in units of the room box's size). You might want to bind functions that increase or decrease these values to keys like Shift-Control-Arrow and/or Control-Numpad-2468. A hotkey to toggle a room's label display from "on" to "off" and back (e.g. Control-Numpad-5?) is also a good idea.<br />
<br />
You also might default to staggering room names. One possible algorithm: whenever a new room's X coordinate, divided by twice your default room distance, would round up, position its label with an offset like "0 -1.6", which would place it above the room in question. The optimal value for the Y offset depends on the font.<br />
<br />
Changes are displayed only when the map is next redrawn.<br />
<br />
Font options are global. Overriding them for a single room can be be implemented if requested.<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This only applies to the part of the path that's in the same area as the destination.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own shortest-path algorithm. Fortunately, as of Mudlet 4.10 you can do that:<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example package that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15699Mapping script2020-10-24T11:59:25Z<p>Smurf: /* Labelling rooms */</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
=== Labelling rooms ===<br />
<br />
Rooms have three attributes you can display:<br />
* an ID. You can't change it; the ID is shown in the room's box when you check "IDs" in the dialog below the map and you're zoomed in far enough.<br />
* a symbol, also displayed in the room's box. You set it with the [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomChar ''setRoomChar''] Lua function, or via the map's context menu.<br />
* a name, typically sent via GMCP. You add it to the map with [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomName ''setRoomName''].<br />
<br />
The room name can be displayed along with a room's box. Its position defaults to "centered below the room". It is not visible by default because many maps have rooms that are quite close to each other; showing the names by default would create an ugly visual mess.<br />
<br />
If you want to enable room names in your mapper, you need to<br />
* stagger rooms. Four or five units' distance instead of one works best if you want to show every label; less is OK if you only show labels when the user asks you to.<br />
* call ''setMapUserData("room.ui_showName","1")''. The existence of this entry controls whether the "Names" checkbox is shown next to "IDs", below the map. This value is zero if the user has unchecked the "Names" checkbox.<br />
* optionally call ''setMapUserData("room.ui_nameFont","FontName")'' to change the names' font. The default is the same monospaced font used for the room IDs and symbols.<br />
* call ''setRoomUserData(room_id, "room.ui_showName","1")'' to show a room's label. You might want to add an entry to the map's pop-up menu which toggles this.<br />
<br />
If the name is misplaced (collision with another room, label, or whatever), you can modify the room's "room.ui_nameOffset" attribute to move it around. The value of this attribute consists of two floating-point values, separated by a space, which offset the room's label (in units of the room box's size). You might want to bind functions that increase or decrease these values to keys like Shift-Control-Arrow and/or Control-Numpad-2468. A hotkey to toggle a room's label display from "on" to "off" and back (e.g. Control-Numpad-5?) is also a good idea.<br />
<br />
You also might default to staggering room names. One possible algorithm: whenever a new room's X coordinate, divided by twice your default room distance, would round up, position its label with an offset like "0 -1.6", which would place it above the room in question. The optimal value for the Y offset depends on the font.<br />
<br />
Changes are displayed only when the map is next redrawn.<br />
<br />
Font options are global. Overriding them for a single room can be be implemented if requested.<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This only applies to the part of the path that's in the same area as the destination.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own shortest-path algorithm. Fortunately, as of Mudlet 4.10 you can do that:<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example package that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15698Mapping script2020-10-24T11:58:01Z<p>Smurf: /* Labelling rooms */</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
=== Labelling rooms ===<br />
<br />
Rooms have three attributes you can display:<br />
* an ID. You can't change it; the ID is shown in the room's box when you check "IDs" in the dialog below the map and you're zoomed in far enough.<br />
* a symbol, also displayed in the room's box. You set it with the [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomChar ''setRoomChar''] Lua function, or via the map's context menu.<br />
* a name, typically sent via GMCP. You add it to the map with [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomName ''setRoomName''].<br />
<br />
The room name can be displayed along with a room's box. Its position defaults to "centered below the room". It is not visible by default because many maps have rooms that are quite close to each other; showing the names by default would create an ugly visual mess.<br />
<br />
If you want to enable room names in your mapper, you need to<br />
* stagger rooms. Four or five units' distance instead of one works best if you want to show every label; less is OK if you only show labels when the user asks you to.<br />
* call ''setMapUserData("room.ui_showName","1")''. The existence of this entry controls whether the "Names" checkbox is shown next to "IDs", below the map. This value is zero if the user has unchecked the "Names" checkbox.<br />
* optionally call ''setMapUserData("room.ui_nameFont","FontName") to change the names' font. The default is the same monospaced font used for the room IDs and symbols.<br />
* call ''setRoomUserData(room_id, "room.ui_showName","1")'' to show a room's label. You might want to add an entry to the map's pop-up menu which toggles this.<br />
<br />
If the name is misplaced (collision with another room, label, or whatever), you can modify the room's "room.ui_nameOffset" attribute to move it around. The value of this attribute consists of two floating-point values, separated by a space, which offset the room's label (in units of the room box's size). You might want to bind functions that increase or decrease these values to keys like Shift-Control-Arrow and/or Control-Numpad-2468. A hotkey to toggle a room's label display from "on" to "off" and back (e.g. Control-Numpad-5?) is also a good idea.<br />
<br />
You also might default to staggering room names. One possible algorithm: whenever a new room's X coordinate, divided by twice your default room distance, would round up, position its label with an offset like "0 -1.6", which would place it above the room in question. The optimal value for the Y offset depends on the font.<br />
<br />
Changes are displayed only when the map is next redrawn.<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This only applies to the part of the path that's in the same area as the destination.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own shortest-path algorithm. Fortunately, as of Mudlet 4.10 you can do that:<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example package that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15697Mapping script2020-10-23T14:36:17Z<p>Smurf: Labelling rooms</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
=== Labelling rooms ===<br />
<br />
Rooms have three attributes you can display:<br />
* an ID. You can't change it; the ID is shown in the room's box when you check "IDs" in the dialog below the map and you're zoomed in far enough.<br />
* a symbol, also displayed in the room's box. You set it with the [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomChar ''setRoomChar''] Lua function, or via the map's context menu.<br />
* a name, typically sent via GMCP. You add it to the map with [https://wiki.mudlet.org/w/Manual:Lua_Functions#setRoomName ''setRoomName''].<br />
<br />
The room name can be displayed along with a room's box. Its position defaults to "centered below the room". It is not visible by default because many maps have rooms that are quite close to each other; showing the names by default would create an ugly visual mess.<br />
<br />
If you want to enable room names in your mapper, you need to<br />
* stagger rooms. Four or five units' distance instead of one works best if you want to show every label; less is OK if you only show labels when the user asks you to.<br />
* call ''setMapUserData("room.ui_showName","1"). The existence of this entry controls whether the "Names" checkbox is shown next to "IDs", below the map.<br />
* optionally call ''setMapUserData("room.ui_nameFont","FontName") to change the names' font. The default is the same monospaced font used for the room IDs and symbols.<br />
* call ''setRoomUserData(room_id, "room.ui_showName","1")'' to actually show this room's label. You might want to add an entry to the map's pop-up menu which toggles this.<br />
<br />
If the name is misplaced (collision with another room, label, or whatever), you can modify the room's "room.ui_nameOffset" attribute to move it around. The value of this attribute consists of two floating-point values, separated by a space, which offset the room's label (in units of the room box's size). You might want to bind functions that increase or decrease this to keys like Shift-Control-Arrow keys and/or Control-Numpad-2468. (As of Mudlet 4.9, binding to Control+Arrows doesn't work correctly.) A hotkey to toggle a room's label display from "on" to "off" and back (Control-Numpad-5?) is also a good idea.<br />
<br />
You also might default to staggering room names. One possible algorithm: whenever the room's X coordinate, divided by twice your default room distance, would round up, position newly-created labels with an offset of "0 -1.6" which would place it above the room in question. The optimal value for the Y offset depends on the font.<br />
<br />
Changes are displayed only when the map is next redrawn.<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This only applies to the part of the path that's in the same area as the destination.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own shortest-path algorithm. Fortunately, as of Mudlet 4.10 you can do that:<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example package that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15696Mapping script2020-10-22T02:45:26Z<p>Smurf: /* More complex speedwalking and pathfinding */</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This only applies to the part of the path that's in the same area as the destination.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own shortest-path algorithm. Fortunately, as of Mudlet 4.10 you can do that:<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example package that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15695Mapping script2020-10-22T02:43:13Z<p>Smurf: /* More complex speedwalking and pathfinding */</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This only applies to the part of the path that's in the same area as the destination.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own shortest-path algorithm. Fortunately, as of Mudlet 4.10 this is possible.<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example script that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15694Mapping script2020-10-22T02:42:47Z<p>Smurf: /* More complex speedwalking and pathfinding */</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This limit only applies to the part of the path that's in the same area as the destination.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own shortest-path algorithm. Fortunately, as of Mudlet 4.10 this is possible.<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example script that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15693Mapping script2020-10-22T02:41:08Z<p>Smurf: /* More complex speedwalking and pathfinding */ link fixed</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This limit is not as much of problem when you cross area boundaries.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own shortest-path algorithm. Fortunately, as of Mudlet 4.10 this is possible.<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930 Wayfinder] contains an example script that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Mapping_script&diff=15692Mapping script2020-10-22T02:01:13Z<p>Smurf: /* Making your own mapping script */ custom speedwalking</p>
<hr />
<div>Mudlet's mapper is split into two parts for the best compatibility on all MUDs - the display and functions in Mudlet, and a per-MUD Lua script that tracks where you are, allows mapping and provides aliases for using the mapper.<br />
<br />
= Existing mapping scripts =<br />
Pre-made mapping scripts are available from [http://forums.mudlet.org/search.php?keywords=mapping+script&terms=all&author=&sc=1&sf=titleonly&sr=topics&sk=t&sd=d&st=0&ch=400&t=0&submit=Search Mudlet forums] - all topics that have the '''(mapping script)''' prefix on them.<br />
<br />
= Making your own mapping script =<br />
<br />
If you'd like to code your own mapping script, see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API]] and read on for a short tutorial.<br />
<br />
To start off, create a new script that'll be included with your mapping script (can even place it into the script folder for your mapping script), and have it do:<br />
<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
This'll let Mudlet know that a mapping script is installed, so it won't bother you or whoever else installs your script with a warning that one is necessary.<br />
<br />
Next, you want to hook into Mudlet's gotoRoom(id) function and the user clicking on a room in the visual map - for that, define your own ''doSpeedWalk()'' function. Mudlet will store the directions / special exits commands your script will need to take in the ''speedWalkDir'' table, and the room IDs you'll pass through in the ''speedWalkPath'' table:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Path we need to take: " .. table.concat(speedWalkDir, ", ") .. "\n")<br />
echo("Rooms we'll pass through: " .. table.concat(speedWalkPath, ", ") .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
''speedWalkPath'' is especially useful for making sure you're still on the path. Most Mudlet mapping scripts keep track of how many rooms along the path they have visited so far and check upon arrival into a new room to make sure it's still on the path.<br />
<br />
That's it! (But see below if you want more.)<br />
<br />
From here, you'd want to build a walking script that'll send the commands to walk you along the path, along with aliases for the user to use - see the [[Manual:Lua_Functions#Mapper_Functions|Mapper API functions]] and [[Manual:Event_Engine#Mudlet-raised_events|Mudlet mapper events]].<br />
<br />
== Adding rooms ==<br />
To make your first room, do the following steps:<br />
<br />
* create an area with setAreaName(areaID, areaname). You can choose any areaID - if you'd like to use the IDs incrementally, see which is the latest from getAreaTable()<br />
* if you want the Mudlet mapper to generate roomIDs for you, get one with createRoomID(). This is an optional step<br />
* create your room with addRoom(roomID)<br />
* give the room coordinates with setRoomCoordinates(roomID, x, y, z). If you're just starting out, put it at 0,0,0 so the room is at the center of the map<br />
* assign your room to an area with setRoomArea(roomID, areaID)<br />
* and finally, call centerview(roomID) to make the map view refresh and show your new room!<br />
<br />
== Working with the mapper API ==<br />
Whenever working with mapper API, keep in mind of the following things:<br />
<br />
* you'll want to call centerview after you do some modifications, to get to have the map render your new changes<br />
<br />
== Translating directions ==<br />
Several functions in the mapper API take and return #'s for directions - and to make it easier to work with them, you can define a table that maps directions to those numbers in a script with the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12,<br />
[1] = "north",<br />
[2] = "northeast",<br />
[3] = "northwest",<br />
[4] = "east",<br />
[5] = "west",<br />
[6] = "south",<br />
[7] = "southeast",<br />
[8] = "southwest",<br />
[9] = "up",<br />
[10] = "down",<br />
[11] = "in",<br />
[12] = "out",<br />
}<br />
</syntaxhighlight><br />
<br />
Then, using exitmap[input], you'll get a direction number or a direction name. Here's an example that uses it to work out in which directions are the exit stubs available in room 6:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(exitmap[stubs[i]]) end<br />
</syntaxhighlight><br />
<br />
= More complex speedwalking and pathfinding =<br />
<br />
The built-in path finder has some limitations you need to be aware of.<br />
<br />
* It can't find ways that aren't linked with exits in the map (how do you map rooms with semi-random destinations?)<br />
* It can't take special conditions into account (what if the generated path goes through a cave and you're out of lamp oil? The path to the healer goes over the mountain but your CON is depleted which is why you need the healer in the first place?)<br />
* It only finds a single unique room (what if you need the closest inn?)<br />
* It can't give you a list of the five closest shops, to pick among them.<br />
* Within a single area, it walks "towards" the destination, i.e. it walks 100 paces north to go to the destination instead of five south to the teleport / dragon / flying horse that'd take you there directly. (This limit is not as much of problem when you cross area boundaries.)<br />
* It won't generate a list of "how to go from A to B" commands if you're not in A.<br />
<br />
If you want any of this, you need to write your own shortest-path algorithm. Fortunately, as of Mudlet 4.10 this is possible.<br />
<br />
* Set ''mudlet.custom_speedwalk = true''.<br />
* Your ''doSpeedwalk'' script will now see different parameters:<br />
<br />
<syntaxhighlight lang="lua"><br />
function doSpeedWalk()<br />
echo("Room we're coming from: " .. speedWalkFrom .. "\n")<br />
echo("Room you're going to: " .. speedWalkTo .. "\n")<br />
end<br />
</syntaxhighlight><br />
<br />
The forum topic [Wayfinder|https://forums.mudlet.org/viewtopic.php?f=6&t=22930&p=45930#p45930] contains an example script that implements a shortest-path-first algorithm.<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mudlet_Object_Functions&diff=15682Manual:Mudlet Object Functions2020-10-15T10:29:53Z<p>Smurf: /* tempAnsiColorTrigger */</p>
<hr />
<div>{{TOC right}}<br />
= Mudlet Object Functions =<br />
<br />
==adjustStopWatch==<br />
;adjustStopWatch(watchID/watchName, amount)<br />
: Adjusts the elapsed time on the stopwatch forward or backwards by the amount of time. It will work even on stopwatches that are not running, and thus can be used to preset a newly created stopwatch with a negative amount so that it runs down from a negative time towards zero at the preset time.<br />
<br />
;Parameters<br />
* watchID (number) / watchName (string): The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
* amount (decimal number): An amount in seconds to adjust the stopwatch by, positive amounts increase the recorded elapsed time.<br />
<br />
;Returns<br />
* true on success if the stopwatch was found and thus adjusted, or nil and an error message if not.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- demo of a persistent stopWatch used to real time a mission<br />
-- called with a positive number of seconds it will start a "missionStopWatch"<br />
-- unless there already is one in which case it will instead report on<br />
-- the deadline. use 'stopStopWatch("missionStopWatch")' when the mission<br />
-- is done and 'deleteStopWatch("missionStopWatch")' when the existing mission<br />
-- is to be disposed of. Until then repeated use of 'mission(interval)' will<br />
-- just give updates...<br />
function mission(time)<br />
local missionTimeTable = missionTimeTable or {}<br />
<br />
if createStopWatch("missionStopWatch") then<br />
adjustStopWatch("missionStopWatch", -tonumber(time))<br />
setStopWatchPersistence("missionStopWatch", true)<br />
missionTimeTable = getStopWatchBrokenDownTime("missionStopWatch")<br />
<br />
echo(string.format("Get cracking, you have %02i:%02i:%02i hg:m:s left.\n", missionTimeTable.hours, missionTimeTable.minutes, missionTimeTable.seconds))<br />
startStopWatch("missionStopWatch")<br />
else<br />
-- it already exists, so instead report what is/was the time on it<br />
--[=[ We know that the stop watch exists - we just need to find the ID<br />
so we can get the running detail which is only available from the getStopWatches()<br />
table and that is indexed by ID]=]<br />
for k,v in pairs(getStopWatches()) do<br />
if v.name == "missionStopWatch" then<br />
missionTimeTable = v<br />
end<br />
end<br />
if missionTimeTable.isRunning then<br />
if missionTimeTable.elapsedTime.negative then<br />
echo(string.format("Better hurry up, the clock is ticking on an existing mission and you only have %02i:%02i:%02i h:m:s left.\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
else<br />
echo(string.format("Bad news, you are past the deadline on an existing mission by %02i:%02i:%02i h:m:s !\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
end<br />
else<br />
if missionTimeTable.elapsedTime.negative then<br />
echo(string.format("Well done! You have already completed a mission %02i:%02i:%02i h:m:s before the deadline ...\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
else<br />
echo(string.format("Uh oh! You failed to meet the deadline on an existing mission by %02i:%02i:%02i h:m:s !\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
end<br />
end<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available from Mudlet 4.4.0<br />
<br />
==appendScript==<br />
;appendScript(scriptName, luaCode, [occurrence])<br />
: Appends Lua code to the script "scriptName". If no occurrence given it sets the code of the first found script.<br />
<br />
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#getScript|getScript()]], [[Manual:Lua_Functions#setScript|setScript()]]<br />
<br />
;Returns<br />
* a unique id number for that script.<br />
<br />
;Parameters<br />
* ''scriptName'': name of the script<br />
* ''luaCode'': scripts luaCode to append<br />
* ''occurence'': (optional) the occurrence of the script in case you have many with the same name<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example of appending the script lua code to the first occurrence of "testscript"<br />
appendScript("testscript", [[echo("This is a test\n")]], 1)<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==appendCmdLine==<br />
;appendCmdLine([name], text)<br />
: Appends text to the main input line.<br />
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, the text will be appended to the main commandline.<br />
* ''text'': text to append<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- adds the text "55 backpacks" to whatever is currently in the input line<br />
appendCmdLine("55 backpacks")<br />
<br />
-- makes a link, that when clicked, will add "55 backpacks" to the input line<br />
echoLink("press me", "appendCmdLine'55 backpack'", "Press me!")<br />
<br />
<br />
-- in use:<br />
lua mission(60*60)<br />
Get cracking, you have 01:00:00 h:m:s left.<br />
<br />
lua mission(60*60)<br />
Better hurry up, the clock is ticking on an existing mission and you only have 00:59:52 h:m:s left.<br />
</syntaxhighlight><br />
<br />
==clearCmdLine==<br />
;clearCmdLine([name])<br />
: Clears the input line of any text that's been entered.<br />
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, the main commandline's text will be cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- don't be evil with this!<br />
clearCmdLine()<br />
</syntaxhighlight><br />
<br />
==createStopWatch==<br />
;createStopWatch()<br />
From Mudlet 4.4.0:<br />
;createStopWatch([start immediately {assumed ''true'' if omitted}])<br />
;createStopWatch([name], [start immediately {assumed ''false'' if omitted}])<br />
<br />
: This function creates a stopwatch, a high resolution time measurement tool. Stopwatches can be started, stopped, reset, asked how much time has passed since the stop watch has been started and, following an update for Mudlet 4.4.0: be adjusted, given a name and be made persistent between sessions (so can time real-life things). Prior to 4.4.0 the function took no parameters '''and the stopwatch would start automatically when it was created'''.<br />
<br />
;Parameters:<br />
* ''start immediately'' (bool) used to override the behaviour prior to Mudlet 4.4.0 so that if it is the ''only'' argument then a ''false'' value will cause the stopwatch to be created but be in a ''stopped'' state, however if a name parameter is provided then this behaviour is assumed and then a ''true'' value is required should it be desired for the stopwatch to be started on creation. This difference between the cases with and without a name argument is to allow for older scripts to continue to work with 4.4.0 or later versions of Mudlet without change, yet to allow for more functionality - such as presetting a time when the stopwatch is created but not to start it counting down until some time afterwards - to be performed as well with a named stopwatch.<br />
<br />
* ''name'' (string) a ''unique'' text to use to identify the stopwatch.<br />
<br />
;Returns:<br />
* the ID (number) of a stopwatch; or, from '''4.4.0''': a nil + error message if the name has already been used.<br />
<br />
: See also: [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#resetStopWatch|resetStopWatch()]], [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]] or, from 4.4.0: [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatches|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]], [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]], [[Manual:Lua_Functions#setStopWatchPersistence|setStopWatchPersistence()]]<br />
<br />
;Example<br />
: (Prior to Mudlet 4.4.0) in a global script you can create all stop watches that you need in your system and store the respective stopWatch-IDs in global variables:<br />
<syntaxhighlight lang="lua"><br />
fightStopWatch = fightStopWatch or createStopWatch() -- create, or re-use a stopwatch, and store the watchID in a global variable to access it from anywhere<br />
<br />
-- then you can start the stop watch in some trigger/alias/script with:<br />
startStopWatch(fightStopWatch)<br />
<br />
-- to stop the watch and measure its time in e.g. a trigger script you can write:<br />
fightTime = stopStopWatch(fightStopWatch)<br />
echo("The fight lasted for " .. fightTime .. " seconds.")<br />
resetStopWatch(fightStopWatch)<br />
</syntaxhighlight><br />
<br />
: (From Mudlet 4.4.0) in a global script you can create all stop watches that you need in your system with unique names:<br />
<syntaxhighlight lang="lua"><br />
createStopWatch("fightStopWatch") -- this will fail if the given named stopwatch already exists so it will create it if needed<br />
<br />
-- then you can start the stop watch (if it is not already started) in some trigger/alias/script with:<br />
startStopWatch("fightStopWatch")<br />
<br />
-- to stop the watch and measure its time in e.g. a trigger script you can write:<br />
fightTime = stopStopWatch("fightStopWatch")<br />
echo("The fight lasted for " .. fightTime .. " seconds.")<br />
resetStopWatch("fightStopWatch")<br />
</syntaxhighlight><br />
<br />
:You can also measure the elapsed time without having to stop the stop watch (equivalent to getting a ''lap-time'') with [[#getStopWatchTime|getStopWatchTime()]].<br />
<br />
{{note}} it's best to re-use stopwatch IDs if you can for Mudlet prior to 4.4.0 as they cannot be deleted, so creating more and more would use more memory. From 4.4.0 the revised internal design has been changed such that there are no internal timers created for each stopwatch - instead either a timestamp or a fixed elapsed time record is used depending on whether the stopwatches is running or stopped so that there are no "moving parts" in the later design and less resources are used - and they can be removed if no longer required.<br />
<br />
==deleteStopWatch==<br />
;deleteStopWatch(watchID/watchName)<br />
<br />
: This function removes an existing stopwatch, whether it only exists for this session or is set to be otherwise saved between sessions by using [[Manual:Lua_Functions#setStopWatchPersistence|setStopWatchPersistence()]] with a ''true'' argument. <br />
<br />
;Parameters<br />
* ''watchID'' (number) / ''watchName'' (string): The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
<br />
;Returns:<br />
* ''true'' if the stopwatch was found and thus deleted, or ''nil'' and an error message if not - obviously using it twice with the same argument will fail the second time unless another one with the same name or ID was recreated before the second use. Note that an empty string as a name ''will'' find the lowest ID numbered ''unnamed'' stopwatch and that will then find the next lowest ID number of unnamed ones until there are none left, if used repetitively!<br />
<br />
<syntaxhighlight lang="lua"><br />
lua MyStopWatch = createStopWatch("stopwatch_mine")<br />
true<br />
<br />
lua display(MyStopWatch)<br />
4<br />
<br />
lua deleteStopWatch(MyStopWatch)<br />
true<br />
<br />
lua deleteStopWatch(MyStopWatch)<br />
nil<br />
<br />
"stopwatch with id 4 not found"<br />
<br />
lua deleteStopWatch("stopwatch_mine")<br />
nil<br />
<br />
"stopwatch with name "stopwatch_mine" not found"<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]],<br />
<br />
{{note}} Available from Mudlet version 4.4.0. Stopwatches that are NOT set to be '''persistent''' will be deleted automatically at the end of a session (or if [[Manual:Miscellaneous_Functions#resetProfile|resetProfile()]] is called).<br />
<br />
==disableAlias==<br />
;disableAlias(name)<br />
:Disables/deactivates the alias by its name. If several aliases have this name, they'll all be disabled. If you disable an alias group, all the aliases inside the group will be disabled as well.<br />
: See also: [[#enableAlias|enableAlias()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the alias. Passed as a string.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
--Disables the alias called 'my alias'<br />
disableAlias("my alias")<br />
</syntaxhighlight><br />
<br />
==disableKey==<br />
;disableKey(name)<br />
:Disables key a key (macro) or a key group. When you disable a key group, all keys within the group will be implicitly disabled as well.<br />
<br />
: See also: [[#enableKey|enableKey()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the key or group to identify what you'd like to disable.<br />
<br />
;Examples<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you could set multiple keys on the F1 key and swap their use as you wish by disabling and enabling them<br />
disableKey("attack macro")<br />
disableKey("jump macro")<br />
enableKey("greet macro")<br />
</syntaxhighlight><br />
{{note}} From Version '''3.10'' returns ''true'' if one or more keys or groups of keys were found that matched the name given or ''false'' if not; prior to then it returns ''true'' if there were '''any''' keys - whether they matched the name or not!<br />
<br />
==disableScript==<br />
;disableScript(name)<br />
:Disables a script that was previously enabled. Note that disabling a script only stops it from running in the future - it won't "undo" anything the script has made, such as labels on the screen.<br />
<br />
: See also: [[#permScript|permScript()]], [[#appendScript|appendScript()]], [[#enableScript|enableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]<br />
<br />
;Parameters<br />
* ''name'': name of the script.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Disables the script called 'my script'<br />
disableScript("my script")<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==disableTimer==<br />
;disableTimer(name)<br />
:Disables a timer from running it’s script when it fires - so the timer cycles will still be happening, just no action on them. If you’d like to permanently delete it, use [[Manual:Lua_Functions#killTrigger|killTrigger]] instead.<br />
<br />
: See also: [[#enableTimer|enableTimer()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Disables the timer called 'my timer'<br />
disableTimer("my timer")<br />
</syntaxhighlight><br />
<br />
==disableTrigger==<br />
;disableTrigger(name)<br />
:Disables a permanent (one in the trigger editor) or a temporary trigger. When you disable a group, all triggers inside the group are disabled as well<br />
<br />
: See also: [[#enableTrigger|enableTrigger()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Disables the trigger called 'my trigger'<br />
disableTrigger("my trigger")<br />
</syntaxhighlight><br />
<br />
==enableAlias==<br />
;enableAlias(name)<br />
:Enables/activates the alias by it’s name. If several aliases have this name, they’ll all be enabled.<br />
<br />
: See also: [[#disableAlias|disableAlias()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the alias ID that was returned by [[Manual:Lua_Functions#tempAlias|tempAlias]] on creation of the alias or the name of the alias in case of a GUI alias.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Enables the alias called 'my alias'<br />
enableAlias("my alias")<br />
</syntaxhighlight><br />
<br />
==enableKey==<br />
;enableKey(name)<br />
:Enables a key (macro) or a group of keys (and thus all keys within it that aren't explicitly deactivated).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the group that identifies the key.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you could use this to disable one key set for the numpad and activate another<br />
disableKey("fighting keys")<br />
enableKey("walking keys")<br />
</syntaxhighlight><br />
{{note}} From Version '''3.10'' returns ''true'' if one or more keys or groups of keys were found that matched the name given or ''false'' if not; prior to then it returns ''true'' if there were '''any''' keys - whether they matched the name or not!<br />
<br />
==enableScript==<br />
;enableScript(name)<br />
:Enables / activates a script that was previously disabled. <br />
<br />
: See also: [[#permScript|permScript()]], [[#appendScript|appendScript()]], [[#disableScript|disableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]<br />
<br />
;Parameters<br />
* ''name'': name of the script.<br />
<syntaxhighlight lang="lua"><br />
-- enable the script called 'my script' that you created in Mudlet's script section<br />
enableScript("my script")<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==enableTimer==<br />
;enableTimer(name)<br />
:Enables or activates a timer that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<syntaxhighlight lang="lua"><br />
-- enable the timer called 'my timer' that you created in Mudlets timers section<br />
enableTimer("my timer")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- or disable & enable a tempTimer you've made<br />
timerID = tempTimer(10, [[echo("hi!")]])<br />
<br />
-- it won't go off now<br />
disableTimer(timerID)<br />
-- it will continue going off again<br />
enableTimer(timerID)<br />
</syntaxhighlight><br />
<br />
==enableTrigger==<br />
;enableTrigger(name)<br />
:Enables or activates a trigger that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or by any other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.<br />
<syntaxhighlight lang="lua"><br />
-- enable the trigger called 'my trigger' that you created in Mudlets triggers section<br />
enableTrigger("my trigger")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- or disable & enable a tempTrigger you've made<br />
triggerID = tempTrigger("some text that will match in a line", [[echo("hi!")]])<br />
<br />
-- it won't go off now when a line with matching text comes by<br />
disableTrigger(triggerID)<br />
<br />
-- and now it will continue going off again<br />
enableTrigger(triggerID)<br />
</syntaxhighlight><br />
<br />
==exists==<br />
;exists(name, type)<br />
:Tells you how many things of the given type exist. <br />
<br />
{{note}} This function is only for objects created in the script editor or via perm* functions. You don't need it for temp* functions and will not work for them.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by the temp* function to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', 'timer', 'keybind' (Mudlet 3.2+), or 'script' (Mudlet 3.17+).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo("I have " .. exists("my trigger", "trigger") .. " triggers called 'my trigger'!")<br />
</syntaxhighlight><br />
<br />
: You can also use this alias to avoid creating duplicate things, for example:<br />
<syntaxhighlight lang="lua"><br />
-- this code doesn't check if an alias already exists and will keep creating new aliases<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
<br />
-- while this code will make sure that such an alias doesn't exist first<br />
-- we do == 0 instead of 'not exists' because 0 is considered true in Lua<br />
if exists("Attack", "alias") == 0 then<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
end<br />
</syntaxhighlight><br />
<br />
: Especially helpful when working with [[Manual:Lua_Functions#permTimer|permTimer]]:<br />
<syntaxhighlight lang="lua"><br />
if not exists("My animation timer", "timer") then<br />
vdragtimer = permTimer("My animation timer", "", .016, onVDragTimer) -- 60fps timer!<br />
end<br />
<br />
enableTimer("My animation timer")<br />
</syntaxhighlight><br />
<br />
==getButtonState==<br />
;getButtonState()<br />
:This function can be used within checkbox button scripts (2-state buttons) to determine the current state of the checkbox.<br />
<br />
:Returns ''2'' if button is checked, and ''1'' if it's not.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local checked = getButtonState()<br />
if checked == 1 then<br />
hideExits()<br />
else<br />
showExits()<br />
end<br />
</syntaxhighlight><br />
<br />
==getCmdLine==<br />
;getCmdLine([name])<br />
: Returns the current content of the given command line.<br />
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, it returns the text of the main commandline.<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replaces whatever is currently in the input line by "55 backpacks"<br />
printCmdLine("55 backpacks")<br />
<br />
--prints the text "55 backpacks" to the main console<br />
echo(getCmdLine())<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.1+<br />
<br />
==getStopWatches==<br />
;table = getStopWatches()<br />
<br />
: Returns a table of the details for each stopwatch in existence, the keys are the watch IDs but since there can be gaps in the ID number allocated for the stopwatches it will be necessary to use the ''pairs(...)'' rather than the ''ipairs(...)'' method to iterate through all of them in ''for'' loops!<br />
: Each stopwatch's details will list the following items: ''name'' (string), ''isRunning'' (boolean), ''isPersistent'' (boolean), ''elapsedTime'' (table). The last of these contains the same data as is returned by the results table from the [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]] function - namely ''days'' (positive integer), ''hours'' (integer, 0 to 23), ''minutes'' (integer, 0 to 59), ''second'' (integer, 0 to 59), ''milliSeconds'' (integer, 0 to 999), ''negative'' (boolean) with an additional ''decimalSeconds'' (number of seconds, with a decimal portion for the milli-seconds and possibly a negative sign, representing the whole elapsed time recorded on the stopwatch) - as would also be returned by the [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]] function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- on the command line:<br />
lua getStopWatches()<br />
-- could return something like:<br />
{<br />
{<br />
isPersistent = true,<br />
elapsedTime = {<br />
minutes = 15,<br />
seconds = 2,<br />
negative = false,<br />
milliSeconds = 66,<br />
hours = 0,<br />
days = 18,<br />
decimalSeconds = 1556102.066<br />
},<br />
name = "Playing time",<br />
isRunning = true<br />
},<br />
{<br />
isPersistent = true,<br />
elapsedTime = {<br />
minutes = 47,<br />
seconds = 1,<br />
negative = true,<br />
milliSeconds = 657,<br />
hours = 23,<br />
days = 2,<br />
decimalSeconds = -258421.657<br />
},<br />
name = "TMC Vote",<br />
isRunning = true<br />
},<br />
{<br />
isPersistent = false,<br />
elapsedTime = {<br />
minutes = 26,<br />
seconds = 36,<br />
negative = false,<br />
milliSeconds = 899,<br />
hours = 3,<br />
days = 0,<br />
decimalSeconds = 12396.899<br />
},<br />
name = "",<br />
isRunning = false<br />
},<br />
[5] = {<br />
isPersistent = false,<br />
elapsedTime = {<br />
minutes = 0,<br />
seconds = 38,<br />
negative = false,<br />
milliSeconds = 763,<br />
hours = 0,<br />
days = 0,<br />
decimalSeconds = 38.763<br />
},<br />
name = "",<br />
isRunning = true<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available from Mudlet 4.4.0 only.<br />
<br />
==getStopWatchTime==<br />
;time = getStopWatchTime(watchID [or watchName from Mudlet 4.4.0])<br />
: Returns the time as a decimal number of seconds with up to three decimal places to give a milli-seconds (thousandths of a second) resolution.<br />
: Please note that, prior to 4.4.0 it was not possible to retrieve the elapsed time after the stopwatch had been stopped, retrieving the time was not possible as the returned value then was an indeterminate, meaningless time; from the 4.4.0 release, however, the elapsed value can be retrieved at any time, even if the stopwatch has not been started since creation or modified with the [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]] function introduced in that release.<br />
<br />
: See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatch es|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]].<br />
<br />
:Returns a number<br />
<br />
;Parameters<br />
* ''watchID''<br />
: The ID number of the watch.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example of showing the time left on the stopwatch<br />
teststopwatch = teststopwatch or createStopWatch()<br />
startStopWatch(teststopwatch)<br />
echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))<br />
tempTimer(1, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])<br />
tempTimer(2, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])<br />
stopStopWatch(teststopwatch)<br />
</syntaxhighlight><br />
<br />
==getStopWatchBrokenDownTime==<br />
; brokenDownTimeTable = getStopWatchBrokenDownTime(watchID or watchName)<br />
: Returns the current stopwatch time, whether the stopwatch is running or is stopped, as a table, broken down into:<br />
* "days" (integer)<br />
* "hours" (integer, 0 to 23)<br />
* "minutes" (integer, 0 to 59)<br />
* "seconds" (integer, 0 to 59)<br />
* "milliSeconds" (integer, 0 to 999)<br />
* "negative" (boolean, true if value is less than zero)<br />
<br />
: See also: [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatch es|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]].<br />
<br />
;Parameters<br />
* ''watchID'' / ''watchName''<br />
: The ID number or the name of the watch.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--an example, showing the presetting of a stopwatch.<br />
<br />
--This will fail if the stopwatch with the given name<br />
-- already exists, but then we can use the existing one:<br />
local watchId = createStopWatch("TopMudSiteVoteStopWatch")<br />
if watchId ~= nil then<br />
-- so we have just created the stopwatch, we want it<br />
-- to be saved for future sessions:<br />
setStopWatchPersistence("TopMudSiteVoteStopWatch", true)<br />
-- and set it to count down the 12 hours until we can<br />
-- revote:<br />
adjustStopWatch("TopMudSiteVoteStopWatch", -60*60*12)<br />
-- and start it running<br />
startStopWatch("TopMudSiteVoteStopWatch")<br />
<br />
openWebPage("http://www.topmudsites.com/vote-wotmud.html")<br />
end<br />
<br />
--[[ now I can check when it is time to vote again, even when<br />
I stop the session and restart later by running the following<br />
from a perm timer - perhaps on a 15 minute interval. Note that<br />
when loaded in a new session the Id it gets is unlikely to be<br />
the same as that when it was created - but that is not a<br />
problem as the name is preserved and, if the timer is running<br />
when the profile is saved at the end of the session then the<br />
elapsed time will continue to increase to reflect the real-life<br />
passage of time:]]<br />
<br />
local voteTimeTable = getStopWatchBrokenDownTime("TopMudSiteVoteStopWatch")<br />
<br />
if voteTimeTable["negative"] then<br />
if voteTimeTable["hours"] == 0 and voteTimeTable["minutes"] < 30 then<br />
echo("Voting for WotMUD on Top Mud Site in " .. voteTimeTable["minutes"] .. " minutes...")<br />
end<br />
else<br />
echo("Oooh, it is " .. voteTimeTable["days"] .. " days, " .. voteTimeTable["hours"] .. " hours and " .. voteTimeTable["minutes"] .. " minutes past the time to Vote on Top Mud Site - doing it now!")<br />
openWebPage("http://www.topmudsites.com/vote-wotmud.html")<br />
resetStopWatch("TopMudSiteVoteStopWatch")<br />
adjustStopWatch("TopMudSiteVoteStopWatch", -60*60*12)<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available from Mudlet 4.7+<br />
<br />
==getScript==<br />
; getScript(scriptName, [occurrence])<br />
: Returns the script with the given name. If you have more than one script with the same name, specify the occurrence to pick a different one. Returns -1 if the script doesn't exist.<br />
<br />
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#setScript|setScript()]], [[Manual:Lua_Functions#appendScript|appendScript()]]<br />
<br />
;Parameters<br />
* ''scriptName'': name of the script.<br />
* ''occurrence'': (optional) occurence of the script in case you have many with the same name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the "New script" on screen<br />
print(getScript("New script"))<br />
<br />
-- an example of returning the script Lua code from the second occurrence of "testscript"<br />
test_script_code = getScript("testscript", 2)<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==invokeFileDialog==<br />
;invokeFileDialog(fileOrFolder, dialogTitle)<br />
:Opens a file chooser dialog, allowing the user to select a file or a folder visually. The function returns the selected path or "" if there was none chosen.<br />
<br />
;Parameters<br />
* ''fileOrFolder:'' ''true'' for file selection, ''false'' for folder selection.<br />
* ''dialogTitle'': what to say in the window title.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function whereisit()<br />
local path = invokeFileDialog(false, "Where should we save the file? Select a folder and click Open")<br />
<br />
if path == "" then return nil else return path end<br />
end<br />
</syntaxhighlight><br />
<br />
==isActive==<br />
;isActive(name, type)<br />
:You can use this function to check if something, or somethings, are active. <br />
:Returns the number of active things - and 0 if none are active. Beware that all numbers are true in Lua, including zero.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by temp* function to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', 'timer', 'keybind' (Mudlet 3.2+), or 'script' (Mudlet 3.17+).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo("I have " .. isActive("my trigger", "trigger") .. " currently active trigger(s) called 'my trigger'!")<br />
</syntaxhighlight><br />
<br />
==isPrompt==<br />
;isPrompt()<br />
:Returns true or false depending on if the line at the cursor position is a prompt. This infallible feature is available for MUDs that supply GA events (to check if yours is one, look to bottom-right of the main window - if it doesn’t say <No GA>, then it supplies them).<br />
<br />
:Example use could be as a Lua function, making closing gates on a prompt real easy.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a trigger pattern with 'Lua function', and this will trigger on every prompt!<br />
return isPrompt()<br />
</syntaxhighlight><br />
<br />
==killAlias==<br />
;killAlias(aliasID)<br />
:Deletes a temporary alias with the given ID.<br />
<br />
;Parameters<br />
* ''aliasID:''<br />
: The id returned by [[Manual:Lua_Functions#tempAlias|tempAlias]] to identify the alias.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- deletes the alias with ID 5<br />
killAlias(5)<br />
</syntaxhighlight><br />
<br />
==killKey==<br />
;killKey(name)<br />
:Deletes a keybinding with the given name. If several keybindings have this name, they'll all be deleted.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempKey|tempKey]] to identify the key.<br />
<br />
{{note}} Available in Mudlet 3.2+<br />
<br />
<syntaxhighlight lang="lua"><br />
-- make a temp key<br />
local keyid = tempKey(mudlet.key.F8, [[echo("hi!")]])<br />
<br />
-- delete the said temp key<br />
killKey(keyid)<br />
</syntaxhighlight><br />
<br />
==killTimer==<br />
;killTimer(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
{{note}} Non-temporary timers that you have set up in the GUI or by using [[#permTimer|permTimer]] cannot be deleted with this function. Use [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#enableTimer|enableTimer()]] to turn them on or off.<br />
<br />
;Parameters<br />
* ''id:'' the ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
: Returns true on success and false if the timer id doesn’t exist anymore (timer has already fired) or the timer is not a temp timer.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create the timer and remember the timer ID<br />
timerID = tempTimer(10, [[echo("hello!")]])<br />
<br />
-- delete the timer<br />
if killTimer(timerID) then echo("deleted the timer") else echo("timer is already deleted") end<br />
</syntaxhighlight><br />
<br />
==killTrigger==<br />
;killTrigger(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTrigger]], or a trigger made with one of the ''temp<type>Trigger()'' functions.<br />
<br />
{{note}} When used in out of trigger contexts, the triggers are disabled and deleted upon the next line received from the game - so if you are testing trigger deletion within an alias, the 'statistics' window will be reporting trigger counts that are disabled and pending removal, and thus are no cause for concern.<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the trigger id doesn’t exist anymore (trigger has already fired) or the trigger is not a temp trigger.<br />
<br />
==permAlias==<br />
;permAlias(name, parent, regex, lua code)<br />
<br />
:Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name you’d like the alias to have.<br />
* ''parent:'' <br />
: The name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''regex:''<br />
: The pattern that you’d like the alias to use.<br />
* ''lua code:'' <br />
: The script the alias will do when it matches.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- creates an alias called "new alias" in a group called "my group"<br />
permAlias("new alias", "my group", "^test$", [[echo ("say it works! This alias will show up in the script editor too.")]])<br />
</syntaxhighlight><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permAlias with the same name will keep creating new aliases. You can check if an alias already exists with the [[Manual:Lua_Functions#exists|exists]] function.<br />
<br />
==permGroup==<br />
;permGroup(name, itemtype, [parent])<br />
<br />
:Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts. <br />
;Parameters<br />
* ''name:''<br />
: The name of the new group item you want to create.<br />
* ''itemtype:''<br />
: The type of the item, can be trigger, alias, timer, or script.<br />
* ''parent:''<br />
: (optional) Name of existing item which the new item will be created as a child of.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</syntaxhighlight><br />
<br />
{{Note}} Added to Mudlet in the 2.0 final release. Parameter ''parent'' available in Mudlet 3.1+<br />
{{Note}} Itemtype script is available from Mudlet 4.7+<br />
<br />
==permPromptTrigger==<br />
;permPromptTrigger(name, parent, lua code)<br />
:Creates a persistent trigger for the in-game prompt that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
{{note}} If the trigger is not working, check that the '''N:''' bottom-right has a number. This feature requires telnet Go-Ahead (GA) or End-of-Record (EOR) to be enabled in your game. Available in Mudlet 3.6+<br />
<br />
;Parameters:<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
<br />
;Example: <br />
<syntaxhighlight lang="lua"><br />
permPromptTrigger("echo on prompt", "", [[echo("hey! this thing is working!\n")]])<br />
</syntaxhighlight><br />
<br />
<br />
==permRegexTrigger==<br />
;permRegexTrigger(name, parent, pattern table, lua code)<br />
:Creates a persistent trigger with one or more ''regex'' patterns that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a regex trigger that will match on the prompt to record your status<br />
permRegexTrigger("Prompt", "", {"^(\d+)h, (\d+)m"}, [[health = tonumber(matches[2]); mana = tonumber(matches[3])]])<br />
</syntaxhighlight><br />
{{note}} Mudlet by design allows duplicate names - so calling permRegexTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permBeginOfLineStringTrigger==<br />
;permBeginOfLineStringTrigger(name, parent, pattern table, lua code)<br />
:Creates a persistent trigger that stays after Mudlet is restarted and shows up in the Script Editor. The trigger will go off whenever one of the ''regex'' patterns it's provided with matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- Create a trigger that will match on anything that starts with "You sit" and do "stand".<br />
-- It will not go into any groups, so it'll be on the top.<br />
permBeginOfLineStringTrigger("Stand up", "", {"You sit"}, [[send ("stand")]])<br />
<br />
-- Another example - lets put our trigger into a "General" folder and give it several patterns.<br />
permBeginOfLineStringTrigger("Stand up", "General", {"You sit", "You fall", "You are knocked over by"}, [[send ("stand")]])<br />
</syntaxhighlight><br />
{{note}} Mudlet by design allows duplicate names - so calling permBeginOfLineStringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permSubstringTrigger==<br />
;permSubstringTrigger( name, parent, pattern table, lua code )<br />
:Creates a persistent trigger with one or more ''substring'' patterns that stays after Mudlet is restarted and shows up in the Script Editor.<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a trigger to highlight the word "pixie" for us<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie"},<br />
[[selectString(line, 1) bg("yellow") resetFormat()]])<br />
<br />
-- Or another trigger to highlight several different things<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie", "cat", "dog", "rabbit"},<br />
[[selectString(line, 1) fg ("blue") bg("yellow") resetFormat()]])<br />
</syntaxhighlight><br />
{{note}} Mudlet by design allows duplicate names - so calling permSubstringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permScript==<br />
;permScript(name, parent, lua code)<br />
: Creates a new script in the Script Editor that stays after Mudlet is restarted.<br />
<br />
;Parameters<br />
* ''name'': name of the script.<br />
* ''parent'': name of the script group you want the script to go in.<br />
* ''lua code'': is the code with string you are putting in your script.<br />
<br />
;Returns<br />
* a unique id number for that script.<br />
<br />
: See also: [[#enableScript|enableScript()]], [[#exists|exists()]], [[#appendScript|appendScript()]], [[#disableScript|disableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- create a script in the "first script group" group<br />
permScript("my script", "first script group", [[send ("my script that's in my first script group fired!")]])<br />
-- create a script that's not in any group; just at the top<br />
permScript("my script", "", [[send ("my script that's in my first script group fired!")]])<br />
<br />
-- enable Script - a script element is disabled at creation<br />
enableScript("my script")<br />
</syntaxhighlight><br />
<br />
{{note}} The script is called once but NOT active after creation, it will need to be enabled by [[#enableScript|enableScript()]].<br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permScript with the same name will keep creating new script elements. You can check if a script already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==permTimer==<br />
;permTimer(name, parent, seconds, lua code)<br />
: Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:name of the timer.<br />
* ''parent'' <br />
:name of the timer group you want the timer to go in.<br />
* ''seconds'' <br />
:a floating point number specifying a delay in seconds after which the timer will do the lua code (stored as the timer's "script") you give it as a string.<br />
* ''lua code'' is the code with string you are doing this to.<br />
<br />
;Returns<br />
* a unique id number for that timer.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- create a timer in the "first timer group" group<br />
permTimer("my timer", "first timer group", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
-- create a timer that's not in any group; just at the top<br />
permTimer("my timer", "", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
<br />
-- enable timer - they start off disabled until you're ready<br />
enableTimer("my timer")<br />
</syntaxhighlight><br />
<br />
{{note}} The timer is NOT active after creation, it will need to be enabled by a call to [[#enableTimer|enableTimer()]] before it starts.<br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permTimer with the same name will keep creating new timers. You can check if a timer already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permKey==<br />
;permKey(name, parent, [modifier], key code, lua code)<br />
: Creates a persistent key that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:name of the key.<br />
* ''parent'' <br />
:name of the timer group you want the timer to go in or "" for the top level.<br />
* ''modifier'' <br />
:(optional) modifier to use - can be one of ''mudlet.keymodifier.Control'', ''mudlet.keymodifier.Alt'', ''mudlet.keymodifier.Shift'', ''mudlet.keymodifier.Meta'', ''mudlet.keymodifier.Keypad'', or ''mudlet.keymodifier.GroupSwitch'' or the default value of ''mudlet.keymodifier.None'' which is used if the argument is omitted. To use multiple modifiers, add them together: ''(mudlet.keymodifier.Shift + mudlet.keymodifier.Control)''<br />
* ''key code'' <br />
: actual key to use - one of the values available in ''mudlet.key'', e.g. ''mudlet.key.Escape'', ''mudlet.key.Tab'', ''mudlet.key.F1'', ''mudlet.key.A'', and so on. The list is a bit long to list out in full so it is [https://github.com/Mudlet/Mudlet/blob/development/src/mudlet-lua/lua/KeyCodes.lua#L2 available here].<br />
: set to -1 if you want to create a key folder instead.<br />
* ''lua code'<br />
: code you would like the key to run.<br />
<br />
;Returns<br />
* a unique id number for that key.<br />
<br />
{{note}} Available in Mudlet 3.2+, creating key folders in Mudlet 4.10+<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- create a key at the top level for F8<br />
permKey("my key", "", mudlet.key.F8, [[echo("hey this thing actually works!\n")]])<br />
<br />
-- or Ctrl+F8<br />
permKey("my key", "", mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hey this thing actually works!\n")]])<br />
<br />
-- Ctrl+Shift+W<br />
permKey("jump keybinding", "", mudlet.keymodifier.Control + mudlet.keymodifier.Shift, mudlet.key.W, [[send("jump")]])<br />
</syntaxhighlight><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permKey with the same name will keep creating new keys. You can check if a key already exists with the [[Manual:Lua_Functions#exists|exists()]] function. The key will be created even if the lua code does not compile correctly - but this will be apparent as it will be seen in the Editor.<br />
<br />
==printCmdLine==<br />
;printCmdLine([name], text)<br />
<br />
: Replaces the current text in the input line, and sets it to the given text.<br />
: See also: [[Manual:Lua_Functions#clearCmdLine|clearCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, main commandline's text will be set.<br />
* ''text'': text to set<br />
<br />
<syntaxhighlight lang="lua"><br />
printCmdLine("say I'd like to buy ")<br />
</syntaxhighlight><br />
<br />
==raiseEvent==<br />
;raiseEvent(event_name, arg-1, … arg-n)<br />
<br />
: Raises the event event_name. The event system will call the main function (the one that is called exactly like the script name) of all such scripts in this profile that have registered event handlers. If an event is raised, but no event handler scripts have been registered with the event system, the event is ignored and nothing happens. This is convenient as you can raise events in your triggers, timers, scripts etc. without having to care if the actual event handling has been implemented yet - or more specifically how it is implemented. Your triggers raise an event to tell the system that they have detected a certain condition to be true or that a certain event has happened. How - and if - the system is going to respond to this event is up to the system and your trigger scripts don’t have to care about such details. For small systems it will be more convenient to use regular function calls instead of events, however, the more complicated your system will get, the more important events will become because they help reduce complexity very much.<br />
<br />
:The corresponding event handlers that listen to the events raised with raiseEvent() need to use the script name as function name and take the correct number of arguments. <br />
<br />
{{note}} possible arguments can be string, number, boolean, table, function, or nil.<br />
<br />
;Example:<br />
<br />
:raiseEvent("fight") a correct event handler function would be: myScript( event_name ). In this example raiseEvent uses minimal arguments, name the event name. There can only be one event handler function per script, but a script can still handle multiple events as the first argument is always the event name - so you can call your own special handlers for individual events. The reason behind this is that you should rather use many individual scripts instead of one huge script that has all your function code etc. Scripts can be organized very well in trees and thus help reduce complexity on large systems.<br />
<br />
Where the number of arguments that your event may receive is not fixed you can use [http://www.lua.org/manual/5.1/manual.html#2.5.9 ''...''] as the last argument in the ''function'' declaration to handle any number of arguments. For example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- try this function out with "lua myscripthandler(1,2,3,4)"<br />
function myscripthandler(a, b, ...)<br />
print("Arguments a and b are: ", a,b)<br />
-- save the rest of the arguments into a table<br />
local otherarguments = {...}<br />
print("Rest of the arguments are:")<br />
display(otherarguments)<br />
<br />
-- access specific otherarguments:<br />
print("First and second otherarguments are: ", otherarguments[1], otherarguments[2])<br />
end<br />
</syntaxhighlight><br />
<br />
==raiseGlobalEvent==<br />
;raiseGlobalEvent(event_name, arg-1, … arg-n)<br />
<br />
: Like [[Manual:Lua_Functions#raiseEvent|raiseEvent()]] this raises the event "event_name", but this event is sent to all '''other''' opened profiles instead. The profiles receive the event in circular alphabetical order (if profile "C" raised this event and we have profiles "A", "C", and "E", the order is "E" -> "A", but if "E" raised the event the order would be "A" -> "C"); execution control is handed to the receiving profiles so that means that long running events may lock up the profile that raised the event.<br />
<br />
: The sending profile's name is automatically appended as the last argument to the event.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- from profile called "My MUD" this raises an event "my event" with additional arguments 1, 2, 3, "My MUD" to all profiles except the original one<br />
raiseGlobalEvent("my event", 1, 2, 3)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available since Mudlet 3.1.0.<br />
<br />
Tip: you might want to add the [[Manual:Miscellaneous_Functions#getProfileName|profile name]] to your plain [[Manual:Miscellaneous_Functions#raiseEvent|raiseEvent()]] arguments. This'll help you tell which profile your event came from similar to [[#raiseGlobalEvent|raiseGlobalEvent()]].<br />
<br />
==remainingTime==<br />
;remainingTime(timer id number or name)<br />
<br />
: Returns the remaining time in floating point form in seconds (if it is active) for the timer (temporary or permanent) with the id number or the (first) one found with the name.<br />
: If the timer is inactive or has expired or is not found it will return a ''nil'' and an ''error message''. It, theoretically could also return 0 if the timer is overdue, i.e. it has expired but the internal code has not yet been run but that has not been seen in during testing. Permanent ''offset timers'' will only show as active during the period when they are running after their parent has expired and started them.<br />
<br />
{{Note}} Available in Mudlet since 3.20.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
tid = tempTimer(600, [[echo("\nYour ten minutes are up.\n")]])<br />
echo("\nYou have " .. remainingTime(tid) .. " seconds left, use it wisely... \n")<br />
<br />
-- Will produce something like:<br />
<br />
You have 599.923 seconds left, use it wisely... <br />
<br />
-- Then ten minutes time later:<br />
<br />
Your ten minutes are up.<br />
<br />
</syntaxhighlight><br />
<br />
==resetProfileIcon==<br />
;resetProfileIcon()<br />
: Resets the profile's icon in the connection screen to default.<br />
<br />
See also: [[#setProfileIcon|setProfileIcon()]].<br />
<br />
{{Note}} Available in Mudlet 4.0+.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
resetProfileIcon()<br />
</syntaxhighlight><br />
<br />
==resetStopWatch==<br />
;resetStopWatch(watchID)<br />
:This function resets the time to 0:0:0.0, but does not start the stop watch. You can start it with [[Manual:Lua_Functions#startStopWatch | startStopWatch]] → [[Manual:Lua_Functions#createStopWatch | createStopWatch]]<br />
<br />
==setConsoleBufferSize==<br />
;setConsoleBufferSize([consoleName], linesLimit, sizeOfBatchDeletion)<br />
:Sets the maximum number of lines a buffer (main window or a miniconsole) can hold. Default is 10,000.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: (optional) The name of the window. If omitted, uses the main console.<br />
* ''linesLimit:''<br />
: Sets the amount of lines the buffer should have. <br />
{{note}} Mudlet performs extremely efficiently with even huge numbers, but there is of course a limit to your computer's memory. As of Mudlet 4.7+, this amount will be capped to that limit on macOS and Linux (on Windows, it's capped lower as Mudlet on Windows is 32bit).<br />
* ''sizeOfBatchDeletion:''<br />
: Specifies how many lines should Mudlet delete at once when you go over the limit - it does it in bulk because it's efficient to do so.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sets the main windows size to 1 million lines maximum - which is more than enough!<br />
setConsoleBufferSize("main", 1000000, 1000)<br />
</syntaxhighlight><br />
<br />
==setProfileIcon==<br />
;setProfileIcon(iconPath)<br />
:Set a custom icon for this profile in the connection screen. <br />
<br />
:Returns true if successful, or nil+error message if not.<br />
<br />
:See also: [[#resetProfileIcon|resetProfileIcon()]].<br />
<br />
{{note}} Available in Mudlet 4.0+<br />
<br />
;Parameters<br />
* ''iconPath:''<br />
: Full location of the icon - can be .png or .jpg with ideal dimensions of 120x30.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set a custom icon that is located in an installed package called "mypackage"<br />
setProfileIcon(getMudletHomeDir().."/mypackage/icon.png")<br />
</syntaxhighlight><br />
<br />
==setScript==<br />
;setScript(scriptName, luaCode, [occurrence])<br />
: Sets the script's Lua code, replacing existing code. If you have many scripts with the same name, use the 'occurrence' parameter to choose between them.<br />
: If you'd like to add code instead of replacing it, have a look at [[Manual:Lua_Functions#appendScript|appendScript()]].<br />
: Returns -1 if the script isn't found - to create a script, use [[Manual:Lua_Functions#permScript|permScript()]].<br />
<br />
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#getScript|getScript()]], [[Manual:Lua_Functions#appendScript|appendScript()]]<br />
<br />
;Returns<br />
* a unique id number for that script.<br />
<br />
;Parameters<br />
* ''scriptName'': name of the script to change the code.<br />
* ''luaCode'': new Lua code to set.<br />
* ''occurrence'': The position of the script. Optional, defaults to 1 (first).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example of setting the script lua code from the first occurrence of "testscript"<br />
setScript("testscript", [[echo("This is a test\n")]], 1)<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==setStopWatchName==<br />
;setStopWatchName(watchID/currentStopWatchName, newStopWatchName)<br />
<br />
;Parameters<br />
* ''watchID'' (number) / ''currentStopWatchName'' (string): The stopwatch ID you get from [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name supplied to that function at that time, or previously applied with this function.<br />
* ''newStopWatchName'' (string): The name to use for this stopwatch from now on.<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found.<br />
<br />
{{note}} Either ''currentStopWatchName'' or ''newStopWatchName'' may be empty strings: if the first of these is so then the ''lowest'' ID numbered stopwatch without a name is chosen; if the second is so then an existing name is removed from the chosen stopwatch.<br />
<br />
==setStopWatchPersistence==<br />
;setStopWatchPersistence(watchID/watchName, state)<br />
<br />
;Parameters<br />
* ''watchID'' (number) / ''watchName'' (string): The stopwatch ID you get from [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name supplied to that function or applied later with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]]<br />
* ''state'' (boolean): if ''true'' the stopWatch will be saved.<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found.<br />
<br />
:Sets or resets the flag so that the stopwatch is saved between sessions or after a [[Manual:Miscellaneous_Functions#resetProfile|resetProfile()]] call. If set then, if ''stopped'' the elapsed time recorded will be unchanged when the stopwatch is reloaded in the next session; if ''running'' the elapsed time will continue to increment and it will include the time that the profile was not loaded, therefore it can be used to measure events in real-time, outside of the profile!<br />
<br />
{{note}} When a persistent stopwatch is reloaded in a later session (or after a use of ''resetProfile()'') the stopwatch may not be allocated the same ID number as before - therefore it is advisable to assign any persistent stopwatches a name, either when it is created or before the session is ended.<br />
<br />
==setTriggerStayOpen==<br />
;setTriggerStayOpen(name, number)<br />
:Sets for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched - so this allows you to extend or shorten the ''fire length'' of a trigger. The main use of this function is to close a chain when a certain condition has been met.<br />
<br />
;Parameters<br />
* ''name:'' The name of the trigger which has a fire length set (and which opens the chain).<br />
* ''number'': 0 to close the chain, or a positive number to keep the chain open that much longer.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if you have a trigger that opens a chain (has some fire length) and you'd like it to be closed <br />
-- on the next prompt, you could make a trigger inside the chain with a Lua function pattern of:<br />
return isPrompt()<br />
-- and a script of:<br />
setTriggerStayOpen("Parent trigger name", 0)<br />
-- to close it on the prompt!<br />
</syntaxhighlight><br />
<br />
==startStopWatch==<br />
;startStopWatch(watchID, [resetAndRestart])<br />
;startStopWatch(watchName)<br />
<br />
:Stopwatches can be stopped (with [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]]) and then re-started any number of times. '''To ensure backwards compatibility, if the stopwatch is identified by a ''numeric'' argument then, ''unless a second argument of false is supplied as well'' this function will also reset the stopwatch to zero and restart it - whether it is running or not'''; otherwise only a stopped watch can be started and only a started watch may be stopped. Trying to repeat either will produce a nil and an error message instead; also the recorded time is no longer reset so that they can now be used to record a total of isolated periods of time like a real stopwatch.<br />
<br />
:See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]]<br />
<br />
;Parameters<br />
* ''watchID''/''watchName'': The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], or from '''4.4.0''' the name assigned with that function or [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
* ''resetAndRestart'': Boolean flag needed (as ''false'') to make the function from '''4.4.0''', when supplied with a numeric watch ID, to '''not''' reset the stopwatch and only start a previously stopped stopwatch. This behavior is automatic when a string watch name is used to identify the stopwatch but differs from how the function behaved prior to that version.<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found or if it cannot be started (because the later style behavior was indicated and it was already running).<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- this is a common pattern for re-using stopwatches prior to 4.4.0 and starting them:<br />
watch = watch or createStopWatch()<br />
startStopWatch(watch)<br />
</syntaxhighlight><br />
<br />
:: After 4.4.0 the above code will work the same as it does not provide a second argument to the ''startStopWatch()'' function - if a ''false'' was used there it would be necessary to call ''stopStopWatch(...)'' and then ''resetStopWatch(...)'' before using ''startStopWatch(...)'' to re-use the stopwatch if the ID form is used, '''this is thus not quite the same behavior but it is more consistent with the model of how a real stopwatch would act.'''<br />
<br />
==stopStopWatch==<br />
;stopStopWatch(watchID or watchName)<br />
:"Stops" (though see the note below) the stop watch and returns (only the '''first''' time it is called after the stopwatch has been set running with [[Manual:Lua_Functions#startStopWatch()|startStopWatchTime()]]) the elapsed time as a number of seconds, with a decimal portion give a resolution in milliseconds (thousandths of a second). You can also retrieve the current time without stopping the stopwatch with [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]], [[Manual:Lua_Functions#getBrokenDownStopWatchTime|getBrokenDownStopWatchTime()]].<br />
<br />
:See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
<br />
;Parameters<br />
* ''watchID:'' The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or from Mudlet '''4.4.0''' the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
<br />
;Returns<br />
* the elapsed time as a floating-point number of seconds - it may be negative if the time was previously adjusted/preset to a negative amount (with [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]]) and that period has not yet elapsed.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- this is a common pattern for re-using stopwatches and starting them:<br />
watch = watch or createStopWatch()<br />
startStopWatch(watch)<br />
<br />
-- do some long-running code here ...<br />
<br />
print("The code took: "..stopStopWatch(watch).."s to run.")<br />
</syntaxhighlight><br />
<br />
==tempAnsiColorTrigger==<br />
;tempAnsiColorTrigger(foregroundColor[, backgroundColor], code[, expireAfter])<br />
:This is an alternative to [[Manual:Lua_Functions#tempColorTrigger|tempColorTrigger()]] which supports the full set of 256 ANSI color codes directly and makes a color trigger that triggers on the specified foreground and background color. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code to do'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function.<br />
* ''expireAfter'': Delete trigger after a specified number of matches. You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
''BackgroundColor'' and/or ''expireAfter'' may be omitted.<br />
<br />
;Color codes (note that the values greater than or equal to zero are the actual number codes that ANSI and the game server uses for the 8/16/256 color modes)<br />
<br />
::Special codes (may be extended in the future):<br />
:::-2 = default text color (what is used after an ANSI SGR 0 m code that resets the foreground and background colors to those set in the preferences)<br />
:::-1 = ignore (only '''one''' of the foreground or background codes can have this value - otherwise it would not be a ''color'' trigger!)<br />
<br />
::ANSI 8-color set:<br />
:::0 = (dark) black<br />
:::1 = (dark) red<br />
:::2 = (dark) green<br />
:::3 = (dark) yellow<br />
:::4 = (dark) blue<br />
:::5 = (dark) magenta<br />
:::6 = (dark) cyan<br />
:::7 = (dark) white {a.k.a. light gray}<br />
<br />
::Additional colors in 16-color set:<br />
:::8 = light black {a.k.a. dark gray}<br />
:::9 = light red<br />
:::10 = light green<br />
:::11 = light yellow<br />
:::12 = light blue<br />
:::13 = light magenta<br />
:::14 = light cyan<br />
:::15 = light white<br />
<br />
::6 x 6 x 6 RGB (216) colors, shown as a 3x2-digit hex code<br />
:::16 = #000000<br />
:::17 = #000033<br />
:::18 = #000066<br />
:::...<br />
:::229 = #FFFF99<br />
:::230 = #FFFFCC<br />
:::231 = #FFFFFF<br />
<br />
::24 gray-scale, also show as a 3x2-digit hex code<br />
:::232 = #000000<br />
:::233 = #0A0A0A<br />
:::234 = #151515<br />
:::...<br />
:::253 = #E9E9E9<br />
:::254 = #F4F4F4<br />
:::255 = #FFFFFF<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- This script will re-highlight all text in a light cyan foreground color on any background with a red foreground color<br />
-- until another foreground color in the current line is being met. temporary color triggers do not offer match_all<br />
-- or filter options like the GUI color triggers because this is rarely necessary for scripting.<br />
-- A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempAnsiColorTrigger(14, -1, [[selectString(matches[1],1) fg("red")]])<br />
-- or:<br />
tempAnsiColorTrigger(14, -1, function()<br />
selectString(matches[1], 1)<br />
fg("red")<br />
end)<br />
<br />
-- match the trigger only 4 times<br />
tempColorTrigger(14, -1, [[selectString(matches[1],1) fg("red")]], 4)<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==tempAlias==<br />
;aliasID = tempAlias(regex, code to do)<br />
:Creates a temporary alias - temporary in the sense that it won't be saved when Mudlet restarts (unless you re-create it). The alias will go off as many times as it matches, it is not a one-shot alias. The function returns an ID for subsequent [[Manual:Lua_Functions#enableAlias|enableAlias()]], [[Manual:Lua_Functions#disableAlias|disableAlias()]] and [[Manual:Lua_Functions#killAlias|killAlias()]] calls.<br />
<br />
;Parameters<br />
* ''regex:'' Alias pattern in regex.<br />
* ''code to do:'' The code to do when the alias fires - wrap it in [[ ]].<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
myaliasID = tempAlias("^hi$", [[send ("hi") echo ("we said hi!")]])<br />
<br />
-- you can also delete the alias later with:<br />
killAlias(myaliasID)<br />
</syntaxhighlight><br />
<br />
==tempBeginOfLineTrigger==<br />
;tempBeginOfLineTrigger(part of line, code, expireAfter)<br />
:Creates a trigger that will go off whenever the part of line it's provided with matches the line right from the start (doesn't matter what the line ends with). The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
<br />
;Parameters<br />
* ''part of line'': start of the line that you'd like to match. This can also be regex.<br />
* ''code to do'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
mytriggerID = tempBeginOfLineTrigger("Hello", [[echo("We matched!")]])<br />
<br />
--[[ now this trigger will match on any of these lines:<br />
Hello<br />
Hello!<br />
Hello, Bob!<br />
<br />
but not on:<br />
Oh, Hello<br />
Oh, Hello!<br />
]]<br />
<br />
-- or as a function:<br />
mytriggerID = tempBeginOfLineTrigger("Hello", function() echo("We matched!") end)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can make the trigger match only a certain amount of times as well, 5 in this example:<br />
tempBeginOfLineTrigger("This is the start of the line", function() echo("We matched!") end, 5)<br />
<br />
-- if you want a trigger match not to count towards expiration, return true. In this example it'll match 5 times unless the line is "Start of line and this is the end."<br />
tempBeginOfLineTrigger("Start of line", <br />
function()<br />
if line == "Start of line and this is the end." then<br />
return true<br />
else<br />
return false<br />
end<br />
end, 5)<br />
</syntaxhighlight><br />
<br />
==tempButton==<br />
;tempButton(toolbar name, button text, orientation)<br />
:Creates a temporary button. Temporary means, it will disappear when Mudlet is closed.<br />
<br />
;Parameters:<br />
* ''toolbar name'': The name of the toolbar to place the button into.<br />
* ''button text'': The text to display on the button.<br />
* ''orientation'': a number 0 or 1 where 0 means horizontal orientation for the button and 1 means vertical orientation for the button. This becomes important when you want to have more than one button in the same toolbar.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- makes a temporary toolbar with two buttons at the top of the main Mudlet window <br />
lua tempButtonToolbar("topToolbar", 0, 0)<br />
lua tempButton("topToolbar", "leftButton", 0)<br />
lua tempButton("topToolbar", "rightButton", 0)<br />
</syntaxhighlight><br />
<br />
{{note}} ''This function is not that useful as there is no function yet to assign a Lua script or command to such a temporary button - though it may have some use to flag a status indication!''<br />
<br />
==tempButtonToolbar==<br />
;tempButtonToolbar(name, location, orientation)<br />
:Creates a temporary button toolbar. Temporary means, it will disappear when Mudlet is closed.<br />
<br />
;Parameters:<br />
* ''name'': The name of the toolbar.<br />
* ''location'': a number from 0 to 3, where 0 means "at the top of the screen", 1 means "left side", 2 means "right side" and 3 means "in a window of its own" which can be dragged and attached to the main Mudlet window if needed.<br />
* ''orientation'': a number 0 or 1, where 0 means horizontal orientation for the toolbar and 1 means vertical orientation for the toolbar. This becomes important when you want to have more than one toolbar in the same location of the window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- makes a temporary toolbar with two buttons at the top of the main Mudlet window <br />
lua tempButtonToolbar("topToolbar", 0, 0)<br />
lua tempButton("topToolbar", "leftButton", 0)<br />
lua tempButton("topToolbar", "rightButton", 0)<br />
</syntaxhighlight><br />
<br />
==tempColorTrigger==<br />
;tempColorTrigger(foregroundColor, backgroundColor, code, expireAfter)<br />
:Makes a color trigger that triggers on the specified foreground and background color. Both colors need to be supplied in form of these simplified ANSI 16 color mode codes. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code to do'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Color codes<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- This script will re-highlight all text in blue foreground colors on a black background with a red foreground color<br />
-- on a blue background color until another color in the current line is being met. temporary color triggers do not <br />
-- offer match_all or filter options like the GUI color triggers because this is rarely necessary for scripting. <br />
-- A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempColorTrigger(9, 2, [[selectString(matches[1],1) fg("red") bg("blue")]])<br />
-- or:<br />
tempColorTrigger(9, 2, function()<br />
selectString(matches[1], 1)<br />
fg("red")<br />
bg("blue")<br />
end)<br />
<br />
-- match the trigger only 4 times<br />
tempColorTrigger(9, 2, [[selectString(matches[1],1) fg("red") bg("blue")]], 4)<br />
</syntaxhighlight><br />
<br />
==tempComplexRegexTrigger==<br />
;tempComplexRegexTrigger(name, regex, code, multiline, fg color, bg color, filter, match all, highlight fg color, highlight bg color, play sound file, fire length, line delta, expireAfter)<br />
:Allows you to create a temporary trigger in Mudlet, using any of the UI-available options. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
:Returns the trigger name, that you can use [[Manual:Lua_Functions#killTrigger|killTrigger()]] later on with.<br />
<br />
;Parameters<br />
* ''name'' - The name you call this trigger. <br />
* ''regex'' - The regular expression you want to match.<br />
* ''code'' - Code to do when the trigger runs. You need to wrap it in [[ ]], or give a Lua function (since Mudlet 3.5.0).<br />
* ''multiline'' - Set this to 1, if you use multiple regex (see note below), and you need the trigger to fire only if all regex have been matched within the specified line delta. Then all captures will be saved in ''multimatches'' instead of ''matches''. If this option is set to 0, the trigger will fire when any regex has been matched.<br />
* ''fg color'' - The foreground color you'd like to trigger on.<br />
* ''bg color'' - The background color you'd like to trigger on.<br />
* ''filter'' - Do you want only the filtered content (=capture groups) to be passed on to child triggers? Otherwise also the initial line.<br />
* ''match all'' - Set to 1, if you want the trigger to match all possible occurrences of the regex in the line. When set to 0, the trigger will stop after the first successful match.<br />
* ''highlight fg color'' - The foreground color you'd like your match to be highlighted in.<br />
* ''highlight bg color'' - The background color you'd like your match to be highlighted in.<br />
* ''play sound file'' - Set to the name of the sound file you want to play upon firing the trigger.<br />
* ''fire length'' - Number of lines within which all condition must be true to fire the trigger.<br />
* ''line delta'' - Keep firing the script for x more lines, after the trigger or chain has matched.<br />
* ''expireAfter'' - Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
{{Note}} Set the options starting at ''multiline'' to 0, if you don't want to use those options. Otherwise enter 1 to activate or the value you want to use.<br />
<br />
{{Note}} If you want to use the color option, you need to provide both fg and bg together.<br />
<br />
;Examples<br />
<br />
<syntaxhighlight lang="lua"><br />
-- This trigger will be activated on any new line received.<br />
triggerNumber = tempComplexRegexTrigger("anyText", "^(.*)$", [[echo("Text received!")]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)<br />
<br />
-- This trigger will match two different regex patterns:<br />
tempComplexRegexTrigger("multiTrigger", "first regex pattern", [[]], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)<br />
tempComplexRegexTrigger("multiTrigger", "second regex pattern", [[echo("Trigger matched!")]], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)<br />
</syntaxhighlight><br />
<br />
{{Note}} For making a multiline trigger like in the second example, you need to use the same trigger name and options, providing the new pattern to add. Note that only the last script given will be set, any others ignored.<br />
<br />
==tempExactMatchTrigger==<br />
;tempExactMatchTrigger(exact line, code, expireAfter)<br />
:Creates a trigger that will go off whenever the line from the game matches the provided line exactly (ends the same, starts the same, and looks the same). You don't need to use any of the regex symbols here (^ and $). The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters<br />
* ''exact line'': exact line you'd like to match.<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
mytriggerID = tempExactMatchTrigger("You have recovered balance on all limbs.", [[echo("We matched!")]])<br />
<br />
-- as a function:<br />
mytriggerID = tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("We matched!") end)<br />
<br />
-- expire after 4 matches:<br />
tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("Got balance back!\n") end, 4)<br />
<br />
-- you can also avoid expiration by returning true:<br />
tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("Got balance back!\n") return true end, 4)<br />
</syntaxhighlight><br />
<br />
==tempKey==<br />
;tempKey([modifier], key code, lua code)<br />
:Creates a keybinding. This keybinding isn't temporary in the sense that it'll go off only once (it'll go off as often as you use it), but rather it won't be saved when Mudlet is closed.<br />
<br />
: See also: [[#permKey|permKey()]], [[#killKey|killKey()]]<br />
<br />
* ''modifier'' <br />
:(optional) modifier to use - can be one of ''mudlet.keymodifier.Control'', ''mudlet.keymodifier.Alt'', ''mudlet.keymodifier.Shift'', ''mudlet.keymodifier.Meta'', ''mudlet.keymodifier.Keypad'', or ''mudlet.keymodifier.GroupSwitch'' or the default value of ''mudlet.keymodifier.None'' which is used if the argument is omitted. To use multiple modifiers, add them together: ''(mudlet.keymodifier.Shift + mudlet.keymodifier.Control)''<br />
* ''key code'' <br />
: actual key to use - one of the values available in ''mudlet.key'', e.g. ''mudlet.key.Escape'', ''mudlet.key.Tab'', ''mudlet.key.F1'', ''mudlet.key.A'', and so on. The list is a bit long to list out in full so it is [https://github.com/Mudlet/Mudlet/blob/development/src/mudlet-lua/lua/KeyCodes.lua#L2 available here].<br />
* ''lua code'<br />
: code you'd like the key to run - wrap it in [[ ]].<br />
<br />
;Returns<br />
* a unique id number for that key.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
local keyID = tempKey(mudlet.key.F8, [[echo("hi")]])<br />
<br />
local anotherKeyID = tempKey(mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hello")]])<br />
<br />
-- bind Ctrl+Shift+W:<br />
tempKey(mudlet.keymodifier.Control + mudlet.keymodifier.Shift, mudlet.key.W, [[send("jump")]])<br />
<br />
-- delete it if you don't like it anymore<br />
killKey(keyID)<br />
</syntaxhighlight><br />
<br />
==tempLineTrigger==<br />
;tempLineTrigger(from, howMany, code, expireAfter)<br />
:Temporary trigger that will fire on ''n'' consecutive lines following the current line. This is useful to parse output that is known to arrive in a certain line margin or to delete unwanted output from the MUD - the trigger does not require any patterns to match on. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters:<br />
* ''from'': from which line after this one should the trigger activate - 1 will activate right on the next line.<br />
* ''howMany'': how many lines to run for after the trigger has activated.<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Example: <br />
<syntaxhighlight lang="lua"><br />
-- Will fire 3 times with the next line from the MUD.<br />
tempLineTrigger(1, 3, function() print(" trigger matched!") end)<br />
<br />
-- Will fire 20 lines after the current line and fire twice on 2 consecutive lines, 7 times.<br />
tempLineTrigger(20, 2, function() print(" trigger matched!") end, 7)<br />
</syntaxhighlight><br />
<br />
==tempPromptTrigger==<br />
;tempPromptTrigger(code, expireAfter)<br />
:Temporary trigger that will match on the games prompt. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
{{note}} If the trigger is not working, check that the '''N:''' bottom-right has a number. This feature requires telnet Go-Ahead to be enabled in the game. Available in Mudlet 3.6+<br />
<br />
;Parameters:<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function.<br />
* ''expireAfter'': Delete trigger after a specified number of matches. You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
{{note}} ''expireAfter'' is available since Mudlet 3.11<br />
<br />
;Example: <br />
<syntaxhighlight lang="lua"><br />
tempPromptTrigger(function()<br />
echo("hello! this is a prompt!")<br />
end)<br />
<br />
-- match only 2 times:<br />
tempPromptTrigger(function()<br />
echo("hello! this is a prompt!")<br />
end, 2)<br />
<br />
-- match only 2 times, unless the prompt is "55 health."<br />
tempPromptTrigger(function()<br />
if line == "55 health." then return true end<br />
end, 2)<br />
</syntaxhighlight><br />
<br />
==tempRegexTrigger==<br />
;tempRegexTrigger(regex, code, expireAfter)<br />
:Creates a temporary regex trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters:<br />
* ''regex:'' regular expression that lines will be matched on.<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- create a non-duplicate trigger that matches on any line and calls a function<br />
html5log = html5log or {}<br />
if html5log.trig then killTrigger(html5log.trig) end<br />
html5log.trig = tempRegexTrigger("^", [[html5log.recordline()]])<br />
-- or a simpler variant:<br />
html5log.trig = tempRegexTrigger("^", html5log.recordline)<br />
<br />
-- only match 3 times:<br />
tempRegexTrigger("^You prick (.+) twice in rapid succession with", function() echo("Hit "..matches[2].."!\n") end, 3)<br />
</syntaxhighlight><br />
<br />
==tempTimer==<br />
;tempTimer(time, code to do[, repeating])<br />
:Creates a temporary one-shot timer and returns the timer ID, which you can use with [[Manual:Lua_Functions#enableTimer|enableTimer()]], [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#killTimer|killTimer()]] functions. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and destroyed, so it will only go off once. Here is a [[Manual:Introduction#Timers|more detailed introduction to tempTimer]].<br />
<br />
;Parameters<br />
* ''time:'' The time in seconds for which to set the timer for - you can use decimals here for precision. The timer will go off ''x'' given seconds after you make it.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
* ''repeating'': (optional) if true, keep firing the timer over and over until you kill it (available in Mudlet 4.0+).<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- wait half a second and then run the command<br />
tempTimer(0.5, function() send("kill monster") end)<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
<br />
-- create a looping timer<br />
timerid = tempTimer(1, function() display("hello!") end, true)<br />
<br />
-- later when you'd like to stop it:<br />
killTimer(timerid)<br />
</syntaxhighlight><br />
<br />
{{note}} Double brackets, e.g: [[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
<br />
{{note}} Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<syntaxhighlight lang="lua"><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
<br />
-- tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</syntaxhighlight><br />
<br />
==tempTrigger==<br />
;tempTrigger(substring, code, expireAfter)<br />
:Creates a substring trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters:<br />
* ''substring'': The substring to look for - this means a part of the line. If your provided text matches anywhere within the line from the game, the trigger will go off.<br />
* ''code'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5)<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
Example:<br />
<syntaxhighlight lang="lua"><br />
-- this example will highlight the contents of the "target" variable.<br />
-- it will also delete the previous trigger it made when you call it again, so you're only ever highlighting one name<br />
if id then killTrigger(id) end<br />
id = tempTrigger(target, [[selectString("]] .. target .. [[", 1) fg("gold") resetFormat()]])<br />
<br />
-- you can also write the same line as:<br />
id = tempTrigger(target, function() selectString(target, 1) fg("gold") resetFormat() end)<br />
<br />
-- or like so if you have a highlightTarget() function somewhere<br />
id = tempTrigger(target, highlightTarget)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a simpler trigger to replace "hi" with "bye" whenever you see it<br />
tempTrigger("hi", [[selectString("hi", 1) replace("bye")]])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this trigger will go off only 2 times<br />
tempTrigger("hi", function() selectString("hi", 1) replace("bye") end, 2)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- table to store our trigger IDs in<br />
nameIDs = nameIDs or {}<br />
-- delete any existing triggers we've already got<br />
for _, id in ipairs(nameIDs) do killTrigger(id) end<br />
<br />
-- create new ones, avoiding lots of ]] [[ to embed the name<br />
for _, name in ipairs{"Alice", "Ashley", "Aaron"} do<br />
nameIDs[#nameIDs+1] = tempTrigger(name, function() print(" Found "..name.."!") end)<br />
end<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mudlet_Object_Functions&diff=15681Manual:Mudlet Object Functions2020-10-15T10:29:26Z<p>Smurf: /* tempAnsiColorTrigger */</p>
<hr />
<div>{{TOC right}}<br />
= Mudlet Object Functions =<br />
<br />
==adjustStopWatch==<br />
;adjustStopWatch(watchID/watchName, amount)<br />
: Adjusts the elapsed time on the stopwatch forward or backwards by the amount of time. It will work even on stopwatches that are not running, and thus can be used to preset a newly created stopwatch with a negative amount so that it runs down from a negative time towards zero at the preset time.<br />
<br />
;Parameters<br />
* watchID (number) / watchName (string): The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
* amount (decimal number): An amount in seconds to adjust the stopwatch by, positive amounts increase the recorded elapsed time.<br />
<br />
;Returns<br />
* true on success if the stopwatch was found and thus adjusted, or nil and an error message if not.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- demo of a persistent stopWatch used to real time a mission<br />
-- called with a positive number of seconds it will start a "missionStopWatch"<br />
-- unless there already is one in which case it will instead report on<br />
-- the deadline. use 'stopStopWatch("missionStopWatch")' when the mission<br />
-- is done and 'deleteStopWatch("missionStopWatch")' when the existing mission<br />
-- is to be disposed of. Until then repeated use of 'mission(interval)' will<br />
-- just give updates...<br />
function mission(time)<br />
local missionTimeTable = missionTimeTable or {}<br />
<br />
if createStopWatch("missionStopWatch") then<br />
adjustStopWatch("missionStopWatch", -tonumber(time))<br />
setStopWatchPersistence("missionStopWatch", true)<br />
missionTimeTable = getStopWatchBrokenDownTime("missionStopWatch")<br />
<br />
echo(string.format("Get cracking, you have %02i:%02i:%02i hg:m:s left.\n", missionTimeTable.hours, missionTimeTable.minutes, missionTimeTable.seconds))<br />
startStopWatch("missionStopWatch")<br />
else<br />
-- it already exists, so instead report what is/was the time on it<br />
--[=[ We know that the stop watch exists - we just need to find the ID<br />
so we can get the running detail which is only available from the getStopWatches()<br />
table and that is indexed by ID]=]<br />
for k,v in pairs(getStopWatches()) do<br />
if v.name == "missionStopWatch" then<br />
missionTimeTable = v<br />
end<br />
end<br />
if missionTimeTable.isRunning then<br />
if missionTimeTable.elapsedTime.negative then<br />
echo(string.format("Better hurry up, the clock is ticking on an existing mission and you only have %02i:%02i:%02i h:m:s left.\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
else<br />
echo(string.format("Bad news, you are past the deadline on an existing mission by %02i:%02i:%02i h:m:s !\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
end<br />
else<br />
if missionTimeTable.elapsedTime.negative then<br />
echo(string.format("Well done! You have already completed a mission %02i:%02i:%02i h:m:s before the deadline ...\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
else<br />
echo(string.format("Uh oh! You failed to meet the deadline on an existing mission by %02i:%02i:%02i h:m:s !\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
end<br />
end<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available from Mudlet 4.4.0<br />
<br />
==appendScript==<br />
;appendScript(scriptName, luaCode, [occurrence])<br />
: Appends Lua code to the script "scriptName". If no occurrence given it sets the code of the first found script.<br />
<br />
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#getScript|getScript()]], [[Manual:Lua_Functions#setScript|setScript()]]<br />
<br />
;Returns<br />
* a unique id number for that script.<br />
<br />
;Parameters<br />
* ''scriptName'': name of the script<br />
* ''luaCode'': scripts luaCode to append<br />
* ''occurence'': (optional) the occurrence of the script in case you have many with the same name<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example of appending the script lua code to the first occurrence of "testscript"<br />
appendScript("testscript", [[echo("This is a test\n")]], 1)<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==appendCmdLine==<br />
;appendCmdLine([name], text)<br />
: Appends text to the main input line.<br />
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, the text will be appended to the main commandline.<br />
* ''text'': text to append<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- adds the text "55 backpacks" to whatever is currently in the input line<br />
appendCmdLine("55 backpacks")<br />
<br />
-- makes a link, that when clicked, will add "55 backpacks" to the input line<br />
echoLink("press me", "appendCmdLine'55 backpack'", "Press me!")<br />
<br />
<br />
-- in use:<br />
lua mission(60*60)<br />
Get cracking, you have 01:00:00 h:m:s left.<br />
<br />
lua mission(60*60)<br />
Better hurry up, the clock is ticking on an existing mission and you only have 00:59:52 h:m:s left.<br />
</syntaxhighlight><br />
<br />
==clearCmdLine==<br />
;clearCmdLine([name])<br />
: Clears the input line of any text that's been entered.<br />
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, the main commandline's text will be cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- don't be evil with this!<br />
clearCmdLine()<br />
</syntaxhighlight><br />
<br />
==createStopWatch==<br />
;createStopWatch()<br />
From Mudlet 4.4.0:<br />
;createStopWatch([start immediately {assumed ''true'' if omitted}])<br />
;createStopWatch([name], [start immediately {assumed ''false'' if omitted}])<br />
<br />
: This function creates a stopwatch, a high resolution time measurement tool. Stopwatches can be started, stopped, reset, asked how much time has passed since the stop watch has been started and, following an update for Mudlet 4.4.0: be adjusted, given a name and be made persistent between sessions (so can time real-life things). Prior to 4.4.0 the function took no parameters '''and the stopwatch would start automatically when it was created'''.<br />
<br />
;Parameters:<br />
* ''start immediately'' (bool) used to override the behaviour prior to Mudlet 4.4.0 so that if it is the ''only'' argument then a ''false'' value will cause the stopwatch to be created but be in a ''stopped'' state, however if a name parameter is provided then this behaviour is assumed and then a ''true'' value is required should it be desired for the stopwatch to be started on creation. This difference between the cases with and without a name argument is to allow for older scripts to continue to work with 4.4.0 or later versions of Mudlet without change, yet to allow for more functionality - such as presetting a time when the stopwatch is created but not to start it counting down until some time afterwards - to be performed as well with a named stopwatch.<br />
<br />
* ''name'' (string) a ''unique'' text to use to identify the stopwatch.<br />
<br />
;Returns:<br />
* the ID (number) of a stopwatch; or, from '''4.4.0''': a nil + error message if the name has already been used.<br />
<br />
: See also: [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#resetStopWatch|resetStopWatch()]], [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]] or, from 4.4.0: [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatches|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]], [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]], [[Manual:Lua_Functions#setStopWatchPersistence|setStopWatchPersistence()]]<br />
<br />
;Example<br />
: (Prior to Mudlet 4.4.0) in a global script you can create all stop watches that you need in your system and store the respective stopWatch-IDs in global variables:<br />
<syntaxhighlight lang="lua"><br />
fightStopWatch = fightStopWatch or createStopWatch() -- create, or re-use a stopwatch, and store the watchID in a global variable to access it from anywhere<br />
<br />
-- then you can start the stop watch in some trigger/alias/script with:<br />
startStopWatch(fightStopWatch)<br />
<br />
-- to stop the watch and measure its time in e.g. a trigger script you can write:<br />
fightTime = stopStopWatch(fightStopWatch)<br />
echo("The fight lasted for " .. fightTime .. " seconds.")<br />
resetStopWatch(fightStopWatch)<br />
</syntaxhighlight><br />
<br />
: (From Mudlet 4.4.0) in a global script you can create all stop watches that you need in your system with unique names:<br />
<syntaxhighlight lang="lua"><br />
createStopWatch("fightStopWatch") -- this will fail if the given named stopwatch already exists so it will create it if needed<br />
<br />
-- then you can start the stop watch (if it is not already started) in some trigger/alias/script with:<br />
startStopWatch("fightStopWatch")<br />
<br />
-- to stop the watch and measure its time in e.g. a trigger script you can write:<br />
fightTime = stopStopWatch("fightStopWatch")<br />
echo("The fight lasted for " .. fightTime .. " seconds.")<br />
resetStopWatch("fightStopWatch")<br />
</syntaxhighlight><br />
<br />
:You can also measure the elapsed time without having to stop the stop watch (equivalent to getting a ''lap-time'') with [[#getStopWatchTime|getStopWatchTime()]].<br />
<br />
{{note}} it's best to re-use stopwatch IDs if you can for Mudlet prior to 4.4.0 as they cannot be deleted, so creating more and more would use more memory. From 4.4.0 the revised internal design has been changed such that there are no internal timers created for each stopwatch - instead either a timestamp or a fixed elapsed time record is used depending on whether the stopwatches is running or stopped so that there are no "moving parts" in the later design and less resources are used - and they can be removed if no longer required.<br />
<br />
==deleteStopWatch==<br />
;deleteStopWatch(watchID/watchName)<br />
<br />
: This function removes an existing stopwatch, whether it only exists for this session or is set to be otherwise saved between sessions by using [[Manual:Lua_Functions#setStopWatchPersistence|setStopWatchPersistence()]] with a ''true'' argument. <br />
<br />
;Parameters<br />
* ''watchID'' (number) / ''watchName'' (string): The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
<br />
;Returns:<br />
* ''true'' if the stopwatch was found and thus deleted, or ''nil'' and an error message if not - obviously using it twice with the same argument will fail the second time unless another one with the same name or ID was recreated before the second use. Note that an empty string as a name ''will'' find the lowest ID numbered ''unnamed'' stopwatch and that will then find the next lowest ID number of unnamed ones until there are none left, if used repetitively!<br />
<br />
<syntaxhighlight lang="lua"><br />
lua MyStopWatch = createStopWatch("stopwatch_mine")<br />
true<br />
<br />
lua display(MyStopWatch)<br />
4<br />
<br />
lua deleteStopWatch(MyStopWatch)<br />
true<br />
<br />
lua deleteStopWatch(MyStopWatch)<br />
nil<br />
<br />
"stopwatch with id 4 not found"<br />
<br />
lua deleteStopWatch("stopwatch_mine")<br />
nil<br />
<br />
"stopwatch with name "stopwatch_mine" not found"<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]],<br />
<br />
{{note}} Available from Mudlet version 4.4.0. Stopwatches that are NOT set to be '''persistent''' will be deleted automatically at the end of a session (or if [[Manual:Miscellaneous_Functions#resetProfile|resetProfile()]] is called).<br />
<br />
==disableAlias==<br />
;disableAlias(name)<br />
:Disables/deactivates the alias by its name. If several aliases have this name, they'll all be disabled. If you disable an alias group, all the aliases inside the group will be disabled as well.<br />
: See also: [[#enableAlias|enableAlias()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the alias. Passed as a string.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
--Disables the alias called 'my alias'<br />
disableAlias("my alias")<br />
</syntaxhighlight><br />
<br />
==disableKey==<br />
;disableKey(name)<br />
:Disables key a key (macro) or a key group. When you disable a key group, all keys within the group will be implicitly disabled as well.<br />
<br />
: See also: [[#enableKey|enableKey()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the key or group to identify what you'd like to disable.<br />
<br />
;Examples<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you could set multiple keys on the F1 key and swap their use as you wish by disabling and enabling them<br />
disableKey("attack macro")<br />
disableKey("jump macro")<br />
enableKey("greet macro")<br />
</syntaxhighlight><br />
{{note}} From Version '''3.10'' returns ''true'' if one or more keys or groups of keys were found that matched the name given or ''false'' if not; prior to then it returns ''true'' if there were '''any''' keys - whether they matched the name or not!<br />
<br />
==disableScript==<br />
;disableScript(name)<br />
:Disables a script that was previously enabled. Note that disabling a script only stops it from running in the future - it won't "undo" anything the script has made, such as labels on the screen.<br />
<br />
: See also: [[#permScript|permScript()]], [[#appendScript|appendScript()]], [[#enableScript|enableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]<br />
<br />
;Parameters<br />
* ''name'': name of the script.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Disables the script called 'my script'<br />
disableScript("my script")<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==disableTimer==<br />
;disableTimer(name)<br />
:Disables a timer from running it’s script when it fires - so the timer cycles will still be happening, just no action on them. If you’d like to permanently delete it, use [[Manual:Lua_Functions#killTrigger|killTrigger]] instead.<br />
<br />
: See also: [[#enableTimer|enableTimer()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Disables the timer called 'my timer'<br />
disableTimer("my timer")<br />
</syntaxhighlight><br />
<br />
==disableTrigger==<br />
;disableTrigger(name)<br />
:Disables a permanent (one in the trigger editor) or a temporary trigger. When you disable a group, all triggers inside the group are disabled as well<br />
<br />
: See also: [[#enableTrigger|enableTrigger()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Disables the trigger called 'my trigger'<br />
disableTrigger("my trigger")<br />
</syntaxhighlight><br />
<br />
==enableAlias==<br />
;enableAlias(name)<br />
:Enables/activates the alias by it’s name. If several aliases have this name, they’ll all be enabled.<br />
<br />
: See also: [[#disableAlias|disableAlias()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the alias ID that was returned by [[Manual:Lua_Functions#tempAlias|tempAlias]] on creation of the alias or the name of the alias in case of a GUI alias.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Enables the alias called 'my alias'<br />
enableAlias("my alias")<br />
</syntaxhighlight><br />
<br />
==enableKey==<br />
;enableKey(name)<br />
:Enables a key (macro) or a group of keys (and thus all keys within it that aren't explicitly deactivated).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the group that identifies the key.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you could use this to disable one key set for the numpad and activate another<br />
disableKey("fighting keys")<br />
enableKey("walking keys")<br />
</syntaxhighlight><br />
{{note}} From Version '''3.10'' returns ''true'' if one or more keys or groups of keys were found that matched the name given or ''false'' if not; prior to then it returns ''true'' if there were '''any''' keys - whether they matched the name or not!<br />
<br />
==enableScript==<br />
;enableScript(name)<br />
:Enables / activates a script that was previously disabled. <br />
<br />
: See also: [[#permScript|permScript()]], [[#appendScript|appendScript()]], [[#disableScript|disableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]<br />
<br />
;Parameters<br />
* ''name'': name of the script.<br />
<syntaxhighlight lang="lua"><br />
-- enable the script called 'my script' that you created in Mudlet's script section<br />
enableScript("my script")<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==enableTimer==<br />
;enableTimer(name)<br />
:Enables or activates a timer that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<syntaxhighlight lang="lua"><br />
-- enable the timer called 'my timer' that you created in Mudlets timers section<br />
enableTimer("my timer")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- or disable & enable a tempTimer you've made<br />
timerID = tempTimer(10, [[echo("hi!")]])<br />
<br />
-- it won't go off now<br />
disableTimer(timerID)<br />
-- it will continue going off again<br />
enableTimer(timerID)<br />
</syntaxhighlight><br />
<br />
==enableTrigger==<br />
;enableTrigger(name)<br />
:Enables or activates a trigger that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or by any other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.<br />
<syntaxhighlight lang="lua"><br />
-- enable the trigger called 'my trigger' that you created in Mudlets triggers section<br />
enableTrigger("my trigger")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- or disable & enable a tempTrigger you've made<br />
triggerID = tempTrigger("some text that will match in a line", [[echo("hi!")]])<br />
<br />
-- it won't go off now when a line with matching text comes by<br />
disableTrigger(triggerID)<br />
<br />
-- and now it will continue going off again<br />
enableTrigger(triggerID)<br />
</syntaxhighlight><br />
<br />
==exists==<br />
;exists(name, type)<br />
:Tells you how many things of the given type exist. <br />
<br />
{{note}} This function is only for objects created in the script editor or via perm* functions. You don't need it for temp* functions and will not work for them.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by the temp* function to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', 'timer', 'keybind' (Mudlet 3.2+), or 'script' (Mudlet 3.17+).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo("I have " .. exists("my trigger", "trigger") .. " triggers called 'my trigger'!")<br />
</syntaxhighlight><br />
<br />
: You can also use this alias to avoid creating duplicate things, for example:<br />
<syntaxhighlight lang="lua"><br />
-- this code doesn't check if an alias already exists and will keep creating new aliases<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
<br />
-- while this code will make sure that such an alias doesn't exist first<br />
-- we do == 0 instead of 'not exists' because 0 is considered true in Lua<br />
if exists("Attack", "alias") == 0 then<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
end<br />
</syntaxhighlight><br />
<br />
: Especially helpful when working with [[Manual:Lua_Functions#permTimer|permTimer]]:<br />
<syntaxhighlight lang="lua"><br />
if not exists("My animation timer", "timer") then<br />
vdragtimer = permTimer("My animation timer", "", .016, onVDragTimer) -- 60fps timer!<br />
end<br />
<br />
enableTimer("My animation timer")<br />
</syntaxhighlight><br />
<br />
==getButtonState==<br />
;getButtonState()<br />
:This function can be used within checkbox button scripts (2-state buttons) to determine the current state of the checkbox.<br />
<br />
:Returns ''2'' if button is checked, and ''1'' if it's not.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local checked = getButtonState()<br />
if checked == 1 then<br />
hideExits()<br />
else<br />
showExits()<br />
end<br />
</syntaxhighlight><br />
<br />
==getCmdLine==<br />
;getCmdLine([name])<br />
: Returns the current content of the given command line.<br />
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, it returns the text of the main commandline.<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replaces whatever is currently in the input line by "55 backpacks"<br />
printCmdLine("55 backpacks")<br />
<br />
--prints the text "55 backpacks" to the main console<br />
echo(getCmdLine())<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.1+<br />
<br />
==getStopWatches==<br />
;table = getStopWatches()<br />
<br />
: Returns a table of the details for each stopwatch in existence, the keys are the watch IDs but since there can be gaps in the ID number allocated for the stopwatches it will be necessary to use the ''pairs(...)'' rather than the ''ipairs(...)'' method to iterate through all of them in ''for'' loops!<br />
: Each stopwatch's details will list the following items: ''name'' (string), ''isRunning'' (boolean), ''isPersistent'' (boolean), ''elapsedTime'' (table). The last of these contains the same data as is returned by the results table from the [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]] function - namely ''days'' (positive integer), ''hours'' (integer, 0 to 23), ''minutes'' (integer, 0 to 59), ''second'' (integer, 0 to 59), ''milliSeconds'' (integer, 0 to 999), ''negative'' (boolean) with an additional ''decimalSeconds'' (number of seconds, with a decimal portion for the milli-seconds and possibly a negative sign, representing the whole elapsed time recorded on the stopwatch) - as would also be returned by the [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]] function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- on the command line:<br />
lua getStopWatches()<br />
-- could return something like:<br />
{<br />
{<br />
isPersistent = true,<br />
elapsedTime = {<br />
minutes = 15,<br />
seconds = 2,<br />
negative = false,<br />
milliSeconds = 66,<br />
hours = 0,<br />
days = 18,<br />
decimalSeconds = 1556102.066<br />
},<br />
name = "Playing time",<br />
isRunning = true<br />
},<br />
{<br />
isPersistent = true,<br />
elapsedTime = {<br />
minutes = 47,<br />
seconds = 1,<br />
negative = true,<br />
milliSeconds = 657,<br />
hours = 23,<br />
days = 2,<br />
decimalSeconds = -258421.657<br />
},<br />
name = "TMC Vote",<br />
isRunning = true<br />
},<br />
{<br />
isPersistent = false,<br />
elapsedTime = {<br />
minutes = 26,<br />
seconds = 36,<br />
negative = false,<br />
milliSeconds = 899,<br />
hours = 3,<br />
days = 0,<br />
decimalSeconds = 12396.899<br />
},<br />
name = "",<br />
isRunning = false<br />
},<br />
[5] = {<br />
isPersistent = false,<br />
elapsedTime = {<br />
minutes = 0,<br />
seconds = 38,<br />
negative = false,<br />
milliSeconds = 763,<br />
hours = 0,<br />
days = 0,<br />
decimalSeconds = 38.763<br />
},<br />
name = "",<br />
isRunning = true<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available from Mudlet 4.4.0 only.<br />
<br />
==getStopWatchTime==<br />
;time = getStopWatchTime(watchID [or watchName from Mudlet 4.4.0])<br />
: Returns the time as a decimal number of seconds with up to three decimal places to give a milli-seconds (thousandths of a second) resolution.<br />
: Please note that, prior to 4.4.0 it was not possible to retrieve the elapsed time after the stopwatch had been stopped, retrieving the time was not possible as the returned value then was an indeterminate, meaningless time; from the 4.4.0 release, however, the elapsed value can be retrieved at any time, even if the stopwatch has not been started since creation or modified with the [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]] function introduced in that release.<br />
<br />
: See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatch es|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]].<br />
<br />
:Returns a number<br />
<br />
;Parameters<br />
* ''watchID''<br />
: The ID number of the watch.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example of showing the time left on the stopwatch<br />
teststopwatch = teststopwatch or createStopWatch()<br />
startStopWatch(teststopwatch)<br />
echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))<br />
tempTimer(1, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])<br />
tempTimer(2, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])<br />
stopStopWatch(teststopwatch)<br />
</syntaxhighlight><br />
<br />
==getStopWatchBrokenDownTime==<br />
; brokenDownTimeTable = getStopWatchBrokenDownTime(watchID or watchName)<br />
: Returns the current stopwatch time, whether the stopwatch is running or is stopped, as a table, broken down into:<br />
* "days" (integer)<br />
* "hours" (integer, 0 to 23)<br />
* "minutes" (integer, 0 to 59)<br />
* "seconds" (integer, 0 to 59)<br />
* "milliSeconds" (integer, 0 to 999)<br />
* "negative" (boolean, true if value is less than zero)<br />
<br />
: See also: [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatch es|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]].<br />
<br />
;Parameters<br />
* ''watchID'' / ''watchName''<br />
: The ID number or the name of the watch.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--an example, showing the presetting of a stopwatch.<br />
<br />
--This will fail if the stopwatch with the given name<br />
-- already exists, but then we can use the existing one:<br />
local watchId = createStopWatch("TopMudSiteVoteStopWatch")<br />
if watchId ~= nil then<br />
-- so we have just created the stopwatch, we want it<br />
-- to be saved for future sessions:<br />
setStopWatchPersistence("TopMudSiteVoteStopWatch", true)<br />
-- and set it to count down the 12 hours until we can<br />
-- revote:<br />
adjustStopWatch("TopMudSiteVoteStopWatch", -60*60*12)<br />
-- and start it running<br />
startStopWatch("TopMudSiteVoteStopWatch")<br />
<br />
openWebPage("http://www.topmudsites.com/vote-wotmud.html")<br />
end<br />
<br />
--[[ now I can check when it is time to vote again, even when<br />
I stop the session and restart later by running the following<br />
from a perm timer - perhaps on a 15 minute interval. Note that<br />
when loaded in a new session the Id it gets is unlikely to be<br />
the same as that when it was created - but that is not a<br />
problem as the name is preserved and, if the timer is running<br />
when the profile is saved at the end of the session then the<br />
elapsed time will continue to increase to reflect the real-life<br />
passage of time:]]<br />
<br />
local voteTimeTable = getStopWatchBrokenDownTime("TopMudSiteVoteStopWatch")<br />
<br />
if voteTimeTable["negative"] then<br />
if voteTimeTable["hours"] == 0 and voteTimeTable["minutes"] < 30 then<br />
echo("Voting for WotMUD on Top Mud Site in " .. voteTimeTable["minutes"] .. " minutes...")<br />
end<br />
else<br />
echo("Oooh, it is " .. voteTimeTable["days"] .. " days, " .. voteTimeTable["hours"] .. " hours and " .. voteTimeTable["minutes"] .. " minutes past the time to Vote on Top Mud Site - doing it now!")<br />
openWebPage("http://www.topmudsites.com/vote-wotmud.html")<br />
resetStopWatch("TopMudSiteVoteStopWatch")<br />
adjustStopWatch("TopMudSiteVoteStopWatch", -60*60*12)<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available from Mudlet 4.7+<br />
<br />
==getScript==<br />
; getScript(scriptName, [occurrence])<br />
: Returns the script with the given name. If you have more than one script with the same name, specify the occurrence to pick a different one. Returns -1 if the script doesn't exist.<br />
<br />
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#setScript|setScript()]], [[Manual:Lua_Functions#appendScript|appendScript()]]<br />
<br />
;Parameters<br />
* ''scriptName'': name of the script.<br />
* ''occurrence'': (optional) occurence of the script in case you have many with the same name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the "New script" on screen<br />
print(getScript("New script"))<br />
<br />
-- an example of returning the script Lua code from the second occurrence of "testscript"<br />
test_script_code = getScript("testscript", 2)<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==invokeFileDialog==<br />
;invokeFileDialog(fileOrFolder, dialogTitle)<br />
:Opens a file chooser dialog, allowing the user to select a file or a folder visually. The function returns the selected path or "" if there was none chosen.<br />
<br />
;Parameters<br />
* ''fileOrFolder:'' ''true'' for file selection, ''false'' for folder selection.<br />
* ''dialogTitle'': what to say in the window title.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function whereisit()<br />
local path = invokeFileDialog(false, "Where should we save the file? Select a folder and click Open")<br />
<br />
if path == "" then return nil else return path end<br />
end<br />
</syntaxhighlight><br />
<br />
==isActive==<br />
;isActive(name, type)<br />
:You can use this function to check if something, or somethings, are active. <br />
:Returns the number of active things - and 0 if none are active. Beware that all numbers are true in Lua, including zero.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by temp* function to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', 'timer', 'keybind' (Mudlet 3.2+), or 'script' (Mudlet 3.17+).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo("I have " .. isActive("my trigger", "trigger") .. " currently active trigger(s) called 'my trigger'!")<br />
</syntaxhighlight><br />
<br />
==isPrompt==<br />
;isPrompt()<br />
:Returns true or false depending on if the line at the cursor position is a prompt. This infallible feature is available for MUDs that supply GA events (to check if yours is one, look to bottom-right of the main window - if it doesn’t say <No GA>, then it supplies them).<br />
<br />
:Example use could be as a Lua function, making closing gates on a prompt real easy.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a trigger pattern with 'Lua function', and this will trigger on every prompt!<br />
return isPrompt()<br />
</syntaxhighlight><br />
<br />
==killAlias==<br />
;killAlias(aliasID)<br />
:Deletes a temporary alias with the given ID.<br />
<br />
;Parameters<br />
* ''aliasID:''<br />
: The id returned by [[Manual:Lua_Functions#tempAlias|tempAlias]] to identify the alias.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- deletes the alias with ID 5<br />
killAlias(5)<br />
</syntaxhighlight><br />
<br />
==killKey==<br />
;killKey(name)<br />
:Deletes a keybinding with the given name. If several keybindings have this name, they'll all be deleted.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempKey|tempKey]] to identify the key.<br />
<br />
{{note}} Available in Mudlet 3.2+<br />
<br />
<syntaxhighlight lang="lua"><br />
-- make a temp key<br />
local keyid = tempKey(mudlet.key.F8, [[echo("hi!")]])<br />
<br />
-- delete the said temp key<br />
killKey(keyid)<br />
</syntaxhighlight><br />
<br />
==killTimer==<br />
;killTimer(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
{{note}} Non-temporary timers that you have set up in the GUI or by using [[#permTimer|permTimer]] cannot be deleted with this function. Use [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#enableTimer|enableTimer()]] to turn them on or off.<br />
<br />
;Parameters<br />
* ''id:'' the ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
: Returns true on success and false if the timer id doesn’t exist anymore (timer has already fired) or the timer is not a temp timer.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create the timer and remember the timer ID<br />
timerID = tempTimer(10, [[echo("hello!")]])<br />
<br />
-- delete the timer<br />
if killTimer(timerID) then echo("deleted the timer") else echo("timer is already deleted") end<br />
</syntaxhighlight><br />
<br />
==killTrigger==<br />
;killTrigger(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTrigger]], or a trigger made with one of the ''temp<type>Trigger()'' functions.<br />
<br />
{{note}} When used in out of trigger contexts, the triggers are disabled and deleted upon the next line received from the game - so if you are testing trigger deletion within an alias, the 'statistics' window will be reporting trigger counts that are disabled and pending removal, and thus are no cause for concern.<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the trigger id doesn’t exist anymore (trigger has already fired) or the trigger is not a temp trigger.<br />
<br />
==permAlias==<br />
;permAlias(name, parent, regex, lua code)<br />
<br />
:Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name you’d like the alias to have.<br />
* ''parent:'' <br />
: The name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''regex:''<br />
: The pattern that you’d like the alias to use.<br />
* ''lua code:'' <br />
: The script the alias will do when it matches.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- creates an alias called "new alias" in a group called "my group"<br />
permAlias("new alias", "my group", "^test$", [[echo ("say it works! This alias will show up in the script editor too.")]])<br />
</syntaxhighlight><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permAlias with the same name will keep creating new aliases. You can check if an alias already exists with the [[Manual:Lua_Functions#exists|exists]] function.<br />
<br />
==permGroup==<br />
;permGroup(name, itemtype, [parent])<br />
<br />
:Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts. <br />
;Parameters<br />
* ''name:''<br />
: The name of the new group item you want to create.<br />
* ''itemtype:''<br />
: The type of the item, can be trigger, alias, timer, or script.<br />
* ''parent:''<br />
: (optional) Name of existing item which the new item will be created as a child of.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</syntaxhighlight><br />
<br />
{{Note}} Added to Mudlet in the 2.0 final release. Parameter ''parent'' available in Mudlet 3.1+<br />
{{Note}} Itemtype script is available from Mudlet 4.7+<br />
<br />
==permPromptTrigger==<br />
;permPromptTrigger(name, parent, lua code)<br />
:Creates a persistent trigger for the in-game prompt that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
{{note}} If the trigger is not working, check that the '''N:''' bottom-right has a number. This feature requires telnet Go-Ahead (GA) or End-of-Record (EOR) to be enabled in your game. Available in Mudlet 3.6+<br />
<br />
;Parameters:<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
<br />
;Example: <br />
<syntaxhighlight lang="lua"><br />
permPromptTrigger("echo on prompt", "", [[echo("hey! this thing is working!\n")]])<br />
</syntaxhighlight><br />
<br />
<br />
==permRegexTrigger==<br />
;permRegexTrigger(name, parent, pattern table, lua code)<br />
:Creates a persistent trigger with one or more ''regex'' patterns that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a regex trigger that will match on the prompt to record your status<br />
permRegexTrigger("Prompt", "", {"^(\d+)h, (\d+)m"}, [[health = tonumber(matches[2]); mana = tonumber(matches[3])]])<br />
</syntaxhighlight><br />
{{note}} Mudlet by design allows duplicate names - so calling permRegexTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permBeginOfLineStringTrigger==<br />
;permBeginOfLineStringTrigger(name, parent, pattern table, lua code)<br />
:Creates a persistent trigger that stays after Mudlet is restarted and shows up in the Script Editor. The trigger will go off whenever one of the ''regex'' patterns it's provided with matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- Create a trigger that will match on anything that starts with "You sit" and do "stand".<br />
-- It will not go into any groups, so it'll be on the top.<br />
permBeginOfLineStringTrigger("Stand up", "", {"You sit"}, [[send ("stand")]])<br />
<br />
-- Another example - lets put our trigger into a "General" folder and give it several patterns.<br />
permBeginOfLineStringTrigger("Stand up", "General", {"You sit", "You fall", "You are knocked over by"}, [[send ("stand")]])<br />
</syntaxhighlight><br />
{{note}} Mudlet by design allows duplicate names - so calling permBeginOfLineStringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permSubstringTrigger==<br />
;permSubstringTrigger( name, parent, pattern table, lua code )<br />
:Creates a persistent trigger with one or more ''substring'' patterns that stays after Mudlet is restarted and shows up in the Script Editor.<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a trigger to highlight the word "pixie" for us<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie"},<br />
[[selectString(line, 1) bg("yellow") resetFormat()]])<br />
<br />
-- Or another trigger to highlight several different things<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie", "cat", "dog", "rabbit"},<br />
[[selectString(line, 1) fg ("blue") bg("yellow") resetFormat()]])<br />
</syntaxhighlight><br />
{{note}} Mudlet by design allows duplicate names - so calling permSubstringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permScript==<br />
;permScript(name, parent, lua code)<br />
: Creates a new script in the Script Editor that stays after Mudlet is restarted.<br />
<br />
;Parameters<br />
* ''name'': name of the script.<br />
* ''parent'': name of the script group you want the script to go in.<br />
* ''lua code'': is the code with string you are putting in your script.<br />
<br />
;Returns<br />
* a unique id number for that script.<br />
<br />
: See also: [[#enableScript|enableScript()]], [[#exists|exists()]], [[#appendScript|appendScript()]], [[#disableScript|disableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- create a script in the "first script group" group<br />
permScript("my script", "first script group", [[send ("my script that's in my first script group fired!")]])<br />
-- create a script that's not in any group; just at the top<br />
permScript("my script", "", [[send ("my script that's in my first script group fired!")]])<br />
<br />
-- enable Script - a script element is disabled at creation<br />
enableScript("my script")<br />
</syntaxhighlight><br />
<br />
{{note}} The script is called once but NOT active after creation, it will need to be enabled by [[#enableScript|enableScript()]].<br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permScript with the same name will keep creating new script elements. You can check if a script already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==permTimer==<br />
;permTimer(name, parent, seconds, lua code)<br />
: Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:name of the timer.<br />
* ''parent'' <br />
:name of the timer group you want the timer to go in.<br />
* ''seconds'' <br />
:a floating point number specifying a delay in seconds after which the timer will do the lua code (stored as the timer's "script") you give it as a string.<br />
* ''lua code'' is the code with string you are doing this to.<br />
<br />
;Returns<br />
* a unique id number for that timer.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- create a timer in the "first timer group" group<br />
permTimer("my timer", "first timer group", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
-- create a timer that's not in any group; just at the top<br />
permTimer("my timer", "", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
<br />
-- enable timer - they start off disabled until you're ready<br />
enableTimer("my timer")<br />
</syntaxhighlight><br />
<br />
{{note}} The timer is NOT active after creation, it will need to be enabled by a call to [[#enableTimer|enableTimer()]] before it starts.<br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permTimer with the same name will keep creating new timers. You can check if a timer already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permKey==<br />
;permKey(name, parent, [modifier], key code, lua code)<br />
: Creates a persistent key that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:name of the key.<br />
* ''parent'' <br />
:name of the timer group you want the timer to go in or "" for the top level.<br />
* ''modifier'' <br />
:(optional) modifier to use - can be one of ''mudlet.keymodifier.Control'', ''mudlet.keymodifier.Alt'', ''mudlet.keymodifier.Shift'', ''mudlet.keymodifier.Meta'', ''mudlet.keymodifier.Keypad'', or ''mudlet.keymodifier.GroupSwitch'' or the default value of ''mudlet.keymodifier.None'' which is used if the argument is omitted. To use multiple modifiers, add them together: ''(mudlet.keymodifier.Shift + mudlet.keymodifier.Control)''<br />
* ''key code'' <br />
: actual key to use - one of the values available in ''mudlet.key'', e.g. ''mudlet.key.Escape'', ''mudlet.key.Tab'', ''mudlet.key.F1'', ''mudlet.key.A'', and so on. The list is a bit long to list out in full so it is [https://github.com/Mudlet/Mudlet/blob/development/src/mudlet-lua/lua/KeyCodes.lua#L2 available here].<br />
: set to -1 if you want to create a key folder instead.<br />
* ''lua code'<br />
: code you would like the key to run.<br />
<br />
;Returns<br />
* a unique id number for that key.<br />
<br />
{{note}} Available in Mudlet 3.2+, creating key folders in Mudlet 4.10+<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- create a key at the top level for F8<br />
permKey("my key", "", mudlet.key.F8, [[echo("hey this thing actually works!\n")]])<br />
<br />
-- or Ctrl+F8<br />
permKey("my key", "", mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hey this thing actually works!\n")]])<br />
<br />
-- Ctrl+Shift+W<br />
permKey("jump keybinding", "", mudlet.keymodifier.Control + mudlet.keymodifier.Shift, mudlet.key.W, [[send("jump")]])<br />
</syntaxhighlight><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permKey with the same name will keep creating new keys. You can check if a key already exists with the [[Manual:Lua_Functions#exists|exists()]] function. The key will be created even if the lua code does not compile correctly - but this will be apparent as it will be seen in the Editor.<br />
<br />
==printCmdLine==<br />
;printCmdLine([name], text)<br />
<br />
: Replaces the current text in the input line, and sets it to the given text.<br />
: See also: [[Manual:Lua_Functions#clearCmdLine|clearCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, main commandline's text will be set.<br />
* ''text'': text to set<br />
<br />
<syntaxhighlight lang="lua"><br />
printCmdLine("say I'd like to buy ")<br />
</syntaxhighlight><br />
<br />
==raiseEvent==<br />
;raiseEvent(event_name, arg-1, … arg-n)<br />
<br />
: Raises the event event_name. The event system will call the main function (the one that is called exactly like the script name) of all such scripts in this profile that have registered event handlers. If an event is raised, but no event handler scripts have been registered with the event system, the event is ignored and nothing happens. This is convenient as you can raise events in your triggers, timers, scripts etc. without having to care if the actual event handling has been implemented yet - or more specifically how it is implemented. Your triggers raise an event to tell the system that they have detected a certain condition to be true or that a certain event has happened. How - and if - the system is going to respond to this event is up to the system and your trigger scripts don’t have to care about such details. For small systems it will be more convenient to use regular function calls instead of events, however, the more complicated your system will get, the more important events will become because they help reduce complexity very much.<br />
<br />
:The corresponding event handlers that listen to the events raised with raiseEvent() need to use the script name as function name and take the correct number of arguments. <br />
<br />
{{note}} possible arguments can be string, number, boolean, table, function, or nil.<br />
<br />
;Example:<br />
<br />
:raiseEvent("fight") a correct event handler function would be: myScript( event_name ). In this example raiseEvent uses minimal arguments, name the event name. There can only be one event handler function per script, but a script can still handle multiple events as the first argument is always the event name - so you can call your own special handlers for individual events. The reason behind this is that you should rather use many individual scripts instead of one huge script that has all your function code etc. Scripts can be organized very well in trees and thus help reduce complexity on large systems.<br />
<br />
Where the number of arguments that your event may receive is not fixed you can use [http://www.lua.org/manual/5.1/manual.html#2.5.9 ''...''] as the last argument in the ''function'' declaration to handle any number of arguments. For example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- try this function out with "lua myscripthandler(1,2,3,4)"<br />
function myscripthandler(a, b, ...)<br />
print("Arguments a and b are: ", a,b)<br />
-- save the rest of the arguments into a table<br />
local otherarguments = {...}<br />
print("Rest of the arguments are:")<br />
display(otherarguments)<br />
<br />
-- access specific otherarguments:<br />
print("First and second otherarguments are: ", otherarguments[1], otherarguments[2])<br />
end<br />
</syntaxhighlight><br />
<br />
==raiseGlobalEvent==<br />
;raiseGlobalEvent(event_name, arg-1, … arg-n)<br />
<br />
: Like [[Manual:Lua_Functions#raiseEvent|raiseEvent()]] this raises the event "event_name", but this event is sent to all '''other''' opened profiles instead. The profiles receive the event in circular alphabetical order (if profile "C" raised this event and we have profiles "A", "C", and "E", the order is "E" -> "A", but if "E" raised the event the order would be "A" -> "C"); execution control is handed to the receiving profiles so that means that long running events may lock up the profile that raised the event.<br />
<br />
: The sending profile's name is automatically appended as the last argument to the event.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- from profile called "My MUD" this raises an event "my event" with additional arguments 1, 2, 3, "My MUD" to all profiles except the original one<br />
raiseGlobalEvent("my event", 1, 2, 3)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available since Mudlet 3.1.0.<br />
<br />
Tip: you might want to add the [[Manual:Miscellaneous_Functions#getProfileName|profile name]] to your plain [[Manual:Miscellaneous_Functions#raiseEvent|raiseEvent()]] arguments. This'll help you tell which profile your event came from similar to [[#raiseGlobalEvent|raiseGlobalEvent()]].<br />
<br />
==remainingTime==<br />
;remainingTime(timer id number or name)<br />
<br />
: Returns the remaining time in floating point form in seconds (if it is active) for the timer (temporary or permanent) with the id number or the (first) one found with the name.<br />
: If the timer is inactive or has expired or is not found it will return a ''nil'' and an ''error message''. It, theoretically could also return 0 if the timer is overdue, i.e. it has expired but the internal code has not yet been run but that has not been seen in during testing. Permanent ''offset timers'' will only show as active during the period when they are running after their parent has expired and started them.<br />
<br />
{{Note}} Available in Mudlet since 3.20.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
tid = tempTimer(600, [[echo("\nYour ten minutes are up.\n")]])<br />
echo("\nYou have " .. remainingTime(tid) .. " seconds left, use it wisely... \n")<br />
<br />
-- Will produce something like:<br />
<br />
You have 599.923 seconds left, use it wisely... <br />
<br />
-- Then ten minutes time later:<br />
<br />
Your ten minutes are up.<br />
<br />
</syntaxhighlight><br />
<br />
==resetProfileIcon==<br />
;resetProfileIcon()<br />
: Resets the profile's icon in the connection screen to default.<br />
<br />
See also: [[#setProfileIcon|setProfileIcon()]].<br />
<br />
{{Note}} Available in Mudlet 4.0+.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
resetProfileIcon()<br />
</syntaxhighlight><br />
<br />
==resetStopWatch==<br />
;resetStopWatch(watchID)<br />
:This function resets the time to 0:0:0.0, but does not start the stop watch. You can start it with [[Manual:Lua_Functions#startStopWatch | startStopWatch]] → [[Manual:Lua_Functions#createStopWatch | createStopWatch]]<br />
<br />
==setConsoleBufferSize==<br />
;setConsoleBufferSize([consoleName], linesLimit, sizeOfBatchDeletion)<br />
:Sets the maximum number of lines a buffer (main window or a miniconsole) can hold. Default is 10,000.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: (optional) The name of the window. If omitted, uses the main console.<br />
* ''linesLimit:''<br />
: Sets the amount of lines the buffer should have. <br />
{{note}} Mudlet performs extremely efficiently with even huge numbers, but there is of course a limit to your computer's memory. As of Mudlet 4.7+, this amount will be capped to that limit on macOS and Linux (on Windows, it's capped lower as Mudlet on Windows is 32bit).<br />
* ''sizeOfBatchDeletion:''<br />
: Specifies how many lines should Mudlet delete at once when you go over the limit - it does it in bulk because it's efficient to do so.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sets the main windows size to 1 million lines maximum - which is more than enough!<br />
setConsoleBufferSize("main", 1000000, 1000)<br />
</syntaxhighlight><br />
<br />
==setProfileIcon==<br />
;setProfileIcon(iconPath)<br />
:Set a custom icon for this profile in the connection screen. <br />
<br />
:Returns true if successful, or nil+error message if not.<br />
<br />
:See also: [[#resetProfileIcon|resetProfileIcon()]].<br />
<br />
{{note}} Available in Mudlet 4.0+<br />
<br />
;Parameters<br />
* ''iconPath:''<br />
: Full location of the icon - can be .png or .jpg with ideal dimensions of 120x30.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set a custom icon that is located in an installed package called "mypackage"<br />
setProfileIcon(getMudletHomeDir().."/mypackage/icon.png")<br />
</syntaxhighlight><br />
<br />
==setScript==<br />
;setScript(scriptName, luaCode, [occurrence])<br />
: Sets the script's Lua code, replacing existing code. If you have many scripts with the same name, use the 'occurrence' parameter to choose between them.<br />
: If you'd like to add code instead of replacing it, have a look at [[Manual:Lua_Functions#appendScript|appendScript()]].<br />
: Returns -1 if the script isn't found - to create a script, use [[Manual:Lua_Functions#permScript|permScript()]].<br />
<br />
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#getScript|getScript()]], [[Manual:Lua_Functions#appendScript|appendScript()]]<br />
<br />
;Returns<br />
* a unique id number for that script.<br />
<br />
;Parameters<br />
* ''scriptName'': name of the script to change the code.<br />
* ''luaCode'': new Lua code to set.<br />
* ''occurrence'': The position of the script. Optional, defaults to 1 (first).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example of setting the script lua code from the first occurrence of "testscript"<br />
setScript("testscript", [[echo("This is a test\n")]], 1)<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==setStopWatchName==<br />
;setStopWatchName(watchID/currentStopWatchName, newStopWatchName)<br />
<br />
;Parameters<br />
* ''watchID'' (number) / ''currentStopWatchName'' (string): The stopwatch ID you get from [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name supplied to that function at that time, or previously applied with this function.<br />
* ''newStopWatchName'' (string): The name to use for this stopwatch from now on.<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found.<br />
<br />
{{note}} Either ''currentStopWatchName'' or ''newStopWatchName'' may be empty strings: if the first of these is so then the ''lowest'' ID numbered stopwatch without a name is chosen; if the second is so then an existing name is removed from the chosen stopwatch.<br />
<br />
==setStopWatchPersistence==<br />
;setStopWatchPersistence(watchID/watchName, state)<br />
<br />
;Parameters<br />
* ''watchID'' (number) / ''watchName'' (string): The stopwatch ID you get from [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name supplied to that function or applied later with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]]<br />
* ''state'' (boolean): if ''true'' the stopWatch will be saved.<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found.<br />
<br />
:Sets or resets the flag so that the stopwatch is saved between sessions or after a [[Manual:Miscellaneous_Functions#resetProfile|resetProfile()]] call. If set then, if ''stopped'' the elapsed time recorded will be unchanged when the stopwatch is reloaded in the next session; if ''running'' the elapsed time will continue to increment and it will include the time that the profile was not loaded, therefore it can be used to measure events in real-time, outside of the profile!<br />
<br />
{{note}} When a persistent stopwatch is reloaded in a later session (or after a use of ''resetProfile()'') the stopwatch may not be allocated the same ID number as before - therefore it is advisable to assign any persistent stopwatches a name, either when it is created or before the session is ended.<br />
<br />
==setTriggerStayOpen==<br />
;setTriggerStayOpen(name, number)<br />
:Sets for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched - so this allows you to extend or shorten the ''fire length'' of a trigger. The main use of this function is to close a chain when a certain condition has been met.<br />
<br />
;Parameters<br />
* ''name:'' The name of the trigger which has a fire length set (and which opens the chain).<br />
* ''number'': 0 to close the chain, or a positive number to keep the chain open that much longer.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if you have a trigger that opens a chain (has some fire length) and you'd like it to be closed <br />
-- on the next prompt, you could make a trigger inside the chain with a Lua function pattern of:<br />
return isPrompt()<br />
-- and a script of:<br />
setTriggerStayOpen("Parent trigger name", 0)<br />
-- to close it on the prompt!<br />
</syntaxhighlight><br />
<br />
==startStopWatch==<br />
;startStopWatch(watchID, [resetAndRestart])<br />
;startStopWatch(watchName)<br />
<br />
:Stopwatches can be stopped (with [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]]) and then re-started any number of times. '''To ensure backwards compatibility, if the stopwatch is identified by a ''numeric'' argument then, ''unless a second argument of false is supplied as well'' this function will also reset the stopwatch to zero and restart it - whether it is running or not'''; otherwise only a stopped watch can be started and only a started watch may be stopped. Trying to repeat either will produce a nil and an error message instead; also the recorded time is no longer reset so that they can now be used to record a total of isolated periods of time like a real stopwatch.<br />
<br />
:See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]]<br />
<br />
;Parameters<br />
* ''watchID''/''watchName'': The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], or from '''4.4.0''' the name assigned with that function or [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
* ''resetAndRestart'': Boolean flag needed (as ''false'') to make the function from '''4.4.0''', when supplied with a numeric watch ID, to '''not''' reset the stopwatch and only start a previously stopped stopwatch. This behavior is automatic when a string watch name is used to identify the stopwatch but differs from how the function behaved prior to that version.<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found or if it cannot be started (because the later style behavior was indicated and it was already running).<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- this is a common pattern for re-using stopwatches prior to 4.4.0 and starting them:<br />
watch = watch or createStopWatch()<br />
startStopWatch(watch)<br />
</syntaxhighlight><br />
<br />
:: After 4.4.0 the above code will work the same as it does not provide a second argument to the ''startStopWatch()'' function - if a ''false'' was used there it would be necessary to call ''stopStopWatch(...)'' and then ''resetStopWatch(...)'' before using ''startStopWatch(...)'' to re-use the stopwatch if the ID form is used, '''this is thus not quite the same behavior but it is more consistent with the model of how a real stopwatch would act.'''<br />
<br />
==stopStopWatch==<br />
;stopStopWatch(watchID or watchName)<br />
:"Stops" (though see the note below) the stop watch and returns (only the '''first''' time it is called after the stopwatch has been set running with [[Manual:Lua_Functions#startStopWatch()|startStopWatchTime()]]) the elapsed time as a number of seconds, with a decimal portion give a resolution in milliseconds (thousandths of a second). You can also retrieve the current time without stopping the stopwatch with [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]], [[Manual:Lua_Functions#getBrokenDownStopWatchTime|getBrokenDownStopWatchTime()]].<br />
<br />
:See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
<br />
;Parameters<br />
* ''watchID:'' The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or from Mudlet '''4.4.0''' the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
<br />
;Returns<br />
* the elapsed time as a floating-point number of seconds - it may be negative if the time was previously adjusted/preset to a negative amount (with [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]]) and that period has not yet elapsed.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- this is a common pattern for re-using stopwatches and starting them:<br />
watch = watch or createStopWatch()<br />
startStopWatch(watch)<br />
<br />
-- do some long-running code here ...<br />
<br />
print("The code took: "..stopStopWatch(watch).."s to run.")<br />
</syntaxhighlight><br />
<br />
==tempAnsiColorTrigger==<br />
;tempAnsiColorTrigger(foregroundColor, [backgroundColor,] code[, expireAfter])<br />
:This is an alternative to [[Manual:Lua_Functions#tempColorTrigger|tempColorTrigger()]] which supports the full set of 256 ANSI color codes directly and makes a color trigger that triggers on the specified foreground and background color. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code to do'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function.<br />
* ''expireAfter'': Delete trigger after a specified number of matches. You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
''BackgroundColor'' and/or ''expireAfter'' may be omitted.<br />
<br />
;Color codes (note that the values greater than or equal to zero are the actual number codes that ANSI and the game server uses for the 8/16/256 color modes)<br />
<br />
::Special codes (may be extended in the future):<br />
:::-2 = default text color (what is used after an ANSI SGR 0 m code that resets the foreground and background colors to those set in the preferences)<br />
:::-1 = ignore (only '''one''' of the foreground or background codes can have this value - otherwise it would not be a ''color'' trigger!)<br />
<br />
::ANSI 8-color set:<br />
:::0 = (dark) black<br />
:::1 = (dark) red<br />
:::2 = (dark) green<br />
:::3 = (dark) yellow<br />
:::4 = (dark) blue<br />
:::5 = (dark) magenta<br />
:::6 = (dark) cyan<br />
:::7 = (dark) white {a.k.a. light gray}<br />
<br />
::Additional colors in 16-color set:<br />
:::8 = light black {a.k.a. dark gray}<br />
:::9 = light red<br />
:::10 = light green<br />
:::11 = light yellow<br />
:::12 = light blue<br />
:::13 = light magenta<br />
:::14 = light cyan<br />
:::15 = light white<br />
<br />
::6 x 6 x 6 RGB (216) colors, shown as a 3x2-digit hex code<br />
:::16 = #000000<br />
:::17 = #000033<br />
:::18 = #000066<br />
:::...<br />
:::229 = #FFFF99<br />
:::230 = #FFFFCC<br />
:::231 = #FFFFFF<br />
<br />
::24 gray-scale, also show as a 3x2-digit hex code<br />
:::232 = #000000<br />
:::233 = #0A0A0A<br />
:::234 = #151515<br />
:::...<br />
:::253 = #E9E9E9<br />
:::254 = #F4F4F4<br />
:::255 = #FFFFFF<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- This script will re-highlight all text in a light cyan foreground color on any background with a red foreground color<br />
-- until another foreground color in the current line is being met. temporary color triggers do not offer match_all<br />
-- or filter options like the GUI color triggers because this is rarely necessary for scripting.<br />
-- A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempAnsiColorTrigger(14, -1, [[selectString(matches[1],1) fg("red")]])<br />
-- or:<br />
tempAnsiColorTrigger(14, -1, function()<br />
selectString(matches[1], 1)<br />
fg("red")<br />
end)<br />
<br />
-- match the trigger only 4 times<br />
tempColorTrigger(14, -1, [[selectString(matches[1],1) fg("red")]], 4)<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==tempAlias==<br />
;aliasID = tempAlias(regex, code to do)<br />
:Creates a temporary alias - temporary in the sense that it won't be saved when Mudlet restarts (unless you re-create it). The alias will go off as many times as it matches, it is not a one-shot alias. The function returns an ID for subsequent [[Manual:Lua_Functions#enableAlias|enableAlias()]], [[Manual:Lua_Functions#disableAlias|disableAlias()]] and [[Manual:Lua_Functions#killAlias|killAlias()]] calls.<br />
<br />
;Parameters<br />
* ''regex:'' Alias pattern in regex.<br />
* ''code to do:'' The code to do when the alias fires - wrap it in [[ ]].<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
myaliasID = tempAlias("^hi$", [[send ("hi") echo ("we said hi!")]])<br />
<br />
-- you can also delete the alias later with:<br />
killAlias(myaliasID)<br />
</syntaxhighlight><br />
<br />
==tempBeginOfLineTrigger==<br />
;tempBeginOfLineTrigger(part of line, code, expireAfter)<br />
:Creates a trigger that will go off whenever the part of line it's provided with matches the line right from the start (doesn't matter what the line ends with). The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
<br />
;Parameters<br />
* ''part of line'': start of the line that you'd like to match. This can also be regex.<br />
* ''code to do'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
mytriggerID = tempBeginOfLineTrigger("Hello", [[echo("We matched!")]])<br />
<br />
--[[ now this trigger will match on any of these lines:<br />
Hello<br />
Hello!<br />
Hello, Bob!<br />
<br />
but not on:<br />
Oh, Hello<br />
Oh, Hello!<br />
]]<br />
<br />
-- or as a function:<br />
mytriggerID = tempBeginOfLineTrigger("Hello", function() echo("We matched!") end)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can make the trigger match only a certain amount of times as well, 5 in this example:<br />
tempBeginOfLineTrigger("This is the start of the line", function() echo("We matched!") end, 5)<br />
<br />
-- if you want a trigger match not to count towards expiration, return true. In this example it'll match 5 times unless the line is "Start of line and this is the end."<br />
tempBeginOfLineTrigger("Start of line", <br />
function()<br />
if line == "Start of line and this is the end." then<br />
return true<br />
else<br />
return false<br />
end<br />
end, 5)<br />
</syntaxhighlight><br />
<br />
==tempButton==<br />
;tempButton(toolbar name, button text, orientation)<br />
:Creates a temporary button. Temporary means, it will disappear when Mudlet is closed.<br />
<br />
;Parameters:<br />
* ''toolbar name'': The name of the toolbar to place the button into.<br />
* ''button text'': The text to display on the button.<br />
* ''orientation'': a number 0 or 1 where 0 means horizontal orientation for the button and 1 means vertical orientation for the button. This becomes important when you want to have more than one button in the same toolbar.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- makes a temporary toolbar with two buttons at the top of the main Mudlet window <br />
lua tempButtonToolbar("topToolbar", 0, 0)<br />
lua tempButton("topToolbar", "leftButton", 0)<br />
lua tempButton("topToolbar", "rightButton", 0)<br />
</syntaxhighlight><br />
<br />
{{note}} ''This function is not that useful as there is no function yet to assign a Lua script or command to such a temporary button - though it may have some use to flag a status indication!''<br />
<br />
==tempButtonToolbar==<br />
;tempButtonToolbar(name, location, orientation)<br />
:Creates a temporary button toolbar. Temporary means, it will disappear when Mudlet is closed.<br />
<br />
;Parameters:<br />
* ''name'': The name of the toolbar.<br />
* ''location'': a number from 0 to 3, where 0 means "at the top of the screen", 1 means "left side", 2 means "right side" and 3 means "in a window of its own" which can be dragged and attached to the main Mudlet window if needed.<br />
* ''orientation'': a number 0 or 1, where 0 means horizontal orientation for the toolbar and 1 means vertical orientation for the toolbar. This becomes important when you want to have more than one toolbar in the same location of the window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- makes a temporary toolbar with two buttons at the top of the main Mudlet window <br />
lua tempButtonToolbar("topToolbar", 0, 0)<br />
lua tempButton("topToolbar", "leftButton", 0)<br />
lua tempButton("topToolbar", "rightButton", 0)<br />
</syntaxhighlight><br />
<br />
==tempColorTrigger==<br />
;tempColorTrigger(foregroundColor, backgroundColor, code, expireAfter)<br />
:Makes a color trigger that triggers on the specified foreground and background color. Both colors need to be supplied in form of these simplified ANSI 16 color mode codes. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code to do'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Color codes<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- This script will re-highlight all text in blue foreground colors on a black background with a red foreground color<br />
-- on a blue background color until another color in the current line is being met. temporary color triggers do not <br />
-- offer match_all or filter options like the GUI color triggers because this is rarely necessary for scripting. <br />
-- A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempColorTrigger(9, 2, [[selectString(matches[1],1) fg("red") bg("blue")]])<br />
-- or:<br />
tempColorTrigger(9, 2, function()<br />
selectString(matches[1], 1)<br />
fg("red")<br />
bg("blue")<br />
end)<br />
<br />
-- match the trigger only 4 times<br />
tempColorTrigger(9, 2, [[selectString(matches[1],1) fg("red") bg("blue")]], 4)<br />
</syntaxhighlight><br />
<br />
==tempComplexRegexTrigger==<br />
;tempComplexRegexTrigger(name, regex, code, multiline, fg color, bg color, filter, match all, highlight fg color, highlight bg color, play sound file, fire length, line delta, expireAfter)<br />
:Allows you to create a temporary trigger in Mudlet, using any of the UI-available options. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
:Returns the trigger name, that you can use [[Manual:Lua_Functions#killTrigger|killTrigger()]] later on with.<br />
<br />
;Parameters<br />
* ''name'' - The name you call this trigger. <br />
* ''regex'' - The regular expression you want to match.<br />
* ''code'' - Code to do when the trigger runs. You need to wrap it in [[ ]], or give a Lua function (since Mudlet 3.5.0).<br />
* ''multiline'' - Set this to 1, if you use multiple regex (see note below), and you need the trigger to fire only if all regex have been matched within the specified line delta. Then all captures will be saved in ''multimatches'' instead of ''matches''. If this option is set to 0, the trigger will fire when any regex has been matched.<br />
* ''fg color'' - The foreground color you'd like to trigger on.<br />
* ''bg color'' - The background color you'd like to trigger on.<br />
* ''filter'' - Do you want only the filtered content (=capture groups) to be passed on to child triggers? Otherwise also the initial line.<br />
* ''match all'' - Set to 1, if you want the trigger to match all possible occurrences of the regex in the line. When set to 0, the trigger will stop after the first successful match.<br />
* ''highlight fg color'' - The foreground color you'd like your match to be highlighted in.<br />
* ''highlight bg color'' - The background color you'd like your match to be highlighted in.<br />
* ''play sound file'' - Set to the name of the sound file you want to play upon firing the trigger.<br />
* ''fire length'' - Number of lines within which all condition must be true to fire the trigger.<br />
* ''line delta'' - Keep firing the script for x more lines, after the trigger or chain has matched.<br />
* ''expireAfter'' - Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
{{Note}} Set the options starting at ''multiline'' to 0, if you don't want to use those options. Otherwise enter 1 to activate or the value you want to use.<br />
<br />
{{Note}} If you want to use the color option, you need to provide both fg and bg together.<br />
<br />
;Examples<br />
<br />
<syntaxhighlight lang="lua"><br />
-- This trigger will be activated on any new line received.<br />
triggerNumber = tempComplexRegexTrigger("anyText", "^(.*)$", [[echo("Text received!")]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)<br />
<br />
-- This trigger will match two different regex patterns:<br />
tempComplexRegexTrigger("multiTrigger", "first regex pattern", [[]], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)<br />
tempComplexRegexTrigger("multiTrigger", "second regex pattern", [[echo("Trigger matched!")]], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)<br />
</syntaxhighlight><br />
<br />
{{Note}} For making a multiline trigger like in the second example, you need to use the same trigger name and options, providing the new pattern to add. Note that only the last script given will be set, any others ignored.<br />
<br />
==tempExactMatchTrigger==<br />
;tempExactMatchTrigger(exact line, code, expireAfter)<br />
:Creates a trigger that will go off whenever the line from the game matches the provided line exactly (ends the same, starts the same, and looks the same). You don't need to use any of the regex symbols here (^ and $). The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters<br />
* ''exact line'': exact line you'd like to match.<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
mytriggerID = tempExactMatchTrigger("You have recovered balance on all limbs.", [[echo("We matched!")]])<br />
<br />
-- as a function:<br />
mytriggerID = tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("We matched!") end)<br />
<br />
-- expire after 4 matches:<br />
tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("Got balance back!\n") end, 4)<br />
<br />
-- you can also avoid expiration by returning true:<br />
tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("Got balance back!\n") return true end, 4)<br />
</syntaxhighlight><br />
<br />
==tempKey==<br />
;tempKey([modifier], key code, lua code)<br />
:Creates a keybinding. This keybinding isn't temporary in the sense that it'll go off only once (it'll go off as often as you use it), but rather it won't be saved when Mudlet is closed.<br />
<br />
: See also: [[#permKey|permKey()]], [[#killKey|killKey()]]<br />
<br />
* ''modifier'' <br />
:(optional) modifier to use - can be one of ''mudlet.keymodifier.Control'', ''mudlet.keymodifier.Alt'', ''mudlet.keymodifier.Shift'', ''mudlet.keymodifier.Meta'', ''mudlet.keymodifier.Keypad'', or ''mudlet.keymodifier.GroupSwitch'' or the default value of ''mudlet.keymodifier.None'' which is used if the argument is omitted. To use multiple modifiers, add them together: ''(mudlet.keymodifier.Shift + mudlet.keymodifier.Control)''<br />
* ''key code'' <br />
: actual key to use - one of the values available in ''mudlet.key'', e.g. ''mudlet.key.Escape'', ''mudlet.key.Tab'', ''mudlet.key.F1'', ''mudlet.key.A'', and so on. The list is a bit long to list out in full so it is [https://github.com/Mudlet/Mudlet/blob/development/src/mudlet-lua/lua/KeyCodes.lua#L2 available here].<br />
* ''lua code'<br />
: code you'd like the key to run - wrap it in [[ ]].<br />
<br />
;Returns<br />
* a unique id number for that key.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
local keyID = tempKey(mudlet.key.F8, [[echo("hi")]])<br />
<br />
local anotherKeyID = tempKey(mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hello")]])<br />
<br />
-- bind Ctrl+Shift+W:<br />
tempKey(mudlet.keymodifier.Control + mudlet.keymodifier.Shift, mudlet.key.W, [[send("jump")]])<br />
<br />
-- delete it if you don't like it anymore<br />
killKey(keyID)<br />
</syntaxhighlight><br />
<br />
==tempLineTrigger==<br />
;tempLineTrigger(from, howMany, code, expireAfter)<br />
:Temporary trigger that will fire on ''n'' consecutive lines following the current line. This is useful to parse output that is known to arrive in a certain line margin or to delete unwanted output from the MUD - the trigger does not require any patterns to match on. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters:<br />
* ''from'': from which line after this one should the trigger activate - 1 will activate right on the next line.<br />
* ''howMany'': how many lines to run for after the trigger has activated.<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Example: <br />
<syntaxhighlight lang="lua"><br />
-- Will fire 3 times with the next line from the MUD.<br />
tempLineTrigger(1, 3, function() print(" trigger matched!") end)<br />
<br />
-- Will fire 20 lines after the current line and fire twice on 2 consecutive lines, 7 times.<br />
tempLineTrigger(20, 2, function() print(" trigger matched!") end, 7)<br />
</syntaxhighlight><br />
<br />
==tempPromptTrigger==<br />
;tempPromptTrigger(code, expireAfter)<br />
:Temporary trigger that will match on the games prompt. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
{{note}} If the trigger is not working, check that the '''N:''' bottom-right has a number. This feature requires telnet Go-Ahead to be enabled in the game. Available in Mudlet 3.6+<br />
<br />
;Parameters:<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function.<br />
* ''expireAfter'': Delete trigger after a specified number of matches. You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
{{note}} ''expireAfter'' is available since Mudlet 3.11<br />
<br />
;Example: <br />
<syntaxhighlight lang="lua"><br />
tempPromptTrigger(function()<br />
echo("hello! this is a prompt!")<br />
end)<br />
<br />
-- match only 2 times:<br />
tempPromptTrigger(function()<br />
echo("hello! this is a prompt!")<br />
end, 2)<br />
<br />
-- match only 2 times, unless the prompt is "55 health."<br />
tempPromptTrigger(function()<br />
if line == "55 health." then return true end<br />
end, 2)<br />
</syntaxhighlight><br />
<br />
==tempRegexTrigger==<br />
;tempRegexTrigger(regex, code, expireAfter)<br />
:Creates a temporary regex trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters:<br />
* ''regex:'' regular expression that lines will be matched on.<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- create a non-duplicate trigger that matches on any line and calls a function<br />
html5log = html5log or {}<br />
if html5log.trig then killTrigger(html5log.trig) end<br />
html5log.trig = tempRegexTrigger("^", [[html5log.recordline()]])<br />
-- or a simpler variant:<br />
html5log.trig = tempRegexTrigger("^", html5log.recordline)<br />
<br />
-- only match 3 times:<br />
tempRegexTrigger("^You prick (.+) twice in rapid succession with", function() echo("Hit "..matches[2].."!\n") end, 3)<br />
</syntaxhighlight><br />
<br />
==tempTimer==<br />
;tempTimer(time, code to do[, repeating])<br />
:Creates a temporary one-shot timer and returns the timer ID, which you can use with [[Manual:Lua_Functions#enableTimer|enableTimer()]], [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#killTimer|killTimer()]] functions. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and destroyed, so it will only go off once. Here is a [[Manual:Introduction#Timers|more detailed introduction to tempTimer]].<br />
<br />
;Parameters<br />
* ''time:'' The time in seconds for which to set the timer for - you can use decimals here for precision. The timer will go off ''x'' given seconds after you make it.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
* ''repeating'': (optional) if true, keep firing the timer over and over until you kill it (available in Mudlet 4.0+).<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- wait half a second and then run the command<br />
tempTimer(0.5, function() send("kill monster") end)<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
<br />
-- create a looping timer<br />
timerid = tempTimer(1, function() display("hello!") end, true)<br />
<br />
-- later when you'd like to stop it:<br />
killTimer(timerid)<br />
</syntaxhighlight><br />
<br />
{{note}} Double brackets, e.g: [[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
<br />
{{note}} Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<syntaxhighlight lang="lua"><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
<br />
-- tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</syntaxhighlight><br />
<br />
==tempTrigger==<br />
;tempTrigger(substring, code, expireAfter)<br />
:Creates a substring trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters:<br />
* ''substring'': The substring to look for - this means a part of the line. If your provided text matches anywhere within the line from the game, the trigger will go off.<br />
* ''code'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5)<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
Example:<br />
<syntaxhighlight lang="lua"><br />
-- this example will highlight the contents of the "target" variable.<br />
-- it will also delete the previous trigger it made when you call it again, so you're only ever highlighting one name<br />
if id then killTrigger(id) end<br />
id = tempTrigger(target, [[selectString("]] .. target .. [[", 1) fg("gold") resetFormat()]])<br />
<br />
-- you can also write the same line as:<br />
id = tempTrigger(target, function() selectString(target, 1) fg("gold") resetFormat() end)<br />
<br />
-- or like so if you have a highlightTarget() function somewhere<br />
id = tempTrigger(target, highlightTarget)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a simpler trigger to replace "hi" with "bye" whenever you see it<br />
tempTrigger("hi", [[selectString("hi", 1) replace("bye")]])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this trigger will go off only 2 times<br />
tempTrigger("hi", function() selectString("hi", 1) replace("bye") end, 2)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- table to store our trigger IDs in<br />
nameIDs = nameIDs or {}<br />
-- delete any existing triggers we've already got<br />
for _, id in ipairs(nameIDs) do killTrigger(id) end<br />
<br />
-- create new ones, avoiding lots of ]] [[ to embed the name<br />
for _, name in ipairs{"Alice", "Ashley", "Aaron"} do<br />
nameIDs[#nameIDs+1] = tempTrigger(name, function() print(" Found "..name.."!") end)<br />
end<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mudlet_Object_Functions&diff=15680Manual:Mudlet Object Functions2020-10-15T10:29:09Z<p>Smurf: /* tempAnsiColorTrigger */ omittables</p>
<hr />
<div>{{TOC right}}<br />
= Mudlet Object Functions =<br />
<br />
==adjustStopWatch==<br />
;adjustStopWatch(watchID/watchName, amount)<br />
: Adjusts the elapsed time on the stopwatch forward or backwards by the amount of time. It will work even on stopwatches that are not running, and thus can be used to preset a newly created stopwatch with a negative amount so that it runs down from a negative time towards zero at the preset time.<br />
<br />
;Parameters<br />
* watchID (number) / watchName (string): The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
* amount (decimal number): An amount in seconds to adjust the stopwatch by, positive amounts increase the recorded elapsed time.<br />
<br />
;Returns<br />
* true on success if the stopwatch was found and thus adjusted, or nil and an error message if not.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- demo of a persistent stopWatch used to real time a mission<br />
-- called with a positive number of seconds it will start a "missionStopWatch"<br />
-- unless there already is one in which case it will instead report on<br />
-- the deadline. use 'stopStopWatch("missionStopWatch")' when the mission<br />
-- is done and 'deleteStopWatch("missionStopWatch")' when the existing mission<br />
-- is to be disposed of. Until then repeated use of 'mission(interval)' will<br />
-- just give updates...<br />
function mission(time)<br />
local missionTimeTable = missionTimeTable or {}<br />
<br />
if createStopWatch("missionStopWatch") then<br />
adjustStopWatch("missionStopWatch", -tonumber(time))<br />
setStopWatchPersistence("missionStopWatch", true)<br />
missionTimeTable = getStopWatchBrokenDownTime("missionStopWatch")<br />
<br />
echo(string.format("Get cracking, you have %02i:%02i:%02i hg:m:s left.\n", missionTimeTable.hours, missionTimeTable.minutes, missionTimeTable.seconds))<br />
startStopWatch("missionStopWatch")<br />
else<br />
-- it already exists, so instead report what is/was the time on it<br />
--[=[ We know that the stop watch exists - we just need to find the ID<br />
so we can get the running detail which is only available from the getStopWatches()<br />
table and that is indexed by ID]=]<br />
for k,v in pairs(getStopWatches()) do<br />
if v.name == "missionStopWatch" then<br />
missionTimeTable = v<br />
end<br />
end<br />
if missionTimeTable.isRunning then<br />
if missionTimeTable.elapsedTime.negative then<br />
echo(string.format("Better hurry up, the clock is ticking on an existing mission and you only have %02i:%02i:%02i h:m:s left.\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
else<br />
echo(string.format("Bad news, you are past the deadline on an existing mission by %02i:%02i:%02i h:m:s !\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
end<br />
else<br />
if missionTimeTable.elapsedTime.negative then<br />
echo(string.format("Well done! You have already completed a mission %02i:%02i:%02i h:m:s before the deadline ...\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
else<br />
echo(string.format("Uh oh! You failed to meet the deadline on an existing mission by %02i:%02i:%02i h:m:s !\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))<br />
end<br />
end<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available from Mudlet 4.4.0<br />
<br />
==appendScript==<br />
;appendScript(scriptName, luaCode, [occurrence])<br />
: Appends Lua code to the script "scriptName". If no occurrence given it sets the code of the first found script.<br />
<br />
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#getScript|getScript()]], [[Manual:Lua_Functions#setScript|setScript()]]<br />
<br />
;Returns<br />
* a unique id number for that script.<br />
<br />
;Parameters<br />
* ''scriptName'': name of the script<br />
* ''luaCode'': scripts luaCode to append<br />
* ''occurence'': (optional) the occurrence of the script in case you have many with the same name<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example of appending the script lua code to the first occurrence of "testscript"<br />
appendScript("testscript", [[echo("This is a test\n")]], 1)<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==appendCmdLine==<br />
;appendCmdLine([name], text)<br />
: Appends text to the main input line.<br />
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, the text will be appended to the main commandline.<br />
* ''text'': text to append<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- adds the text "55 backpacks" to whatever is currently in the input line<br />
appendCmdLine("55 backpacks")<br />
<br />
-- makes a link, that when clicked, will add "55 backpacks" to the input line<br />
echoLink("press me", "appendCmdLine'55 backpack'", "Press me!")<br />
<br />
<br />
-- in use:<br />
lua mission(60*60)<br />
Get cracking, you have 01:00:00 h:m:s left.<br />
<br />
lua mission(60*60)<br />
Better hurry up, the clock is ticking on an existing mission and you only have 00:59:52 h:m:s left.<br />
</syntaxhighlight><br />
<br />
==clearCmdLine==<br />
;clearCmdLine([name])<br />
: Clears the input line of any text that's been entered.<br />
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, the main commandline's text will be cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- don't be evil with this!<br />
clearCmdLine()<br />
</syntaxhighlight><br />
<br />
==createStopWatch==<br />
;createStopWatch()<br />
From Mudlet 4.4.0:<br />
;createStopWatch([start immediately {assumed ''true'' if omitted}])<br />
;createStopWatch([name], [start immediately {assumed ''false'' if omitted}])<br />
<br />
: This function creates a stopwatch, a high resolution time measurement tool. Stopwatches can be started, stopped, reset, asked how much time has passed since the stop watch has been started and, following an update for Mudlet 4.4.0: be adjusted, given a name and be made persistent between sessions (so can time real-life things). Prior to 4.4.0 the function took no parameters '''and the stopwatch would start automatically when it was created'''.<br />
<br />
;Parameters:<br />
* ''start immediately'' (bool) used to override the behaviour prior to Mudlet 4.4.0 so that if it is the ''only'' argument then a ''false'' value will cause the stopwatch to be created but be in a ''stopped'' state, however if a name parameter is provided then this behaviour is assumed and then a ''true'' value is required should it be desired for the stopwatch to be started on creation. This difference between the cases with and without a name argument is to allow for older scripts to continue to work with 4.4.0 or later versions of Mudlet without change, yet to allow for more functionality - such as presetting a time when the stopwatch is created but not to start it counting down until some time afterwards - to be performed as well with a named stopwatch.<br />
<br />
* ''name'' (string) a ''unique'' text to use to identify the stopwatch.<br />
<br />
;Returns:<br />
* the ID (number) of a stopwatch; or, from '''4.4.0''': a nil + error message if the name has already been used.<br />
<br />
: See also: [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#resetStopWatch|resetStopWatch()]], [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]] or, from 4.4.0: [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatches|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]], [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]], [[Manual:Lua_Functions#setStopWatchPersistence|setStopWatchPersistence()]]<br />
<br />
;Example<br />
: (Prior to Mudlet 4.4.0) in a global script you can create all stop watches that you need in your system and store the respective stopWatch-IDs in global variables:<br />
<syntaxhighlight lang="lua"><br />
fightStopWatch = fightStopWatch or createStopWatch() -- create, or re-use a stopwatch, and store the watchID in a global variable to access it from anywhere<br />
<br />
-- then you can start the stop watch in some trigger/alias/script with:<br />
startStopWatch(fightStopWatch)<br />
<br />
-- to stop the watch and measure its time in e.g. a trigger script you can write:<br />
fightTime = stopStopWatch(fightStopWatch)<br />
echo("The fight lasted for " .. fightTime .. " seconds.")<br />
resetStopWatch(fightStopWatch)<br />
</syntaxhighlight><br />
<br />
: (From Mudlet 4.4.0) in a global script you can create all stop watches that you need in your system with unique names:<br />
<syntaxhighlight lang="lua"><br />
createStopWatch("fightStopWatch") -- this will fail if the given named stopwatch already exists so it will create it if needed<br />
<br />
-- then you can start the stop watch (if it is not already started) in some trigger/alias/script with:<br />
startStopWatch("fightStopWatch")<br />
<br />
-- to stop the watch and measure its time in e.g. a trigger script you can write:<br />
fightTime = stopStopWatch("fightStopWatch")<br />
echo("The fight lasted for " .. fightTime .. " seconds.")<br />
resetStopWatch("fightStopWatch")<br />
</syntaxhighlight><br />
<br />
:You can also measure the elapsed time without having to stop the stop watch (equivalent to getting a ''lap-time'') with [[#getStopWatchTime|getStopWatchTime()]].<br />
<br />
{{note}} it's best to re-use stopwatch IDs if you can for Mudlet prior to 4.4.0 as they cannot be deleted, so creating more and more would use more memory. From 4.4.0 the revised internal design has been changed such that there are no internal timers created for each stopwatch - instead either a timestamp or a fixed elapsed time record is used depending on whether the stopwatches is running or stopped so that there are no "moving parts" in the later design and less resources are used - and they can be removed if no longer required.<br />
<br />
==deleteStopWatch==<br />
;deleteStopWatch(watchID/watchName)<br />
<br />
: This function removes an existing stopwatch, whether it only exists for this session or is set to be otherwise saved between sessions by using [[Manual:Lua_Functions#setStopWatchPersistence|setStopWatchPersistence()]] with a ''true'' argument. <br />
<br />
;Parameters<br />
* ''watchID'' (number) / ''watchName'' (string): The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
<br />
;Returns:<br />
* ''true'' if the stopwatch was found and thus deleted, or ''nil'' and an error message if not - obviously using it twice with the same argument will fail the second time unless another one with the same name or ID was recreated before the second use. Note that an empty string as a name ''will'' find the lowest ID numbered ''unnamed'' stopwatch and that will then find the next lowest ID number of unnamed ones until there are none left, if used repetitively!<br />
<br />
<syntaxhighlight lang="lua"><br />
lua MyStopWatch = createStopWatch("stopwatch_mine")<br />
true<br />
<br />
lua display(MyStopWatch)<br />
4<br />
<br />
lua deleteStopWatch(MyStopWatch)<br />
true<br />
<br />
lua deleteStopWatch(MyStopWatch)<br />
nil<br />
<br />
"stopwatch with id 4 not found"<br />
<br />
lua deleteStopWatch("stopwatch_mine")<br />
nil<br />
<br />
"stopwatch with name "stopwatch_mine" not found"<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]],<br />
<br />
{{note}} Available from Mudlet version 4.4.0. Stopwatches that are NOT set to be '''persistent''' will be deleted automatically at the end of a session (or if [[Manual:Miscellaneous_Functions#resetProfile|resetProfile()]] is called).<br />
<br />
==disableAlias==<br />
;disableAlias(name)<br />
:Disables/deactivates the alias by its name. If several aliases have this name, they'll all be disabled. If you disable an alias group, all the aliases inside the group will be disabled as well.<br />
: See also: [[#enableAlias|enableAlias()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the alias. Passed as a string.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
--Disables the alias called 'my alias'<br />
disableAlias("my alias")<br />
</syntaxhighlight><br />
<br />
==disableKey==<br />
;disableKey(name)<br />
:Disables key a key (macro) or a key group. When you disable a key group, all keys within the group will be implicitly disabled as well.<br />
<br />
: See also: [[#enableKey|enableKey()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the key or group to identify what you'd like to disable.<br />
<br />
;Examples<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you could set multiple keys on the F1 key and swap their use as you wish by disabling and enabling them<br />
disableKey("attack macro")<br />
disableKey("jump macro")<br />
enableKey("greet macro")<br />
</syntaxhighlight><br />
{{note}} From Version '''3.10'' returns ''true'' if one or more keys or groups of keys were found that matched the name given or ''false'' if not; prior to then it returns ''true'' if there were '''any''' keys - whether they matched the name or not!<br />
<br />
==disableScript==<br />
;disableScript(name)<br />
:Disables a script that was previously enabled. Note that disabling a script only stops it from running in the future - it won't "undo" anything the script has made, such as labels on the screen.<br />
<br />
: See also: [[#permScript|permScript()]], [[#appendScript|appendScript()]], [[#enableScript|enableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]<br />
<br />
;Parameters<br />
* ''name'': name of the script.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Disables the script called 'my script'<br />
disableScript("my script")<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==disableTimer==<br />
;disableTimer(name)<br />
:Disables a timer from running it’s script when it fires - so the timer cycles will still be happening, just no action on them. If you’d like to permanently delete it, use [[Manual:Lua_Functions#killTrigger|killTrigger]] instead.<br />
<br />
: See also: [[#enableTimer|enableTimer()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Disables the timer called 'my timer'<br />
disableTimer("my timer")<br />
</syntaxhighlight><br />
<br />
==disableTrigger==<br />
;disableTrigger(name)<br />
:Disables a permanent (one in the trigger editor) or a temporary trigger. When you disable a group, all triggers inside the group are disabled as well<br />
<br />
: See also: [[#enableTrigger|enableTrigger()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Disables the trigger called 'my trigger'<br />
disableTrigger("my trigger")<br />
</syntaxhighlight><br />
<br />
==enableAlias==<br />
;enableAlias(name)<br />
:Enables/activates the alias by it’s name. If several aliases have this name, they’ll all be enabled.<br />
<br />
: See also: [[#disableAlias|disableAlias()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the alias ID that was returned by [[Manual:Lua_Functions#tempAlias|tempAlias]] on creation of the alias or the name of the alias in case of a GUI alias.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Enables the alias called 'my alias'<br />
enableAlias("my alias")<br />
</syntaxhighlight><br />
<br />
==enableKey==<br />
;enableKey(name)<br />
:Enables a key (macro) or a group of keys (and thus all keys within it that aren't explicitly deactivated).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the group that identifies the key.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you could use this to disable one key set for the numpad and activate another<br />
disableKey("fighting keys")<br />
enableKey("walking keys")<br />
</syntaxhighlight><br />
{{note}} From Version '''3.10'' returns ''true'' if one or more keys or groups of keys were found that matched the name given or ''false'' if not; prior to then it returns ''true'' if there were '''any''' keys - whether they matched the name or not!<br />
<br />
==enableScript==<br />
;enableScript(name)<br />
:Enables / activates a script that was previously disabled. <br />
<br />
: See also: [[#permScript|permScript()]], [[#appendScript|appendScript()]], [[#disableScript|disableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]<br />
<br />
;Parameters<br />
* ''name'': name of the script.<br />
<syntaxhighlight lang="lua"><br />
-- enable the script called 'my script' that you created in Mudlet's script section<br />
enableScript("my script")<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==enableTimer==<br />
;enableTimer(name)<br />
:Enables or activates a timer that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<syntaxhighlight lang="lua"><br />
-- enable the timer called 'my timer' that you created in Mudlets timers section<br />
enableTimer("my timer")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- or disable & enable a tempTimer you've made<br />
timerID = tempTimer(10, [[echo("hi!")]])<br />
<br />
-- it won't go off now<br />
disableTimer(timerID)<br />
-- it will continue going off again<br />
enableTimer(timerID)<br />
</syntaxhighlight><br />
<br />
==enableTrigger==<br />
;enableTrigger(name)<br />
:Enables or activates a trigger that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or by any other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.<br />
<syntaxhighlight lang="lua"><br />
-- enable the trigger called 'my trigger' that you created in Mudlets triggers section<br />
enableTrigger("my trigger")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- or disable & enable a tempTrigger you've made<br />
triggerID = tempTrigger("some text that will match in a line", [[echo("hi!")]])<br />
<br />
-- it won't go off now when a line with matching text comes by<br />
disableTrigger(triggerID)<br />
<br />
-- and now it will continue going off again<br />
enableTrigger(triggerID)<br />
</syntaxhighlight><br />
<br />
==exists==<br />
;exists(name, type)<br />
:Tells you how many things of the given type exist. <br />
<br />
{{note}} This function is only for objects created in the script editor or via perm* functions. You don't need it for temp* functions and will not work for them.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by the temp* function to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', 'timer', 'keybind' (Mudlet 3.2+), or 'script' (Mudlet 3.17+).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo("I have " .. exists("my trigger", "trigger") .. " triggers called 'my trigger'!")<br />
</syntaxhighlight><br />
<br />
: You can also use this alias to avoid creating duplicate things, for example:<br />
<syntaxhighlight lang="lua"><br />
-- this code doesn't check if an alias already exists and will keep creating new aliases<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
<br />
-- while this code will make sure that such an alias doesn't exist first<br />
-- we do == 0 instead of 'not exists' because 0 is considered true in Lua<br />
if exists("Attack", "alias") == 0 then<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
end<br />
</syntaxhighlight><br />
<br />
: Especially helpful when working with [[Manual:Lua_Functions#permTimer|permTimer]]:<br />
<syntaxhighlight lang="lua"><br />
if not exists("My animation timer", "timer") then<br />
vdragtimer = permTimer("My animation timer", "", .016, onVDragTimer) -- 60fps timer!<br />
end<br />
<br />
enableTimer("My animation timer")<br />
</syntaxhighlight><br />
<br />
==getButtonState==<br />
;getButtonState()<br />
:This function can be used within checkbox button scripts (2-state buttons) to determine the current state of the checkbox.<br />
<br />
:Returns ''2'' if button is checked, and ''1'' if it's not.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local checked = getButtonState()<br />
if checked == 1 then<br />
hideExits()<br />
else<br />
showExits()<br />
end<br />
</syntaxhighlight><br />
<br />
==getCmdLine==<br />
;getCmdLine([name])<br />
: Returns the current content of the given command line.<br />
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, it returns the text of the main commandline.<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replaces whatever is currently in the input line by "55 backpacks"<br />
printCmdLine("55 backpacks")<br />
<br />
--prints the text "55 backpacks" to the main console<br />
echo(getCmdLine())<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.1+<br />
<br />
==getStopWatches==<br />
;table = getStopWatches()<br />
<br />
: Returns a table of the details for each stopwatch in existence, the keys are the watch IDs but since there can be gaps in the ID number allocated for the stopwatches it will be necessary to use the ''pairs(...)'' rather than the ''ipairs(...)'' method to iterate through all of them in ''for'' loops!<br />
: Each stopwatch's details will list the following items: ''name'' (string), ''isRunning'' (boolean), ''isPersistent'' (boolean), ''elapsedTime'' (table). The last of these contains the same data as is returned by the results table from the [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]] function - namely ''days'' (positive integer), ''hours'' (integer, 0 to 23), ''minutes'' (integer, 0 to 59), ''second'' (integer, 0 to 59), ''milliSeconds'' (integer, 0 to 999), ''negative'' (boolean) with an additional ''decimalSeconds'' (number of seconds, with a decimal portion for the milli-seconds and possibly a negative sign, representing the whole elapsed time recorded on the stopwatch) - as would also be returned by the [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]] function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- on the command line:<br />
lua getStopWatches()<br />
-- could return something like:<br />
{<br />
{<br />
isPersistent = true,<br />
elapsedTime = {<br />
minutes = 15,<br />
seconds = 2,<br />
negative = false,<br />
milliSeconds = 66,<br />
hours = 0,<br />
days = 18,<br />
decimalSeconds = 1556102.066<br />
},<br />
name = "Playing time",<br />
isRunning = true<br />
},<br />
{<br />
isPersistent = true,<br />
elapsedTime = {<br />
minutes = 47,<br />
seconds = 1,<br />
negative = true,<br />
milliSeconds = 657,<br />
hours = 23,<br />
days = 2,<br />
decimalSeconds = -258421.657<br />
},<br />
name = "TMC Vote",<br />
isRunning = true<br />
},<br />
{<br />
isPersistent = false,<br />
elapsedTime = {<br />
minutes = 26,<br />
seconds = 36,<br />
negative = false,<br />
milliSeconds = 899,<br />
hours = 3,<br />
days = 0,<br />
decimalSeconds = 12396.899<br />
},<br />
name = "",<br />
isRunning = false<br />
},<br />
[5] = {<br />
isPersistent = false,<br />
elapsedTime = {<br />
minutes = 0,<br />
seconds = 38,<br />
negative = false,<br />
milliSeconds = 763,<br />
hours = 0,<br />
days = 0,<br />
decimalSeconds = 38.763<br />
},<br />
name = "",<br />
isRunning = true<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available from Mudlet 4.4.0 only.<br />
<br />
==getStopWatchTime==<br />
;time = getStopWatchTime(watchID [or watchName from Mudlet 4.4.0])<br />
: Returns the time as a decimal number of seconds with up to three decimal places to give a milli-seconds (thousandths of a second) resolution.<br />
: Please note that, prior to 4.4.0 it was not possible to retrieve the elapsed time after the stopwatch had been stopped, retrieving the time was not possible as the returned value then was an indeterminate, meaningless time; from the 4.4.0 release, however, the elapsed value can be retrieved at any time, even if the stopwatch has not been started since creation or modified with the [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]] function introduced in that release.<br />
<br />
: See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatch es|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]].<br />
<br />
:Returns a number<br />
<br />
;Parameters<br />
* ''watchID''<br />
: The ID number of the watch.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example of showing the time left on the stopwatch<br />
teststopwatch = teststopwatch or createStopWatch()<br />
startStopWatch(teststopwatch)<br />
echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))<br />
tempTimer(1, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])<br />
tempTimer(2, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])<br />
stopStopWatch(teststopwatch)<br />
</syntaxhighlight><br />
<br />
==getStopWatchBrokenDownTime==<br />
; brokenDownTimeTable = getStopWatchBrokenDownTime(watchID or watchName)<br />
: Returns the current stopwatch time, whether the stopwatch is running or is stopped, as a table, broken down into:<br />
* "days" (integer)<br />
* "hours" (integer, 0 to 23)<br />
* "minutes" (integer, 0 to 59)<br />
* "seconds" (integer, 0 to 59)<br />
* "milliSeconds" (integer, 0 to 999)<br />
* "negative" (boolean, true if value is less than zero)<br />
<br />
: See also: [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatch es|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]].<br />
<br />
;Parameters<br />
* ''watchID'' / ''watchName''<br />
: The ID number or the name of the watch.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--an example, showing the presetting of a stopwatch.<br />
<br />
--This will fail if the stopwatch with the given name<br />
-- already exists, but then we can use the existing one:<br />
local watchId = createStopWatch("TopMudSiteVoteStopWatch")<br />
if watchId ~= nil then<br />
-- so we have just created the stopwatch, we want it<br />
-- to be saved for future sessions:<br />
setStopWatchPersistence("TopMudSiteVoteStopWatch", true)<br />
-- and set it to count down the 12 hours until we can<br />
-- revote:<br />
adjustStopWatch("TopMudSiteVoteStopWatch", -60*60*12)<br />
-- and start it running<br />
startStopWatch("TopMudSiteVoteStopWatch")<br />
<br />
openWebPage("http://www.topmudsites.com/vote-wotmud.html")<br />
end<br />
<br />
--[[ now I can check when it is time to vote again, even when<br />
I stop the session and restart later by running the following<br />
from a perm timer - perhaps on a 15 minute interval. Note that<br />
when loaded in a new session the Id it gets is unlikely to be<br />
the same as that when it was created - but that is not a<br />
problem as the name is preserved and, if the timer is running<br />
when the profile is saved at the end of the session then the<br />
elapsed time will continue to increase to reflect the real-life<br />
passage of time:]]<br />
<br />
local voteTimeTable = getStopWatchBrokenDownTime("TopMudSiteVoteStopWatch")<br />
<br />
if voteTimeTable["negative"] then<br />
if voteTimeTable["hours"] == 0 and voteTimeTable["minutes"] < 30 then<br />
echo("Voting for WotMUD on Top Mud Site in " .. voteTimeTable["minutes"] .. " minutes...")<br />
end<br />
else<br />
echo("Oooh, it is " .. voteTimeTable["days"] .. " days, " .. voteTimeTable["hours"] .. " hours and " .. voteTimeTable["minutes"] .. " minutes past the time to Vote on Top Mud Site - doing it now!")<br />
openWebPage("http://www.topmudsites.com/vote-wotmud.html")<br />
resetStopWatch("TopMudSiteVoteStopWatch")<br />
adjustStopWatch("TopMudSiteVoteStopWatch", -60*60*12)<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available from Mudlet 4.7+<br />
<br />
==getScript==<br />
; getScript(scriptName, [occurrence])<br />
: Returns the script with the given name. If you have more than one script with the same name, specify the occurrence to pick a different one. Returns -1 if the script doesn't exist.<br />
<br />
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#setScript|setScript()]], [[Manual:Lua_Functions#appendScript|appendScript()]]<br />
<br />
;Parameters<br />
* ''scriptName'': name of the script.<br />
* ''occurrence'': (optional) occurence of the script in case you have many with the same name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the "New script" on screen<br />
print(getScript("New script"))<br />
<br />
-- an example of returning the script Lua code from the second occurrence of "testscript"<br />
test_script_code = getScript("testscript", 2)<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==invokeFileDialog==<br />
;invokeFileDialog(fileOrFolder, dialogTitle)<br />
:Opens a file chooser dialog, allowing the user to select a file or a folder visually. The function returns the selected path or "" if there was none chosen.<br />
<br />
;Parameters<br />
* ''fileOrFolder:'' ''true'' for file selection, ''false'' for folder selection.<br />
* ''dialogTitle'': what to say in the window title.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function whereisit()<br />
local path = invokeFileDialog(false, "Where should we save the file? Select a folder and click Open")<br />
<br />
if path == "" then return nil else return path end<br />
end<br />
</syntaxhighlight><br />
<br />
==isActive==<br />
;isActive(name, type)<br />
:You can use this function to check if something, or somethings, are active. <br />
:Returns the number of active things - and 0 if none are active. Beware that all numbers are true in Lua, including zero.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by temp* function to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', 'timer', 'keybind' (Mudlet 3.2+), or 'script' (Mudlet 3.17+).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo("I have " .. isActive("my trigger", "trigger") .. " currently active trigger(s) called 'my trigger'!")<br />
</syntaxhighlight><br />
<br />
==isPrompt==<br />
;isPrompt()<br />
:Returns true or false depending on if the line at the cursor position is a prompt. This infallible feature is available for MUDs that supply GA events (to check if yours is one, look to bottom-right of the main window - if it doesn’t say <No GA>, then it supplies them).<br />
<br />
:Example use could be as a Lua function, making closing gates on a prompt real easy.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a trigger pattern with 'Lua function', and this will trigger on every prompt!<br />
return isPrompt()<br />
</syntaxhighlight><br />
<br />
==killAlias==<br />
;killAlias(aliasID)<br />
:Deletes a temporary alias with the given ID.<br />
<br />
;Parameters<br />
* ''aliasID:''<br />
: The id returned by [[Manual:Lua_Functions#tempAlias|tempAlias]] to identify the alias.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- deletes the alias with ID 5<br />
killAlias(5)<br />
</syntaxhighlight><br />
<br />
==killKey==<br />
;killKey(name)<br />
:Deletes a keybinding with the given name. If several keybindings have this name, they'll all be deleted.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempKey|tempKey]] to identify the key.<br />
<br />
{{note}} Available in Mudlet 3.2+<br />
<br />
<syntaxhighlight lang="lua"><br />
-- make a temp key<br />
local keyid = tempKey(mudlet.key.F8, [[echo("hi!")]])<br />
<br />
-- delete the said temp key<br />
killKey(keyid)<br />
</syntaxhighlight><br />
<br />
==killTimer==<br />
;killTimer(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
{{note}} Non-temporary timers that you have set up in the GUI or by using [[#permTimer|permTimer]] cannot be deleted with this function. Use [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#enableTimer|enableTimer()]] to turn them on or off.<br />
<br />
;Parameters<br />
* ''id:'' the ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
: Returns true on success and false if the timer id doesn’t exist anymore (timer has already fired) or the timer is not a temp timer.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create the timer and remember the timer ID<br />
timerID = tempTimer(10, [[echo("hello!")]])<br />
<br />
-- delete the timer<br />
if killTimer(timerID) then echo("deleted the timer") else echo("timer is already deleted") end<br />
</syntaxhighlight><br />
<br />
==killTrigger==<br />
;killTrigger(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTrigger]], or a trigger made with one of the ''temp<type>Trigger()'' functions.<br />
<br />
{{note}} When used in out of trigger contexts, the triggers are disabled and deleted upon the next line received from the game - so if you are testing trigger deletion within an alias, the 'statistics' window will be reporting trigger counts that are disabled and pending removal, and thus are no cause for concern.<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the trigger id doesn’t exist anymore (trigger has already fired) or the trigger is not a temp trigger.<br />
<br />
==permAlias==<br />
;permAlias(name, parent, regex, lua code)<br />
<br />
:Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name you’d like the alias to have.<br />
* ''parent:'' <br />
: The name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''regex:''<br />
: The pattern that you’d like the alias to use.<br />
* ''lua code:'' <br />
: The script the alias will do when it matches.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- creates an alias called "new alias" in a group called "my group"<br />
permAlias("new alias", "my group", "^test$", [[echo ("say it works! This alias will show up in the script editor too.")]])<br />
</syntaxhighlight><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permAlias with the same name will keep creating new aliases. You can check if an alias already exists with the [[Manual:Lua_Functions#exists|exists]] function.<br />
<br />
==permGroup==<br />
;permGroup(name, itemtype, [parent])<br />
<br />
:Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts. <br />
;Parameters<br />
* ''name:''<br />
: The name of the new group item you want to create.<br />
* ''itemtype:''<br />
: The type of the item, can be trigger, alias, timer, or script.<br />
* ''parent:''<br />
: (optional) Name of existing item which the new item will be created as a child of.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</syntaxhighlight><br />
<br />
{{Note}} Added to Mudlet in the 2.0 final release. Parameter ''parent'' available in Mudlet 3.1+<br />
{{Note}} Itemtype script is available from Mudlet 4.7+<br />
<br />
==permPromptTrigger==<br />
;permPromptTrigger(name, parent, lua code)<br />
:Creates a persistent trigger for the in-game prompt that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
{{note}} If the trigger is not working, check that the '''N:''' bottom-right has a number. This feature requires telnet Go-Ahead (GA) or End-of-Record (EOR) to be enabled in your game. Available in Mudlet 3.6+<br />
<br />
;Parameters:<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
<br />
;Example: <br />
<syntaxhighlight lang="lua"><br />
permPromptTrigger("echo on prompt", "", [[echo("hey! this thing is working!\n")]])<br />
</syntaxhighlight><br />
<br />
<br />
==permRegexTrigger==<br />
;permRegexTrigger(name, parent, pattern table, lua code)<br />
:Creates a persistent trigger with one or more ''regex'' patterns that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a regex trigger that will match on the prompt to record your status<br />
permRegexTrigger("Prompt", "", {"^(\d+)h, (\d+)m"}, [[health = tonumber(matches[2]); mana = tonumber(matches[3])]])<br />
</syntaxhighlight><br />
{{note}} Mudlet by design allows duplicate names - so calling permRegexTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permBeginOfLineStringTrigger==<br />
;permBeginOfLineStringTrigger(name, parent, pattern table, lua code)<br />
:Creates a persistent trigger that stays after Mudlet is restarted and shows up in the Script Editor. The trigger will go off whenever one of the ''regex'' patterns it's provided with matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- Create a trigger that will match on anything that starts with "You sit" and do "stand".<br />
-- It will not go into any groups, so it'll be on the top.<br />
permBeginOfLineStringTrigger("Stand up", "", {"You sit"}, [[send ("stand")]])<br />
<br />
-- Another example - lets put our trigger into a "General" folder and give it several patterns.<br />
permBeginOfLineStringTrigger("Stand up", "General", {"You sit", "You fall", "You are knocked over by"}, [[send ("stand")]])<br />
</syntaxhighlight><br />
{{note}} Mudlet by design allows duplicate names - so calling permBeginOfLineStringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permSubstringTrigger==<br />
;permSubstringTrigger( name, parent, pattern table, lua code )<br />
:Creates a persistent trigger with one or more ''substring'' patterns that stays after Mudlet is restarted and shows up in the Script Editor.<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a trigger to highlight the word "pixie" for us<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie"},<br />
[[selectString(line, 1) bg("yellow") resetFormat()]])<br />
<br />
-- Or another trigger to highlight several different things<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie", "cat", "dog", "rabbit"},<br />
[[selectString(line, 1) fg ("blue") bg("yellow") resetFormat()]])<br />
</syntaxhighlight><br />
{{note}} Mudlet by design allows duplicate names - so calling permSubstringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permScript==<br />
;permScript(name, parent, lua code)<br />
: Creates a new script in the Script Editor that stays after Mudlet is restarted.<br />
<br />
;Parameters<br />
* ''name'': name of the script.<br />
* ''parent'': name of the script group you want the script to go in.<br />
* ''lua code'': is the code with string you are putting in your script.<br />
<br />
;Returns<br />
* a unique id number for that script.<br />
<br />
: See also: [[#enableScript|enableScript()]], [[#exists|exists()]], [[#appendScript|appendScript()]], [[#disableScript|disableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- create a script in the "first script group" group<br />
permScript("my script", "first script group", [[send ("my script that's in my first script group fired!")]])<br />
-- create a script that's not in any group; just at the top<br />
permScript("my script", "", [[send ("my script that's in my first script group fired!")]])<br />
<br />
-- enable Script - a script element is disabled at creation<br />
enableScript("my script")<br />
</syntaxhighlight><br />
<br />
{{note}} The script is called once but NOT active after creation, it will need to be enabled by [[#enableScript|enableScript()]].<br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permScript with the same name will keep creating new script elements. You can check if a script already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==permTimer==<br />
;permTimer(name, parent, seconds, lua code)<br />
: Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:name of the timer.<br />
* ''parent'' <br />
:name of the timer group you want the timer to go in.<br />
* ''seconds'' <br />
:a floating point number specifying a delay in seconds after which the timer will do the lua code (stored as the timer's "script") you give it as a string.<br />
* ''lua code'' is the code with string you are doing this to.<br />
<br />
;Returns<br />
* a unique id number for that timer.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- create a timer in the "first timer group" group<br />
permTimer("my timer", "first timer group", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
-- create a timer that's not in any group; just at the top<br />
permTimer("my timer", "", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
<br />
-- enable timer - they start off disabled until you're ready<br />
enableTimer("my timer")<br />
</syntaxhighlight><br />
<br />
{{note}} The timer is NOT active after creation, it will need to be enabled by a call to [[#enableTimer|enableTimer()]] before it starts.<br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permTimer with the same name will keep creating new timers. You can check if a timer already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
==permKey==<br />
;permKey(name, parent, [modifier], key code, lua code)<br />
: Creates a persistent key that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:name of the key.<br />
* ''parent'' <br />
:name of the timer group you want the timer to go in or "" for the top level.<br />
* ''modifier'' <br />
:(optional) modifier to use - can be one of ''mudlet.keymodifier.Control'', ''mudlet.keymodifier.Alt'', ''mudlet.keymodifier.Shift'', ''mudlet.keymodifier.Meta'', ''mudlet.keymodifier.Keypad'', or ''mudlet.keymodifier.GroupSwitch'' or the default value of ''mudlet.keymodifier.None'' which is used if the argument is omitted. To use multiple modifiers, add them together: ''(mudlet.keymodifier.Shift + mudlet.keymodifier.Control)''<br />
* ''key code'' <br />
: actual key to use - one of the values available in ''mudlet.key'', e.g. ''mudlet.key.Escape'', ''mudlet.key.Tab'', ''mudlet.key.F1'', ''mudlet.key.A'', and so on. The list is a bit long to list out in full so it is [https://github.com/Mudlet/Mudlet/blob/development/src/mudlet-lua/lua/KeyCodes.lua#L2 available here].<br />
: set to -1 if you want to create a key folder instead.<br />
* ''lua code'<br />
: code you would like the key to run.<br />
<br />
;Returns<br />
* a unique id number for that key.<br />
<br />
{{note}} Available in Mudlet 3.2+, creating key folders in Mudlet 4.10+<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- create a key at the top level for F8<br />
permKey("my key", "", mudlet.key.F8, [[echo("hey this thing actually works!\n")]])<br />
<br />
-- or Ctrl+F8<br />
permKey("my key", "", mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hey this thing actually works!\n")]])<br />
<br />
-- Ctrl+Shift+W<br />
permKey("jump keybinding", "", mudlet.keymodifier.Control + mudlet.keymodifier.Shift, mudlet.key.W, [[send("jump")]])<br />
</syntaxhighlight><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permKey with the same name will keep creating new keys. You can check if a key already exists with the [[Manual:Lua_Functions#exists|exists()]] function. The key will be created even if the lua code does not compile correctly - but this will be apparent as it will be seen in the Editor.<br />
<br />
==printCmdLine==<br />
;printCmdLine([name], text)<br />
<br />
: Replaces the current text in the input line, and sets it to the given text.<br />
: See also: [[Manual:Lua_Functions#clearCmdLine|clearCmdLine()]]<br />
<br />
;Parameters<br />
* ''name'': (optional) name of the command line. If not given, main commandline's text will be set.<br />
* ''text'': text to set<br />
<br />
<syntaxhighlight lang="lua"><br />
printCmdLine("say I'd like to buy ")<br />
</syntaxhighlight><br />
<br />
==raiseEvent==<br />
;raiseEvent(event_name, arg-1, … arg-n)<br />
<br />
: Raises the event event_name. The event system will call the main function (the one that is called exactly like the script name) of all such scripts in this profile that have registered event handlers. If an event is raised, but no event handler scripts have been registered with the event system, the event is ignored and nothing happens. This is convenient as you can raise events in your triggers, timers, scripts etc. without having to care if the actual event handling has been implemented yet - or more specifically how it is implemented. Your triggers raise an event to tell the system that they have detected a certain condition to be true or that a certain event has happened. How - and if - the system is going to respond to this event is up to the system and your trigger scripts don’t have to care about such details. For small systems it will be more convenient to use regular function calls instead of events, however, the more complicated your system will get, the more important events will become because they help reduce complexity very much.<br />
<br />
:The corresponding event handlers that listen to the events raised with raiseEvent() need to use the script name as function name and take the correct number of arguments. <br />
<br />
{{note}} possible arguments can be string, number, boolean, table, function, or nil.<br />
<br />
;Example:<br />
<br />
:raiseEvent("fight") a correct event handler function would be: myScript( event_name ). In this example raiseEvent uses minimal arguments, name the event name. There can only be one event handler function per script, but a script can still handle multiple events as the first argument is always the event name - so you can call your own special handlers for individual events. The reason behind this is that you should rather use many individual scripts instead of one huge script that has all your function code etc. Scripts can be organized very well in trees and thus help reduce complexity on large systems.<br />
<br />
Where the number of arguments that your event may receive is not fixed you can use [http://www.lua.org/manual/5.1/manual.html#2.5.9 ''...''] as the last argument in the ''function'' declaration to handle any number of arguments. For example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- try this function out with "lua myscripthandler(1,2,3,4)"<br />
function myscripthandler(a, b, ...)<br />
print("Arguments a and b are: ", a,b)<br />
-- save the rest of the arguments into a table<br />
local otherarguments = {...}<br />
print("Rest of the arguments are:")<br />
display(otherarguments)<br />
<br />
-- access specific otherarguments:<br />
print("First and second otherarguments are: ", otherarguments[1], otherarguments[2])<br />
end<br />
</syntaxhighlight><br />
<br />
==raiseGlobalEvent==<br />
;raiseGlobalEvent(event_name, arg-1, … arg-n)<br />
<br />
: Like [[Manual:Lua_Functions#raiseEvent|raiseEvent()]] this raises the event "event_name", but this event is sent to all '''other''' opened profiles instead. The profiles receive the event in circular alphabetical order (if profile "C" raised this event and we have profiles "A", "C", and "E", the order is "E" -> "A", but if "E" raised the event the order would be "A" -> "C"); execution control is handed to the receiving profiles so that means that long running events may lock up the profile that raised the event.<br />
<br />
: The sending profile's name is automatically appended as the last argument to the event.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- from profile called "My MUD" this raises an event "my event" with additional arguments 1, 2, 3, "My MUD" to all profiles except the original one<br />
raiseGlobalEvent("my event", 1, 2, 3)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available since Mudlet 3.1.0.<br />
<br />
Tip: you might want to add the [[Manual:Miscellaneous_Functions#getProfileName|profile name]] to your plain [[Manual:Miscellaneous_Functions#raiseEvent|raiseEvent()]] arguments. This'll help you tell which profile your event came from similar to [[#raiseGlobalEvent|raiseGlobalEvent()]].<br />
<br />
==remainingTime==<br />
;remainingTime(timer id number or name)<br />
<br />
: Returns the remaining time in floating point form in seconds (if it is active) for the timer (temporary or permanent) with the id number or the (first) one found with the name.<br />
: If the timer is inactive or has expired or is not found it will return a ''nil'' and an ''error message''. It, theoretically could also return 0 if the timer is overdue, i.e. it has expired but the internal code has not yet been run but that has not been seen in during testing. Permanent ''offset timers'' will only show as active during the period when they are running after their parent has expired and started them.<br />
<br />
{{Note}} Available in Mudlet since 3.20.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
tid = tempTimer(600, [[echo("\nYour ten minutes are up.\n")]])<br />
echo("\nYou have " .. remainingTime(tid) .. " seconds left, use it wisely... \n")<br />
<br />
-- Will produce something like:<br />
<br />
You have 599.923 seconds left, use it wisely... <br />
<br />
-- Then ten minutes time later:<br />
<br />
Your ten minutes are up.<br />
<br />
</syntaxhighlight><br />
<br />
==resetProfileIcon==<br />
;resetProfileIcon()<br />
: Resets the profile's icon in the connection screen to default.<br />
<br />
See also: [[#setProfileIcon|setProfileIcon()]].<br />
<br />
{{Note}} Available in Mudlet 4.0+.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
resetProfileIcon()<br />
</syntaxhighlight><br />
<br />
==resetStopWatch==<br />
;resetStopWatch(watchID)<br />
:This function resets the time to 0:0:0.0, but does not start the stop watch. You can start it with [[Manual:Lua_Functions#startStopWatch | startStopWatch]] → [[Manual:Lua_Functions#createStopWatch | createStopWatch]]<br />
<br />
==setConsoleBufferSize==<br />
;setConsoleBufferSize([consoleName], linesLimit, sizeOfBatchDeletion)<br />
:Sets the maximum number of lines a buffer (main window or a miniconsole) can hold. Default is 10,000.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: (optional) The name of the window. If omitted, uses the main console.<br />
* ''linesLimit:''<br />
: Sets the amount of lines the buffer should have. <br />
{{note}} Mudlet performs extremely efficiently with even huge numbers, but there is of course a limit to your computer's memory. As of Mudlet 4.7+, this amount will be capped to that limit on macOS and Linux (on Windows, it's capped lower as Mudlet on Windows is 32bit).<br />
* ''sizeOfBatchDeletion:''<br />
: Specifies how many lines should Mudlet delete at once when you go over the limit - it does it in bulk because it's efficient to do so.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sets the main windows size to 1 million lines maximum - which is more than enough!<br />
setConsoleBufferSize("main", 1000000, 1000)<br />
</syntaxhighlight><br />
<br />
==setProfileIcon==<br />
;setProfileIcon(iconPath)<br />
:Set a custom icon for this profile in the connection screen. <br />
<br />
:Returns true if successful, or nil+error message if not.<br />
<br />
:See also: [[#resetProfileIcon|resetProfileIcon()]].<br />
<br />
{{note}} Available in Mudlet 4.0+<br />
<br />
;Parameters<br />
* ''iconPath:''<br />
: Full location of the icon - can be .png or .jpg with ideal dimensions of 120x30.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set a custom icon that is located in an installed package called "mypackage"<br />
setProfileIcon(getMudletHomeDir().."/mypackage/icon.png")<br />
</syntaxhighlight><br />
<br />
==setScript==<br />
;setScript(scriptName, luaCode, [occurrence])<br />
: Sets the script's Lua code, replacing existing code. If you have many scripts with the same name, use the 'occurrence' parameter to choose between them.<br />
: If you'd like to add code instead of replacing it, have a look at [[Manual:Lua_Functions#appendScript|appendScript()]].<br />
: Returns -1 if the script isn't found - to create a script, use [[Manual:Lua_Functions#permScript|permScript()]].<br />
<br />
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#getScript|getScript()]], [[Manual:Lua_Functions#appendScript|appendScript()]]<br />
<br />
;Returns<br />
* a unique id number for that script.<br />
<br />
;Parameters<br />
* ''scriptName'': name of the script to change the code.<br />
* ''luaCode'': new Lua code to set.<br />
* ''occurrence'': The position of the script. Optional, defaults to 1 (first).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example of setting the script lua code from the first occurrence of "testscript"<br />
setScript("testscript", [[echo("This is a test\n")]], 1)<br />
</syntaxhighlight><br />
{{note}} Available from Mudlet 4.8+<br />
<br />
==setStopWatchName==<br />
;setStopWatchName(watchID/currentStopWatchName, newStopWatchName)<br />
<br />
;Parameters<br />
* ''watchID'' (number) / ''currentStopWatchName'' (string): The stopwatch ID you get from [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name supplied to that function at that time, or previously applied with this function.<br />
* ''newStopWatchName'' (string): The name to use for this stopwatch from now on.<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found.<br />
<br />
{{note}} Either ''currentStopWatchName'' or ''newStopWatchName'' may be empty strings: if the first of these is so then the ''lowest'' ID numbered stopwatch without a name is chosen; if the second is so then an existing name is removed from the chosen stopwatch.<br />
<br />
==setStopWatchPersistence==<br />
;setStopWatchPersistence(watchID/watchName, state)<br />
<br />
;Parameters<br />
* ''watchID'' (number) / ''watchName'' (string): The stopwatch ID you get from [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name supplied to that function or applied later with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]]<br />
* ''state'' (boolean): if ''true'' the stopWatch will be saved.<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found.<br />
<br />
:Sets or resets the flag so that the stopwatch is saved between sessions or after a [[Manual:Miscellaneous_Functions#resetProfile|resetProfile()]] call. If set then, if ''stopped'' the elapsed time recorded will be unchanged when the stopwatch is reloaded in the next session; if ''running'' the elapsed time will continue to increment and it will include the time that the profile was not loaded, therefore it can be used to measure events in real-time, outside of the profile!<br />
<br />
{{note}} When a persistent stopwatch is reloaded in a later session (or after a use of ''resetProfile()'') the stopwatch may not be allocated the same ID number as before - therefore it is advisable to assign any persistent stopwatches a name, either when it is created or before the session is ended.<br />
<br />
==setTriggerStayOpen==<br />
;setTriggerStayOpen(name, number)<br />
:Sets for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched - so this allows you to extend or shorten the ''fire length'' of a trigger. The main use of this function is to close a chain when a certain condition has been met.<br />
<br />
;Parameters<br />
* ''name:'' The name of the trigger which has a fire length set (and which opens the chain).<br />
* ''number'': 0 to close the chain, or a positive number to keep the chain open that much longer.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if you have a trigger that opens a chain (has some fire length) and you'd like it to be closed <br />
-- on the next prompt, you could make a trigger inside the chain with a Lua function pattern of:<br />
return isPrompt()<br />
-- and a script of:<br />
setTriggerStayOpen("Parent trigger name", 0)<br />
-- to close it on the prompt!<br />
</syntaxhighlight><br />
<br />
==startStopWatch==<br />
;startStopWatch(watchID, [resetAndRestart])<br />
;startStopWatch(watchName)<br />
<br />
:Stopwatches can be stopped (with [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]]) and then re-started any number of times. '''To ensure backwards compatibility, if the stopwatch is identified by a ''numeric'' argument then, ''unless a second argument of false is supplied as well'' this function will also reset the stopwatch to zero and restart it - whether it is running or not'''; otherwise only a stopped watch can be started and only a started watch may be stopped. Trying to repeat either will produce a nil and an error message instead; also the recorded time is no longer reset so that they can now be used to record a total of isolated periods of time like a real stopwatch.<br />
<br />
:See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]]<br />
<br />
;Parameters<br />
* ''watchID''/''watchName'': The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], or from '''4.4.0''' the name assigned with that function or [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
* ''resetAndRestart'': Boolean flag needed (as ''false'') to make the function from '''4.4.0''', when supplied with a numeric watch ID, to '''not''' reset the stopwatch and only start a previously stopped stopwatch. This behavior is automatic when a string watch name is used to identify the stopwatch but differs from how the function behaved prior to that version.<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found or if it cannot be started (because the later style behavior was indicated and it was already running).<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- this is a common pattern for re-using stopwatches prior to 4.4.0 and starting them:<br />
watch = watch or createStopWatch()<br />
startStopWatch(watch)<br />
</syntaxhighlight><br />
<br />
:: After 4.4.0 the above code will work the same as it does not provide a second argument to the ''startStopWatch()'' function - if a ''false'' was used there it would be necessary to call ''stopStopWatch(...)'' and then ''resetStopWatch(...)'' before using ''startStopWatch(...)'' to re-use the stopwatch if the ID form is used, '''this is thus not quite the same behavior but it is more consistent with the model of how a real stopwatch would act.'''<br />
<br />
==stopStopWatch==<br />
;stopStopWatch(watchID or watchName)<br />
:"Stops" (though see the note below) the stop watch and returns (only the '''first''' time it is called after the stopwatch has been set running with [[Manual:Lua_Functions#startStopWatch()|startStopWatchTime()]]) the elapsed time as a number of seconds, with a decimal portion give a resolution in milliseconds (thousandths of a second). You can also retrieve the current time without stopping the stopwatch with [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]], [[Manual:Lua_Functions#getBrokenDownStopWatchTime|getBrokenDownStopWatchTime()]].<br />
<br />
:See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
<br />
;Parameters<br />
* ''watchID:'' The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or from Mudlet '''4.4.0''' the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].<br />
<br />
;Returns<br />
* the elapsed time as a floating-point number of seconds - it may be negative if the time was previously adjusted/preset to a negative amount (with [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]]) and that period has not yet elapsed.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- this is a common pattern for re-using stopwatches and starting them:<br />
watch = watch or createStopWatch()<br />
startStopWatch(watch)<br />
<br />
-- do some long-running code here ...<br />
<br />
print("The code took: "..stopStopWatch(watch).."s to run.")<br />
</syntaxhighlight><br />
<br />
==tempAnsiColorTrigger==<br />
;tempAnsiColorTrigger(foregroundColor, [backgroundColor,] code[, expireAfter])<br />
:This is an alternative to [[Manual:Lua_Functions#tempColorTrigger|tempColorTrigger()]] which supports the full set of 256 ANSI color codes directly and makes a color trigger that triggers on the specified foreground and background color. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code to do'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function.<br />
* ''expireAfter'': Delete trigger after a specified number of matches. You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;''BackgroundColor'' and/or ''expireAfter'' may be omitted.<br />
<br />
;Color codes (note that the values greater than or equal to zero are the actual number codes that ANSI and the game server uses for the 8/16/256 color modes)<br />
<br />
::Special codes (may be extended in the future):<br />
:::-2 = default text color (what is used after an ANSI SGR 0 m code that resets the foreground and background colors to those set in the preferences)<br />
:::-1 = ignore (only '''one''' of the foreground or background codes can have this value - otherwise it would not be a ''color'' trigger!)<br />
<br />
::ANSI 8-color set:<br />
:::0 = (dark) black<br />
:::1 = (dark) red<br />
:::2 = (dark) green<br />
:::3 = (dark) yellow<br />
:::4 = (dark) blue<br />
:::5 = (dark) magenta<br />
:::6 = (dark) cyan<br />
:::7 = (dark) white {a.k.a. light gray}<br />
<br />
::Additional colors in 16-color set:<br />
:::8 = light black {a.k.a. dark gray}<br />
:::9 = light red<br />
:::10 = light green<br />
:::11 = light yellow<br />
:::12 = light blue<br />
:::13 = light magenta<br />
:::14 = light cyan<br />
:::15 = light white<br />
<br />
::6 x 6 x 6 RGB (216) colors, shown as a 3x2-digit hex code<br />
:::16 = #000000<br />
:::17 = #000033<br />
:::18 = #000066<br />
:::...<br />
:::229 = #FFFF99<br />
:::230 = #FFFFCC<br />
:::231 = #FFFFFF<br />
<br />
::24 gray-scale, also show as a 3x2-digit hex code<br />
:::232 = #000000<br />
:::233 = #0A0A0A<br />
:::234 = #151515<br />
:::...<br />
:::253 = #E9E9E9<br />
:::254 = #F4F4F4<br />
:::255 = #FFFFFF<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- This script will re-highlight all text in a light cyan foreground color on any background with a red foreground color<br />
-- until another foreground color in the current line is being met. temporary color triggers do not offer match_all<br />
-- or filter options like the GUI color triggers because this is rarely necessary for scripting.<br />
-- A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempAnsiColorTrigger(14, -1, [[selectString(matches[1],1) fg("red")]])<br />
-- or:<br />
tempAnsiColorTrigger(14, -1, function()<br />
selectString(matches[1], 1)<br />
fg("red")<br />
end)<br />
<br />
-- match the trigger only 4 times<br />
tempColorTrigger(14, -1, [[selectString(matches[1],1) fg("red")]], 4)<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==tempAlias==<br />
;aliasID = tempAlias(regex, code to do)<br />
:Creates a temporary alias - temporary in the sense that it won't be saved when Mudlet restarts (unless you re-create it). The alias will go off as many times as it matches, it is not a one-shot alias. The function returns an ID for subsequent [[Manual:Lua_Functions#enableAlias|enableAlias()]], [[Manual:Lua_Functions#disableAlias|disableAlias()]] and [[Manual:Lua_Functions#killAlias|killAlias()]] calls.<br />
<br />
;Parameters<br />
* ''regex:'' Alias pattern in regex.<br />
* ''code to do:'' The code to do when the alias fires - wrap it in [[ ]].<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
myaliasID = tempAlias("^hi$", [[send ("hi") echo ("we said hi!")]])<br />
<br />
-- you can also delete the alias later with:<br />
killAlias(myaliasID)<br />
</syntaxhighlight><br />
<br />
==tempBeginOfLineTrigger==<br />
;tempBeginOfLineTrigger(part of line, code, expireAfter)<br />
:Creates a trigger that will go off whenever the part of line it's provided with matches the line right from the start (doesn't matter what the line ends with). The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
<br />
;Parameters<br />
* ''part of line'': start of the line that you'd like to match. This can also be regex.<br />
* ''code to do'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
mytriggerID = tempBeginOfLineTrigger("Hello", [[echo("We matched!")]])<br />
<br />
--[[ now this trigger will match on any of these lines:<br />
Hello<br />
Hello!<br />
Hello, Bob!<br />
<br />
but not on:<br />
Oh, Hello<br />
Oh, Hello!<br />
]]<br />
<br />
-- or as a function:<br />
mytriggerID = tempBeginOfLineTrigger("Hello", function() echo("We matched!") end)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can make the trigger match only a certain amount of times as well, 5 in this example:<br />
tempBeginOfLineTrigger("This is the start of the line", function() echo("We matched!") end, 5)<br />
<br />
-- if you want a trigger match not to count towards expiration, return true. In this example it'll match 5 times unless the line is "Start of line and this is the end."<br />
tempBeginOfLineTrigger("Start of line", <br />
function()<br />
if line == "Start of line and this is the end." then<br />
return true<br />
else<br />
return false<br />
end<br />
end, 5)<br />
</syntaxhighlight><br />
<br />
==tempButton==<br />
;tempButton(toolbar name, button text, orientation)<br />
:Creates a temporary button. Temporary means, it will disappear when Mudlet is closed.<br />
<br />
;Parameters:<br />
* ''toolbar name'': The name of the toolbar to place the button into.<br />
* ''button text'': The text to display on the button.<br />
* ''orientation'': a number 0 or 1 where 0 means horizontal orientation for the button and 1 means vertical orientation for the button. This becomes important when you want to have more than one button in the same toolbar.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- makes a temporary toolbar with two buttons at the top of the main Mudlet window <br />
lua tempButtonToolbar("topToolbar", 0, 0)<br />
lua tempButton("topToolbar", "leftButton", 0)<br />
lua tempButton("topToolbar", "rightButton", 0)<br />
</syntaxhighlight><br />
<br />
{{note}} ''This function is not that useful as there is no function yet to assign a Lua script or command to such a temporary button - though it may have some use to flag a status indication!''<br />
<br />
==tempButtonToolbar==<br />
;tempButtonToolbar(name, location, orientation)<br />
:Creates a temporary button toolbar. Temporary means, it will disappear when Mudlet is closed.<br />
<br />
;Parameters:<br />
* ''name'': The name of the toolbar.<br />
* ''location'': a number from 0 to 3, where 0 means "at the top of the screen", 1 means "left side", 2 means "right side" and 3 means "in a window of its own" which can be dragged and attached to the main Mudlet window if needed.<br />
* ''orientation'': a number 0 or 1, where 0 means horizontal orientation for the toolbar and 1 means vertical orientation for the toolbar. This becomes important when you want to have more than one toolbar in the same location of the window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- makes a temporary toolbar with two buttons at the top of the main Mudlet window <br />
lua tempButtonToolbar("topToolbar", 0, 0)<br />
lua tempButton("topToolbar", "leftButton", 0)<br />
lua tempButton("topToolbar", "rightButton", 0)<br />
</syntaxhighlight><br />
<br />
==tempColorTrigger==<br />
;tempColorTrigger(foregroundColor, backgroundColor, code, expireAfter)<br />
:Makes a color trigger that triggers on the specified foreground and background color. Both colors need to be supplied in form of these simplified ANSI 16 color mode codes. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code to do'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Color codes<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- This script will re-highlight all text in blue foreground colors on a black background with a red foreground color<br />
-- on a blue background color until another color in the current line is being met. temporary color triggers do not <br />
-- offer match_all or filter options like the GUI color triggers because this is rarely necessary for scripting. <br />
-- A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempColorTrigger(9, 2, [[selectString(matches[1],1) fg("red") bg("blue")]])<br />
-- or:<br />
tempColorTrigger(9, 2, function()<br />
selectString(matches[1], 1)<br />
fg("red")<br />
bg("blue")<br />
end)<br />
<br />
-- match the trigger only 4 times<br />
tempColorTrigger(9, 2, [[selectString(matches[1],1) fg("red") bg("blue")]], 4)<br />
</syntaxhighlight><br />
<br />
==tempComplexRegexTrigger==<br />
;tempComplexRegexTrigger(name, regex, code, multiline, fg color, bg color, filter, match all, highlight fg color, highlight bg color, play sound file, fire length, line delta, expireAfter)<br />
:Allows you to create a temporary trigger in Mudlet, using any of the UI-available options. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
:Returns the trigger name, that you can use [[Manual:Lua_Functions#killTrigger|killTrigger()]] later on with.<br />
<br />
;Parameters<br />
* ''name'' - The name you call this trigger. <br />
* ''regex'' - The regular expression you want to match.<br />
* ''code'' - Code to do when the trigger runs. You need to wrap it in [[ ]], or give a Lua function (since Mudlet 3.5.0).<br />
* ''multiline'' - Set this to 1, if you use multiple regex (see note below), and you need the trigger to fire only if all regex have been matched within the specified line delta. Then all captures will be saved in ''multimatches'' instead of ''matches''. If this option is set to 0, the trigger will fire when any regex has been matched.<br />
* ''fg color'' - The foreground color you'd like to trigger on.<br />
* ''bg color'' - The background color you'd like to trigger on.<br />
* ''filter'' - Do you want only the filtered content (=capture groups) to be passed on to child triggers? Otherwise also the initial line.<br />
* ''match all'' - Set to 1, if you want the trigger to match all possible occurrences of the regex in the line. When set to 0, the trigger will stop after the first successful match.<br />
* ''highlight fg color'' - The foreground color you'd like your match to be highlighted in.<br />
* ''highlight bg color'' - The background color you'd like your match to be highlighted in.<br />
* ''play sound file'' - Set to the name of the sound file you want to play upon firing the trigger.<br />
* ''fire length'' - Number of lines within which all condition must be true to fire the trigger.<br />
* ''line delta'' - Keep firing the script for x more lines, after the trigger or chain has matched.<br />
* ''expireAfter'' - Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
{{Note}} Set the options starting at ''multiline'' to 0, if you don't want to use those options. Otherwise enter 1 to activate or the value you want to use.<br />
<br />
{{Note}} If you want to use the color option, you need to provide both fg and bg together.<br />
<br />
;Examples<br />
<br />
<syntaxhighlight lang="lua"><br />
-- This trigger will be activated on any new line received.<br />
triggerNumber = tempComplexRegexTrigger("anyText", "^(.*)$", [[echo("Text received!")]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)<br />
<br />
-- This trigger will match two different regex patterns:<br />
tempComplexRegexTrigger("multiTrigger", "first regex pattern", [[]], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)<br />
tempComplexRegexTrigger("multiTrigger", "second regex pattern", [[echo("Trigger matched!")]], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)<br />
</syntaxhighlight><br />
<br />
{{Note}} For making a multiline trigger like in the second example, you need to use the same trigger name and options, providing the new pattern to add. Note that only the last script given will be set, any others ignored.<br />
<br />
==tempExactMatchTrigger==<br />
;tempExactMatchTrigger(exact line, code, expireAfter)<br />
:Creates a trigger that will go off whenever the line from the game matches the provided line exactly (ends the same, starts the same, and looks the same). You don't need to use any of the regex symbols here (^ and $). The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters<br />
* ''exact line'': exact line you'd like to match.<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
mytriggerID = tempExactMatchTrigger("You have recovered balance on all limbs.", [[echo("We matched!")]])<br />
<br />
-- as a function:<br />
mytriggerID = tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("We matched!") end)<br />
<br />
-- expire after 4 matches:<br />
tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("Got balance back!\n") end, 4)<br />
<br />
-- you can also avoid expiration by returning true:<br />
tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("Got balance back!\n") return true end, 4)<br />
</syntaxhighlight><br />
<br />
==tempKey==<br />
;tempKey([modifier], key code, lua code)<br />
:Creates a keybinding. This keybinding isn't temporary in the sense that it'll go off only once (it'll go off as often as you use it), but rather it won't be saved when Mudlet is closed.<br />
<br />
: See also: [[#permKey|permKey()]], [[#killKey|killKey()]]<br />
<br />
* ''modifier'' <br />
:(optional) modifier to use - can be one of ''mudlet.keymodifier.Control'', ''mudlet.keymodifier.Alt'', ''mudlet.keymodifier.Shift'', ''mudlet.keymodifier.Meta'', ''mudlet.keymodifier.Keypad'', or ''mudlet.keymodifier.GroupSwitch'' or the default value of ''mudlet.keymodifier.None'' which is used if the argument is omitted. To use multiple modifiers, add them together: ''(mudlet.keymodifier.Shift + mudlet.keymodifier.Control)''<br />
* ''key code'' <br />
: actual key to use - one of the values available in ''mudlet.key'', e.g. ''mudlet.key.Escape'', ''mudlet.key.Tab'', ''mudlet.key.F1'', ''mudlet.key.A'', and so on. The list is a bit long to list out in full so it is [https://github.com/Mudlet/Mudlet/blob/development/src/mudlet-lua/lua/KeyCodes.lua#L2 available here].<br />
* ''lua code'<br />
: code you'd like the key to run - wrap it in [[ ]].<br />
<br />
;Returns<br />
* a unique id number for that key.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
local keyID = tempKey(mudlet.key.F8, [[echo("hi")]])<br />
<br />
local anotherKeyID = tempKey(mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hello")]])<br />
<br />
-- bind Ctrl+Shift+W:<br />
tempKey(mudlet.keymodifier.Control + mudlet.keymodifier.Shift, mudlet.key.W, [[send("jump")]])<br />
<br />
-- delete it if you don't like it anymore<br />
killKey(keyID)<br />
</syntaxhighlight><br />
<br />
==tempLineTrigger==<br />
;tempLineTrigger(from, howMany, code, expireAfter)<br />
:Temporary trigger that will fire on ''n'' consecutive lines following the current line. This is useful to parse output that is known to arrive in a certain line margin or to delete unwanted output from the MUD - the trigger does not require any patterns to match on. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters:<br />
* ''from'': from which line after this one should the trigger activate - 1 will activate right on the next line.<br />
* ''howMany'': how many lines to run for after the trigger has activated.<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Example: <br />
<syntaxhighlight lang="lua"><br />
-- Will fire 3 times with the next line from the MUD.<br />
tempLineTrigger(1, 3, function() print(" trigger matched!") end)<br />
<br />
-- Will fire 20 lines after the current line and fire twice on 2 consecutive lines, 7 times.<br />
tempLineTrigger(20, 2, function() print(" trigger matched!") end, 7)<br />
</syntaxhighlight><br />
<br />
==tempPromptTrigger==<br />
;tempPromptTrigger(code, expireAfter)<br />
:Temporary trigger that will match on the games prompt. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
{{note}} If the trigger is not working, check that the '''N:''' bottom-right has a number. This feature requires telnet Go-Ahead to be enabled in the game. Available in Mudlet 3.6+<br />
<br />
;Parameters:<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function.<br />
* ''expireAfter'': Delete trigger after a specified number of matches. You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
{{note}} ''expireAfter'' is available since Mudlet 3.11<br />
<br />
;Example: <br />
<syntaxhighlight lang="lua"><br />
tempPromptTrigger(function()<br />
echo("hello! this is a prompt!")<br />
end)<br />
<br />
-- match only 2 times:<br />
tempPromptTrigger(function()<br />
echo("hello! this is a prompt!")<br />
end, 2)<br />
<br />
-- match only 2 times, unless the prompt is "55 health."<br />
tempPromptTrigger(function()<br />
if line == "55 health." then return true end<br />
end, 2)<br />
</syntaxhighlight><br />
<br />
==tempRegexTrigger==<br />
;tempRegexTrigger(regex, code, expireAfter)<br />
:Creates a temporary regex trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters:<br />
* ''regex:'' regular expression that lines will be matched on.<br />
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- create a non-duplicate trigger that matches on any line and calls a function<br />
html5log = html5log or {}<br />
if html5log.trig then killTrigger(html5log.trig) end<br />
html5log.trig = tempRegexTrigger("^", [[html5log.recordline()]])<br />
-- or a simpler variant:<br />
html5log.trig = tempRegexTrigger("^", html5log.recordline)<br />
<br />
-- only match 3 times:<br />
tempRegexTrigger("^You prick (.+) twice in rapid succession with", function() echo("Hit "..matches[2].."!\n") end, 3)<br />
</syntaxhighlight><br />
<br />
==tempTimer==<br />
;tempTimer(time, code to do[, repeating])<br />
:Creates a temporary one-shot timer and returns the timer ID, which you can use with [[Manual:Lua_Functions#enableTimer|enableTimer()]], [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#killTimer|killTimer()]] functions. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and destroyed, so it will only go off once. Here is a [[Manual:Introduction#Timers|more detailed introduction to tempTimer]].<br />
<br />
;Parameters<br />
* ''time:'' The time in seconds for which to set the timer for - you can use decimals here for precision. The timer will go off ''x'' given seconds after you make it.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
* ''repeating'': (optional) if true, keep firing the timer over and over until you kill it (available in Mudlet 4.0+).<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- wait half a second and then run the command<br />
tempTimer(0.5, function() send("kill monster") end)<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
<br />
-- create a looping timer<br />
timerid = tempTimer(1, function() display("hello!") end, true)<br />
<br />
-- later when you'd like to stop it:<br />
killTimer(timerid)<br />
</syntaxhighlight><br />
<br />
{{note}} Double brackets, e.g: [[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
<br />
{{note}} Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<syntaxhighlight lang="lua"><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
<br />
-- tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</syntaxhighlight><br />
<br />
==tempTrigger==<br />
;tempTrigger(substring, code, expireAfter)<br />
:Creates a substring trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.<br />
<br />
;Parameters:<br />
* ''substring'': The substring to look for - this means a part of the line. If your provided text matches anywhere within the line from the game, the trigger will go off.<br />
* ''code'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5)<br />
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.<br />
<br />
Example:<br />
<syntaxhighlight lang="lua"><br />
-- this example will highlight the contents of the "target" variable.<br />
-- it will also delete the previous trigger it made when you call it again, so you're only ever highlighting one name<br />
if id then killTrigger(id) end<br />
id = tempTrigger(target, [[selectString("]] .. target .. [[", 1) fg("gold") resetFormat()]])<br />
<br />
-- you can also write the same line as:<br />
id = tempTrigger(target, function() selectString(target, 1) fg("gold") resetFormat() end)<br />
<br />
-- or like so if you have a highlightTarget() function somewhere<br />
id = tempTrigger(target, highlightTarget)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a simpler trigger to replace "hi" with "bye" whenever you see it<br />
tempTrigger("hi", [[selectString("hi", 1) replace("bye")]])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this trigger will go off only 2 times<br />
tempTrigger("hi", function() selectString("hi", 1) replace("bye") end, 2)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- table to store our trigger IDs in<br />
nameIDs = nameIDs or {}<br />
-- delete any existing triggers we've already got<br />
for _, id in ipairs(nameIDs) do killTrigger(id) end<br />
<br />
-- create new ones, avoiding lots of ]] [[ to embed the name<br />
for _, name in ipairs{"Alice", "Ashley", "Aaron"} do<br />
nameIDs[#nameIDs+1] = tempTrigger(name, function() print(" Found "..name.."!") end)<br />
end<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Geyser&diff=15635Manual:Geyser2020-10-09T11:57:33Z<p>Smurf: /* Geyser.UserWindow */</p>
<hr />
<div>{{TOC right}}<br />
<br />
= Introduction =<br />
<br />
The Geyser Layout Manager is an object oriented framework for creating, updating and organizing GUI elements within Mudlet - it allows you to make your UI easier on Mudlet, and makes it easier for the UI to be compatible with different screen sizes.<br />
<br />
=== Motivation ===<br />
<br />
Mudlet makes the creation of label, miniconsoles and gauges a quick and easy thing. Mudlet provides a nice signal when window resize events happen. To help with complex window management, Geyser steps in.<br />
<br />
=== Main Geyser Features ===<br />
<br />
Geyser is based on traditional GUI concepts and should feel similar to using Java's Swing. The biggest difference is in how positions are specified.<br />
<br />
* All window positions are specified relative to their container - nothing new there. However, window positions can also take on percentages and negative pixel and character values. For instance, a window could be constrained to have a height of 50% of its container and a width such that the window's right edge is always 20 characters from its container's right edge. See examples below and the demos/tests that come with Geyser.<br />
* All windows under Geyser control are automatically resized as necessary when the main Mudlet window is resized. Once you create a window and assign it to a container, you never have to worry about positioning it again. Nonetheless, it's very easy to shift the container that a window is in, maintaining its constraints so that it resizes as needed according to the dimensions of the new container.<br />
* Due to the container hierarchy, hiding a container window automatically hides all its contained windows too. The same for show. With clever construction and labels with callbacks, this lets one make complex GUI elements that are minimizable or maximizable or ...<br />
* However, there is always some overhead for automation systems and Geyser is no exception. Fortunately, most of the overhead is during window creation and resize events - not things that happen frequently.<br />
<br />
=== Getting pictures for your stuff ===<br />
You can find good, freely-available assets for your UI here:<br />
* [https://kenney.nl/assets?q=2d kenney.nl]<br />
* [https://opengameart.org/ opengameart.org]<br />
* [https://game-icons.net/ game-icons.net]<br />
<br />
=== Constraints format ===<br />
<br />
Geyser position constraints are a string composed of a number and a format type. For example, "10px" means 10 pixels, either pixels from the origin (e.g. x or y) or a value for the width or height. A negative number indicates distance from a container's right or bottom border depending on whether is a constraint for x/width or y/height, respectively. Percentages for width and height are in terms of the container's dimensions and negative values are converted to the equivalent positive value. A 100% width subwindow with an x-coordinate of 10 will have part of itself displayed outside the confines of its container. There is no hard limit on maximum window size, just as with regular Mudlet windows. If a number, n, is passed as a constraint instead of a string, it is assumed to be equivalent to "npx". Any Lua table that contains entries for x, y, width and height in the proper format can be used for Geyser constructors and setting constraints. Just like in Mudlet, 0,0 coordinates mean the top-left corner.<br />
<br />
The following is a valid example for coordinates of a Geyser object:<br />
<br />
<syntaxhighlight lang="lua"><br />
{x = "20px", y = "-10c", width = "40%", height = 30}<br />
</syntaxhighlight><br />
<br />
= Geyser elements =<br />
The purpose of this document is to go through every Geyser element and provide practical examples on how they are used. Read it from top to bottom, preferably doing all of the examples to understand how they work!<br />
<br />
See also: https://www.mudlet.org/geyser/files/index.html for a brief and technical overview of all elements and their functions.<br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html Geyser.Container]==<br />
An invisible, organizing object in Geyser - use it to divide your screen and position elements accordingly. '''[http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html See here]''' for all of the functions that are available to you to use.<br />
<br />
A container is also the base class - which means that everything (labels, miniconsoles and gauges) can use its functions, since everything else is at heart a container.<br />
<br />
=== Creating a container ===<br />
To get started with a container, here's an example that'll create a 200px border on the left side of Mudlet for you, and make a container cover all of it - so you can place other visual elements inside it:<br />
<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(200)<br />
left_container = Geyser.Container:new({<br />
name = "left_container", -- give it a unique name here<br />
x=0, y=0, -- have it start at the top-left corner of mudlet<br />
width = 200, height="100%", -- with a width of 200, and a height of the full screen, hence 100%<br />
})<br />
</syntaxhighlight><br />
<br />
Right away, you'll see space appear on the left side. It'll be black, as the container is an invisible unit by itself. You can make sure it's there by making it flash by doing this from the input line:<br />
<br />
<syntaxhighlight lang="lua">lua left_container:flash()</syntaxhighlight><br />
<br />
The command will cause your container to flash for a moment for you, revealing itself.<br />
<br />
{{Note}} If you hide a container and create new Geyser elements within it, they'll be shown automatically for you.<br />
<br />
=== Container within a container ===<br />
You can place containers within other containers by specifying which "parent" the new container should have when you create one. Given our [[#Creating a container|previous example]], you can split the left side into two halves like this:<br />
<br />
<syntaxhighlight lang="lua"><br />
left_container_top = Geyser.Container:new({<br />
name = "left_container_top",<br />
x=0, y=0, -- this container occupies the top, so it starts top-left as well<br />
width = "100%", height="50%", -- but only uses up half of the height<br />
}, left_container) -- this is the important bit - it says that left_container_top should be inside left_container<br />
<br />
left_container_bottom = Geyser.Container:new({<br />
name = "left_container_bottom",<br />
x=0, y="50%", -- this container starts halfway down the first one<br />
width = "100%", height="50%", -- and has the same half height of the original container<br />
}, left_container) <br />
</syntaxhighlight><br />
<br />
=== Aligning relative to bottom or right sides ===<br />
The aligning point within Mudlet is the top-left corner, and it's the same for the elements they are aligned - the position you specify is used by the top-left corner of the element.<br />
<br />
Using Geyser, you can align to the opposite side as well, using the coordinates in negatives, while keeping the dimensions of the object in mind. For example, if you want to align a box that's 20px wide on the usual left side, you'd give it a width of 20 and an x value of 0. If you'd like to align it on the right side, then you'd give it an x value of -20. The box will spawn 20px away from the right side and "grow" to the right by 20px.<br />
<br />
<syntaxhighlight lang="lua"><br />
right_container = Geyser.Container:new({<br />
name = "right_container",<br />
x="-20%", y=0, -- makes the container start 20% of the screen away from the right side<br />
width = "20%", height="50%", -- filling it up until the end<br />
}) <br />
</syntaxhighlight><br />
<br />
Do make sure to account for the scrollbar, as Mudlet UI elements can overlap it. You can also move the scrollbar with [[Manual:UI_Functions#setBorderRight|setBorderRight()]].<br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html Geyser.Label]==<br />
Labels allow you to use pictures in your interface, as well as nicely-formatted text - see docs for label [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html functions].<br />
<br />
=== Basic label ===<br />
<br />
Here's an example to get you started with:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "50%", y = 0,<br />
width = "50%", height = "100%",<br />
fgColor = "black",<br />
color = "SeaGreen",<br />
message = [[<center>heey</center>]]<br />
})<br />
</syntaxhighlight><br />
<br />
This labels '''x''' coordinate is specified as 50% - and because it's not attached to any container, this implies that the window will start halfway at the main window. You can tell it's not attached to a container because there's nothing in between the last ''}'' and '')'', the place where the container goes.<br />
<br />
The '''y''' coordinate is 0 - which means that the label will start at the top of the screen. With the width being 50%, the label will occupy 50% of the screen - and since it starts at the halfway point, it means it'll occupy the entire right side. A height of 100% means that it'll stretch from the top to the full bottom.<br />
<br />
Here's what that'll look like:<br />
<br />
[[File:Simple-label.png|center|600px]]<br />
<br />
<br />
Playing around with the starting location and dimensions, we can also place it in the center of the screen with:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "25%", y = "25%",<br />
width = "50%", height = "50%",<br />
fgColor = "black",<br />
message = [[<center>heey</center>]]<br />
})<br />
testlabel:setColor(0,255,0,150)<br />
</syntaxhighlight><br />
<br />
[[File:Simple_label_centered.png|center|600px]]<br />
<br />
To change the message on a label, you can use the ''mylabel:echo()'' function, where ''mylabel'' is the name of the label you gave it:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:echo("hello!")<br />
</syntaxhighlight><br />
<br />
=== Setting the font size ===<br />
<br />
To set a different font size for your Label, use the ''setFontSize()'' method. For example:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel:setFontSize(14)<br />
</syntaxhighlight><br />
<br />
The font size is set in Pt, so anything above 30 will likely be too large to be useful.<br />
<br />
=== Label inside a container ===<br />
<br />
Once you've got your containers and mastered the basic labels, you can drop labels into your nicely-organized containers. Doing so is similar to nesting containers:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "25%", y = "25%",<br />
width = "50%", height = "50%",<br />
fgColor = "black",<br />
message = [[<center>heey</center>]]<br />
}, left_container_bottom) -- this is where we tell it what container to go into<br />
testlabel:setColor(0,255,0,150)<br />
</syntaxhighlight><br />
<br />
That label is exactly the same as the one above that goes across the screen, except it's in our bottom-left container - so it looks appropriately different:<br />
<br />
[[File:Label in a container.png|center]]<br />
<br />
=== Image on a label ===<br />
One of the more amazing things labels allow you to do is put pictures anywhere on your Mudlet screen, that blend in very well. To do so, once the label is created, use the [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:setBackgroundImage setBackgroundImage()] function with the exact path to the image ([[File:Skullface.png]]):<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = 0, y = "-14px",<br />
width = "16px", height = "14px",<br />
})<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/skullface.png]]) -- update location to actual image location on your computer<br />
</syntaxhighlight><br />
<br />
This'll plop the picture to the bottom-left of your screen. To make the picture show, download the skullface picture above - save it to your desktop, and adjust the location of the image within [[]]'s to what it is on your computer. For example, if you saved this on your Windows 7 desktop, it would be:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label:setBackgroundImage([[C:/Users/<your user name>/Desktop/skullface.png]])<br />
</syntaxhighlight><br />
<br />
(yes, that's / and not \ - \ has been known not to work)<br />
<br />
If you saved this on your Mac desktop, it would be:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label:setBackgroundImage([[/Users/<your user name>/Desktop/skullface.png]])<br />
</syntaxhighlight><br />
<br />
If you saved this on your Ubuntu desktop, it would be:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label:setBackgroundImage([[/home/<your user name>/Desktop/skullface.png]])<br />
</syntaxhighlight><br />
<br />
Using this basic building block, you can work up to making yourself a UI!<br />
<br />
=== Stretching an image on a label ===<br />
If you'd like your image not to keep its original size, but instead use up the available space of the label - you can use the [http://doc.qt.io/qt-5/stylesheet-reference.html#border-image border-image] stylesheet property to do so.<br />
<br />
<syntaxhighlight lang="lua"><br />
label = Geyser.Label:new({<br />
name = "label",<br />
x = "50%", y = "50%",<br />
width = "50%", height = "50%",<br />
})<br />
<br />
-- change the location to your picture<br />
-- on windows, use / to separate folders still, not \<br />
label:setStyleSheet[[<br />
border-image: url(/home/vadi/Desktop/iso-avatar-draft_0.png);<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}} If you're on a Mudlet earlier than 3.15 and are having difficulty with the image coming up, it may be because of strange differences between Qt's CSS engine which does not affect mudlet's Lua. You may want to try appending :gsub("\\","/") to your string including getMudletHomeDir() (e.g. <code>getMudletHomeDir():gsub("\\","/")</code>). No longer necessary after Mudlet 3.15.<br />
<br />
=== Aligning an image within a label ===<br />
You can use background-image in combination with background-position to align an image within a label (if, say, the image is much smaller than the label).<br />
<br />
<syntaxhighlight lang="lua"><br />
-- this will set and align an image top-right of the label<br />
if stunning then<br />
mylabel:setStyleSheet([[<br />
background-image: url("/home/vadi/Games/Mudlet/Offensive/Artwork/dialog-ok.png");<br />
background-repeat: no-repeat; background-position: top right; background-origin: margin;<br />
]])<br />
else<br />
mylabel:setStyleSheet([[<br />
background-image: url("/home/vadi/Games/Mudlet/Offensive/Artwork/dialog-no.png");<br />
background-repeat: no-repeat; background-position: top right; background-origin: margin;<br />
]])<br />
end<br />
</syntaxhighlight><br />
<br />
=== Showing / hiding a label ===<br />
You can show and hide labels, as you can any container, miniconsole or a gauge in Geyser with [http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html#Geyser.Container:show Geyser.Container:show()] and [http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html#Geyser.Container:hide Geyser.Container:hide()]. Remember that since labels are a type of a container, all container functions work on them.<br />
<br />
Hiding a label will allow you to click through on what is below the label, as well as free up the visual space for something else.<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "50%", y = 0,<br />
width = "50%", height = "100%",<br />
fgColor = "black",<br />
color = "SeaGreen",<br />
message = [[<center>heey</center>]]<br />
})<br />
<br />
-- hide the label with:<br />
testlabel:hide()<br />
<br />
-- show the label with:<br />
testlabel:show()<br />
</syntaxhighlight><br />
<br />
=== Clickable images ===<br />
Tacking onto the fact that you can plop images anywhere on your Mudlet screen now, you can also make them react to your clicks. You can do so with the [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:setClickCallback setClickCallback()] function - by giving it a function to call when your label is clicked, you'll make it react.<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = "-215px", y = "0px",<br />
width = "200px", height = "200px",<br />
})<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/qubodup-opengameart-cc0-200px-missile_icon.png]]) -- update location to actual image location on your computer<br />
picture_label:setClickCallback("on_bomb_press")<br />
<br />
function on_bomb_press()<br />
send("say BOOM!")<br />
end<br />
</syntaxhighlight><br />
<br />
That's it! Pressing on the image will make the ''on_bomb_press()'' function go off, which will do its code of ''send("say BOOM!")''. Download the picture for use [http://opengameart.org/content/missile-rts-icon here].<br />
<br />
[[File:Clickable_image.png|500px|center]]<br />
<br />
=== Styling labels ===<br />
Besides putting text or images on labels, you can also style them using Qt's stylesheets feature. Doing so allows you to create various graphics that make the label look more appealing:<br />
<br />
[[File:Label_styling_examples.png|center]]<br />
<br />
To set a stylesheet on a label, use the [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:setStyleSheet Geyser.Label:setStyleSheet()] function on your label, describing the stylesheet you'd like to give it. A stylesheet consists of properties you set - for example the background color, borders, padding, and so forth. You describe properties in the following format: ''property name''''':'''''values''''';'''. See here for a [http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties list of all supported properties]. For example, to make your labels background be yellow, you'd use the background-color property:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel = Geyser.Label:new({<br />
x = "50%", y = "50%",<br />
width = 200, height = 100<br />
})<br />
<br />
mylabel:setStyleSheet([[<br />
background-color: yellow;<br />
]])<br />
</syntaxhighlight><br />
<br />
[[File:Basic_stylesheet.png|center]]<br />
<br />
Which is nice, but not particularly impressive.<br />
<br />
Scrolling down the list of properties, you'll come along a border one. Plopping it into our stylesheet nets the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
background-color: yellow;<br />
border: 5px solid white;<br />
]])<br />
</syntaxhighlight><br />
<br />
[[File:Basic_stylesheet_border.png|center]]<br />
<br />
Which gives a border!<br />
<br />
Fiddling with it some more and applying new properties we find on that page, we get a rounded border on our label:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
background-color: grey;<br />
border-width: 15px;<br />
border-style: solid;<br />
border-color: green;<br />
border-radius: 10px;<br />
]])<br />
</syntaxhighlight><br />
<br />
[[File:Basic_stylesheet_border_radius.png|center]]<br />
<br />
Which'll conclude our exploration for now. Try out all of the other possible options available there - there's loads, from [http://doc.qt.io/qt-5/stylesheet-reference.html#border-style funky borders], to tiling images and fancy color combinations using gradients.<br />
<br />
=== Adding a tooltip to a label ===<br />
<br />
Since Mudlet 4.6, you can now add a tooltip to labels and gauges. You can start by making a simple label and echoing some text to it:<br />
<br />
<syntaxhighlight lang="lua"><br />
testLabel = Geyser.Label:new({<br />
name = "testLabel",<br />
x = "50%",<br />
y = "50%",<br />
height = "25%",<br />
width = "25%",<br />
})<br />
testLabel:echo("This is on the label!")<br />
testLabel:setAlignment("center")<br />
-- sets the tooltip text<br />
testLabel:setToolTip("This is the tooltip", "10")<br />
<br />
<br />
-- optionally - you can customise the tooltip, too!<br />
testLabel:setStyleSheet("QToolTip{background: yellow; color: blue; border:none;}")<br />
</syntaxhighlight><br />
<br />
Without tooltip<br />
[[File:TestLabelForTooltips.png|thumb|center]]<br />
<br />
With tooltip<br />
<br />
[[File:LabelTooltip.png|thumb|center]]<br />
<br />
=== Avoid stylesheet inheritance by tooltip ===<br />
<br />
{{note}} If you set a new stylesheet for a label and with that a background image it is possible that through inheritance the tooltip also has this stylesheet image.<br />
<br />
To avoid this specify that the stylesheet is meant for the Label by using QLabel{...} in your Label stylesheet for exampleː<br />
<syntaxhighlight lang="lua"><br />
label = Geyser.Label:new({<br />
name = "label",<br />
x = "50%", y = "50%",<br />
width = "50%", height = "50%",<br />
})<br />
<br />
-- by using QLabel{...} the stylesheet won't be given to the tooltip as well<br />
label:setStyleSheet[[<br />
QLabel{<br />
border-image: url(/home/vadi/Desktop/iso-avatar-draft_0.png);}<br />
]]<br />
</syntaxhighlight><br />
<br />
<br />
=== Aligning text/images inside a label ===<br />
By default, text is [http://qt-project.org/doc/qt-5/qlabel.html#alignment-prop centered vertically and left aligned] in a label. To align it to a specific side, use the stylesheets we learnt about earlier with the qproperty-alignment:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "50%", y = 0,<br />
width = "50%", height = "100%",<br />
fgColor = "black",<br />
color = "SeaGreen",<br />
message = [[<center>heey</center>]]<br />
})<br />
<br />
-- specify one property this way:<br />
mylabel:setStyleSheet([[qproperty-alignment: 'AlignTop';]])<br />
<br />
-- or multiple ones separated with a |, for example this will align text to top-left:<br />
-- specify one property this way:<br />
mylabel:setStyleSheet([[<br />
qproperty-alignment: 'AlignLeft | AlignTop';<br />
]])<br />
<br />
mylabel:echo("hi!")<br />
</syntaxhighlight><br />
<br />
[[File:Text_aligned.png|center]]<br />
<br />
=== Enabling wordwrap in a label ===<br />
If you need to enable word wrapping in a label (which by default is off), add the following line to the labels stylesheet:<br />
<br />
qproperty-wordWrap: true;<br />
<br />
As an example:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
qproperty-wordWrap: true;<br />
]])<br />
</syntaxhighlight><br />
<br />
If you'd like to set multiple properties, set them all at once - not via multiple :setStyleSheet() calls:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
background: red;<br />
]])<br />
</syntaxhighlight><br />
<br />
=== Adding a hover effect to a label ===<br />
The labels support adding stylesheets for specific cases, such as when a mouse is [http://doc.qt.io/qt-5/stylesheet-reference.html#hover-ps hovering] over them. To make this work, you provide CSS for when the label is in its usual state, and for when it is hovered over:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example will add a border to the label when it is hovered over<br />
mylabell:setStyleSheet([[<br />
QLabel{ border-radius: 4px; }<br />
QLabel::hover{<br />
background-color: rgba(0,0,0,0%);<br />
border: 4px double green;<br />
border-radius: 4px;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
=== Checkboxes ===<br />
Combining the fact that you can click on a label with an image to do something with the fact that you can change pictures on a label at will, you can make an image that changes itself when you click on it.<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = "50%", y = "50%",<br />
width = "21px", height = "19px"<br />
})<br />
-- a little trick we do to make the background of the label be transparent<br />
picture_label:setStyleSheet([[<br />
background-color: rgba(0,0,0,0%);<br />
]])<br />
<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/checkbox_ticked.png]])<br />
picture_label:setClickCallback("on_checkbox_press")<br />
<br />
function on_checkbox_press()<br />
if checkbox_ticked then<br />
checkbox_ticked = false<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/checkbox_unticked.png]])<br />
echo("Checkbox unticked.\n")<br />
else<br />
checkbox_ticked = true<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/checkbox_ticked.png]])<br />
echo("Checkbox TICKED!\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
The ''on_checkbox_press()'' function this time keeps the track of the checkbox with the ''checkbox_ticked'' variable and sets the image appropriately. You can download the ticked ([[File:Checkbox_ticked.png]]) and unticked images ([[File:Checkbox_unticked.png]]) or the [http://wiki.mudlet.org/images/6/6d/Checkbox.mpackage whole package] altogether.<br />
<br />
[[File:Checkbox_demo.png|500px|center]]<br />
<br />
=== Animated labels ===<br />
Using timers and several pictures, you can make your labels change quickly enough and look animated. Here's one such example:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = 10, y = "-24px",<br />
width = "16px", height = "14px",<br />
})<br />
<br />
santa_counter = nil<br />
<br />
function animate_santa()<br />
santa_counter = (santa_counter or 0) + 1<br />
if santa_counter > 8 then santa_counter = 1 end<br />
<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/santa/santa]]..santa_counter..[[.png]]) -- update location to actual image location on your computer<br />
santa_timer = tempTimer(.16, animate_santa)<br />
end<br />
<br />
animate_santa()<br />
</syntaxhighlight><br />
<br />
The completed package is available [http://wiki.mudlet.org/images/6/6b/Dancing-santa.mpackage here], install it and do '''start/end animation''' to watch.<br />
<br />
=== Inserting extra spaces and newlines ===<br />
Echoing text into Mudlet and Geyser labels is different from miniconsoles and the main window, due to their nature. One of the differences is that extra spaces in a label, by default, get compressed down to one. '''To add extra spaces in a label''', replace extra spaces with '''&amp;nbsp;''' or by wrapping your text with them inside '''<nowiki><pre>my text here</pre></nowiki>'''.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- this won't work, it'll show as one space:<br />
mylabel:echo("You -> point")<br />
<br />
-- but this would, because it replaces all spaces with &nbsp before echoing<br />
mylabel:echo(string.gsub("You -> point", " ", "&nbsp;"))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- here is another way to go about this - and it additionally makes the font be monospaced:<br />
mylabel:echo("<pre>You -> point</pre>")<br />
</syntaxhighlight><br />
<br />
'''To add a new line in a label''' (aka linebreak), use '''<br>''' (instead of ''\n'' as you are used to in an echo).<br />
<syntaxhighlight lang="lua"><br />
mylabel:echo("These<br>words<br>are<br>split")<br />
</syntaxhighlight><br />
<br />
=== Transparent labels ===<br />
One of the possible ways of achieving transparency on a label is to add <code>background-color: rgba(0,0,0,0%);</code> to its stylesheet. Here's an example:<br />
<br />
<syntaxhighlight lang="lua"><br />
my_transparent_label:setStyleSheet([[<br />
background-color: rgba(0,0,0,0%);<br />
]])<br />
</syntaxhighlight><br />
<br />
=== Custom mouse cursor ===<br />
You can change the shape of the cursor when it's over your label with:<br />
<syntaxhighlight lang="lua"><br />
mylabel:setCursor("Forbidden") -- will change your mouse cursor to "forbidden" (as in "can't do this") cursor<br />
</syntaxhighlight><br />
Possible cursor shapes are [[CursorShapes| available here]], and you can import this [[Media:Cursor grid.zip|demo package]] to try them all out.<br />
<br />
It is also possible to change the mouse cursor to a custom made cursor by:<br />
<syntaxhighlight lang="lua"><br />
mylabel:setCustomCursor(getMudletHomeDir().."/custom_cursor.png")<br />
</syntaxhighlight><br />
It is recommended that the custom cursor is a png with size of 32x32 to be supported on all systems.<br />
<br />
[[File:Changecursoroverlabel.gif]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
=== Flyout Labels ===<br />
<br />
Flyout labels allow you to create 'dropdown' or 'flyout' menus - menus that reveal more items once you hover your mouse over them. To create flyout labels:<br />
# add <code>nestable=true</code> (left click to open menu) or <code>nestflyout=true</code> (mouse hover to open menu) to your main label.<br />
# use [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:addChild :addChild()] on your main label to add flyout labels to it.<br />
## [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:addChild :addChild()] uses the same arguments as when creating a new label but also takes the '''layoutDir''' option to specify in which direction and axis should the labels align, where 2 letters combine into the option: first letter R for right, L for left, T for top, B for bottom, followed by the orientation: V for vertical or H for horizontal. So options are: <code>layoutDir="RV"</code>, <code>layoutDir="RH"</code>, <code>layoutDir="LV"</code>, <code>layoutDir="LH"</code>, and so on.<br />
# optionally, add <code>flyOut=true</code> to your flyout labels to make the labels dissapear when the mouse isn't hovering over them anymore.<br />
<br />
Note that the main flyout label cannot go into a container and needs to be on its own.<br />
<br />
{{note}} Requires Mudlet 3.0.<br />
<br />
==== Demo ====<br />
Here's an example that follows the steps above:<br />
<br />
<syntaxhighlight lang="lua"><br />
label0 = Geyser.Label:new({name="label0", <br />
x="50%",y="50%",height=50,width=300,nestable=true, <br />
message="<center>Clicky clicky</center>"})<br />
<br />
-- and add 3 labels to it with RV layout - so Right of the label, aligned Vertically<br />
label1 = label0:addChild({name="label1",height=30,width=70, layoutDir="RV", flyOut=true, message="label one"})<br />
label1:setStyleSheet([[background-color: purple; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px; font-size: 7pt;]])<br />
<br />
label2 = label0:addChild({name="label2",height=30,width=70, layoutDir="RV", flyOut=true, message="label two"}) <br />
label2:setStyleSheet([[background-color: green; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px; font-size: 7pt;]])<br />
<br />
label3 = label0:addChild({name="label3",height=30,width=70, layoutDir="RV", flyOut=true, message="label three"})<br />
label3:setStyleSheet([[background-color: red; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px; font-size: 7pt;]])<br />
</syntaxhighlight><br />
<br />
A more thorough example. Try it out to see what you can create with flyout labels:<br />
<syntaxhighlight lang="lua"><br />
-- create a label with a nestable=true property to say that it can nest labels<br />
mainlabel = Geyser.Label:new({name="testa", x=400,y=50,height=50,width=300,nestflyout=true, message="<center>HOVER HERE TO SEE FLY-OUT LABELS!</center>"})<br />
<br />
-- create 15 labels and store them in a table <br />
table_for_flyout_labels = {}<br />
for i=1,15 do<br />
-- options to layoutDir are the direction the window should go (R for right, L for left, T for top, B for bottom), followed by how the nested labels should be oriented (V for vertical or H for horizontal). So "BH" here means it'll go on the bottom of the label, while expanding horizontally<br />
table_for_flyout_labels[i] = mainlabel:addChild({name="test"..tostring(i),height=30,width=70, layoutDir="BH", flyOut=true, message="test"..tostring(i)})<br />
<br />
table_for_flyout_labels[i]:setStyleSheet([[background-color: purple; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px;]])<br />
end<br />
<br />
-- make the test5 label look a bit special as it has got a surprise<br />
table_for_flyout_labels[5]:echo("Hover here")<br />
<br />
-- add even more nested labels to the 5th label!<br />
even_more_flyout_labels = {}<br />
for i=1,60 do<br />
-- here, the layout will be to the right of it, while expanding vertically<br />
even_more_flyout_labels[i]=table_for_flyout_labels[5]:addChild({name="hover label "..tostring(i),height=30,width=100, layoutDir="RV", flyOut=true, message="label "..tostring(i)})<br />
even_more_flyout_labels[i]:setClickCallback("testFunc", even_more_flyout_labels[i].name)<br />
even_more_flyout_labels[i]:setStyleSheet([[background-color: grey; border-width: 2px; border-style: solid; border-color: green; border-width: 2px; font-size: 7pt;]])<br />
end<br />
<br />
function testFunc(name)<br />
display(name)<br />
end<br />
</syntaxhighlight><br />
<br />
It'll look something like this: <br />
<br />
[[File:Flyout_labels_demo.png|150px]]<br />
<br />
==== Demo of layouts ====<br />
Here's another demo that explains all of the layout styles quite well:<br />
<syntaxhighlight lang="lua"><br />
local directions = {"R", "L", "T", "B"}<br />
local orientations = {"V", "H"}<br />
local mappings = {R = "right", L = "left", T = "top", B = "bottom", V = "vertical", H = "horizontal"}<br />
<br />
local combinations, combination_labels = {}, {}<br />
for _, direction in pairs(directions) do<br />
for _, orientation in pairs(orientations) do<br />
combinations[#combinations+1] = direction..orientation<br />
end<br />
end<br />
<br />
local function get_foreground_text_colour(r,g,b)<br />
local luminosity = (0.2126 * ((r/255)^2.2)) + (0.7152 * ((g/255)^2.2)) + (0.0722 * ((b /255)^2.2))<br />
if luminosity > 0.5 then<br />
return "black"<br />
else<br />
return "white"<br />
end<br />
end<br />
<br />
local function get_random_colour_rgb()<br />
return math.random(1,255), math.random(1,255), math.random(1,255)<br />
end<br />
<br />
-- create a label with a nestable=true property to say that it can nest labels<br />
all_possible_combinations_label = Geyser.Label:new({name="all_possible_combinations_label", x=0,y="-400",height=50,width=500,<br />
nestable = true, message="<center>Click to see a listing of possible combinations</center>"})<br />
<br />
for i = 1, #combinations do<br />
local combination = combinations[i]<br />
combination_labels[i] = all_possible_combinations_label:addChild({name="combo_"..combination,height=30,width=150, nestable = true, flyOut=true, layoutDir="BH", message="<center>Combination "..combination.."</center>"})<br />
<br />
local r,g,b = get_random_colour_rgb()<br />
local text_colour = get_foreground_text_colour(r,g,b)<br />
<br />
local combination_labels_children = {}<br />
for ii = 1, 3 do<br />
combination_labels_children[ii] = combination_labels[i]:addChild({<br />
name="combo_"..combination.."_"..ii, height = 30, width = 150, layoutDir=combination, flyOut = true,<br />
message = string.format("<center><b>%s</b>%s+<b>%s</b>%s layout</center>", <br />
combination:sub(1,1), mappings[combination:sub(1,1)]:sub(2), combination:sub(2,2), mappings[combination:sub(2,2)]:sub(2)),<br />
fgColor = text_colour})<br />
<br />
combination_labels_children[ii]:setStyleSheet(string.format([[background-color:rgb(%d, %d, %d); border-width: 2px; border-style: solid; border-color: green; border-width: 2px; font-size: 7pt;]], r,g,b))<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
It'll look like this:<br />
<br />
[[File:Flyoutlabels-layout-demo.png]]<br />
<br />
=== Geyser.Label right click menu ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
You can create a right click menu for a label just by using the function (assuming your label name is 'myLabel')<br />
<syntaxhighlight lang="lua"> myLabelːcreateRightClickMenu(MenuItems = myMenuTable, other cons) -- see example below for details </syntaxhighlight><br />
<br />
The menu table comprises of all the items and their names. To create a parent menu just create a nested table of names.<br />
Example of a menuTable<br />
<syntaxhighlight lang="lua"> menuTable = {"First Item", "Second Item (Parent)",{"First ChildItem","Second ChildItem"}, "Third Item"} </syntaxhighlight><br />
As menu would look likeː<br />
<br />
[[File:RCDemo1.gif|250px]]<br />
<br />
==== Style your right click menu ====<br />
Your right click menu has 2 default styles integratedː "light" and "dark" which are defined by the constraint "Style".<br />
To set a default style just give the constraint Style the preferred value, for exampleː<br />
<syntaxhighlight lang="lua"> Style = "dark" </syntaxhighlight><br />
To give different levels of your menu different style just add the number of the level to the constraint, for exampleː<br />
<syntaxhighlight lang="lua"> Style2 = "light" -- Gives the second level of your menu the "light" style</syntaxhighlight><br />
<br />
For adding your own stylesheet use the constraint MenuStyle (use the same method as above to define stylesheets for different levels)<br />
<syntaxhighlight lang="lua"> MenuStyle2 = [[QLabel::hover{ background-color: rgba(0,255,150,100%); color: white;} QLabel::!hover{color: brown; background-color: rgba(100,240,240,100%);} ]] <br />
-- Gives the second level of your menu this stylesheet</syntaxhighlight><br />
<br />
The same methods are used for defining the format, width and height for the menu item.<br />
<syntaxhighlight lang="lua"> <br />
MenuWidth = 70 -- standard menu width if nothing else is given<br />
MenuWidth2 = 80 -- menu width for the second level <br />
MenuFormat1 = "c10" -- menu format for the first level (format works like any other label echo format, in this case c is center and 10 is the font-size)<br />
MenuHeight = 30<br />
</syntaxhighlight><br />
<br />
==== Set onClick action for your menu item ====<br />
To set an action if your menu item is clicked use the function (assuming your label name is 'myLabel' and using the same MenuItems as defined above)<br />
<syntaxhighlight lang="lua"> <br />
myLabelːsetMenuAction("First Item", function() echo("Clicked on the first item\n") end<br />
myLabelːsetMenuAction("Second Item (Parent).First ChildItem", function() echo("Clicked on the first child item\n") end) -- To set an action to a child item find it by using "Parent.Child" as name (only one parent is needed to be given the parents parent is not needed)<br />
</syntaxhighlight><br />
<br />
==== Access an menu item directly ====<br />
The simplest way to access a menu item directly is by just using the function (assuming your label name is 'myLabel' and using the same MenuItems as defined above)<br />
For example to change the menu item textː<br />
<syntaxhighlight lang="lua"> <br />
myLabelːfindMenuElement("First Item"):echo([[my first Item]])<br />
</syntaxhighlight><br />
<br />
==== Right click menu example ====<br />
Better then any further explanation is probably this practical example. <br />
<br />
<syntaxhighlight lang="lua"> <br />
-- create the label the right click menu will be in<br />
myRightClickLabel = myRightClickLabel or Geyser.Label:new({<br />
name = "myRightClickLabel", message = "Please right click!", <br />
format = "cb15", x=10, y=10, width ="30%", height = "15%", <br />
color = "purple"})<br />
<br />
-- right click menu creation with custom styleheet on level2 and default "Dark" style <br />
myRightClickLabel:createRightClickMenu(<br />
{MenuItems = {"Emergency", "Drink",{"ManaPotion","HealthPotion"}, "Disappear", "Cast",{"Blindness", "Blink"}}, <br />
Style = "Dark", <br />
MenuWidth2 = 80, <br />
MenuFormat1 = "c10",<br />
MenuStyle2 = [[QLabel::hover{ background-color: rgba(0,255,150,100%); color: white;} QLabel::!hover{color: brown; background-color: rgba(100,240,240,100%);} ]]}<br />
)<br />
<br />
myRightClickLabel:setMenuAction("Emergency", function() <br />
cecho("<red:pink>[Emergency Mode] Run as fast as possible!\n") <br />
send("emergency") <br />
closeAllLevels(myRightClickLabel) -- this can be used to close the right click menu if clicked on this item<br />
end)<br />
<br />
myRightClickLabel:setMenuAction("Drink.ManaPotion", function()<br />
cecho("<blue>Drinking my mana potion.\n") <br />
send("drink mp") <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Drink.HealthPotion", function() <br />
cecho("<red>Drinking my health potion.\n") <br />
send("drink hp") <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Disappear", function() <br />
cecho("<grey>Disappearing.. \n") <br />
send("disappear") <br />
closeAllLevels(myRightClickLabel) <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Cast.Blindness", function() <br />
cecho("<light_blue>Casting blindness \n") <br />
send("cast blindness enemy") <br />
closeAllLevels(myRightClickLabel) <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Cast.Blink", function() <br />
cecho("<light_blue>Casting blink \n") <br />
send("cast blink") <br />
end )<br />
</syntaxhighlight><br />
<br />
This looks likeː<br />
<br />
<br />
[[File:Right click example demo.gif]]<br />
<br />
=== Add right click menu to label with already existing left click action ===<br />
If your label has an already existing left click action you'll have to create the right click menu<br />
"before" creating the labels "setClickCallBack" action and then just put into your labels onClick function<br />
(assuming your label name is 'myLabel' and 'event' is the last parameter of your onClick function)<br />
<br />
<syntaxhighlight lang="lua"> <br />
myLabel:onRightClick(event)<br />
</syntaxhighlight><br />
<br />
=== Background for Mudlets buttons ===<br />
You can give Mudlets buttons a background to have them blend in with your UI by doing this:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace the /home/vadi/Pictures/tile.png location below with the one of your picture!<br />
-- you can download the sample tile.png from https://opengameart.org/content/bevouliin-free-game-background-for-game-developers<br />
local backgroundpath = [[/home/vadi/Pictures/tile.png]]<br />
-- Windows:<br />
-- local backgroundpath = [[C:/Users/Vadim/Downloads/Free game background/transparent PNG/tile.png]]<br />
<br />
setAppStyleSheet([[<br />
QToolBar {<br />
border-image: url(]]..backgroundpath..[[);<br />
<br />
}<br />
<br />
QToolBar QToolButton:!hover {<br />
color: white;<br />
}<br />
QToolBar QToolButton:hover {<br />
color: black;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
Result:<br />
<br />
[[File:Mudlet tiled buttons.png|frame|left]]<br />
<br clear=all><br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserMiniConsole.html Geyser.MiniConsole]==<br />
This allows you to spawn a Mudlet miniconsole - unlike labels, these aren't as styleable, but they do format text better. They make a good fit for text-based menus, chat and map capture, and other things.<br />
<br />
Spawning one is very similar to other Geyser elements - paste this into a new script:<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
autoWrap = true,<br />
color = "black",<br />
scrollBar = false,<br />
fontSize = 8,<br />
width="30%", height="50%",<br />
})<br />
</syntaxhighlight><br />
<br />
This'll make you one at the bottom-right of the screen. The miniconsole will have a grey background by default, but you can set it to any color you'd like with [http://www.mudlet.org/geyser/files/geyser/GeyserWindow.html#Geyser.Window:setColor miniconsole:setColor()]:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:setColor("black") -- give it a nice black background<br />
</syntaxhighlight><br />
<br />
A special dimension property that MiniConsoles have is a character - instead of specifying a miniconsole to be % of a container or a certain number of pixels, you can specify it as a certain number of characters. You do this by using "c" at the end of a number. This way, you can, for example, specify miniconsole to be 10 letters long and 2 lines high:<br />
<br />
<syntaxhighlight lang="lua"><br />
flatbox = Geyser.MiniConsole:new({<br />
name="flatbox",<br />
x="70%", y="50%",<br />
wrapAt = 10,<br />
width="10c", height="2c",<br />
})<br />
flatbox:setColor("red")<br />
flatbox:echo("ABCDEFGHIJ") -- that is 10 letters<br />
</syntaxhighlight><br />
<br />
=== Adding text ===<br />
You can use [[Manual:Technical_Manual#echo|echo()]] the same way with a miniconsole to add text as to the usual window:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("hello!")<br />
</syntaxhighlight><br />
<br />
As well as [[Manual:Technical_Manual#cecho|cecho]], [[Manual:Technical_Manual#decho|decho]], or [[Manual:Technical_Manual#hecho|hecho]]:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:cecho("<green>hey, <blue>colored <red>text!\n")<br />
</syntaxhighlight><br />
<br />
=== Copying lines with color ===<br />
To copy a line over to the miniconsole, as it is from the game with all colors preserved, you can [[Manual:UI_Functions#selectCurrentLine|select]], [[Manual:UI_Functions#copy|copy]], and [[Manual:UI_Functions#appendBuffer|append]] it. For an example, try making a trigger with this as the ''Lua function'' pattern type:<br />
<br />
<syntaxhighlight lang="lua"><br />
return true<br />
</syntaxhighlight><br />
<br />
That'll make the trigger go off on every line. Then give it the following script (assumed you have made the HelloWorld miniconsole from earlier):<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
copy()<br />
HelloWorld:appendBuffer()<br />
</syntaxhighlight><br />
<br />
... and you'll see all MUD output duplicated exactly as it is to the miniconsole. Amazing! It's very efficient as well, so you can have many miniconsoles, even in spam, not lag you down.<br />
<br />
=== Clearing the miniconsole ===<br />
Clearing the miniconsole just requires using the following script (assumes you have made the HelloWorld miniconsole from earlier):<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:clear()<br />
</syntaxhighlight><br />
<br />
=== Doing edits in copied lines ===<br />
Sometimes you'll want to edit the line before stuffing it into the miniconsole. For example, if you're making a chat capture, you'd want to condense a really long org name into something that's more space-friendly.<br />
<br />
To do so, you'd use the [[Manual:Technical_Manual#selectString|selectString()]] the text you'd like to modify, [[Manual:Technical_Manual#replace|replace()]] it with a different one:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString("Your", 1) -- select the word you'd like to replace - in this case, 'Your'<br />
setBgColor(getBgColor()) -- preserve the background color in the replacement<br />
setFgColor(getFgColor()) -- preserve the foreground color in the replacement<br />
replace("Mine") -- replace the selection with the wird 'Mine'<br />
<br />
selectCurrentLine()<br />
copy()<br />
HelloWorld:appendBuffer()<br />
</syntaxhighlight><br />
<br />
=== Gagging from the main window ===<br />
If you'd like to gag the line from the main window so it only shows up in your miniconsole, [[Manual:Technical_Manual#deleteLine|delete]] it after moving it over:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
copy()<br />
HelloWorld:appendBuffer()<br />
deleteLine()<br />
</syntaxhighlight><br />
<br />
=== Clickable menus ===<br />
Using the [[Manual:Technical_Manual#echoLink|echoLink]], [[Manual:Technical_Manual#insertLink|insertLink]] and [[Manual:Technical_Manual#setLink|setLink]] functions, you can turn text into one that reacts on a click. Combined with your power of placing text anywhere on the screen with a miniconsole, you can make menus with options. Here is one such example, where selecting an item causes an echo to happen:<br />
<br />
<syntaxhighlight lang="lua"><br />
flatbox = Geyser.MiniConsole:new({<br />
name="flatbox",<br />
x="20%", y="80%",<br />
width="40c", height="4c",<br />
})<br />
flatbox:setColor("red")<br />
clearWindow("flatbox")<br />
<br />
flatbox:cecho("<white:red>Choose one of the following options:\n")<br />
<br />
flatbox:fg("white")<br />
flatbox:bg("red")<br />
<br />
for _, fruit in ipairs{"banana", "apple", "orange"} do<br />
echoLink("flatbox", "* "..fruit:title().."\n", [[echo("You picked ]]..fruit..[[\n")]], "The "..fruit.." option", true)<br />
end<br />
<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
This will produce something like the following:<br />
<br />
[[File:Fruit_menu.png|center]]<br />
<br />
=== Change your miniconsole background image ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
To set a custom background image for your miniconsole use (assumes you have made the HelloWorld miniconsole from earlier): <br />
<syntaxhighlight lang="lua"><br />
HelloWorld:setBackgroundImage(getMudletHomeDir().."/myBgImage.png", "center") -- put's your image myBgImage.png which is in your profile folder in the center of the miniconsole<br />
</syntaxhighlight><br />
<br />
For different modes/options see here [[Manual:Lua_Functions#setConsoleBackgroundImage|setConsoleBackgroundImage()]]<br />
<br />
=== Enable and use your miniconsole command line ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
Every miniconsole has a hidden command line.<br />
Enable it with (assumes you have made the HelloWorld miniconsole from earlier): <br />
<syntaxhighlight lang="lua"><br />
HelloWorld:enableCommandLine()<br />
</syntaxhighlight><br />
<br />
=== Set an action to your miniconsole command line ===<br />
If no action is set to your miniconsole command line the commands are send to the game the same way <br />
as for the main command line <br />
<br />
(aliases still work and there is a command echo in your main and miniconsole if not deactivated in the settings)<br />
<br />
It is possible to set an action to your command line which means that it is possible to use the input text and perform an action.<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:enableCommandLine()<br />
local function channelChat(text)<br />
send("chat "..text)<br />
HelloWorld:echo("[chat] " ..text.."\n")<br />
end<br />
<br />
HelloWorld:setCmdAction(channelChat)<br />
</syntaxhighlight><br />
<br />
This will send your miniconsole command line input to the chat channel.<br />
<br />
More complicated/sophisticated actions are possible, setCmdAction works the same way as the Label clickCallback functions.<br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserGauge.html Geyser.Gauge]==<br />
<!--<br />
This is a composite window. Gauge duplicates the functionality of the built in Mudlet gauges, but in a clean and easily extended way. Internally, a Geyser Gauge is a container holding two Labels, front and back, which are initially scaled to fill the entire Gauge container. Hence, a gauge, g, can be given callbacks with the g.front:setClickCallback() method.<br />
<br />
The backgroundColor parameter initially sets the colors of the gauge, but of course the front and back components can be accessed individually as labels for high control over their looks. Gauges can be horizontal or vertical and decrease in value left to right, right to left, down up or up down depending on the value of the orientation parameter.<br />
--><br />
<br />
A Gauge allows you to represent numbers on a scale - and most typically, you've seen it be used as your standard hp/mana/whatever bar. A basic bar is made similarly to other Geyser elements. To set the value on the gauge that it should represent, use the [http://www.mudlet.org/geyser/files/geyser/GeyserGauge.html#Geyser.Gauge:setValue setValue()] function:<br />
<br />
<syntaxhighlight lang="lua"><br />
hpbar = Geyser.Gauge:new({<br />
name="hpbar",<br />
x="50%", y="85%",<br />
width="45%", height="5%",<br />
})<br />
hpbar:setValue(math.random(1,100),100)<br />
</syntaxhighlight><br />
<br />
That'll spawn you a pretty basic gauge with a horizontal orientation and a grey colour - and as a test, with a random value.<br />
<br />
[[File:Basic_gauge.png|center]]<br />
<br />
=== Updating a gauge ===<br />
You'd want your gauge to stay in sync with your actual values. To make that happen, you want to call [http://www.mudlet.org/geyser/files/geyser/GeyserGauge.html#Geyser.Gauge:setValue setValue()] whenever the value that the gauge is tracking changes.<br />
<br />
So for example, if you make a health bar - wherever you get your new health at (be it prompt, gmcp, atcp or whatever), update the gauge as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- theoretical example<br />
current_health, max_health = tonumber(matches[2]), tonumber(matches[3])<br />
<br />
-- update the bar<br />
hp_bar:setValue(current_health, max_health)<br />
</syntaxhighlight><br />
<br />
You can also write down how much health have you got on the bar with:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local hp = math.random(1,100) <br />
hpbar:setValue(current_health, max_health, "<b>"..max_health.."hp</b>")<br />
<br />
-- example using GMCP in IRE games:<br />
hpbar:setValue((100/gmcp.Char.Vitals.maxhp)*gmcp.Char.Vitals.hp,100,gmcp.Char.Vitals.hp)<br />
</syntaxhighlight><br />
<br />
[[File:Hpbar_basic.png|center]]<br />
<br />
=== Styling a gauge ===<br />
The Geyser gauge is composed of three labels - one is called ''mygauge.front'', ''mygauge.back'' and ''mygauge.text''. Combining this with Geyser:Label.setStyleSheet, you can improve the visuals of your gauges by using Qt-supported CSS. The syntax for specifying CSS is a bit different - it requires a semicolon after every property, and is done in the format of ''property name''''':'''''values''''';'''. A list of all possible properties you can use is [http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties available here] and you can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create them. Practical example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hpbar = Geyser.Gauge:new({<br />
name="hpbar",<br />
x="50%", y="85%",<br />
width="45%", height="20px",<br />
})<br />
hpbar.front:setStyleSheet([[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #98f041, stop: 0.1 #8cf029, stop: 0.49 #66cc00, stop: 0.5 #52a300, stop: 1 #66cc00);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;<br />
]])<br />
hpbar.back:setStyleSheet([[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #78bd33, stop: 0.1 #6ebd20, stop: 0.49 #4c9900, stop: 0.5 #387000, stop: 1 #4c9900);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;<br />
]])<br />
<br />
hpbar:setValue(math.random(1,100),100)<br />
</syntaxhighlight><br />
<br />
[[File:Fancy_Geyser_gauge.png|center]]<br />
<br />
The same style can be adjusted by colors to red as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
hpbar = Geyser.Gauge:new({<br />
name="hpbar",<br />
x="50%", y="85%",<br />
width="45%", height="20px",<br />
})<br />
hpbar.front:setStyleSheet([[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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
hpbar.back:setStyleSheet([[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
<br />
hpbar:setValue(math.random(1,100),100)<br />
</syntaxhighlight><br />
<br />
[[File:Fancy_Geyser_gauge_red.png|center]]<br />
<br />
=== Updating a gauge ===<br />
The Geyser gauge is composed of three labels - one is called ''mygauge.front'', ''mygauge.back'' and ''mygauge.text''. To make a gauge clickable you can set a ClickCallBack on the top label which is ''mygauge.text'' example: <syntaxhighlight lang="lua">mygauge.text:setClickCallback("functionName", variableToSendToFunctionName)</syntaxhighlight><br><br />
If you would like to have different click events for the top or back of a gauge you can enable clickThrough for the top or ''mygauge.text'' label example<br />
<br />
<syntaxhighlight lang="lua"><br />
mygauge.text:enableClickthrough()<br />
mygauge.front:setClickCallback("functionOne", variableToSendToFunctionOne)<br />
mygauge.back:setClickCallback("functionTwo", variableToSendToFunctionTwo)<br />
</syntaxhighlight><br />
<br />
<br />
=== Tooltips on gauges ===<br />
Tooltips are available since Mudlet 4.6 as explained in above section [[#Adding_a_tooltip_to_a_label]], and as gauges are really only made up of labels as well, you could add a tooltip then by just using <syntaxhighlight lang="lua">mygauge.text:setToolTip("This is the gauge's tooltip", "10")</syntaxhighlight> the same as it's handled for clickback.<br />
<br />
== HBox/VBox ==<br />
<br />
These are special types of containers. Every window in these is horizontally or vertically aligned in the order they were added.<br />
<br />
<sub>Added to Mudlet in 2.0-rc4</sub><br />
<br />
== Geyser.UserWindow ==<br />
Allows you to use Mudlets UserWindows within Geyser, which allows you to use all the functionality of a MiniConsole in its basic form.<br />
The big advantage is the possibility to add other Geyser Elements like Labels, MiniConsole, Gauges, Mappers to the UserWindow.<br />
The UserWindow then can act as container for those elements with all the perks of dynamic resizing or any other Geyser functionality.<br />
<br />
{{note}} available in Mudlet 4.6.1+<br />
<br />
===Basic floating UserWindow ===<br />
This will create a movable floating UserWindow.<br />
<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "TestUserWindow",<br />
titleText ="My Test UserWindow", -- only available since Mudlet 4.8+<br />
x = "20%", y="20%",<br />
width="30%", height ="40%"<br />
})<br />
</syntaxhighlight><br />
{{note}} Since Mudlet 4.8+ it is possible to change the Title of the UserWindow by using the constraint titleText and the functions belowː<br />
<br />
To revert to the standard title useː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:resetTitle()<br />
</syntaxhighlight><br />
To set a new title after creation useː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:setTitle("My new title Text")<br />
</syntaxhighlight><br />
<br />
=== Docked UserWindow ===<br />
To create the window docked at the right side,<br />
set the variable docked (at creation of the container) to true.<br />
Be aware that with this variable set to true the position and the size at creation of the userwindow will be ignored.<br />
<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "DockedTestUserWindow",<br />
docked = true<br />
<br />
})<br />
</syntaxhighlight><br />
<br />
Since Mudlet 4.8+ it is also possible to choose the docking Position of the UserWindow at creation and by function withː<br />
<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "DockedTestUserWindow",<br />
docked = true,<br />
dockPosition = "top" -- Possible dockPositions are left "l", right "r", top "t", bottom "b" and floating "f" <br />
})<br />
</syntaxhighlight><br />
<br />
To change it for a already created UserWindow use the function setDockPosition(dockPosition) likeː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:setDockPosition("left")<br />
</syntaxhighlight><br />
<br />
=== Disable\Enable UserWindow autoDock ===<br />
{{note}} available in Mudlet 4.8+<br />
<br />
The auto docking feature can be really annoying at times. To disable it use the functionsː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:disableAutoDock() -- disables autoDock. Docking still possible with ːsetDockPosition<br />
testuserwindow:enableAutoDock() -- reenables autoDock<br />
</syntaxhighlight><br />
<br />
=== Styling the UserWindow border and title area ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
Geyser.UserWindows can accept a stylesheet to change the appearance of the border and title area and make<br />
the UserWindow look more appealing.<br />
<syntaxhighlight lang="lua"><br />
myUserWindow = myUserWindow or Geyser.UserWindow:new({<br />
name = "myUserWindow", titleText = "myUserWindow", autoDock = false<br />
})<br />
<br />
myUserWindow:setStyleSheet( <br />
[[QDockWidget{<br />
border: 1px solid green; /* UserWindow border style */<br />
font: bold 15pt "Arial"; /* Font of the titleBar */<br />
color: rgb(0,0,150); /* Font color */<br />
}<br />
<br />
QDockWidget::title{ <br />
background-color: rgb(0,255,150); /* TitleBar color */<br />
border: 2px solid red; /* TitleBar border */<br />
border-radius: 2px; /* TitleBar border radius */<br />
text-align: center; /* alignment of the titleText */<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
This looks likeː<br />
<br />
<br />
[[File:UserWindowStyleSheet.png]]<br />
<br />
=== UserWindow as Container ===<br />
This is the feature which shows the versatile nature of Geyser.UserWindows.<br />
The UserWindow act as container and is at that possible to dynamically resize the containing Geyser Elments.<br />
Put a label in the UserWindow resize it as rectangle.<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "ParentTestUserWindow",<br />
x = "20%", y="20%",<br />
width="30%", height ="40%"<br />
})<br />
<br />
testuserwindow:setColor("dark_green") -- give the userwindow a bit of color <br />
<br />
labelinuserw = Geyser.Label:new({<br />
name = "LabelinUserWindow",<br />
x=20, y=20,<br />
width = -20, height = -20,<br />
color="light_blue", fontSize=20,<br />
},testuserwindow)<br />
<br />
labelinuserw:echo("This is a label in an userwindow", "black", "c")<br />
</syntaxhighlight><br />
[[File:LabelInUserWindow.png]]<br />
<br />
The same way you are able to add your favorite Geyser Application (like tabbed chat, animated timers, gauges) to an UserWindow.<br />
<br />
Note that you don't need to add MiniConsoles to a UserWindow - as UserWindows already have them built-in.<br />
<br />
[[File:Tabbedchatinuserwindow.png]]<br />
<br />
== Geyser.CommandLine ==<br />
{{note}} available in Mudlet 4.10+<br />
<br />
Allows you to create your custom command lines which can resize/move like any other Geyser object.<br />
<br />
If you just need a command line which is integrated in a miniconsole or userwindow check out [[Manual:Geyser#Enable and use your miniconsole command line|this]].<br />
<br />
=== Creating a Geyser.CommandLine ===<br />
An example to get you startedː<br />
<syntaxhighlight lang="lua"><br />
myCommandLine = myCommandLine or Geyser.CommandLine:new({<br />
name = "myCommandLine", <br />
x = "-20%", y = -40, <br />
width = "20%", height = 40,<br />
stylesheet = "border: 1px solid silver;"})<br />
</syntaxhighlight><br />
This creates a new command line in the right bottom of your screen.<br />
<br />
=== Bind action to your command line input ===<br />
If you use your previous created command line any command will just be send to the game and/or the alias engine.<br />
<br />
To react to any input in a custom manner we can set an action to the command line and use the input as parameter.<br />
<br />
Example of a command line changing the background color of your main console (assumes you have created "myCommandLine" from earlier): <br />
<syntaxhighlight lang="lua"><br />
myCommandLine:setAction(<br />
function(commandLineInput)<br />
r, g, b = Geyser.Color.parse(commandLineInput) -- gets the r, g, b values of the color you input to the command line<br />
if b then -- checks if the color is valid<br />
setBackgroundColor(r, g, b)<br />
else<br />
echo("\n"..commandLineInput.." is not a valid color. Try again.")<br />
end<br />
end)<br />
</syntaxhighlight><br />
<br />
=== Styling a command line ===<br />
You can style your Geyser command line by using Qt-supported CSS. A list of all possible properties you can use is [http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties available here]<br />
<br />
Practical example (assuming "myCommandLine" is created)ː<br />
<syntaxhighlight lang="lua"><br />
myCommandLine:setStyleSheet([[<br />
QPlainTextEdit{ /* QPlainTextEdit is used to prevent the styleSheet bleeding to the right click menu*/<br />
border: 1px solid silver; /* Command line border style */<br />
background-color: rgb(0,255,150); /* Command line background color */<br />
font: bold 12pt "Arial"; /* Font and font-size of your command line */<br />
color: rgb(0,0,150); /* Command line text color */<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
== Create an extra command line in Mudlet ==<br />
If your goal is to just have an extra command/input line copy/paste the example below into a new script in Mudletː<br />
<br />
<syntaxhighlight lang="lua"><br />
inputContainer = inputContainer or Adjustable.Container:new({<br />
x = 0, y = "-4c", <br />
name = "InputContainer", padding = 2, <br />
width = "100%", height = "4c", <br />
autoLoad = false})<br />
<br />
extraCmdLine = extraCmdLine or Geyser.CommandLine:new({<br />
name = "extraCmdLine", <br />
x = 0, y = 0, width = "100%", height = "100%"}, inputContainer)<br />
<br />
inputContainer:attachToBorder("bottom")<br />
</syntaxhighlight><br />
<br />
This will look likeː <br />
<br />
[[File:AdditionalCommandLine.png|extra command line]]<br />
<br />
== Adjustable.Container ==<br />
{{note}} available in Mudlet 4.8+<br />
<br />
Adjustable Containers are a new "GeyserClass" which act as containers for Geyser elements, but with more flexible and user configurable features. They are referred to as "adjustable" because they can be minimized, loaded, saved, moved, adjusted in size with the mouse pointer, and attached to borders. <br />
<br />
A brief video of [https://www.youtube.com/watch?v=GT2ScizuM48&feature=youtu.be Introduction to Adjustable Containers] is available.<br />
<br />
=== Creating an Adjustable.Container ===<br />
An Adjustable.Container is created just like any other Geyser Object. For example, we might experiment with creating a new Adjustable.Container by running the following line of lua code:<br />
<syntaxhighlight lang="lua"><br />
testCon = testCon or Adjustable.Container:new({name="testContainer"})<br />
</syntaxhighlight><br />
This will create a new Adjustable.Container with the name ''testContainer''. Specifying the adjustable container's name is important for saving. Defining a variable, such as ''testCon'' in our above example, allows functions to be used with the Adjustable.Container.<br />
<br />
Our newly created Adjustable.Container may be used the same way as any other Geyser.Container might. For example, let's put a Geyser.Label in our new testContainer:<br />
<br />
<syntaxhighlight lang="lua"><br />
testCon = testCon or Adjustable.Container:new({name="testContainer"})<br />
testLabel = Geyser.Label:new({x=0, y=0, height="100%", width="100%", color="green"},testCon)<br />
</syntaxhighlight><br />
<br />
The above code creates a new, green-colored Geyser.Label in the ''testCon'' adjustable.container as shown below:<br />
<br />
[[File:GreenLabelinAdjustableContainer.png]]<br />
<br />
You can also create one for miniconsole:<br />
<br />
<syntaxhighlight lang="lua"><br />
miniconsoleContainer = miniconsoleContainer or Adjustable.Container:new({name="miniconsoleContainer"})<br />
myMiniconsole = Geyser.MiniConsole:new({<br />
name="myMiniconsole",<br />
x=0, y=0,<br />
autoWrap = true,<br />
color = "black",<br />
scrollBar = false,<br />
fontSize = 8,<br />
width="100%", height="100%",<br />
}, miniconsoleContainer)<br />
<br />
myMiniconsole:echo("Hello!\n")<br />
</syntaxhighlight><br />
<br />
That will give you:<br />
<br />
[[File:Adjustable container miniconsole.png]]<br />
<br />
=== Key Functions ===<br />
A listing of key functions for the Adjustable.Container module can be found hereː https://www.mudlet.org/geyser/files/geyser/AdjustableContainer.html<br />
<br />
=== Change Title Text ===<br />
To specify the title text of a new container, use the constraint <code>titleText</code> in the constructor (see [[Manual:Geyser#valid constraints|valid constraints]]).<br />
<br />
To change the title text after a container has already been created, use <code>setTitle</code>. Continuing from the previous example, the title for an existing container named "testCon" might be adjusted in a number of ways: <br />
<br />
<syntaxhighlight lang="lua"><br />
testCon:setTitle("Title") -- changes the container's title to "Title"<br />
</syntaxhighlight><br />
<br />
A container's title text defaults to the color green, but this can also be adjusted by using <code>setTitle</code>: <br />
<br />
<syntaxhighlight lang="lua"><br />
testCon:setTitle("Red Title Test","red") -- changes the container's title text to "Red Title Test" and displays the text in the specified color "red".<br />
</syntaxhighlight><br />
<br />
To restore a container's default title text, <code>setTitle</code> is issued without any specified title or color: <br />
<br />
<syntaxhighlight lang="lua"><br />
testCon:setTitle() -- resets the container's title text<br />
</syntaxhighlight><br />
<br />
=== AutoSave and AutoLoad ===<br />
The following Adjustable.Container settings can be saved and loadedː<br />
<br />
<code>x</code>, <code>y</code>, <code>height</code>, <code>width</code>, <code>minimized</code>, <code>locked</code>, <code>lock Style</code>, <code>padding</code>, and <code>hidden</code>.<br />
<br />
These settings will be automatically saved when the Mudlet profile is closed, and automatically loaded when a previous Adjustable.Container is created within the corresponding profile.<br />
<br />
To prevent automatic saving and/or loading of these settings, the <code>autoLoad</code> and <code>autoSave</code> constraints can be included in the constructor. For example, the following code will prevent the settings of the ''testCon2'' Adjustable.Container from being loaded upon creation:<br />
<br />
<syntaxhighlight lang="lua"><br />
testCon2 = testCon2 or Adjustable.Container:new({name="testCon2", autoLoad=false})<br />
</syntaxhighlight><br />
<br />
To also prevent the ''testCon2'' Adjustable.Container from automatically saving its settings when the Mudlet profile is closed, the <code>autoSave=false</code> constraint would be added at creation as follows:<br />
<br />
<syntaxhighlight lang="lua"><br />
testCont2 = testCont2 or Adjustable.Container:new({name="testCont2", autoLoad=false, autoSave=false})<br />
</syntaxhighlight><br />
<br />
Automatic saving can also be deactivated after an Adjustable.Container has been created, by invoking <code>testCont:disableAutoSave()</code><br />
<br />
Note that even with autoSave and autoLoad disabled, it is still possible to save and load manually through the right-click menu and/or by using <code>testCont:save()</code> or <code>testCont:load()</code> in a script.<br />
<br />
To save/load all your containers manually at the same time, we use <code>Adjustable.Container:saveAll()</code> and/or <code>Adjustable.Container:loadAll()</code><br />
<br />
=== "All" Functions ===<br />
The following functions affect all Adjustable Containers at the same time.<br />
<br />
{{note}} You must create the Adjustable Containers before these functions will have an effect.<br />
<br />
<code>Adjustable.Container.loadAll()</code> loads all the settings from your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container.saveAll()</code> saves all your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container.loadAll()</code> loads all the settings from your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container:showAll()</code> shows all your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container:doAll(myfunc)</code> creates a function that will affect all your Adjustable Containers. For example:<br />
<syntaxhighlight lang="lua"><br />
Adjustable.Container:doAll(function(self) self:hide() end) -- hides all your adjustable containers<br />
</syntaxhighlight><br />
<br />
===Right-Click Menu===<br />
Your Adjustable Container has also integrated a right-click Menu with the main key functions for easier usability.<br />
<br />
[[File:AdjustableContainerRightClickMenu.png]]<br />
<br />
The right-click menu also automatically shows you the possible attach position (by clicking on Attach to:) <br />
<br />
and possible lockStyles (by clicking on Lockstyle, integrated are 4 standard lockStyles)<br />
<br />
=== Create a Custom Menu with Custom Items ===<br />
To create a new menu element in your right click menu called "Custom" and add an item to it use:<br />
<syntaxhighlight lang="lua"><br />
testcontainer:newCustomItem(name, func)<br />
-- for example<br />
testcontainer:newCustomItem("Hello world", function(self) echo("Hello world\n") self:flash() end)<br />
-- this will write "Hello world" to the main console and flashes your container.<br />
</syntaxhighlight><br />
<br />
=== Add new LockStyles ===<br />
For more advanced users it's possible to add a new Lockstyles by:<br />
<syntaxhighlight lang="lua"><br />
testcontainer:newLockStyle(name, func)<br />
-- for example<br />
testcontainer:newLockStyle("NewLockStyle", function(self) self.Inside:move(40, 40) self.Inside:resize(-40,-40) self:setTitle("") end)<br />
</syntaxhighlight><br />
<br />
=== Change Adjustable Container Style ===<br />
Additionally to the standard container constraints Adjustable Containers allow you to change at creation: the internal Label style, the menu style, min/close buttons, the menu text, title text... <br />
<br />
( see [[Manual:Geyser#valid constraints|valid constraints]])<br />
An example of a Adjustable Container with different style.<br />
<syntaxhighlight lang="lua"><br />
testCont =<br />
testCont or<br />
Adjustable.Container:new(<br />
{<br />
name = "TestNewStyleContainer",<br />
adjLabelstyle = "background-color:rgba(220,220,220,100%); border: 5px groove grey;",<br />
buttonstyle=[[<br />
QLabel{ border-radius: 7px; background-color: rgba(140,140,140,100%);}<br />
QLabel::hover{ background-color: rgba(160,160,160,50%);}<br />
]],<br />
buttonFontSize = 10,<br />
buttonsize = 20,<br />
titleText = "My new Style",<br />
titleTxtColor = "black",<br />
padding = 15,<br />
}<br />
)<br />
</syntaxhighlight><br />
This code creates a container which looks like this:<br />
<br />
[[File:NewStyleAdjustableContainer.png|Adjustable Container with different style]]<br />
<br />
===<div id="valid constraints"> Valid Constraints</div>===<br />
Adjustable Container constraints and their default values. <br />
<br />
These are in addition to the standard Geyser.Container constraints.<br />
<syntaxhighlight lang="lua"><br />
{<br />
ParentMenuWidth = "102" -- menu width of the main right click menu<br />
<br />
ChildMenuWidth = "82" -- menu width of the children in the right click menu (for attached, lockstyles and custom items)<br />
<br />
MenuHeight = "22" -- height of a single menu item<br />
<br />
MenuFontSize = "8" -- font size of the menu items<br />
<br />
buttonsize = "15" -- size of the minimize and close buttons<br />
<br />
buttonFontSize = "8" -- font size of the minimize and close buttons<br />
<br />
padding = 10 -- how far is the inside element placed from the corner (depends also on the lockstyle setting)<br />
<br />
adjLabelstyle = [[ background-color: rgba(0,0,0,100%); border: 4px double green; border-radius: 4px;]] -- style of the main Label where all elements are in<br />
<br />
menustyle = [[QLabel::hover{ background-color: rgba(0,150,255,100%); color: white;} QLabel::!hover{color: black; background-color: rgba(240,240,240,100%);} <br />
QLabel{ font-size:]]..MenuFontSize..[[pt;}]] -- menu items style<br />
<br />
buttonstyle = [[ QLabel{ border-radius: 7px; background-color: rgba(255,30,30,100%);} QLabel::hover{ background-color: rgba(255,0,0,50%);}<br />
]] -- close and minimize buttons style<br />
<br />
minimized = false -- minimized at creation?<br />
<br />
locked = false -- locked at creation?<br />
<br />
lockLabel.txt = [[<font size="5">🔒</font> Lock/Unlock]] -- text of the "lock" menu item<br />
<br />
minLabel.txt = [[<font size="5">🗕</font> Min/Restore]] -- text of the "min/restore" menu item<br />
<br />
saveLabel.txt = [[<font size="5">💾</font> Save]] -- text of the "save" menu item<br />
<br />
loadLabel.txt = [[<font size="5">📁</font> Load]] -- text of the "load" menu item<br />
<br />
attLabel.txt = [[<font size="5">⚓</font> Attach to:]] -- text of the "attached menu" item<br />
<br />
lockStylesLabel.txt = [[<font size="5">🖌</font> Lockstyle:]] -- text of the "lockstyle menu" item<br />
<br />
customItemsLabel.txt = [[<font size="5">🖇</font> Custom:]] -- text of the "custom menu" item<br />
<br />
titleTxtColor = "green" -- color of the title text<br />
<br />
titleText = name.." - Adjustable Container" -- title text<br />
<br />
lockStyle = "standard" -- choose lockstyle at creation. possible integrated lockstyle are: "standard", "border", "light" and "full"<br />
<br />
noLimit = false -- there is a minimum size limit if this constraint is set to false.<br />
<br />
raiseOnClick = true -- raise your container if you click on it with your left mouse button<br />
<br />
autoSave = true -- saves your container settings on exit (sysExitEvent). If set to false it won't autoSave<br />
<br />
autoLoad = true -- loads the container settings (if there are some to load) at creation of the container. If set to false it won't load the settings at creation<br />
}<br />
</syntaxhighlight><br />
<br />
==Change Container==<br />
{{note}} available in Mudlet 4.8+<br />
<br />
With this command it is possible to change an elements or even a containers location to that from another container.<br />
For example:<br />
<syntaxhighlight lang="lua"><br />
mycontainerone:changeContainer(mycontainertwo)<br />
--puts container one into container two which means container two will be the parent of container one<br />
</syntaxhighlight><br />
It is also possible to change to a container which is not located on the main window:<br />
<syntaxhighlight lang="lua"><br />
myEmco:changeContainer(emco_userwindow)<br />
--puts my tabbed chat Emco into my userwindow<br />
--to put it back to the main window change to a container located on the main window<br />
myEmco:changeContainer(mymainwindow_container)<br />
--or if it the element wasn't in a container use the main Geyser Root container called Geyser<br />
myEmco:changeContainer(Geyser)<br />
</syntaxhighlight><br />
<br />
==Create Map Window==<br />
{{note}} available in Mudlet 4.8+<br />
<br />
It‘s possible to create the mapper as a map window (similar to clicking the icon) like this:<br />
<syntaxhighlight lang="lua"><br />
myMapWidget = Geyser.Mapper:new({embedded= false})<br />
</syntaxhighlight><br />
<br />
This will open a map window with your saved layout (if there is one, otherwise it will dock at the right corner)<br />
<br />
To choose the position of the DockWindow at creation use: (this will create a map window docked at the left corner)<br />
<br />
<syntaxhighlight lang="lua"><br />
myMapWidget = Geyser.Mapper:new({embedded= false, dockPosition="left"})<br />
</syntaxhighlight><br />
<br />
Possible dockPositions are "left", "right", "top", "bottom", and "floating".<br><br />
To change the dockPosition after creation use:<br />
<br />
<syntaxhighlight lang="lua"><br />
myMapWidget:setDockPosition("floating")<br />
-- this will change myMapWidget dockPosition to floating <br />
</syntaxhighlight><br />
<br />
= Tutorial =<br />
Note: This tutorial assumes you know how scripts in Mudlet work. If not then you should look at the manual first. Also it only shows how Geyser basically works and explains Geysers special windows. It wont go into detail about the windows that where already in Mudlet.<br />
<br />
=== Hello World ===<br />
Let's start with something simple. A Label.<br />
<br />
<syntaxhighlight lang="lua"><br />
Geyser.Label:new({<br />
name="HelloWorld",<br />
x=50, y=50,<br />
width=200, height=50,<br />
})<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_1.png]]<br />
<br />
This code creates a blank Label with a size of 200x50 at a position of 50 points horizontal and vertical from its parent window - which is the main window since we didn't specify any.<br />
<br />
You can manipulate the Label through the normal functions but Geyser.Label:new() returns an object which can be used to manipulate the label directly. So you should store it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local HelloWorld = Geyser.Label:new({<br />
name="HelloWorld",<br />
x=50, y=50,<br />
width=200, height=50,<br />
})<br />
</syntaxhighlight><br />
<br />
Then you can, for example print a text on it:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("Hello World")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_2.png]]<br />
<br />
You can put a format parameter so that the text is, for example, centered.<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("Hello World", nil, "c")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_3.png]]<br />
<br />
The second parameter is the color. We set it to nil which means the labels foreground color will be used.<br />
<br />
The color parameter either accepts a string ("red"), a hex value("#FF0000" or "0xFF0000" or "|cFF0000"), or a decimal value "&lt;255,0,0&gt;"<br />
<br />
Example:<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("Hello World", "red", "c")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_4.png]]<br />
<br />
{{note}} This will automatically set the foreground color, so any echo, without the color parameter set, after that will use the same color.<br />
<br />
You can also set the foreground color with the setFgColor method:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:setFgColor("red")<br />
HelloWorld:echo("Hello World", nil, "c")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_4.png]]<br />
<br />
=== Containers ===<br />
<br />
Containers are windows that can contain other windows. Actually, since all other Geyser windows subclass container, every window can do that. But containers do not have any visible content by themselves. <br />
<br />
Let's show that by an example:<br />
<syntaxhighlight lang="lua"><br />
local container = Geyser.Container:new({<br />
name="container",<br />
x=50, y=50,<br />
width=250, height=50,<br />
})<br />
</syntaxhighlight><br />
<br />
This will create a container, but if you look at the screen you will see nothing at the positon.<br />
There is a way to make containers visible though:<br />
<syntaxhighlight lang="lua"><br />
container:flash()<br />
</syntaxhighlight><br />
<br />
This will flash the container for a short period of time.<br />
<br />
[[Image:Geyser_Container_1.png]]<br />
<br />
flash() accepts a number as paremeter which defines the time, in seconds, the flash is shown.<br />
<br />
Now, that the container is created, you can add other windows to it. There are 2 ways:<br />
<br />
Directly when creating the window:<br />
<br />
<syntaxhighlight lang="lua"><br />
local container_label = Geyser.Label:new({<br />
name="container_label",<br />
x=0, y=0,<br />
width="100%", height="100%",<br />
},<br />
container)<br />
container_label:echo("This is a label in a container", nil, "c")<br />
</syntaxhighlight><br />
<br />
Later, after the window was created<br />
<syntaxhighlight lang="lua"><br />
local container_label = Geyser.Label:new({<br />
name="container_label",<br />
x=0, y=0,<br />
width="100%", height="100%",<br />
})<br />
container_label:echo("This is a label in a container", nil, "c")<br />
container:add(container_label)<br />
</syntaxhighlight><br />
<br />
Both will lead to the same outcome.<br />
<br />
[[Image:Geyser_Container_2.png]]<br />
<br />
Note that we gave a width and height of "100%" to the constructor of the container. This means that the label will take 100% of the containers width and height. If values are given in percent they will even resize with its parent:<br />
<br />
<syntaxhighlight lang="lua"><br />
container:resize(325, nil)<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_Container_3.png]]<br />
<br />
The first parameter is the width, the second the height. If the value is nil the current value is used.<br />
<br />
As said in the "Hello World" tutorial the position is relative to its parent window. That's why we could set both x and y to 0 and it is at the position we wanted - the position of the container.<br />
<br />
When we now move the container the label moves with it:<br />
<syntaxhighlight lang="lua"><br />
container:move(400, nil)<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_Container_4.png]]<br />
<br />
The first parameter is the x-, the second the y-position. If the value is nil the current value is used.<br />
<br />
=== VBox and HBox ===<br />
<br />
The VBox and HBox classes are special Containers.<br />
They will automatically align its containing windows vertically or horizontally, respectively, in the order they where added to them.<br />
<br />
<syntaxhighlight lang="lua"><br />
<br />
local HBox = Geyser.HBox:new({<br />
name="HBox",<br />
x=0, y=0,<br />
width=400, height=30,<br />
})<br />
<br />
</syntaxhighlight><br />
<br />
Like containers you won't see them by themselves.<br />
<br />
Adding children works like with containers<br />
<syntaxhighlight lang="lua"><br />
<br />
local label1 = Geyser.Label:new({<br />
name="Label1",<br />
},<br />
HBox)<br />
label1:echo("Label 1", "black", "c")<br />
label1:setColor(255, 0, 0)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_1.png]]<br />
<br />
We didn't set any position or size, but the label gets the same size as the HBox.<br />
<br />
If we add another window:<br />
<syntaxhighlight lang="lua"><br />
<br />
local label2 = Geyser.Label:new({<br />
name="Label2",<br />
},<br />
HBox)<br />
label2:echo("Label 2", "black", "c")<br />
label2:setColor(0, 255, 0)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_2.png]]<br />
<br />
the size will be divided equally between them!<br />
<br />
What if you want a child that takes more or less space than the others?<br />
That's possible too:<br />
<syntaxhighlight lang="lua"><br />
<br />
local label3 = Geyser.Label:new({<br />
name="Label3",<br />
h_stretch_factor=2.0,<br />
},<br />
HBox)<br />
label3:echo("Label 3", nil, "c")<br />
label3:setColor(0, 0, 255)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_3.png]]<br />
<br />
As you can see, Label 3 takes the same space as Label 1 and 2 Together. <br />
That's because we supplied a horizontal stretch factor with "h_stretch_factor=2.0"<br />
<br />
This works also with a vertical stretch factor, just replace "h_stretch_factor" with "v_stretch_factor"<br />
<br />
Now you may have windows that should not be stretched at all.<br />
To accomplish this you have to set the horizontal and/or vertical policy:<br />
<br />
<syntaxhighlight lang="lua"><br />
<br />
local label4 = Geyser.Label:new({<br />
name="Label4",<br />
width="13%",<br />
h_policy=Geyser.Fixed,<br />
},<br />
HBox)<br />
label4:echo("Label 4", "black", "c")<br />
label4:setColor(0, 255, 255)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_4.png]]<br />
<br />
Possible values for the policies are Geyser.Fixed and Geyser.Dynamic (which is the default). They can also be applied to VBox and HBox in exactly the same way.<br />
<br />
Note that, like in the example above, the label will retain relative values (like percent) if used.<br />
<br />
The VBox works like the HBox, only that the child windows are aligned vertically.<br />
<br />
= Walkthroughs =<br />
Here are a few walkthroughs that will show you how to combine Geyser elements to create some simple GUI widgets.<br />
<br />
===Create a Clickable Compass===<br />
[[File: compass.png]]<br />
The following will walk you through the process of creating your own clickable compass using the Geyser framework.<br />
====Setup the image files====<br />
The compass requires a handful of images to work properly. You can find them here: https://www.dropbox.com/sh/53l7xrn4ds35wnq/WpWOziVKmH <br><br />
Download each image and place it in your profile folder. You can find your profile folder with getMudletHomeDir()<br><br />
If you're using Mudlet 2.1+ you can enter '''lua getMudletHomeDir()''' from the command line to return the profile folder path on your computer.<br />
<br />
====Create a new script====<br />
Script Name: '''''compass.resize'''''<br><br />
Registered Event Handlers: '''''sysWindowResizeEvent'''''<p><br />
Every snippet of code will be placed within this script.<br />
====Store the screen size====<br />
We'll want to store the screen size in some local variables so they can be easily referenced to later on.<br />
<syntaxhighlight lang="lua">local mw, mh = getMainWindowSize()</syntaxhighlight><br />
<br />
====Create a global table or namespace====<br />
Creating a global table will make each of your variables unique. Our namespace will be called '''''compass''''' and everything we make from here on out will be stored within the compass table. We'll also add a few values to it: dirs and ratio. '''''compass.dirs''''' will store each direction while '''''compass.ratio''''' will store the ratio of our screen size so you can 'square up' your compass.<br />
<syntaxhighlight lang="lua">compass = compass or {<br />
dirs = {"nw","n","ne","w","center","e","sw","s","se"},<br />
ratio = mw / mh<br />
}</syntaxhighlight><br />
<br />
====Create the parent label====<br />
[[File: grey.png|thumbnail]]<br />
The 'parent label' refers to the label on the bottom layer. The entire compass will be created within this label. It's container is '''main''' for it's parent is the main window.<br />
<syntaxhighlight lang="lua">compass.back = Geyser.Label:new({<br />
name = "compass.back",<br />
x = "25%",<br />
y = "25%",<br />
width = "10%",<br />
height = "10%",<br />
},main)</syntaxhighlight><br />
<br />
====Set the parent label stylesheet====<br />
[[File: blue.png|thumbnail]]<br />
This will create the blue sphere that makes up most of the compass. The background color is a radial gradient that goes from a deep blue to a brighter shade. The border radius rounds the edges. When the radius is exactly half of the label width it forms a circle. The arrows of the compass actually protrude from the sphere so we give it a margin to suck it in a bit for this effect.<br />
<syntaxhighlight lang="lua">compass.back:setStyleSheet([[<br />
background-color: QRadialGradient(cx:.3,cy:1,radius:1,stop:0 rgb(0,0,50),stop:.5 rgb(0,0,100),stop:1 rgb(0,0,255));<br />
border-radius: ]]..tostring(compass.back:get_width()/2-14)..[[px;<br />
margin: 10px;<br />
]])</syntaxhighlight><br />
<br />
====Create a 3x3 grid====<br />
The compass is split into 9 sections. One for each cardinal direction plus an extra space that sits in the center. This 3x3 grid is created by 3 VBoxes that sit within a single HBox (or vice versa but I flipped a coin and this is what it gave me).<br><br />
So first off, we create the HBox. It will be the same size as its parent, ''compass.back''.<br />
<syntaxhighlight lang="lua"> compass.box = Geyser.HBox:new({<br />
name = "compass.box",<br />
x = 0,<br />
y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},compass.back)</syntaxhighlight><br />
Next, we create our 3 VBoxes. You don't need to specify position or size because these are placed within ''compass.box'', an HBox.<br />
<syntaxhighlight lang="lua"> compass.row1 = Geyser.VBox:new({<br />
name = "compass.row1",<br />
},compass.box)<br />
compass.row2 = Geyser.VBox:new({<br />
name = "compass.row2",<br />
},compass.box)<br />
compass.row3 = Geyser.VBox:new({<br />
name = "compass.row3",<br />
},compass.box)</syntaxhighlight><br />
Finally, we add our 9 labels. Take note that they are split up into even groups of 3. Each group is placed into a different ''compass.row#''<br />
<syntaxhighlight lang="lua"> compass.nw = Geyser.Label:new({<br />
name = "compass.nw",<br />
},compass.row1)<br />
<br />
compass.w = Geyser.Label:new({<br />
name = "compass.w",<br />
},compass.row1)<br />
<br />
compass.sw = Geyser.Label:new({<br />
name = "compass.sw",<br />
},compass.row1)<br />
<br />
compass.n = Geyser.Label:new({<br />
name = "compass.n",<br />
},compass.row2)<br />
<br />
compass.center = Geyser.Label:new({<br />
name = "compass.center",<br />
},compass.row2)<br />
<br />
compass.s = Geyser.Label:new({<br />
name = "compass.s",<br />
},compass.row2)<br />
<br />
compass.ne = Geyser.Label:new({<br />
name = "compass.ne",<br />
},compass.row3)<br />
<br />
compass.e = Geyser.Label:new({<br />
name = "compass.e",<br />
},compass.row3)<br />
<br />
compass.se = Geyser.Label:new({<br />
name = "compass.se",<br />
},compass.row3)</syntaxhighlight><br />
====Create a callback function====<br />
We'll want our compass to head in the direction of the arrow we're clicking. This is where we specify so. When the arrow is clicked, this function will be ran with the arrow direction as the argument.<br />
<syntaxhighlight lang="lua">function compass.click(name)<br />
send(name)<br />
end</syntaxhighlight><br />
====Create the hover functions====<br />
We want our arrows to turn yellow when we hover over them. We do so by simply resetting the label's stylesheet and changing the border image. Don't forget to include the margin as we still want that.<br />
<syntaxhighlight lang="lua">function compass.onEnter(name)<br />
compass[name]:setStyleSheet([[<br />
border-image: url("]]..getMudletHomeDir()..[[/]]..name..[[hover.png");<br />
margin: 5px;<br />
]])<br />
end<br />
<br />
function compass.onLeave(name)<br />
compass[name]:setStyleSheet([[<br />
border-image: url("]]..getMudletHomeDir()..[[/]]..name..[[.png");<br />
margin: 5px;<br />
]])<br />
end</syntaxhighlight><br />
====Set the stylesheets in the grid====<br />
[[File: Sample.png|thumb]]<br />
Each of the 9 labels need an image of an arrow. Rather than setting each individually, we'll iterate over the ''compass.dirs'' table we made awhile back and add the respective image to each. The names of images are a reflection of the ''compass.dirs'' table. This keeps it consistent and easy to refer to. During the iteration, the callback, setLabelOnEnter and setLabelOnLeave are also set for each label.<br />
<syntaxhighlight lang="lua">for k,v in pairs(compass.dirs) do<br />
compass[v]:setStyleSheet([[<br />
border-image: url("]]..getMudletHomeDir()..[[/]]..v..[[.png");<br />
margin: 5px;<br />
]])<br />
compass[v]:setClickCallback("compass.click",v)<br />
setLabelOnEnter("compass."..v,"compass.onEnter",v)<br />
setLabelOnLeave("compass."..v,"compass.onLeave",v)<br />
end</syntaxhighlight><br />
<br />
====Resize the compass into a square====<br />
[[File: final.png|thumb]]<br />
Most screen size ratios aren't a perfect 1:1. This will cause a 10% x 10% label to be far from square. By setting our height (the smaller of the two numbers) to our width, we can resize our compass to a near perfect square. This function is also the name of our script because we want it to run each time sysWindowResizeEvent is raised.<br />
<syntaxhighlight lang="lua">function compass.resize()<br />
compass.back:resize(compass.back.width, compass.back:get_width())<br />
end<br />
<br />
compass.resize()</syntaxhighlight><br />
<br />
===Create a Tabbed Window===<br />
[[File: tabwindow.png]]<br />
The following will walk you through the process of creating your own tabbed window using the Geyser framework.<br />
<br />
====Create a new script====<br />
Script Name: '''''Tabbed Window'''''<br><br />
Every snippet of code will be placed within this script.<br />
====Create a global table====<br />
Creating a global table will make each of your variables unique. Our namespace will be called '''''menu''''' and everything we make from here on out will be stored within the menu table. We'll also add a few values to it: tabs, color1, color2, width, height and current. <br><br />
''''tabs'''' will be a table that stores all our tab names. If we want our tabs to have different names, we alter this table.<br><br />
''''color1'''' and ''''color2'''' will store the colors of our tabbed window. If we want to change the color of our tabbed window, we alter these values.<br><br />
''''width'''' and ''''height'''' will store the size of our tabbed window. If we want to change the size of the tabbed window, we alter these values.<br><br />
''''current'''' keeps track of which tab is selected. We will set this to the first tab in the table by default. We do this outside the initial table creation so we can easily access menu.tabs<br><br />
<syntaxhighlight lang="lua">menu = menu or {<br />
tabs = {"Tab1","Tab2","Tab3","Tab4"},<br />
color1 = "rgb(0,0,70)",<br />
color2 = "rgb(0,0,50)",<br />
width = "20%",<br />
height = "40%",<br />
}<br />
menu.current = menu.current or menu.tabs[1]</syntaxhighlight><br />
<br />
====Create the main container====<br />
Our tabbed window will need a container. This will be the bottom layer. Containers are invisible so no need to set a stylesheet.<br />
<syntaxhighlight lang="lua">menu.container = Geyser.Container:new({<br />
name = "menu.back",<br />
x = "50%", y = "25%",<br />
width = menu.width,<br />
height = menu.height,<br />
},main)</syntaxhighlight><br />
====Create an HBox====<br />
All of our tabs will be evenly spaced. So we'll create an HBox to sit at the top of our container.<br />
<syntaxhighlight lang="lua">menu.header = Geyser.HBox:new({<br />
name = "menu.header",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "10%",<br />
},menu.container)</syntaxhighlight><br />
====Create a label====<br />
This label will serve as a container for each window. It sits right underneath the HBox we just created for the tabs.<br />
<syntaxhighlight lang="lua">menu.footer = Geyser.Label:new({<br />
name = "menu.footer",<br />
x = 0, y = "10%",<br />
width = "100%",<br />
height = "90%",<br />
},menu.container)</syntaxhighlight><br />
We don't want this to be a big grey box at startup, so we'll set the stylesheet to appear like the rest of the windows.<br />
<syntaxhighlight lang="lua"><br />
menu.footer:setStyleSheet([[<br />
background-color: ]]..menu.color1..[[;<br />
border-bottom-left-radius: 10px;<br />
border-bottom-right-radius: 10px;<br />
]])</syntaxhighlight><br />
Each window actually has two labels. One for the light blue background, and another for the dark blue center. This will create that dark blue center.<br />
<syntaxhighlight lang="lua">menu.center = Geyser.Label:new({<br />
name = "menu.center",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu.footer)<br />
menu.center:setStyleSheet([[<br />
background-color: ]]..menu.color2..[[;<br />
border-radius: 10px;<br />
margin: 5px;<br />
]])</syntaxhighlight><br />
====Add your tabs and their windows====<br />
Now we'll want to add our tabs and windows. We do this in a single for loop of the ''''menu.tabs'''' table since it holds all our tab names.<br />
<syntaxhighlight lang="lua">for k,v in pairs(menu.tabs) do<br />
</syntaxhighlight><br />
This will create the tabs. Each tab will be named: menu.<tabname>tab<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"] = Geyser.Label:new({<br />
name = "menu."..v.."tab",<br />
},menu.header)<br />
</syntaxhighlight><br />
Here is where we set the tab stylesheet. Each tab has a rounded top, so we set the border-radius of the top-left and top-right to 10px. Each tab has a small space for separation so we give the right and left sides a tiny margin of 1px.<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"]:setStyleSheet([[<br />
background-color: ]]..menu.color1..[[;<br />
border-top-left-radius: 10px;<br />
border-top-right-radius: 10px;<br />
margin-right: 1px;<br />
margin-left: 1px;<br />
]])<br />
</syntaxhighlight><br />
This will display the name of each tab on the tab.<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"]:echo("<center>"..v)<br />
</syntaxhighlight><br />
We need our tabs to do stuff when clicked, so we'll assign it a callback function, '''''menu.click''''', which we'll create later on. Our tab name is the argument.<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"]:setClickCallback("menu.click",v)<br />
</syntaxhighlight><br />
Now we create the windows that appear when each tab is clicked. Each window has two labels, one atop the other. The first, which we'll create here, has rounded edges on its bottom.<br />
<syntaxhighlight lang="lua"><br />
menu[v] = Geyser.Label:new({<br />
name = "menu."..v,<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu.footer)<br />
<br />
menu[v]:setStyleSheet([[<br />
background-color: ]]..menu.color1..[[;<br />
border-bottom-left-radius: 10px;<br />
border-bottom-right-radius: 10px;<br />
]])<br />
</syntaxhighlight><br />
The second label serves as the window's center and has rounded edges on all sides. And a margin of 5px from it's parent, the label we just created. When adding stuff to your windows, this is the label you'll want to use. '''''menu.<tabname>center'''''<br />
<syntaxhighlight lang="lua"><br />
menu[v.."center"] = Geyser.Label:new({<br />
name = "menu."..v.."center",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu[v])<br />
</syntaxhighlight><syntaxhighlight lang="lua"><br />
menu[v.."center"]:setStyleSheet([[<br />
background-color: ]]..menu.color2..[[;<br />
border-radius: 10px;<br />
margin: 5px;<br />
]])<br />
</syntaxhighlight><br />
Finally, we hide all the windows and end the for loop.<br />
<syntaxhighlight lang="lua"><br />
menu[v]:hide()<br />
end</syntaxhighlight><br />
====Create a callback function====<br />
The last step is to create our callback function for when a tab is clicked. This will hide that tab that is stored in '''''menu.current''''', set menu.current to the clicked tab, and then show the menu.current tab.<br />
<syntaxhighlight lang="lua">function menu.click(tab)<br />
menu[menu.current]:hide()<br />
menu.current = tab<br />
menu[menu.current]:show()<br />
end</syntaxhighlight><br />
====Adding content to your windows====<br />
Add content to '''menu.<tab name>center'''<br />
So if we wanted to display our gold in a window we could:<syntaxhighlight lang="lua">menu.Tab1center:echo(myGold)</syntaxhighlight><br />
If we wanted to add a map to a window we could:<br />
<syntaxhighlight lang="lua">myMap = Geyser.Mapper:new({<br />
name = "myMap",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu.Tab2center)</syntaxhighlight><br />
<br />
===Create a Window with a resize label===<br />
[[File: resize_window.png]]<br />
This walkthrough will create a window with a smaller label which will let you resize the window.<br />
<br />
====Create a new script====<br />
Script Name: '''''Resize Window'''''<br><br />
Every snippet of code will be placed within this script.<br />
<br />
====Create a window====<br />
Create a window label which will be resizable.<br />
<syntaxhighlight lang="lua">--<br />
-- Create a label that will be resized and contain the drag icon.<br />
---<br />
mLabel = Geyser.Label:new({<br />
name = "mLabel",<br />
x = 400, y = 200,<br />
width = 200, height = 200,<br />
fgColor = "black",<br />
color = "blue",<br />
message = [[<center>drag the white label to resize</center>]]<br />
})<br />
mLabel:setStyleSheet([[qproperty-wordWrap: true]])<br />
</syntaxhighlight><br />
<br />
====Create small icon inside the window====<br />
Create the label that will be used as a drag icon.<br />
<syntaxhighlight lang="lua">--<br />
-- Create the small drag label within the window.<br />
-- The y position is set to "-15px" to align it to<br />
-- the bottom of the main label.<br />
--<br />
mVDrag = Geyser.Label:new({<br />
name = "mVDrag",<br />
x = 85, y = "-15px",<br />
width = 30, height = 15,<br />
fgColor = "black",<br />
color = "white",<br />
}, mLabel)<br />
</syntaxhighlight><br />
<br />
====Create callback functions====<br />
Create the callback functions that will be called by mouse and timer events.<br><br />
<br />
Create a timer function that will be called repeatedly while the mouse button is pressed.<br />
<syntaxhighlight lang="lua"><br />
function onVDragTimer()<br />
local x<br />
local y<br />
local height<br />
<br />
-- Get mouse position<br />
x, y = getMousePosition()<br />
<br />
-- Substract the top of the label to get the new height.<br />
height = y - 200<br />
if height < MIN_HEIGHT then<br />
-- Height is too small.<br />
height = MIN_HEIGHT<br />
end<br />
<br />
-- Set the new size and restart timer.<br />
mLabel:resize(200, height)<br />
vdragtimer = tempTimer(0.2, onVDragTimer)<br />
end<br />
</syntaxhighlight><br><br />
<br />
Create a function which will be called when we first press the icon. The function will create the timer which will trigger as long as the button is pressed.<br />
<syntaxhighlight lang="lua"><br />
function onVDragClick()<br />
-- The user clicked the drag label.<br />
-- Start a temp timer to update the size of the label.<br />
if not exists("vdragtimer", "timer") then<br />
vdragtimer = permTimer("vdragtimer", "", .016, "onVDragTimer()")<br />
end<br />
<br />
enableTimer("vdragtimer")<br />
end<br />
</syntaxhighlight><br><br />
<br />
Create the callback function which will be called when we release the drag icon.<br />
<syntaxhighlight lang="lua"><br />
function onVDragRelease()<br />
-- Button is release so stop timer and updates.<br />
disableTimer("vdragtimer")<br />
end<br />
</syntaxhighlight><br />
<br />
====Set up the callback functions====<br />
Set up the limit how small the window can be, and setup the callback functions.<br />
<syntaxhighlight lang="lua"><br />
MAX_HEIGHT = 100<br />
--<br />
-- Set mouse event callbacks.<br />
--<br />
setLabelClickCallback("mVDrag", "onVDragClick")<br />
setLabelReleaseCallback("mVDrag", "onVDragRelease")<br />
</syntaxhighlight><br />
<br />
====Final result====<br />
The whole script looks like this:<br />
<br />
<syntaxhighlight lang="lua"><br />
--<br />
-- Example: Resize a label.<br />
--<br />
-- Creates a blue label with a smaller white label, which is<br />
-- used to resize the blue label.<br />
--<br />
-- Utilizing:<br />
-- * getMousePosition()<br />
-- * setLabelClickCallback()<br />
-- * setLabelReleaseCallback()<br />
-- * tempTimer().<br />
--<br />
<br />
--<br />
-- Create labels<br />
--<br />
mLabel = Geyser.Label:new({<br />
name = "mLabel",<br />
x = 400, y = 200,<br />
width = 200, height = 200,<br />
})<br />
mLabel:setStyleSheet([[<br />
background-color: rgba(30, 30, 30, 80%);<br />
qproperty-wordWrap: true;<br />
]])<br />
mLabel:setFontSize(10)<br />
mLabel:echo([[<center>Drag the white label to resize.</center>]])<br />
<br />
--<br />
-- Create the small drag label within the window.<br />
-- The y position is set to "-15px" to align it to<br />
-- the bottom of the main label.<br />
mVDrag = Geyser.Label:new({<br />
name = "mVDrag",<br />
x = 85, y = "-15px",<br />
width = 30, height = 15,<br />
fgColor = "black",<br />
color = "white",<br />
}, mLabel)<br />
mVDrag:setStyleSheet([[<br />
border-radius: 6;<br />
background-color: white;<br />
]])<br />
<br />
MIN_HEIGHT = 100<br />
<br />
--<br />
-- Callback functions.<br />
--<br />
function onVDragTimer()<br />
local x<br />
local y<br />
local height<br />
<br />
-- Get mouse position<br />
x, y = getMousePosition()<br />
<br />
-- Substract the top of the label to get the new height.<br />
height = y - 200<br />
if height < MIN_HEIGHT then<br />
-- Height is too small.<br />
height = MIN_HEIGHT<br />
end<br />
<br />
-- Set the new size and restart timer.<br />
mLabel:resize(200, height)<br />
end<br />
<br />
function onVDragClick()<br />
-- The user clicked the drag label.<br />
-- Start a temp timer to update the size of the label.<br />
if not exists("vdragtimer", "timer") then<br />
vdragtimer = permTimer("vdragtimer", "", .016, "onVDragTimer()")<br />
end<br />
<br />
enableTimer("vdragtimer")<br />
end<br />
<br />
function onVDragRelease()<br />
-- Button is release so stop timer and updates.<br />
disableTimer("vdragtimer")<br />
end<br />
<br />
--<br />
-- Set mouse event callbacks.<br />
--<br />
setLabelClickCallback("mVDrag", "onVDragClick")<br />
setLabelReleaseCallback("mVDrag", "onVDragRelease")<br />
</syntaxhighlight><br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Geyser&diff=15634Manual:Geyser2020-10-09T11:57:13Z<p>Smurf: /* Geyser.UserWindow */</p>
<hr />
<div>{{TOC right}}<br />
<br />
= Introduction =<br />
<br />
The Geyser Layout Manager is an object oriented framework for creating, updating and organizing GUI elements within Mudlet - it allows you to make your UI easier on Mudlet, and makes it easier for the UI to be compatible with different screen sizes.<br />
<br />
=== Motivation ===<br />
<br />
Mudlet makes the creation of label, miniconsoles and gauges a quick and easy thing. Mudlet provides a nice signal when window resize events happen. To help with complex window management, Geyser steps in.<br />
<br />
=== Main Geyser Features ===<br />
<br />
Geyser is based on traditional GUI concepts and should feel similar to using Java's Swing. The biggest difference is in how positions are specified.<br />
<br />
* All window positions are specified relative to their container - nothing new there. However, window positions can also take on percentages and negative pixel and character values. For instance, a window could be constrained to have a height of 50% of its container and a width such that the window's right edge is always 20 characters from its container's right edge. See examples below and the demos/tests that come with Geyser.<br />
* All windows under Geyser control are automatically resized as necessary when the main Mudlet window is resized. Once you create a window and assign it to a container, you never have to worry about positioning it again. Nonetheless, it's very easy to shift the container that a window is in, maintaining its constraints so that it resizes as needed according to the dimensions of the new container.<br />
* Due to the container hierarchy, hiding a container window automatically hides all its contained windows too. The same for show. With clever construction and labels with callbacks, this lets one make complex GUI elements that are minimizable or maximizable or ...<br />
* However, there is always some overhead for automation systems and Geyser is no exception. Fortunately, most of the overhead is during window creation and resize events - not things that happen frequently.<br />
<br />
=== Getting pictures for your stuff ===<br />
You can find good, freely-available assets for your UI here:<br />
* [https://kenney.nl/assets?q=2d kenney.nl]<br />
* [https://opengameart.org/ opengameart.org]<br />
* [https://game-icons.net/ game-icons.net]<br />
<br />
=== Constraints format ===<br />
<br />
Geyser position constraints are a string composed of a number and a format type. For example, "10px" means 10 pixels, either pixels from the origin (e.g. x or y) or a value for the width or height. A negative number indicates distance from a container's right or bottom border depending on whether is a constraint for x/width or y/height, respectively. Percentages for width and height are in terms of the container's dimensions and negative values are converted to the equivalent positive value. A 100% width subwindow with an x-coordinate of 10 will have part of itself displayed outside the confines of its container. There is no hard limit on maximum window size, just as with regular Mudlet windows. If a number, n, is passed as a constraint instead of a string, it is assumed to be equivalent to "npx". Any Lua table that contains entries for x, y, width and height in the proper format can be used for Geyser constructors and setting constraints. Just like in Mudlet, 0,0 coordinates mean the top-left corner.<br />
<br />
The following is a valid example for coordinates of a Geyser object:<br />
<br />
<syntaxhighlight lang="lua"><br />
{x = "20px", y = "-10c", width = "40%", height = 30}<br />
</syntaxhighlight><br />
<br />
= Geyser elements =<br />
The purpose of this document is to go through every Geyser element and provide practical examples on how they are used. Read it from top to bottom, preferably doing all of the examples to understand how they work!<br />
<br />
See also: https://www.mudlet.org/geyser/files/index.html for a brief and technical overview of all elements and their functions.<br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html Geyser.Container]==<br />
An invisible, organizing object in Geyser - use it to divide your screen and position elements accordingly. '''[http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html See here]''' for all of the functions that are available to you to use.<br />
<br />
A container is also the base class - which means that everything (labels, miniconsoles and gauges) can use its functions, since everything else is at heart a container.<br />
<br />
=== Creating a container ===<br />
To get started with a container, here's an example that'll create a 200px border on the left side of Mudlet for you, and make a container cover all of it - so you can place other visual elements inside it:<br />
<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(200)<br />
left_container = Geyser.Container:new({<br />
name = "left_container", -- give it a unique name here<br />
x=0, y=0, -- have it start at the top-left corner of mudlet<br />
width = 200, height="100%", -- with a width of 200, and a height of the full screen, hence 100%<br />
})<br />
</syntaxhighlight><br />
<br />
Right away, you'll see space appear on the left side. It'll be black, as the container is an invisible unit by itself. You can make sure it's there by making it flash by doing this from the input line:<br />
<br />
<syntaxhighlight lang="lua">lua left_container:flash()</syntaxhighlight><br />
<br />
The command will cause your container to flash for a moment for you, revealing itself.<br />
<br />
{{Note}} If you hide a container and create new Geyser elements within it, they'll be shown automatically for you.<br />
<br />
=== Container within a container ===<br />
You can place containers within other containers by specifying which "parent" the new container should have when you create one. Given our [[#Creating a container|previous example]], you can split the left side into two halves like this:<br />
<br />
<syntaxhighlight lang="lua"><br />
left_container_top = Geyser.Container:new({<br />
name = "left_container_top",<br />
x=0, y=0, -- this container occupies the top, so it starts top-left as well<br />
width = "100%", height="50%", -- but only uses up half of the height<br />
}, left_container) -- this is the important bit - it says that left_container_top should be inside left_container<br />
<br />
left_container_bottom = Geyser.Container:new({<br />
name = "left_container_bottom",<br />
x=0, y="50%", -- this container starts halfway down the first one<br />
width = "100%", height="50%", -- and has the same half height of the original container<br />
}, left_container) <br />
</syntaxhighlight><br />
<br />
=== Aligning relative to bottom or right sides ===<br />
The aligning point within Mudlet is the top-left corner, and it's the same for the elements they are aligned - the position you specify is used by the top-left corner of the element.<br />
<br />
Using Geyser, you can align to the opposite side as well, using the coordinates in negatives, while keeping the dimensions of the object in mind. For example, if you want to align a box that's 20px wide on the usual left side, you'd give it a width of 20 and an x value of 0. If you'd like to align it on the right side, then you'd give it an x value of -20. The box will spawn 20px away from the right side and "grow" to the right by 20px.<br />
<br />
<syntaxhighlight lang="lua"><br />
right_container = Geyser.Container:new({<br />
name = "right_container",<br />
x="-20%", y=0, -- makes the container start 20% of the screen away from the right side<br />
width = "20%", height="50%", -- filling it up until the end<br />
}) <br />
</syntaxhighlight><br />
<br />
Do make sure to account for the scrollbar, as Mudlet UI elements can overlap it. You can also move the scrollbar with [[Manual:UI_Functions#setBorderRight|setBorderRight()]].<br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html Geyser.Label]==<br />
Labels allow you to use pictures in your interface, as well as nicely-formatted text - see docs for label [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html functions].<br />
<br />
=== Basic label ===<br />
<br />
Here's an example to get you started with:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "50%", y = 0,<br />
width = "50%", height = "100%",<br />
fgColor = "black",<br />
color = "SeaGreen",<br />
message = [[<center>heey</center>]]<br />
})<br />
</syntaxhighlight><br />
<br />
This labels '''x''' coordinate is specified as 50% - and because it's not attached to any container, this implies that the window will start halfway at the main window. You can tell it's not attached to a container because there's nothing in between the last ''}'' and '')'', the place where the container goes.<br />
<br />
The '''y''' coordinate is 0 - which means that the label will start at the top of the screen. With the width being 50%, the label will occupy 50% of the screen - and since it starts at the halfway point, it means it'll occupy the entire right side. A height of 100% means that it'll stretch from the top to the full bottom.<br />
<br />
Here's what that'll look like:<br />
<br />
[[File:Simple-label.png|center|600px]]<br />
<br />
<br />
Playing around with the starting location and dimensions, we can also place it in the center of the screen with:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "25%", y = "25%",<br />
width = "50%", height = "50%",<br />
fgColor = "black",<br />
message = [[<center>heey</center>]]<br />
})<br />
testlabel:setColor(0,255,0,150)<br />
</syntaxhighlight><br />
<br />
[[File:Simple_label_centered.png|center|600px]]<br />
<br />
To change the message on a label, you can use the ''mylabel:echo()'' function, where ''mylabel'' is the name of the label you gave it:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:echo("hello!")<br />
</syntaxhighlight><br />
<br />
=== Setting the font size ===<br />
<br />
To set a different font size for your Label, use the ''setFontSize()'' method. For example:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel:setFontSize(14)<br />
</syntaxhighlight><br />
<br />
The font size is set in Pt, so anything above 30 will likely be too large to be useful.<br />
<br />
=== Label inside a container ===<br />
<br />
Once you've got your containers and mastered the basic labels, you can drop labels into your nicely-organized containers. Doing so is similar to nesting containers:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "25%", y = "25%",<br />
width = "50%", height = "50%",<br />
fgColor = "black",<br />
message = [[<center>heey</center>]]<br />
}, left_container_bottom) -- this is where we tell it what container to go into<br />
testlabel:setColor(0,255,0,150)<br />
</syntaxhighlight><br />
<br />
That label is exactly the same as the one above that goes across the screen, except it's in our bottom-left container - so it looks appropriately different:<br />
<br />
[[File:Label in a container.png|center]]<br />
<br />
=== Image on a label ===<br />
One of the more amazing things labels allow you to do is put pictures anywhere on your Mudlet screen, that blend in very well. To do so, once the label is created, use the [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:setBackgroundImage setBackgroundImage()] function with the exact path to the image ([[File:Skullface.png]]):<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = 0, y = "-14px",<br />
width = "16px", height = "14px",<br />
})<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/skullface.png]]) -- update location to actual image location on your computer<br />
</syntaxhighlight><br />
<br />
This'll plop the picture to the bottom-left of your screen. To make the picture show, download the skullface picture above - save it to your desktop, and adjust the location of the image within [[]]'s to what it is on your computer. For example, if you saved this on your Windows 7 desktop, it would be:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label:setBackgroundImage([[C:/Users/<your user name>/Desktop/skullface.png]])<br />
</syntaxhighlight><br />
<br />
(yes, that's / and not \ - \ has been known not to work)<br />
<br />
If you saved this on your Mac desktop, it would be:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label:setBackgroundImage([[/Users/<your user name>/Desktop/skullface.png]])<br />
</syntaxhighlight><br />
<br />
If you saved this on your Ubuntu desktop, it would be:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label:setBackgroundImage([[/home/<your user name>/Desktop/skullface.png]])<br />
</syntaxhighlight><br />
<br />
Using this basic building block, you can work up to making yourself a UI!<br />
<br />
=== Stretching an image on a label ===<br />
If you'd like your image not to keep its original size, but instead use up the available space of the label - you can use the [http://doc.qt.io/qt-5/stylesheet-reference.html#border-image border-image] stylesheet property to do so.<br />
<br />
<syntaxhighlight lang="lua"><br />
label = Geyser.Label:new({<br />
name = "label",<br />
x = "50%", y = "50%",<br />
width = "50%", height = "50%",<br />
})<br />
<br />
-- change the location to your picture<br />
-- on windows, use / to separate folders still, not \<br />
label:setStyleSheet[[<br />
border-image: url(/home/vadi/Desktop/iso-avatar-draft_0.png);<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}} If you're on a Mudlet earlier than 3.15 and are having difficulty with the image coming up, it may be because of strange differences between Qt's CSS engine which does not affect mudlet's Lua. You may want to try appending :gsub("\\","/") to your string including getMudletHomeDir() (e.g. <code>getMudletHomeDir():gsub("\\","/")</code>). No longer necessary after Mudlet 3.15.<br />
<br />
=== Aligning an image within a label ===<br />
You can use background-image in combination with background-position to align an image within a label (if, say, the image is much smaller than the label).<br />
<br />
<syntaxhighlight lang="lua"><br />
-- this will set and align an image top-right of the label<br />
if stunning then<br />
mylabel:setStyleSheet([[<br />
background-image: url("/home/vadi/Games/Mudlet/Offensive/Artwork/dialog-ok.png");<br />
background-repeat: no-repeat; background-position: top right; background-origin: margin;<br />
]])<br />
else<br />
mylabel:setStyleSheet([[<br />
background-image: url("/home/vadi/Games/Mudlet/Offensive/Artwork/dialog-no.png");<br />
background-repeat: no-repeat; background-position: top right; background-origin: margin;<br />
]])<br />
end<br />
</syntaxhighlight><br />
<br />
=== Showing / hiding a label ===<br />
You can show and hide labels, as you can any container, miniconsole or a gauge in Geyser with [http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html#Geyser.Container:show Geyser.Container:show()] and [http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html#Geyser.Container:hide Geyser.Container:hide()]. Remember that since labels are a type of a container, all container functions work on them.<br />
<br />
Hiding a label will allow you to click through on what is below the label, as well as free up the visual space for something else.<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "50%", y = 0,<br />
width = "50%", height = "100%",<br />
fgColor = "black",<br />
color = "SeaGreen",<br />
message = [[<center>heey</center>]]<br />
})<br />
<br />
-- hide the label with:<br />
testlabel:hide()<br />
<br />
-- show the label with:<br />
testlabel:show()<br />
</syntaxhighlight><br />
<br />
=== Clickable images ===<br />
Tacking onto the fact that you can plop images anywhere on your Mudlet screen now, you can also make them react to your clicks. You can do so with the [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:setClickCallback setClickCallback()] function - by giving it a function to call when your label is clicked, you'll make it react.<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = "-215px", y = "0px",<br />
width = "200px", height = "200px",<br />
})<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/qubodup-opengameart-cc0-200px-missile_icon.png]]) -- update location to actual image location on your computer<br />
picture_label:setClickCallback("on_bomb_press")<br />
<br />
function on_bomb_press()<br />
send("say BOOM!")<br />
end<br />
</syntaxhighlight><br />
<br />
That's it! Pressing on the image will make the ''on_bomb_press()'' function go off, which will do its code of ''send("say BOOM!")''. Download the picture for use [http://opengameart.org/content/missile-rts-icon here].<br />
<br />
[[File:Clickable_image.png|500px|center]]<br />
<br />
=== Styling labels ===<br />
Besides putting text or images on labels, you can also style them using Qt's stylesheets feature. Doing so allows you to create various graphics that make the label look more appealing:<br />
<br />
[[File:Label_styling_examples.png|center]]<br />
<br />
To set a stylesheet on a label, use the [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:setStyleSheet Geyser.Label:setStyleSheet()] function on your label, describing the stylesheet you'd like to give it. A stylesheet consists of properties you set - for example the background color, borders, padding, and so forth. You describe properties in the following format: ''property name''''':'''''values''''';'''. See here for a [http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties list of all supported properties]. For example, to make your labels background be yellow, you'd use the background-color property:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel = Geyser.Label:new({<br />
x = "50%", y = "50%",<br />
width = 200, height = 100<br />
})<br />
<br />
mylabel:setStyleSheet([[<br />
background-color: yellow;<br />
]])<br />
</syntaxhighlight><br />
<br />
[[File:Basic_stylesheet.png|center]]<br />
<br />
Which is nice, but not particularly impressive.<br />
<br />
Scrolling down the list of properties, you'll come along a border one. Plopping it into our stylesheet nets the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
background-color: yellow;<br />
border: 5px solid white;<br />
]])<br />
</syntaxhighlight><br />
<br />
[[File:Basic_stylesheet_border.png|center]]<br />
<br />
Which gives a border!<br />
<br />
Fiddling with it some more and applying new properties we find on that page, we get a rounded border on our label:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
background-color: grey;<br />
border-width: 15px;<br />
border-style: solid;<br />
border-color: green;<br />
border-radius: 10px;<br />
]])<br />
</syntaxhighlight><br />
<br />
[[File:Basic_stylesheet_border_radius.png|center]]<br />
<br />
Which'll conclude our exploration for now. Try out all of the other possible options available there - there's loads, from [http://doc.qt.io/qt-5/stylesheet-reference.html#border-style funky borders], to tiling images and fancy color combinations using gradients.<br />
<br />
=== Adding a tooltip to a label ===<br />
<br />
Since Mudlet 4.6, you can now add a tooltip to labels and gauges. You can start by making a simple label and echoing some text to it:<br />
<br />
<syntaxhighlight lang="lua"><br />
testLabel = Geyser.Label:new({<br />
name = "testLabel",<br />
x = "50%",<br />
y = "50%",<br />
height = "25%",<br />
width = "25%",<br />
})<br />
testLabel:echo("This is on the label!")<br />
testLabel:setAlignment("center")<br />
-- sets the tooltip text<br />
testLabel:setToolTip("This is the tooltip", "10")<br />
<br />
<br />
-- optionally - you can customise the tooltip, too!<br />
testLabel:setStyleSheet("QToolTip{background: yellow; color: blue; border:none;}")<br />
</syntaxhighlight><br />
<br />
Without tooltip<br />
[[File:TestLabelForTooltips.png|thumb|center]]<br />
<br />
With tooltip<br />
<br />
[[File:LabelTooltip.png|thumb|center]]<br />
<br />
=== Avoid stylesheet inheritance by tooltip ===<br />
<br />
{{note}} If you set a new stylesheet for a label and with that a background image it is possible that through inheritance the tooltip also has this stylesheet image.<br />
<br />
To avoid this specify that the stylesheet is meant for the Label by using QLabel{...} in your Label stylesheet for exampleː<br />
<syntaxhighlight lang="lua"><br />
label = Geyser.Label:new({<br />
name = "label",<br />
x = "50%", y = "50%",<br />
width = "50%", height = "50%",<br />
})<br />
<br />
-- by using QLabel{...} the stylesheet won't be given to the tooltip as well<br />
label:setStyleSheet[[<br />
QLabel{<br />
border-image: url(/home/vadi/Desktop/iso-avatar-draft_0.png);}<br />
]]<br />
</syntaxhighlight><br />
<br />
<br />
=== Aligning text/images inside a label ===<br />
By default, text is [http://qt-project.org/doc/qt-5/qlabel.html#alignment-prop centered vertically and left aligned] in a label. To align it to a specific side, use the stylesheets we learnt about earlier with the qproperty-alignment:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "50%", y = 0,<br />
width = "50%", height = "100%",<br />
fgColor = "black",<br />
color = "SeaGreen",<br />
message = [[<center>heey</center>]]<br />
})<br />
<br />
-- specify one property this way:<br />
mylabel:setStyleSheet([[qproperty-alignment: 'AlignTop';]])<br />
<br />
-- or multiple ones separated with a |, for example this will align text to top-left:<br />
-- specify one property this way:<br />
mylabel:setStyleSheet([[<br />
qproperty-alignment: 'AlignLeft | AlignTop';<br />
]])<br />
<br />
mylabel:echo("hi!")<br />
</syntaxhighlight><br />
<br />
[[File:Text_aligned.png|center]]<br />
<br />
=== Enabling wordwrap in a label ===<br />
If you need to enable word wrapping in a label (which by default is off), add the following line to the labels stylesheet:<br />
<br />
qproperty-wordWrap: true;<br />
<br />
As an example:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
qproperty-wordWrap: true;<br />
]])<br />
</syntaxhighlight><br />
<br />
If you'd like to set multiple properties, set them all at once - not via multiple :setStyleSheet() calls:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
background: red;<br />
]])<br />
</syntaxhighlight><br />
<br />
=== Adding a hover effect to a label ===<br />
The labels support adding stylesheets for specific cases, such as when a mouse is [http://doc.qt.io/qt-5/stylesheet-reference.html#hover-ps hovering] over them. To make this work, you provide CSS for when the label is in its usual state, and for when it is hovered over:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example will add a border to the label when it is hovered over<br />
mylabell:setStyleSheet([[<br />
QLabel{ border-radius: 4px; }<br />
QLabel::hover{<br />
background-color: rgba(0,0,0,0%);<br />
border: 4px double green;<br />
border-radius: 4px;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
=== Checkboxes ===<br />
Combining the fact that you can click on a label with an image to do something with the fact that you can change pictures on a label at will, you can make an image that changes itself when you click on it.<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = "50%", y = "50%",<br />
width = "21px", height = "19px"<br />
})<br />
-- a little trick we do to make the background of the label be transparent<br />
picture_label:setStyleSheet([[<br />
background-color: rgba(0,0,0,0%);<br />
]])<br />
<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/checkbox_ticked.png]])<br />
picture_label:setClickCallback("on_checkbox_press")<br />
<br />
function on_checkbox_press()<br />
if checkbox_ticked then<br />
checkbox_ticked = false<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/checkbox_unticked.png]])<br />
echo("Checkbox unticked.\n")<br />
else<br />
checkbox_ticked = true<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/checkbox_ticked.png]])<br />
echo("Checkbox TICKED!\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
The ''on_checkbox_press()'' function this time keeps the track of the checkbox with the ''checkbox_ticked'' variable and sets the image appropriately. You can download the ticked ([[File:Checkbox_ticked.png]]) and unticked images ([[File:Checkbox_unticked.png]]) or the [http://wiki.mudlet.org/images/6/6d/Checkbox.mpackage whole package] altogether.<br />
<br />
[[File:Checkbox_demo.png|500px|center]]<br />
<br />
=== Animated labels ===<br />
Using timers and several pictures, you can make your labels change quickly enough and look animated. Here's one such example:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = 10, y = "-24px",<br />
width = "16px", height = "14px",<br />
})<br />
<br />
santa_counter = nil<br />
<br />
function animate_santa()<br />
santa_counter = (santa_counter or 0) + 1<br />
if santa_counter > 8 then santa_counter = 1 end<br />
<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/santa/santa]]..santa_counter..[[.png]]) -- update location to actual image location on your computer<br />
santa_timer = tempTimer(.16, animate_santa)<br />
end<br />
<br />
animate_santa()<br />
</syntaxhighlight><br />
<br />
The completed package is available [http://wiki.mudlet.org/images/6/6b/Dancing-santa.mpackage here], install it and do '''start/end animation''' to watch.<br />
<br />
=== Inserting extra spaces and newlines ===<br />
Echoing text into Mudlet and Geyser labels is different from miniconsoles and the main window, due to their nature. One of the differences is that extra spaces in a label, by default, get compressed down to one. '''To add extra spaces in a label''', replace extra spaces with '''&amp;nbsp;''' or by wrapping your text with them inside '''<nowiki><pre>my text here</pre></nowiki>'''.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- this won't work, it'll show as one space:<br />
mylabel:echo("You -> point")<br />
<br />
-- but this would, because it replaces all spaces with &nbsp before echoing<br />
mylabel:echo(string.gsub("You -> point", " ", "&nbsp;"))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- here is another way to go about this - and it additionally makes the font be monospaced:<br />
mylabel:echo("<pre>You -> point</pre>")<br />
</syntaxhighlight><br />
<br />
'''To add a new line in a label''' (aka linebreak), use '''<br>''' (instead of ''\n'' as you are used to in an echo).<br />
<syntaxhighlight lang="lua"><br />
mylabel:echo("These<br>words<br>are<br>split")<br />
</syntaxhighlight><br />
<br />
=== Transparent labels ===<br />
One of the possible ways of achieving transparency on a label is to add <code>background-color: rgba(0,0,0,0%);</code> to its stylesheet. Here's an example:<br />
<br />
<syntaxhighlight lang="lua"><br />
my_transparent_label:setStyleSheet([[<br />
background-color: rgba(0,0,0,0%);<br />
]])<br />
</syntaxhighlight><br />
<br />
=== Custom mouse cursor ===<br />
You can change the shape of the cursor when it's over your label with:<br />
<syntaxhighlight lang="lua"><br />
mylabel:setCursor("Forbidden") -- will change your mouse cursor to "forbidden" (as in "can't do this") cursor<br />
</syntaxhighlight><br />
Possible cursor shapes are [[CursorShapes| available here]], and you can import this [[Media:Cursor grid.zip|demo package]] to try them all out.<br />
<br />
It is also possible to change the mouse cursor to a custom made cursor by:<br />
<syntaxhighlight lang="lua"><br />
mylabel:setCustomCursor(getMudletHomeDir().."/custom_cursor.png")<br />
</syntaxhighlight><br />
It is recommended that the custom cursor is a png with size of 32x32 to be supported on all systems.<br />
<br />
[[File:Changecursoroverlabel.gif]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
=== Flyout Labels ===<br />
<br />
Flyout labels allow you to create 'dropdown' or 'flyout' menus - menus that reveal more items once you hover your mouse over them. To create flyout labels:<br />
# add <code>nestable=true</code> (left click to open menu) or <code>nestflyout=true</code> (mouse hover to open menu) to your main label.<br />
# use [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:addChild :addChild()] on your main label to add flyout labels to it.<br />
## [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:addChild :addChild()] uses the same arguments as when creating a new label but also takes the '''layoutDir''' option to specify in which direction and axis should the labels align, where 2 letters combine into the option: first letter R for right, L for left, T for top, B for bottom, followed by the orientation: V for vertical or H for horizontal. So options are: <code>layoutDir="RV"</code>, <code>layoutDir="RH"</code>, <code>layoutDir="LV"</code>, <code>layoutDir="LH"</code>, and so on.<br />
# optionally, add <code>flyOut=true</code> to your flyout labels to make the labels dissapear when the mouse isn't hovering over them anymore.<br />
<br />
Note that the main flyout label cannot go into a container and needs to be on its own.<br />
<br />
{{note}} Requires Mudlet 3.0.<br />
<br />
==== Demo ====<br />
Here's an example that follows the steps above:<br />
<br />
<syntaxhighlight lang="lua"><br />
label0 = Geyser.Label:new({name="label0", <br />
x="50%",y="50%",height=50,width=300,nestable=true, <br />
message="<center>Clicky clicky</center>"})<br />
<br />
-- and add 3 labels to it with RV layout - so Right of the label, aligned Vertically<br />
label1 = label0:addChild({name="label1",height=30,width=70, layoutDir="RV", flyOut=true, message="label one"})<br />
label1:setStyleSheet([[background-color: purple; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px; font-size: 7pt;]])<br />
<br />
label2 = label0:addChild({name="label2",height=30,width=70, layoutDir="RV", flyOut=true, message="label two"}) <br />
label2:setStyleSheet([[background-color: green; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px; font-size: 7pt;]])<br />
<br />
label3 = label0:addChild({name="label3",height=30,width=70, layoutDir="RV", flyOut=true, message="label three"})<br />
label3:setStyleSheet([[background-color: red; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px; font-size: 7pt;]])<br />
</syntaxhighlight><br />
<br />
A more thorough example. Try it out to see what you can create with flyout labels:<br />
<syntaxhighlight lang="lua"><br />
-- create a label with a nestable=true property to say that it can nest labels<br />
mainlabel = Geyser.Label:new({name="testa", x=400,y=50,height=50,width=300,nestflyout=true, message="<center>HOVER HERE TO SEE FLY-OUT LABELS!</center>"})<br />
<br />
-- create 15 labels and store them in a table <br />
table_for_flyout_labels = {}<br />
for i=1,15 do<br />
-- options to layoutDir are the direction the window should go (R for right, L for left, T for top, B for bottom), followed by how the nested labels should be oriented (V for vertical or H for horizontal). So "BH" here means it'll go on the bottom of the label, while expanding horizontally<br />
table_for_flyout_labels[i] = mainlabel:addChild({name="test"..tostring(i),height=30,width=70, layoutDir="BH", flyOut=true, message="test"..tostring(i)})<br />
<br />
table_for_flyout_labels[i]:setStyleSheet([[background-color: purple; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px;]])<br />
end<br />
<br />
-- make the test5 label look a bit special as it has got a surprise<br />
table_for_flyout_labels[5]:echo("Hover here")<br />
<br />
-- add even more nested labels to the 5th label!<br />
even_more_flyout_labels = {}<br />
for i=1,60 do<br />
-- here, the layout will be to the right of it, while expanding vertically<br />
even_more_flyout_labels[i]=table_for_flyout_labels[5]:addChild({name="hover label "..tostring(i),height=30,width=100, layoutDir="RV", flyOut=true, message="label "..tostring(i)})<br />
even_more_flyout_labels[i]:setClickCallback("testFunc", even_more_flyout_labels[i].name)<br />
even_more_flyout_labels[i]:setStyleSheet([[background-color: grey; border-width: 2px; border-style: solid; border-color: green; border-width: 2px; font-size: 7pt;]])<br />
end<br />
<br />
function testFunc(name)<br />
display(name)<br />
end<br />
</syntaxhighlight><br />
<br />
It'll look something like this: <br />
<br />
[[File:Flyout_labels_demo.png|150px]]<br />
<br />
==== Demo of layouts ====<br />
Here's another demo that explains all of the layout styles quite well:<br />
<syntaxhighlight lang="lua"><br />
local directions = {"R", "L", "T", "B"}<br />
local orientations = {"V", "H"}<br />
local mappings = {R = "right", L = "left", T = "top", B = "bottom", V = "vertical", H = "horizontal"}<br />
<br />
local combinations, combination_labels = {}, {}<br />
for _, direction in pairs(directions) do<br />
for _, orientation in pairs(orientations) do<br />
combinations[#combinations+1] = direction..orientation<br />
end<br />
end<br />
<br />
local function get_foreground_text_colour(r,g,b)<br />
local luminosity = (0.2126 * ((r/255)^2.2)) + (0.7152 * ((g/255)^2.2)) + (0.0722 * ((b /255)^2.2))<br />
if luminosity > 0.5 then<br />
return "black"<br />
else<br />
return "white"<br />
end<br />
end<br />
<br />
local function get_random_colour_rgb()<br />
return math.random(1,255), math.random(1,255), math.random(1,255)<br />
end<br />
<br />
-- create a label with a nestable=true property to say that it can nest labels<br />
all_possible_combinations_label = Geyser.Label:new({name="all_possible_combinations_label", x=0,y="-400",height=50,width=500,<br />
nestable = true, message="<center>Click to see a listing of possible combinations</center>"})<br />
<br />
for i = 1, #combinations do<br />
local combination = combinations[i]<br />
combination_labels[i] = all_possible_combinations_label:addChild({name="combo_"..combination,height=30,width=150, nestable = true, flyOut=true, layoutDir="BH", message="<center>Combination "..combination.."</center>"})<br />
<br />
local r,g,b = get_random_colour_rgb()<br />
local text_colour = get_foreground_text_colour(r,g,b)<br />
<br />
local combination_labels_children = {}<br />
for ii = 1, 3 do<br />
combination_labels_children[ii] = combination_labels[i]:addChild({<br />
name="combo_"..combination.."_"..ii, height = 30, width = 150, layoutDir=combination, flyOut = true,<br />
message = string.format("<center><b>%s</b>%s+<b>%s</b>%s layout</center>", <br />
combination:sub(1,1), mappings[combination:sub(1,1)]:sub(2), combination:sub(2,2), mappings[combination:sub(2,2)]:sub(2)),<br />
fgColor = text_colour})<br />
<br />
combination_labels_children[ii]:setStyleSheet(string.format([[background-color:rgb(%d, %d, %d); border-width: 2px; border-style: solid; border-color: green; border-width: 2px; font-size: 7pt;]], r,g,b))<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
It'll look like this:<br />
<br />
[[File:Flyoutlabels-layout-demo.png]]<br />
<br />
=== Geyser.Label right click menu ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
You can create a right click menu for a label just by using the function (assuming your label name is 'myLabel')<br />
<syntaxhighlight lang="lua"> myLabelːcreateRightClickMenu(MenuItems = myMenuTable, other cons) -- see example below for details </syntaxhighlight><br />
<br />
The menu table comprises of all the items and their names. To create a parent menu just create a nested table of names.<br />
Example of a menuTable<br />
<syntaxhighlight lang="lua"> menuTable = {"First Item", "Second Item (Parent)",{"First ChildItem","Second ChildItem"}, "Third Item"} </syntaxhighlight><br />
As menu would look likeː<br />
<br />
[[File:RCDemo1.gif|250px]]<br />
<br />
==== Style your right click menu ====<br />
Your right click menu has 2 default styles integratedː "light" and "dark" which are defined by the constraint "Style".<br />
To set a default style just give the constraint Style the preferred value, for exampleː<br />
<syntaxhighlight lang="lua"> Style = "dark" </syntaxhighlight><br />
To give different levels of your menu different style just add the number of the level to the constraint, for exampleː<br />
<syntaxhighlight lang="lua"> Style2 = "light" -- Gives the second level of your menu the "light" style</syntaxhighlight><br />
<br />
For adding your own stylesheet use the constraint MenuStyle (use the same method as above to define stylesheets for different levels)<br />
<syntaxhighlight lang="lua"> MenuStyle2 = [[QLabel::hover{ background-color: rgba(0,255,150,100%); color: white;} QLabel::!hover{color: brown; background-color: rgba(100,240,240,100%);} ]] <br />
-- Gives the second level of your menu this stylesheet</syntaxhighlight><br />
<br />
The same methods are used for defining the format, width and height for the menu item.<br />
<syntaxhighlight lang="lua"> <br />
MenuWidth = 70 -- standard menu width if nothing else is given<br />
MenuWidth2 = 80 -- menu width for the second level <br />
MenuFormat1 = "c10" -- menu format for the first level (format works like any other label echo format, in this case c is center and 10 is the font-size)<br />
MenuHeight = 30<br />
</syntaxhighlight><br />
<br />
==== Set onClick action for your menu item ====<br />
To set an action if your menu item is clicked use the function (assuming your label name is 'myLabel' and using the same MenuItems as defined above)<br />
<syntaxhighlight lang="lua"> <br />
myLabelːsetMenuAction("First Item", function() echo("Clicked on the first item\n") end<br />
myLabelːsetMenuAction("Second Item (Parent).First ChildItem", function() echo("Clicked on the first child item\n") end) -- To set an action to a child item find it by using "Parent.Child" as name (only one parent is needed to be given the parents parent is not needed)<br />
</syntaxhighlight><br />
<br />
==== Access an menu item directly ====<br />
The simplest way to access a menu item directly is by just using the function (assuming your label name is 'myLabel' and using the same MenuItems as defined above)<br />
For example to change the menu item textː<br />
<syntaxhighlight lang="lua"> <br />
myLabelːfindMenuElement("First Item"):echo([[my first Item]])<br />
</syntaxhighlight><br />
<br />
==== Right click menu example ====<br />
Better then any further explanation is probably this practical example. <br />
<br />
<syntaxhighlight lang="lua"> <br />
-- create the label the right click menu will be in<br />
myRightClickLabel = myRightClickLabel or Geyser.Label:new({<br />
name = "myRightClickLabel", message = "Please right click!", <br />
format = "cb15", x=10, y=10, width ="30%", height = "15%", <br />
color = "purple"})<br />
<br />
-- right click menu creation with custom styleheet on level2 and default "Dark" style <br />
myRightClickLabel:createRightClickMenu(<br />
{MenuItems = {"Emergency", "Drink",{"ManaPotion","HealthPotion"}, "Disappear", "Cast",{"Blindness", "Blink"}}, <br />
Style = "Dark", <br />
MenuWidth2 = 80, <br />
MenuFormat1 = "c10",<br />
MenuStyle2 = [[QLabel::hover{ background-color: rgba(0,255,150,100%); color: white;} QLabel::!hover{color: brown; background-color: rgba(100,240,240,100%);} ]]}<br />
)<br />
<br />
myRightClickLabel:setMenuAction("Emergency", function() <br />
cecho("<red:pink>[Emergency Mode] Run as fast as possible!\n") <br />
send("emergency") <br />
closeAllLevels(myRightClickLabel) -- this can be used to close the right click menu if clicked on this item<br />
end)<br />
<br />
myRightClickLabel:setMenuAction("Drink.ManaPotion", function()<br />
cecho("<blue>Drinking my mana potion.\n") <br />
send("drink mp") <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Drink.HealthPotion", function() <br />
cecho("<red>Drinking my health potion.\n") <br />
send("drink hp") <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Disappear", function() <br />
cecho("<grey>Disappearing.. \n") <br />
send("disappear") <br />
closeAllLevels(myRightClickLabel) <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Cast.Blindness", function() <br />
cecho("<light_blue>Casting blindness \n") <br />
send("cast blindness enemy") <br />
closeAllLevels(myRightClickLabel) <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Cast.Blink", function() <br />
cecho("<light_blue>Casting blink \n") <br />
send("cast blink") <br />
end )<br />
</syntaxhighlight><br />
<br />
This looks likeː<br />
<br />
<br />
[[File:Right click example demo.gif]]<br />
<br />
=== Add right click menu to label with already existing left click action ===<br />
If your label has an already existing left click action you'll have to create the right click menu<br />
"before" creating the labels "setClickCallBack" action and then just put into your labels onClick function<br />
(assuming your label name is 'myLabel' and 'event' is the last parameter of your onClick function)<br />
<br />
<syntaxhighlight lang="lua"> <br />
myLabel:onRightClick(event)<br />
</syntaxhighlight><br />
<br />
=== Background for Mudlets buttons ===<br />
You can give Mudlets buttons a background to have them blend in with your UI by doing this:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace the /home/vadi/Pictures/tile.png location below with the one of your picture!<br />
-- you can download the sample tile.png from https://opengameart.org/content/bevouliin-free-game-background-for-game-developers<br />
local backgroundpath = [[/home/vadi/Pictures/tile.png]]<br />
-- Windows:<br />
-- local backgroundpath = [[C:/Users/Vadim/Downloads/Free game background/transparent PNG/tile.png]]<br />
<br />
setAppStyleSheet([[<br />
QToolBar {<br />
border-image: url(]]..backgroundpath..[[);<br />
<br />
}<br />
<br />
QToolBar QToolButton:!hover {<br />
color: white;<br />
}<br />
QToolBar QToolButton:hover {<br />
color: black;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
Result:<br />
<br />
[[File:Mudlet tiled buttons.png|frame|left]]<br />
<br clear=all><br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserMiniConsole.html Geyser.MiniConsole]==<br />
This allows you to spawn a Mudlet miniconsole - unlike labels, these aren't as styleable, but they do format text better. They make a good fit for text-based menus, chat and map capture, and other things.<br />
<br />
Spawning one is very similar to other Geyser elements - paste this into a new script:<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
autoWrap = true,<br />
color = "black",<br />
scrollBar = false,<br />
fontSize = 8,<br />
width="30%", height="50%",<br />
})<br />
</syntaxhighlight><br />
<br />
This'll make you one at the bottom-right of the screen. The miniconsole will have a grey background by default, but you can set it to any color you'd like with [http://www.mudlet.org/geyser/files/geyser/GeyserWindow.html#Geyser.Window:setColor miniconsole:setColor()]:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:setColor("black") -- give it a nice black background<br />
</syntaxhighlight><br />
<br />
A special dimension property that MiniConsoles have is a character - instead of specifying a miniconsole to be % of a container or a certain number of pixels, you can specify it as a certain number of characters. You do this by using "c" at the end of a number. This way, you can, for example, specify miniconsole to be 10 letters long and 2 lines high:<br />
<br />
<syntaxhighlight lang="lua"><br />
flatbox = Geyser.MiniConsole:new({<br />
name="flatbox",<br />
x="70%", y="50%",<br />
wrapAt = 10,<br />
width="10c", height="2c",<br />
})<br />
flatbox:setColor("red")<br />
flatbox:echo("ABCDEFGHIJ") -- that is 10 letters<br />
</syntaxhighlight><br />
<br />
=== Adding text ===<br />
You can use [[Manual:Technical_Manual#echo|echo()]] the same way with a miniconsole to add text as to the usual window:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("hello!")<br />
</syntaxhighlight><br />
<br />
As well as [[Manual:Technical_Manual#cecho|cecho]], [[Manual:Technical_Manual#decho|decho]], or [[Manual:Technical_Manual#hecho|hecho]]:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:cecho("<green>hey, <blue>colored <red>text!\n")<br />
</syntaxhighlight><br />
<br />
=== Copying lines with color ===<br />
To copy a line over to the miniconsole, as it is from the game with all colors preserved, you can [[Manual:UI_Functions#selectCurrentLine|select]], [[Manual:UI_Functions#copy|copy]], and [[Manual:UI_Functions#appendBuffer|append]] it. For an example, try making a trigger with this as the ''Lua function'' pattern type:<br />
<br />
<syntaxhighlight lang="lua"><br />
return true<br />
</syntaxhighlight><br />
<br />
That'll make the trigger go off on every line. Then give it the following script (assumed you have made the HelloWorld miniconsole from earlier):<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
copy()<br />
HelloWorld:appendBuffer()<br />
</syntaxhighlight><br />
<br />
... and you'll see all MUD output duplicated exactly as it is to the miniconsole. Amazing! It's very efficient as well, so you can have many miniconsoles, even in spam, not lag you down.<br />
<br />
=== Clearing the miniconsole ===<br />
Clearing the miniconsole just requires using the following script (assumes you have made the HelloWorld miniconsole from earlier):<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:clear()<br />
</syntaxhighlight><br />
<br />
=== Doing edits in copied lines ===<br />
Sometimes you'll want to edit the line before stuffing it into the miniconsole. For example, if you're making a chat capture, you'd want to condense a really long org name into something that's more space-friendly.<br />
<br />
To do so, you'd use the [[Manual:Technical_Manual#selectString|selectString()]] the text you'd like to modify, [[Manual:Technical_Manual#replace|replace()]] it with a different one:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString("Your", 1) -- select the word you'd like to replace - in this case, 'Your'<br />
setBgColor(getBgColor()) -- preserve the background color in the replacement<br />
setFgColor(getFgColor()) -- preserve the foreground color in the replacement<br />
replace("Mine") -- replace the selection with the wird 'Mine'<br />
<br />
selectCurrentLine()<br />
copy()<br />
HelloWorld:appendBuffer()<br />
</syntaxhighlight><br />
<br />
=== Gagging from the main window ===<br />
If you'd like to gag the line from the main window so it only shows up in your miniconsole, [[Manual:Technical_Manual#deleteLine|delete]] it after moving it over:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
copy()<br />
HelloWorld:appendBuffer()<br />
deleteLine()<br />
</syntaxhighlight><br />
<br />
=== Clickable menus ===<br />
Using the [[Manual:Technical_Manual#echoLink|echoLink]], [[Manual:Technical_Manual#insertLink|insertLink]] and [[Manual:Technical_Manual#setLink|setLink]] functions, you can turn text into one that reacts on a click. Combined with your power of placing text anywhere on the screen with a miniconsole, you can make menus with options. Here is one such example, where selecting an item causes an echo to happen:<br />
<br />
<syntaxhighlight lang="lua"><br />
flatbox = Geyser.MiniConsole:new({<br />
name="flatbox",<br />
x="20%", y="80%",<br />
width="40c", height="4c",<br />
})<br />
flatbox:setColor("red")<br />
clearWindow("flatbox")<br />
<br />
flatbox:cecho("<white:red>Choose one of the following options:\n")<br />
<br />
flatbox:fg("white")<br />
flatbox:bg("red")<br />
<br />
for _, fruit in ipairs{"banana", "apple", "orange"} do<br />
echoLink("flatbox", "* "..fruit:title().."\n", [[echo("You picked ]]..fruit..[[\n")]], "The "..fruit.." option", true)<br />
end<br />
<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
This will produce something like the following:<br />
<br />
[[File:Fruit_menu.png|center]]<br />
<br />
=== Change your miniconsole background image ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
To set a custom background image for your miniconsole use (assumes you have made the HelloWorld miniconsole from earlier): <br />
<syntaxhighlight lang="lua"><br />
HelloWorld:setBackgroundImage(getMudletHomeDir().."/myBgImage.png", "center") -- put's your image myBgImage.png which is in your profile folder in the center of the miniconsole<br />
</syntaxhighlight><br />
<br />
For different modes/options see here [[Manual:Lua_Functions#setConsoleBackgroundImage|setConsoleBackgroundImage()]]<br />
<br />
=== Enable and use your miniconsole command line ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
Every miniconsole has a hidden command line.<br />
Enable it with (assumes you have made the HelloWorld miniconsole from earlier): <br />
<syntaxhighlight lang="lua"><br />
HelloWorld:enableCommandLine()<br />
</syntaxhighlight><br />
<br />
=== Set an action to your miniconsole command line ===<br />
If no action is set to your miniconsole command line the commands are send to the game the same way <br />
as for the main command line <br />
<br />
(aliases still work and there is a command echo in your main and miniconsole if not deactivated in the settings)<br />
<br />
It is possible to set an action to your command line which means that it is possible to use the input text and perform an action.<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:enableCommandLine()<br />
local function channelChat(text)<br />
send("chat "..text)<br />
HelloWorld:echo("[chat] " ..text.."\n")<br />
end<br />
<br />
HelloWorld:setCmdAction(channelChat)<br />
</syntaxhighlight><br />
<br />
This will send your miniconsole command line input to the chat channel.<br />
<br />
More complicated/sophisticated actions are possible, setCmdAction works the same way as the Label clickCallback functions.<br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserGauge.html Geyser.Gauge]==<br />
<!--<br />
This is a composite window. Gauge duplicates the functionality of the built in Mudlet gauges, but in a clean and easily extended way. Internally, a Geyser Gauge is a container holding two Labels, front and back, which are initially scaled to fill the entire Gauge container. Hence, a gauge, g, can be given callbacks with the g.front:setClickCallback() method.<br />
<br />
The backgroundColor parameter initially sets the colors of the gauge, but of course the front and back components can be accessed individually as labels for high control over their looks. Gauges can be horizontal or vertical and decrease in value left to right, right to left, down up or up down depending on the value of the orientation parameter.<br />
--><br />
<br />
A Gauge allows you to represent numbers on a scale - and most typically, you've seen it be used as your standard hp/mana/whatever bar. A basic bar is made similarly to other Geyser elements. To set the value on the gauge that it should represent, use the [http://www.mudlet.org/geyser/files/geyser/GeyserGauge.html#Geyser.Gauge:setValue setValue()] function:<br />
<br />
<syntaxhighlight lang="lua"><br />
hpbar = Geyser.Gauge:new({<br />
name="hpbar",<br />
x="50%", y="85%",<br />
width="45%", height="5%",<br />
})<br />
hpbar:setValue(math.random(1,100),100)<br />
</syntaxhighlight><br />
<br />
That'll spawn you a pretty basic gauge with a horizontal orientation and a grey colour - and as a test, with a random value.<br />
<br />
[[File:Basic_gauge.png|center]]<br />
<br />
=== Updating a gauge ===<br />
You'd want your gauge to stay in sync with your actual values. To make that happen, you want to call [http://www.mudlet.org/geyser/files/geyser/GeyserGauge.html#Geyser.Gauge:setValue setValue()] whenever the value that the gauge is tracking changes.<br />
<br />
So for example, if you make a health bar - wherever you get your new health at (be it prompt, gmcp, atcp or whatever), update the gauge as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- theoretical example<br />
current_health, max_health = tonumber(matches[2]), tonumber(matches[3])<br />
<br />
-- update the bar<br />
hp_bar:setValue(current_health, max_health)<br />
</syntaxhighlight><br />
<br />
You can also write down how much health have you got on the bar with:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local hp = math.random(1,100) <br />
hpbar:setValue(current_health, max_health, "<b>"..max_health.."hp</b>")<br />
<br />
-- example using GMCP in IRE games:<br />
hpbar:setValue((100/gmcp.Char.Vitals.maxhp)*gmcp.Char.Vitals.hp,100,gmcp.Char.Vitals.hp)<br />
</syntaxhighlight><br />
<br />
[[File:Hpbar_basic.png|center]]<br />
<br />
=== Styling a gauge ===<br />
The Geyser gauge is composed of three labels - one is called ''mygauge.front'', ''mygauge.back'' and ''mygauge.text''. Combining this with Geyser:Label.setStyleSheet, you can improve the visuals of your gauges by using Qt-supported CSS. The syntax for specifying CSS is a bit different - it requires a semicolon after every property, and is done in the format of ''property name''''':'''''values''''';'''. A list of all possible properties you can use is [http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties available here] and you can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create them. Practical example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hpbar = Geyser.Gauge:new({<br />
name="hpbar",<br />
x="50%", y="85%",<br />
width="45%", height="20px",<br />
})<br />
hpbar.front:setStyleSheet([[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #98f041, stop: 0.1 #8cf029, stop: 0.49 #66cc00, stop: 0.5 #52a300, stop: 1 #66cc00);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;<br />
]])<br />
hpbar.back:setStyleSheet([[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #78bd33, stop: 0.1 #6ebd20, stop: 0.49 #4c9900, stop: 0.5 #387000, stop: 1 #4c9900);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;<br />
]])<br />
<br />
hpbar:setValue(math.random(1,100),100)<br />
</syntaxhighlight><br />
<br />
[[File:Fancy_Geyser_gauge.png|center]]<br />
<br />
The same style can be adjusted by colors to red as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
hpbar = Geyser.Gauge:new({<br />
name="hpbar",<br />
x="50%", y="85%",<br />
width="45%", height="20px",<br />
})<br />
hpbar.front:setStyleSheet([[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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
hpbar.back:setStyleSheet([[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
<br />
hpbar:setValue(math.random(1,100),100)<br />
</syntaxhighlight><br />
<br />
[[File:Fancy_Geyser_gauge_red.png|center]]<br />
<br />
=== Updating a gauge ===<br />
The Geyser gauge is composed of three labels - one is called ''mygauge.front'', ''mygauge.back'' and ''mygauge.text''. To make a gauge clickable you can set a ClickCallBack on the top label which is ''mygauge.text'' example: <syntaxhighlight lang="lua">mygauge.text:setClickCallback("functionName", variableToSendToFunctionName)</syntaxhighlight><br><br />
If you would like to have different click events for the top or back of a gauge you can enable clickThrough for the top or ''mygauge.text'' label example<br />
<br />
<syntaxhighlight lang="lua"><br />
mygauge.text:enableClickthrough()<br />
mygauge.front:setClickCallback("functionOne", variableToSendToFunctionOne)<br />
mygauge.back:setClickCallback("functionTwo", variableToSendToFunctionTwo)<br />
</syntaxhighlight><br />
<br />
<br />
=== Tooltips on gauges ===<br />
Tooltips are available since Mudlet 4.6 as explained in above section [[#Adding_a_tooltip_to_a_label]], and as gauges are really only made up of labels as well, you could add a tooltip then by just using <syntaxhighlight lang="lua">mygauge.text:setToolTip("This is the gauge's tooltip", "10")</syntaxhighlight> the same as it's handled for clickback.<br />
<br />
== HBox/VBox ==<br />
<br />
These are special types of containers. Every window in these is horizontally or vertically aligned in the order they were added.<br />
<br />
<sub>Added to Mudlet in 2.0-rc4</sub><br />
<br />
== Geyser.UserWindow ==<br />
Allows you to use Mudlets UserWindows within Geyser. Which allows you to use all the functionality of a MiniConsole in its basic form.<br />
The big advantage is the possibility to add other Geyser Elements like Labels, MiniConsole, Gauges, Mappers to the UserWindow.<br />
The UserWindow then can act as container for those elements with all the perks of dynamic resizing or any other Geyser functionality.<br />
<br />
{{note}} available in Mudlet 4.6.1+<br />
<br />
===Basic floating UserWindow ===<br />
This will create a movable floating UserWindow.<br />
<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "TestUserWindow",<br />
titleText ="My Test UserWindow", -- only available since Mudlet 4.8+<br />
x = "20%", y="20%",<br />
width="30%", height ="40%"<br />
})<br />
</syntaxhighlight><br />
{{note}} Since Mudlet 4.8+ it is possible to change the Title of the UserWindow by using the constraint titleText and the functions belowː<br />
<br />
To revert to the standard title useː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:resetTitle()<br />
</syntaxhighlight><br />
To set a new title after creation useː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:setTitle("My new title Text")<br />
</syntaxhighlight><br />
<br />
=== Docked UserWindow ===<br />
To create the window docked at the right side,<br />
set the variable docked (at creation of the container) to true.<br />
Be aware that with this variable set to true the position and the size at creation of the userwindow will be ignored.<br />
<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "DockedTestUserWindow",<br />
docked = true<br />
<br />
})<br />
</syntaxhighlight><br />
<br />
Since Mudlet 4.8+ it is also possible to choose the docking Position of the UserWindow at creation and by function withː<br />
<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "DockedTestUserWindow",<br />
docked = true,<br />
dockPosition = "top" -- Possible dockPositions are left "l", right "r", top "t", bottom "b" and floating "f" <br />
})<br />
</syntaxhighlight><br />
<br />
To change it for a already created UserWindow use the function setDockPosition(dockPosition) likeː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:setDockPosition("left")<br />
</syntaxhighlight><br />
<br />
=== Disable\Enable UserWindow autoDock ===<br />
{{note}} available in Mudlet 4.8+<br />
<br />
The auto docking feature can be really annoying at times. To disable it use the functionsː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:disableAutoDock() -- disables autoDock. Docking still possible with ːsetDockPosition<br />
testuserwindow:enableAutoDock() -- reenables autoDock<br />
</syntaxhighlight><br />
<br />
=== Styling the UserWindow border and title area ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
Geyser.UserWindows can accept a stylesheet to change the appearance of the border and title area and make<br />
the UserWindow look more appealing.<br />
<syntaxhighlight lang="lua"><br />
myUserWindow = myUserWindow or Geyser.UserWindow:new({<br />
name = "myUserWindow", titleText = "myUserWindow", autoDock = false<br />
})<br />
<br />
myUserWindow:setStyleSheet( <br />
[[QDockWidget{<br />
border: 1px solid green; /* UserWindow border style */<br />
font: bold 15pt "Arial"; /* Font of the titleBar */<br />
color: rgb(0,0,150); /* Font color */<br />
}<br />
<br />
QDockWidget::title{ <br />
background-color: rgb(0,255,150); /* TitleBar color */<br />
border: 2px solid red; /* TitleBar border */<br />
border-radius: 2px; /* TitleBar border radius */<br />
text-align: center; /* alignment of the titleText */<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
This looks likeː<br />
<br />
<br />
[[File:UserWindowStyleSheet.png]]<br />
<br />
=== UserWindow as Container ===<br />
This is the feature which shows the versatile nature of Geyser.UserWindows.<br />
The UserWindow act as container and is at that possible to dynamically resize the containing Geyser Elments.<br />
Put a label in the UserWindow resize it as rectangle.<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "ParentTestUserWindow",<br />
x = "20%", y="20%",<br />
width="30%", height ="40%"<br />
})<br />
<br />
testuserwindow:setColor("dark_green") -- give the userwindow a bit of color <br />
<br />
labelinuserw = Geyser.Label:new({<br />
name = "LabelinUserWindow",<br />
x=20, y=20,<br />
width = -20, height = -20,<br />
color="light_blue", fontSize=20,<br />
},testuserwindow)<br />
<br />
labelinuserw:echo("This is a label in an userwindow", "black", "c")<br />
</syntaxhighlight><br />
[[File:LabelInUserWindow.png]]<br />
<br />
The same way you are able to add your favorite Geyser Application (like tabbed chat, animated timers, gauges) to an UserWindow.<br />
<br />
Note that you don't need to add MiniConsoles to a UserWindow - as UserWindows already have them built-in.<br />
<br />
[[File:Tabbedchatinuserwindow.png]]<br />
<br />
== Geyser.CommandLine ==<br />
{{note}} available in Mudlet 4.10+<br />
<br />
Allows you to create your custom command lines which can resize/move like any other Geyser object.<br />
<br />
If you just need a command line which is integrated in a miniconsole or userwindow check out [[Manual:Geyser#Enable and use your miniconsole command line|this]].<br />
<br />
=== Creating a Geyser.CommandLine ===<br />
An example to get you startedː<br />
<syntaxhighlight lang="lua"><br />
myCommandLine = myCommandLine or Geyser.CommandLine:new({<br />
name = "myCommandLine", <br />
x = "-20%", y = -40, <br />
width = "20%", height = 40,<br />
stylesheet = "border: 1px solid silver;"})<br />
</syntaxhighlight><br />
This creates a new command line in the right bottom of your screen.<br />
<br />
=== Bind action to your command line input ===<br />
If you use your previous created command line any command will just be send to the game and/or the alias engine.<br />
<br />
To react to any input in a custom manner we can set an action to the command line and use the input as parameter.<br />
<br />
Example of a command line changing the background color of your main console (assumes you have created "myCommandLine" from earlier): <br />
<syntaxhighlight lang="lua"><br />
myCommandLine:setAction(<br />
function(commandLineInput)<br />
r, g, b = Geyser.Color.parse(commandLineInput) -- gets the r, g, b values of the color you input to the command line<br />
if b then -- checks if the color is valid<br />
setBackgroundColor(r, g, b)<br />
else<br />
echo("\n"..commandLineInput.." is not a valid color. Try again.")<br />
end<br />
end)<br />
</syntaxhighlight><br />
<br />
=== Styling a command line ===<br />
You can style your Geyser command line by using Qt-supported CSS. A list of all possible properties you can use is [http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties available here]<br />
<br />
Practical example (assuming "myCommandLine" is created)ː<br />
<syntaxhighlight lang="lua"><br />
myCommandLine:setStyleSheet([[<br />
QPlainTextEdit{ /* QPlainTextEdit is used to prevent the styleSheet bleeding to the right click menu*/<br />
border: 1px solid silver; /* Command line border style */<br />
background-color: rgb(0,255,150); /* Command line background color */<br />
font: bold 12pt "Arial"; /* Font and font-size of your command line */<br />
color: rgb(0,0,150); /* Command line text color */<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
== Create an extra command line in Mudlet ==<br />
If your goal is to just have an extra command/input line copy/paste the example below into a new script in Mudletː<br />
<br />
<syntaxhighlight lang="lua"><br />
inputContainer = inputContainer or Adjustable.Container:new({<br />
x = 0, y = "-4c", <br />
name = "InputContainer", padding = 2, <br />
width = "100%", height = "4c", <br />
autoLoad = false})<br />
<br />
extraCmdLine = extraCmdLine or Geyser.CommandLine:new({<br />
name = "extraCmdLine", <br />
x = 0, y = 0, width = "100%", height = "100%"}, inputContainer)<br />
<br />
inputContainer:attachToBorder("bottom")<br />
</syntaxhighlight><br />
<br />
This will look likeː <br />
<br />
[[File:AdditionalCommandLine.png|extra command line]]<br />
<br />
== Adjustable.Container ==<br />
{{note}} available in Mudlet 4.8+<br />
<br />
Adjustable Containers are a new "GeyserClass" which act as containers for Geyser elements, but with more flexible and user configurable features. They are referred to as "adjustable" because they can be minimized, loaded, saved, moved, adjusted in size with the mouse pointer, and attached to borders. <br />
<br />
A brief video of [https://www.youtube.com/watch?v=GT2ScizuM48&feature=youtu.be Introduction to Adjustable Containers] is available.<br />
<br />
=== Creating an Adjustable.Container ===<br />
An Adjustable.Container is created just like any other Geyser Object. For example, we might experiment with creating a new Adjustable.Container by running the following line of lua code:<br />
<syntaxhighlight lang="lua"><br />
testCon = testCon or Adjustable.Container:new({name="testContainer"})<br />
</syntaxhighlight><br />
This will create a new Adjustable.Container with the name ''testContainer''. Specifying the adjustable container's name is important for saving. Defining a variable, such as ''testCon'' in our above example, allows functions to be used with the Adjustable.Container.<br />
<br />
Our newly created Adjustable.Container may be used the same way as any other Geyser.Container might. For example, let's put a Geyser.Label in our new testContainer:<br />
<br />
<syntaxhighlight lang="lua"><br />
testCon = testCon or Adjustable.Container:new({name="testContainer"})<br />
testLabel = Geyser.Label:new({x=0, y=0, height="100%", width="100%", color="green"},testCon)<br />
</syntaxhighlight><br />
<br />
The above code creates a new, green-colored Geyser.Label in the ''testCon'' adjustable.container as shown below:<br />
<br />
[[File:GreenLabelinAdjustableContainer.png]]<br />
<br />
You can also create one for miniconsole:<br />
<br />
<syntaxhighlight lang="lua"><br />
miniconsoleContainer = miniconsoleContainer or Adjustable.Container:new({name="miniconsoleContainer"})<br />
myMiniconsole = Geyser.MiniConsole:new({<br />
name="myMiniconsole",<br />
x=0, y=0,<br />
autoWrap = true,<br />
color = "black",<br />
scrollBar = false,<br />
fontSize = 8,<br />
width="100%", height="100%",<br />
}, miniconsoleContainer)<br />
<br />
myMiniconsole:echo("Hello!\n")<br />
</syntaxhighlight><br />
<br />
That will give you:<br />
<br />
[[File:Adjustable container miniconsole.png]]<br />
<br />
=== Key Functions ===<br />
A listing of key functions for the Adjustable.Container module can be found hereː https://www.mudlet.org/geyser/files/geyser/AdjustableContainer.html<br />
<br />
=== Change Title Text ===<br />
To specify the title text of a new container, use the constraint <code>titleText</code> in the constructor (see [[Manual:Geyser#valid constraints|valid constraints]]).<br />
<br />
To change the title text after a container has already been created, use <code>setTitle</code>. Continuing from the previous example, the title for an existing container named "testCon" might be adjusted in a number of ways: <br />
<br />
<syntaxhighlight lang="lua"><br />
testCon:setTitle("Title") -- changes the container's title to "Title"<br />
</syntaxhighlight><br />
<br />
A container's title text defaults to the color green, but this can also be adjusted by using <code>setTitle</code>: <br />
<br />
<syntaxhighlight lang="lua"><br />
testCon:setTitle("Red Title Test","red") -- changes the container's title text to "Red Title Test" and displays the text in the specified color "red".<br />
</syntaxhighlight><br />
<br />
To restore a container's default title text, <code>setTitle</code> is issued without any specified title or color: <br />
<br />
<syntaxhighlight lang="lua"><br />
testCon:setTitle() -- resets the container's title text<br />
</syntaxhighlight><br />
<br />
=== AutoSave and AutoLoad ===<br />
The following Adjustable.Container settings can be saved and loadedː<br />
<br />
<code>x</code>, <code>y</code>, <code>height</code>, <code>width</code>, <code>minimized</code>, <code>locked</code>, <code>lock Style</code>, <code>padding</code>, and <code>hidden</code>.<br />
<br />
These settings will be automatically saved when the Mudlet profile is closed, and automatically loaded when a previous Adjustable.Container is created within the corresponding profile.<br />
<br />
To prevent automatic saving and/or loading of these settings, the <code>autoLoad</code> and <code>autoSave</code> constraints can be included in the constructor. For example, the following code will prevent the settings of the ''testCon2'' Adjustable.Container from being loaded upon creation:<br />
<br />
<syntaxhighlight lang="lua"><br />
testCon2 = testCon2 or Adjustable.Container:new({name="testCon2", autoLoad=false})<br />
</syntaxhighlight><br />
<br />
To also prevent the ''testCon2'' Adjustable.Container from automatically saving its settings when the Mudlet profile is closed, the <code>autoSave=false</code> constraint would be added at creation as follows:<br />
<br />
<syntaxhighlight lang="lua"><br />
testCont2 = testCont2 or Adjustable.Container:new({name="testCont2", autoLoad=false, autoSave=false})<br />
</syntaxhighlight><br />
<br />
Automatic saving can also be deactivated after an Adjustable.Container has been created, by invoking <code>testCont:disableAutoSave()</code><br />
<br />
Note that even with autoSave and autoLoad disabled, it is still possible to save and load manually through the right-click menu and/or by using <code>testCont:save()</code> or <code>testCont:load()</code> in a script.<br />
<br />
To save/load all your containers manually at the same time, we use <code>Adjustable.Container:saveAll()</code> and/or <code>Adjustable.Container:loadAll()</code><br />
<br />
=== "All" Functions ===<br />
The following functions affect all Adjustable Containers at the same time.<br />
<br />
{{note}} You must create the Adjustable Containers before these functions will have an effect.<br />
<br />
<code>Adjustable.Container.loadAll()</code> loads all the settings from your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container.saveAll()</code> saves all your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container.loadAll()</code> loads all the settings from your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container:showAll()</code> shows all your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container:doAll(myfunc)</code> creates a function that will affect all your Adjustable Containers. For example:<br />
<syntaxhighlight lang="lua"><br />
Adjustable.Container:doAll(function(self) self:hide() end) -- hides all your adjustable containers<br />
</syntaxhighlight><br />
<br />
===Right-Click Menu===<br />
Your Adjustable Container has also integrated a right-click Menu with the main key functions for easier usability.<br />
<br />
[[File:AdjustableContainerRightClickMenu.png]]<br />
<br />
The right-click menu also automatically shows you the possible attach position (by clicking on Attach to:) <br />
<br />
and possible lockStyles (by clicking on Lockstyle, integrated are 4 standard lockStyles)<br />
<br />
=== Create a Custom Menu with Custom Items ===<br />
To create a new menu element in your right click menu called "Custom" and add an item to it use:<br />
<syntaxhighlight lang="lua"><br />
testcontainer:newCustomItem(name, func)<br />
-- for example<br />
testcontainer:newCustomItem("Hello world", function(self) echo("Hello world\n") self:flash() end)<br />
-- this will write "Hello world" to the main console and flashes your container.<br />
</syntaxhighlight><br />
<br />
=== Add new LockStyles ===<br />
For more advanced users it's possible to add a new Lockstyles by:<br />
<syntaxhighlight lang="lua"><br />
testcontainer:newLockStyle(name, func)<br />
-- for example<br />
testcontainer:newLockStyle("NewLockStyle", function(self) self.Inside:move(40, 40) self.Inside:resize(-40,-40) self:setTitle("") end)<br />
</syntaxhighlight><br />
<br />
=== Change Adjustable Container Style ===<br />
Additionally to the standard container constraints Adjustable Containers allow you to change at creation: the internal Label style, the menu style, min/close buttons, the menu text, title text... <br />
<br />
( see [[Manual:Geyser#valid constraints|valid constraints]])<br />
An example of a Adjustable Container with different style.<br />
<syntaxhighlight lang="lua"><br />
testCont =<br />
testCont or<br />
Adjustable.Container:new(<br />
{<br />
name = "TestNewStyleContainer",<br />
adjLabelstyle = "background-color:rgba(220,220,220,100%); border: 5px groove grey;",<br />
buttonstyle=[[<br />
QLabel{ border-radius: 7px; background-color: rgba(140,140,140,100%);}<br />
QLabel::hover{ background-color: rgba(160,160,160,50%);}<br />
]],<br />
buttonFontSize = 10,<br />
buttonsize = 20,<br />
titleText = "My new Style",<br />
titleTxtColor = "black",<br />
padding = 15,<br />
}<br />
)<br />
</syntaxhighlight><br />
This code creates a container which looks like this:<br />
<br />
[[File:NewStyleAdjustableContainer.png|Adjustable Container with different style]]<br />
<br />
===<div id="valid constraints"> Valid Constraints</div>===<br />
Adjustable Container constraints and their default values. <br />
<br />
These are in addition to the standard Geyser.Container constraints.<br />
<syntaxhighlight lang="lua"><br />
{<br />
ParentMenuWidth = "102" -- menu width of the main right click menu<br />
<br />
ChildMenuWidth = "82" -- menu width of the children in the right click menu (for attached, lockstyles and custom items)<br />
<br />
MenuHeight = "22" -- height of a single menu item<br />
<br />
MenuFontSize = "8" -- font size of the menu items<br />
<br />
buttonsize = "15" -- size of the minimize and close buttons<br />
<br />
buttonFontSize = "8" -- font size of the minimize and close buttons<br />
<br />
padding = 10 -- how far is the inside element placed from the corner (depends also on the lockstyle setting)<br />
<br />
adjLabelstyle = [[ background-color: rgba(0,0,0,100%); border: 4px double green; border-radius: 4px;]] -- style of the main Label where all elements are in<br />
<br />
menustyle = [[QLabel::hover{ background-color: rgba(0,150,255,100%); color: white;} QLabel::!hover{color: black; background-color: rgba(240,240,240,100%);} <br />
QLabel{ font-size:]]..MenuFontSize..[[pt;}]] -- menu items style<br />
<br />
buttonstyle = [[ QLabel{ border-radius: 7px; background-color: rgba(255,30,30,100%);} QLabel::hover{ background-color: rgba(255,0,0,50%);}<br />
]] -- close and minimize buttons style<br />
<br />
minimized = false -- minimized at creation?<br />
<br />
locked = false -- locked at creation?<br />
<br />
lockLabel.txt = [[<font size="5">🔒</font> Lock/Unlock]] -- text of the "lock" menu item<br />
<br />
minLabel.txt = [[<font size="5">🗕</font> Min/Restore]] -- text of the "min/restore" menu item<br />
<br />
saveLabel.txt = [[<font size="5">💾</font> Save]] -- text of the "save" menu item<br />
<br />
loadLabel.txt = [[<font size="5">📁</font> Load]] -- text of the "load" menu item<br />
<br />
attLabel.txt = [[<font size="5">⚓</font> Attach to:]] -- text of the "attached menu" item<br />
<br />
lockStylesLabel.txt = [[<font size="5">🖌</font> Lockstyle:]] -- text of the "lockstyle menu" item<br />
<br />
customItemsLabel.txt = [[<font size="5">🖇</font> Custom:]] -- text of the "custom menu" item<br />
<br />
titleTxtColor = "green" -- color of the title text<br />
<br />
titleText = name.." - Adjustable Container" -- title text<br />
<br />
lockStyle = "standard" -- choose lockstyle at creation. possible integrated lockstyle are: "standard", "border", "light" and "full"<br />
<br />
noLimit = false -- there is a minimum size limit if this constraint is set to false.<br />
<br />
raiseOnClick = true -- raise your container if you click on it with your left mouse button<br />
<br />
autoSave = true -- saves your container settings on exit (sysExitEvent). If set to false it won't autoSave<br />
<br />
autoLoad = true -- loads the container settings (if there are some to load) at creation of the container. If set to false it won't load the settings at creation<br />
}<br />
</syntaxhighlight><br />
<br />
==Change Container==<br />
{{note}} available in Mudlet 4.8+<br />
<br />
With this command it is possible to change an elements or even a containers location to that from another container.<br />
For example:<br />
<syntaxhighlight lang="lua"><br />
mycontainerone:changeContainer(mycontainertwo)<br />
--puts container one into container two which means container two will be the parent of container one<br />
</syntaxhighlight><br />
It is also possible to change to a container which is not located on the main window:<br />
<syntaxhighlight lang="lua"><br />
myEmco:changeContainer(emco_userwindow)<br />
--puts my tabbed chat Emco into my userwindow<br />
--to put it back to the main window change to a container located on the main window<br />
myEmco:changeContainer(mymainwindow_container)<br />
--or if it the element wasn't in a container use the main Geyser Root container called Geyser<br />
myEmco:changeContainer(Geyser)<br />
</syntaxhighlight><br />
<br />
==Create Map Window==<br />
{{note}} available in Mudlet 4.8+<br />
<br />
It‘s possible to create the mapper as a map window (similar to clicking the icon) like this:<br />
<syntaxhighlight lang="lua"><br />
myMapWidget = Geyser.Mapper:new({embedded= false})<br />
</syntaxhighlight><br />
<br />
This will open a map window with your saved layout (if there is one, otherwise it will dock at the right corner)<br />
<br />
To choose the position of the DockWindow at creation use: (this will create a map window docked at the left corner)<br />
<br />
<syntaxhighlight lang="lua"><br />
myMapWidget = Geyser.Mapper:new({embedded= false, dockPosition="left"})<br />
</syntaxhighlight><br />
<br />
Possible dockPositions are "left", "right", "top", "bottom", and "floating".<br><br />
To change the dockPosition after creation use:<br />
<br />
<syntaxhighlight lang="lua"><br />
myMapWidget:setDockPosition("floating")<br />
-- this will change myMapWidget dockPosition to floating <br />
</syntaxhighlight><br />
<br />
= Tutorial =<br />
Note: This tutorial assumes you know how scripts in Mudlet work. If not then you should look at the manual first. Also it only shows how Geyser basically works and explains Geysers special windows. It wont go into detail about the windows that where already in Mudlet.<br />
<br />
=== Hello World ===<br />
Let's start with something simple. A Label.<br />
<br />
<syntaxhighlight lang="lua"><br />
Geyser.Label:new({<br />
name="HelloWorld",<br />
x=50, y=50,<br />
width=200, height=50,<br />
})<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_1.png]]<br />
<br />
This code creates a blank Label with a size of 200x50 at a position of 50 points horizontal and vertical from its parent window - which is the main window since we didn't specify any.<br />
<br />
You can manipulate the Label through the normal functions but Geyser.Label:new() returns an object which can be used to manipulate the label directly. So you should store it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local HelloWorld = Geyser.Label:new({<br />
name="HelloWorld",<br />
x=50, y=50,<br />
width=200, height=50,<br />
})<br />
</syntaxhighlight><br />
<br />
Then you can, for example print a text on it:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("Hello World")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_2.png]]<br />
<br />
You can put a format parameter so that the text is, for example, centered.<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("Hello World", nil, "c")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_3.png]]<br />
<br />
The second parameter is the color. We set it to nil which means the labels foreground color will be used.<br />
<br />
The color parameter either accepts a string ("red"), a hex value("#FF0000" or "0xFF0000" or "|cFF0000"), or a decimal value "&lt;255,0,0&gt;"<br />
<br />
Example:<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("Hello World", "red", "c")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_4.png]]<br />
<br />
{{note}} This will automatically set the foreground color, so any echo, without the color parameter set, after that will use the same color.<br />
<br />
You can also set the foreground color with the setFgColor method:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:setFgColor("red")<br />
HelloWorld:echo("Hello World", nil, "c")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_4.png]]<br />
<br />
=== Containers ===<br />
<br />
Containers are windows that can contain other windows. Actually, since all other Geyser windows subclass container, every window can do that. But containers do not have any visible content by themselves. <br />
<br />
Let's show that by an example:<br />
<syntaxhighlight lang="lua"><br />
local container = Geyser.Container:new({<br />
name="container",<br />
x=50, y=50,<br />
width=250, height=50,<br />
})<br />
</syntaxhighlight><br />
<br />
This will create a container, but if you look at the screen you will see nothing at the positon.<br />
There is a way to make containers visible though:<br />
<syntaxhighlight lang="lua"><br />
container:flash()<br />
</syntaxhighlight><br />
<br />
This will flash the container for a short period of time.<br />
<br />
[[Image:Geyser_Container_1.png]]<br />
<br />
flash() accepts a number as paremeter which defines the time, in seconds, the flash is shown.<br />
<br />
Now, that the container is created, you can add other windows to it. There are 2 ways:<br />
<br />
Directly when creating the window:<br />
<br />
<syntaxhighlight lang="lua"><br />
local container_label = Geyser.Label:new({<br />
name="container_label",<br />
x=0, y=0,<br />
width="100%", height="100%",<br />
},<br />
container)<br />
container_label:echo("This is a label in a container", nil, "c")<br />
</syntaxhighlight><br />
<br />
Later, after the window was created<br />
<syntaxhighlight lang="lua"><br />
local container_label = Geyser.Label:new({<br />
name="container_label",<br />
x=0, y=0,<br />
width="100%", height="100%",<br />
})<br />
container_label:echo("This is a label in a container", nil, "c")<br />
container:add(container_label)<br />
</syntaxhighlight><br />
<br />
Both will lead to the same outcome.<br />
<br />
[[Image:Geyser_Container_2.png]]<br />
<br />
Note that we gave a width and height of "100%" to the constructor of the container. This means that the label will take 100% of the containers width and height. If values are given in percent they will even resize with its parent:<br />
<br />
<syntaxhighlight lang="lua"><br />
container:resize(325, nil)<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_Container_3.png]]<br />
<br />
The first parameter is the width, the second the height. If the value is nil the current value is used.<br />
<br />
As said in the "Hello World" tutorial the position is relative to its parent window. That's why we could set both x and y to 0 and it is at the position we wanted - the position of the container.<br />
<br />
When we now move the container the label moves with it:<br />
<syntaxhighlight lang="lua"><br />
container:move(400, nil)<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_Container_4.png]]<br />
<br />
The first parameter is the x-, the second the y-position. If the value is nil the current value is used.<br />
<br />
=== VBox and HBox ===<br />
<br />
The VBox and HBox classes are special Containers.<br />
They will automatically align its containing windows vertically or horizontally, respectively, in the order they where added to them.<br />
<br />
<syntaxhighlight lang="lua"><br />
<br />
local HBox = Geyser.HBox:new({<br />
name="HBox",<br />
x=0, y=0,<br />
width=400, height=30,<br />
})<br />
<br />
</syntaxhighlight><br />
<br />
Like containers you won't see them by themselves.<br />
<br />
Adding children works like with containers<br />
<syntaxhighlight lang="lua"><br />
<br />
local label1 = Geyser.Label:new({<br />
name="Label1",<br />
},<br />
HBox)<br />
label1:echo("Label 1", "black", "c")<br />
label1:setColor(255, 0, 0)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_1.png]]<br />
<br />
We didn't set any position or size, but the label gets the same size as the HBox.<br />
<br />
If we add another window:<br />
<syntaxhighlight lang="lua"><br />
<br />
local label2 = Geyser.Label:new({<br />
name="Label2",<br />
},<br />
HBox)<br />
label2:echo("Label 2", "black", "c")<br />
label2:setColor(0, 255, 0)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_2.png]]<br />
<br />
the size will be divided equally between them!<br />
<br />
What if you want a child that takes more or less space than the others?<br />
That's possible too:<br />
<syntaxhighlight lang="lua"><br />
<br />
local label3 = Geyser.Label:new({<br />
name="Label3",<br />
h_stretch_factor=2.0,<br />
},<br />
HBox)<br />
label3:echo("Label 3", nil, "c")<br />
label3:setColor(0, 0, 255)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_3.png]]<br />
<br />
As you can see, Label 3 takes the same space as Label 1 and 2 Together. <br />
That's because we supplied a horizontal stretch factor with "h_stretch_factor=2.0"<br />
<br />
This works also with a vertical stretch factor, just replace "h_stretch_factor" with "v_stretch_factor"<br />
<br />
Now you may have windows that should not be stretched at all.<br />
To accomplish this you have to set the horizontal and/or vertical policy:<br />
<br />
<syntaxhighlight lang="lua"><br />
<br />
local label4 = Geyser.Label:new({<br />
name="Label4",<br />
width="13%",<br />
h_policy=Geyser.Fixed,<br />
},<br />
HBox)<br />
label4:echo("Label 4", "black", "c")<br />
label4:setColor(0, 255, 255)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_4.png]]<br />
<br />
Possible values for the policies are Geyser.Fixed and Geyser.Dynamic (which is the default). They can also be applied to VBox and HBox in exactly the same way.<br />
<br />
Note that, like in the example above, the label will retain relative values (like percent) if used.<br />
<br />
The VBox works like the HBox, only that the child windows are aligned vertically.<br />
<br />
= Walkthroughs =<br />
Here are a few walkthroughs that will show you how to combine Geyser elements to create some simple GUI widgets.<br />
<br />
===Create a Clickable Compass===<br />
[[File: compass.png]]<br />
The following will walk you through the process of creating your own clickable compass using the Geyser framework.<br />
====Setup the image files====<br />
The compass requires a handful of images to work properly. You can find them here: https://www.dropbox.com/sh/53l7xrn4ds35wnq/WpWOziVKmH <br><br />
Download each image and place it in your profile folder. You can find your profile folder with getMudletHomeDir()<br><br />
If you're using Mudlet 2.1+ you can enter '''lua getMudletHomeDir()''' from the command line to return the profile folder path on your computer.<br />
<br />
====Create a new script====<br />
Script Name: '''''compass.resize'''''<br><br />
Registered Event Handlers: '''''sysWindowResizeEvent'''''<p><br />
Every snippet of code will be placed within this script.<br />
====Store the screen size====<br />
We'll want to store the screen size in some local variables so they can be easily referenced to later on.<br />
<syntaxhighlight lang="lua">local mw, mh = getMainWindowSize()</syntaxhighlight><br />
<br />
====Create a global table or namespace====<br />
Creating a global table will make each of your variables unique. Our namespace will be called '''''compass''''' and everything we make from here on out will be stored within the compass table. We'll also add a few values to it: dirs and ratio. '''''compass.dirs''''' will store each direction while '''''compass.ratio''''' will store the ratio of our screen size so you can 'square up' your compass.<br />
<syntaxhighlight lang="lua">compass = compass or {<br />
dirs = {"nw","n","ne","w","center","e","sw","s","se"},<br />
ratio = mw / mh<br />
}</syntaxhighlight><br />
<br />
====Create the parent label====<br />
[[File: grey.png|thumbnail]]<br />
The 'parent label' refers to the label on the bottom layer. The entire compass will be created within this label. It's container is '''main''' for it's parent is the main window.<br />
<syntaxhighlight lang="lua">compass.back = Geyser.Label:new({<br />
name = "compass.back",<br />
x = "25%",<br />
y = "25%",<br />
width = "10%",<br />
height = "10%",<br />
},main)</syntaxhighlight><br />
<br />
====Set the parent label stylesheet====<br />
[[File: blue.png|thumbnail]]<br />
This will create the blue sphere that makes up most of the compass. The background color is a radial gradient that goes from a deep blue to a brighter shade. The border radius rounds the edges. When the radius is exactly half of the label width it forms a circle. The arrows of the compass actually protrude from the sphere so we give it a margin to suck it in a bit for this effect.<br />
<syntaxhighlight lang="lua">compass.back:setStyleSheet([[<br />
background-color: QRadialGradient(cx:.3,cy:1,radius:1,stop:0 rgb(0,0,50),stop:.5 rgb(0,0,100),stop:1 rgb(0,0,255));<br />
border-radius: ]]..tostring(compass.back:get_width()/2-14)..[[px;<br />
margin: 10px;<br />
]])</syntaxhighlight><br />
<br />
====Create a 3x3 grid====<br />
The compass is split into 9 sections. One for each cardinal direction plus an extra space that sits in the center. This 3x3 grid is created by 3 VBoxes that sit within a single HBox (or vice versa but I flipped a coin and this is what it gave me).<br><br />
So first off, we create the HBox. It will be the same size as its parent, ''compass.back''.<br />
<syntaxhighlight lang="lua"> compass.box = Geyser.HBox:new({<br />
name = "compass.box",<br />
x = 0,<br />
y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},compass.back)</syntaxhighlight><br />
Next, we create our 3 VBoxes. You don't need to specify position or size because these are placed within ''compass.box'', an HBox.<br />
<syntaxhighlight lang="lua"> compass.row1 = Geyser.VBox:new({<br />
name = "compass.row1",<br />
},compass.box)<br />
compass.row2 = Geyser.VBox:new({<br />
name = "compass.row2",<br />
},compass.box)<br />
compass.row3 = Geyser.VBox:new({<br />
name = "compass.row3",<br />
},compass.box)</syntaxhighlight><br />
Finally, we add our 9 labels. Take note that they are split up into even groups of 3. Each group is placed into a different ''compass.row#''<br />
<syntaxhighlight lang="lua"> compass.nw = Geyser.Label:new({<br />
name = "compass.nw",<br />
},compass.row1)<br />
<br />
compass.w = Geyser.Label:new({<br />
name = "compass.w",<br />
},compass.row1)<br />
<br />
compass.sw = Geyser.Label:new({<br />
name = "compass.sw",<br />
},compass.row1)<br />
<br />
compass.n = Geyser.Label:new({<br />
name = "compass.n",<br />
},compass.row2)<br />
<br />
compass.center = Geyser.Label:new({<br />
name = "compass.center",<br />
},compass.row2)<br />
<br />
compass.s = Geyser.Label:new({<br />
name = "compass.s",<br />
},compass.row2)<br />
<br />
compass.ne = Geyser.Label:new({<br />
name = "compass.ne",<br />
},compass.row3)<br />
<br />
compass.e = Geyser.Label:new({<br />
name = "compass.e",<br />
},compass.row3)<br />
<br />
compass.se = Geyser.Label:new({<br />
name = "compass.se",<br />
},compass.row3)</syntaxhighlight><br />
====Create a callback function====<br />
We'll want our compass to head in the direction of the arrow we're clicking. This is where we specify so. When the arrow is clicked, this function will be ran with the arrow direction as the argument.<br />
<syntaxhighlight lang="lua">function compass.click(name)<br />
send(name)<br />
end</syntaxhighlight><br />
====Create the hover functions====<br />
We want our arrows to turn yellow when we hover over them. We do so by simply resetting the label's stylesheet and changing the border image. Don't forget to include the margin as we still want that.<br />
<syntaxhighlight lang="lua">function compass.onEnter(name)<br />
compass[name]:setStyleSheet([[<br />
border-image: url("]]..getMudletHomeDir()..[[/]]..name..[[hover.png");<br />
margin: 5px;<br />
]])<br />
end<br />
<br />
function compass.onLeave(name)<br />
compass[name]:setStyleSheet([[<br />
border-image: url("]]..getMudletHomeDir()..[[/]]..name..[[.png");<br />
margin: 5px;<br />
]])<br />
end</syntaxhighlight><br />
====Set the stylesheets in the grid====<br />
[[File: Sample.png|thumb]]<br />
Each of the 9 labels need an image of an arrow. Rather than setting each individually, we'll iterate over the ''compass.dirs'' table we made awhile back and add the respective image to each. The names of images are a reflection of the ''compass.dirs'' table. This keeps it consistent and easy to refer to. During the iteration, the callback, setLabelOnEnter and setLabelOnLeave are also set for each label.<br />
<syntaxhighlight lang="lua">for k,v in pairs(compass.dirs) do<br />
compass[v]:setStyleSheet([[<br />
border-image: url("]]..getMudletHomeDir()..[[/]]..v..[[.png");<br />
margin: 5px;<br />
]])<br />
compass[v]:setClickCallback("compass.click",v)<br />
setLabelOnEnter("compass."..v,"compass.onEnter",v)<br />
setLabelOnLeave("compass."..v,"compass.onLeave",v)<br />
end</syntaxhighlight><br />
<br />
====Resize the compass into a square====<br />
[[File: final.png|thumb]]<br />
Most screen size ratios aren't a perfect 1:1. This will cause a 10% x 10% label to be far from square. By setting our height (the smaller of the two numbers) to our width, we can resize our compass to a near perfect square. This function is also the name of our script because we want it to run each time sysWindowResizeEvent is raised.<br />
<syntaxhighlight lang="lua">function compass.resize()<br />
compass.back:resize(compass.back.width, compass.back:get_width())<br />
end<br />
<br />
compass.resize()</syntaxhighlight><br />
<br />
===Create a Tabbed Window===<br />
[[File: tabwindow.png]]<br />
The following will walk you through the process of creating your own tabbed window using the Geyser framework.<br />
<br />
====Create a new script====<br />
Script Name: '''''Tabbed Window'''''<br><br />
Every snippet of code will be placed within this script.<br />
====Create a global table====<br />
Creating a global table will make each of your variables unique. Our namespace will be called '''''menu''''' and everything we make from here on out will be stored within the menu table. We'll also add a few values to it: tabs, color1, color2, width, height and current. <br><br />
''''tabs'''' will be a table that stores all our tab names. If we want our tabs to have different names, we alter this table.<br><br />
''''color1'''' and ''''color2'''' will store the colors of our tabbed window. If we want to change the color of our tabbed window, we alter these values.<br><br />
''''width'''' and ''''height'''' will store the size of our tabbed window. If we want to change the size of the tabbed window, we alter these values.<br><br />
''''current'''' keeps track of which tab is selected. We will set this to the first tab in the table by default. We do this outside the initial table creation so we can easily access menu.tabs<br><br />
<syntaxhighlight lang="lua">menu = menu or {<br />
tabs = {"Tab1","Tab2","Tab3","Tab4"},<br />
color1 = "rgb(0,0,70)",<br />
color2 = "rgb(0,0,50)",<br />
width = "20%",<br />
height = "40%",<br />
}<br />
menu.current = menu.current or menu.tabs[1]</syntaxhighlight><br />
<br />
====Create the main container====<br />
Our tabbed window will need a container. This will be the bottom layer. Containers are invisible so no need to set a stylesheet.<br />
<syntaxhighlight lang="lua">menu.container = Geyser.Container:new({<br />
name = "menu.back",<br />
x = "50%", y = "25%",<br />
width = menu.width,<br />
height = menu.height,<br />
},main)</syntaxhighlight><br />
====Create an HBox====<br />
All of our tabs will be evenly spaced. So we'll create an HBox to sit at the top of our container.<br />
<syntaxhighlight lang="lua">menu.header = Geyser.HBox:new({<br />
name = "menu.header",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "10%",<br />
},menu.container)</syntaxhighlight><br />
====Create a label====<br />
This label will serve as a container for each window. It sits right underneath the HBox we just created for the tabs.<br />
<syntaxhighlight lang="lua">menu.footer = Geyser.Label:new({<br />
name = "menu.footer",<br />
x = 0, y = "10%",<br />
width = "100%",<br />
height = "90%",<br />
},menu.container)</syntaxhighlight><br />
We don't want this to be a big grey box at startup, so we'll set the stylesheet to appear like the rest of the windows.<br />
<syntaxhighlight lang="lua"><br />
menu.footer:setStyleSheet([[<br />
background-color: ]]..menu.color1..[[;<br />
border-bottom-left-radius: 10px;<br />
border-bottom-right-radius: 10px;<br />
]])</syntaxhighlight><br />
Each window actually has two labels. One for the light blue background, and another for the dark blue center. This will create that dark blue center.<br />
<syntaxhighlight lang="lua">menu.center = Geyser.Label:new({<br />
name = "menu.center",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu.footer)<br />
menu.center:setStyleSheet([[<br />
background-color: ]]..menu.color2..[[;<br />
border-radius: 10px;<br />
margin: 5px;<br />
]])</syntaxhighlight><br />
====Add your tabs and their windows====<br />
Now we'll want to add our tabs and windows. We do this in a single for loop of the ''''menu.tabs'''' table since it holds all our tab names.<br />
<syntaxhighlight lang="lua">for k,v in pairs(menu.tabs) do<br />
</syntaxhighlight><br />
This will create the tabs. Each tab will be named: menu.<tabname>tab<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"] = Geyser.Label:new({<br />
name = "menu."..v.."tab",<br />
},menu.header)<br />
</syntaxhighlight><br />
Here is where we set the tab stylesheet. Each tab has a rounded top, so we set the border-radius of the top-left and top-right to 10px. Each tab has a small space for separation so we give the right and left sides a tiny margin of 1px.<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"]:setStyleSheet([[<br />
background-color: ]]..menu.color1..[[;<br />
border-top-left-radius: 10px;<br />
border-top-right-radius: 10px;<br />
margin-right: 1px;<br />
margin-left: 1px;<br />
]])<br />
</syntaxhighlight><br />
This will display the name of each tab on the tab.<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"]:echo("<center>"..v)<br />
</syntaxhighlight><br />
We need our tabs to do stuff when clicked, so we'll assign it a callback function, '''''menu.click''''', which we'll create later on. Our tab name is the argument.<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"]:setClickCallback("menu.click",v)<br />
</syntaxhighlight><br />
Now we create the windows that appear when each tab is clicked. Each window has two labels, one atop the other. The first, which we'll create here, has rounded edges on its bottom.<br />
<syntaxhighlight lang="lua"><br />
menu[v] = Geyser.Label:new({<br />
name = "menu."..v,<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu.footer)<br />
<br />
menu[v]:setStyleSheet([[<br />
background-color: ]]..menu.color1..[[;<br />
border-bottom-left-radius: 10px;<br />
border-bottom-right-radius: 10px;<br />
]])<br />
</syntaxhighlight><br />
The second label serves as the window's center and has rounded edges on all sides. And a margin of 5px from it's parent, the label we just created. When adding stuff to your windows, this is the label you'll want to use. '''''menu.<tabname>center'''''<br />
<syntaxhighlight lang="lua"><br />
menu[v.."center"] = Geyser.Label:new({<br />
name = "menu."..v.."center",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu[v])<br />
</syntaxhighlight><syntaxhighlight lang="lua"><br />
menu[v.."center"]:setStyleSheet([[<br />
background-color: ]]..menu.color2..[[;<br />
border-radius: 10px;<br />
margin: 5px;<br />
]])<br />
</syntaxhighlight><br />
Finally, we hide all the windows and end the for loop.<br />
<syntaxhighlight lang="lua"><br />
menu[v]:hide()<br />
end</syntaxhighlight><br />
====Create a callback function====<br />
The last step is to create our callback function for when a tab is clicked. This will hide that tab that is stored in '''''menu.current''''', set menu.current to the clicked tab, and then show the menu.current tab.<br />
<syntaxhighlight lang="lua">function menu.click(tab)<br />
menu[menu.current]:hide()<br />
menu.current = tab<br />
menu[menu.current]:show()<br />
end</syntaxhighlight><br />
====Adding content to your windows====<br />
Add content to '''menu.<tab name>center'''<br />
So if we wanted to display our gold in a window we could:<syntaxhighlight lang="lua">menu.Tab1center:echo(myGold)</syntaxhighlight><br />
If we wanted to add a map to a window we could:<br />
<syntaxhighlight lang="lua">myMap = Geyser.Mapper:new({<br />
name = "myMap",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu.Tab2center)</syntaxhighlight><br />
<br />
===Create a Window with a resize label===<br />
[[File: resize_window.png]]<br />
This walkthrough will create a window with a smaller label which will let you resize the window.<br />
<br />
====Create a new script====<br />
Script Name: '''''Resize Window'''''<br><br />
Every snippet of code will be placed within this script.<br />
<br />
====Create a window====<br />
Create a window label which will be resizable.<br />
<syntaxhighlight lang="lua">--<br />
-- Create a label that will be resized and contain the drag icon.<br />
---<br />
mLabel = Geyser.Label:new({<br />
name = "mLabel",<br />
x = 400, y = 200,<br />
width = 200, height = 200,<br />
fgColor = "black",<br />
color = "blue",<br />
message = [[<center>drag the white label to resize</center>]]<br />
})<br />
mLabel:setStyleSheet([[qproperty-wordWrap: true]])<br />
</syntaxhighlight><br />
<br />
====Create small icon inside the window====<br />
Create the label that will be used as a drag icon.<br />
<syntaxhighlight lang="lua">--<br />
-- Create the small drag label within the window.<br />
-- The y position is set to "-15px" to align it to<br />
-- the bottom of the main label.<br />
--<br />
mVDrag = Geyser.Label:new({<br />
name = "mVDrag",<br />
x = 85, y = "-15px",<br />
width = 30, height = 15,<br />
fgColor = "black",<br />
color = "white",<br />
}, mLabel)<br />
</syntaxhighlight><br />
<br />
====Create callback functions====<br />
Create the callback functions that will be called by mouse and timer events.<br><br />
<br />
Create a timer function that will be called repeatedly while the mouse button is pressed.<br />
<syntaxhighlight lang="lua"><br />
function onVDragTimer()<br />
local x<br />
local y<br />
local height<br />
<br />
-- Get mouse position<br />
x, y = getMousePosition()<br />
<br />
-- Substract the top of the label to get the new height.<br />
height = y - 200<br />
if height < MIN_HEIGHT then<br />
-- Height is too small.<br />
height = MIN_HEIGHT<br />
end<br />
<br />
-- Set the new size and restart timer.<br />
mLabel:resize(200, height)<br />
vdragtimer = tempTimer(0.2, onVDragTimer)<br />
end<br />
</syntaxhighlight><br><br />
<br />
Create a function which will be called when we first press the icon. The function will create the timer which will trigger as long as the button is pressed.<br />
<syntaxhighlight lang="lua"><br />
function onVDragClick()<br />
-- The user clicked the drag label.<br />
-- Start a temp timer to update the size of the label.<br />
if not exists("vdragtimer", "timer") then<br />
vdragtimer = permTimer("vdragtimer", "", .016, "onVDragTimer()")<br />
end<br />
<br />
enableTimer("vdragtimer")<br />
end<br />
</syntaxhighlight><br><br />
<br />
Create the callback function which will be called when we release the drag icon.<br />
<syntaxhighlight lang="lua"><br />
function onVDragRelease()<br />
-- Button is release so stop timer and updates.<br />
disableTimer("vdragtimer")<br />
end<br />
</syntaxhighlight><br />
<br />
====Set up the callback functions====<br />
Set up the limit how small the window can be, and setup the callback functions.<br />
<syntaxhighlight lang="lua"><br />
MAX_HEIGHT = 100<br />
--<br />
-- Set mouse event callbacks.<br />
--<br />
setLabelClickCallback("mVDrag", "onVDragClick")<br />
setLabelReleaseCallback("mVDrag", "onVDragRelease")<br />
</syntaxhighlight><br />
<br />
====Final result====<br />
The whole script looks like this:<br />
<br />
<syntaxhighlight lang="lua"><br />
--<br />
-- Example: Resize a label.<br />
--<br />
-- Creates a blue label with a smaller white label, which is<br />
-- used to resize the blue label.<br />
--<br />
-- Utilizing:<br />
-- * getMousePosition()<br />
-- * setLabelClickCallback()<br />
-- * setLabelReleaseCallback()<br />
-- * tempTimer().<br />
--<br />
<br />
--<br />
-- Create labels<br />
--<br />
mLabel = Geyser.Label:new({<br />
name = "mLabel",<br />
x = 400, y = 200,<br />
width = 200, height = 200,<br />
})<br />
mLabel:setStyleSheet([[<br />
background-color: rgba(30, 30, 30, 80%);<br />
qproperty-wordWrap: true;<br />
]])<br />
mLabel:setFontSize(10)<br />
mLabel:echo([[<center>Drag the white label to resize.</center>]])<br />
<br />
--<br />
-- Create the small drag label within the window.<br />
-- The y position is set to "-15px" to align it to<br />
-- the bottom of the main label.<br />
mVDrag = Geyser.Label:new({<br />
name = "mVDrag",<br />
x = 85, y = "-15px",<br />
width = 30, height = 15,<br />
fgColor = "black",<br />
color = "white",<br />
}, mLabel)<br />
mVDrag:setStyleSheet([[<br />
border-radius: 6;<br />
background-color: white;<br />
]])<br />
<br />
MIN_HEIGHT = 100<br />
<br />
--<br />
-- Callback functions.<br />
--<br />
function onVDragTimer()<br />
local x<br />
local y<br />
local height<br />
<br />
-- Get mouse position<br />
x, y = getMousePosition()<br />
<br />
-- Substract the top of the label to get the new height.<br />
height = y - 200<br />
if height < MIN_HEIGHT then<br />
-- Height is too small.<br />
height = MIN_HEIGHT<br />
end<br />
<br />
-- Set the new size and restart timer.<br />
mLabel:resize(200, height)<br />
end<br />
<br />
function onVDragClick()<br />
-- The user clicked the drag label.<br />
-- Start a temp timer to update the size of the label.<br />
if not exists("vdragtimer", "timer") then<br />
vdragtimer = permTimer("vdragtimer", "", .016, "onVDragTimer()")<br />
end<br />
<br />
enableTimer("vdragtimer")<br />
end<br />
<br />
function onVDragRelease()<br />
-- Button is release so stop timer and updates.<br />
disableTimer("vdragtimer")<br />
end<br />
<br />
--<br />
-- Set mouse event callbacks.<br />
--<br />
setLabelClickCallback("mVDrag", "onVDragClick")<br />
setLabelReleaseCallback("mVDrag", "onVDragRelease")<br />
</syntaxhighlight><br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Geyser&diff=15633Manual:Geyser2020-10-09T11:45:02Z<p>Smurf: /* Stretching an image on a label */</p>
<hr />
<div>{{TOC right}}<br />
<br />
= Introduction =<br />
<br />
The Geyser Layout Manager is an object oriented framework for creating, updating and organizing GUI elements within Mudlet - it allows you to make your UI easier on Mudlet, and makes it easier for the UI to be compatible with different screen sizes.<br />
<br />
=== Motivation ===<br />
<br />
Mudlet makes the creation of label, miniconsoles and gauges a quick and easy thing. Mudlet provides a nice signal when window resize events happen. To help with complex window management, Geyser steps in.<br />
<br />
=== Main Geyser Features ===<br />
<br />
Geyser is based on traditional GUI concepts and should feel similar to using Java's Swing. The biggest difference is in how positions are specified.<br />
<br />
* All window positions are specified relative to their container - nothing new there. However, window positions can also take on percentages and negative pixel and character values. For instance, a window could be constrained to have a height of 50% of its container and a width such that the window's right edge is always 20 characters from its container's right edge. See examples below and the demos/tests that come with Geyser.<br />
* All windows under Geyser control are automatically resized as necessary when the main Mudlet window is resized. Once you create a window and assign it to a container, you never have to worry about positioning it again. Nonetheless, it's very easy to shift the container that a window is in, maintaining its constraints so that it resizes as needed according to the dimensions of the new container.<br />
* Due to the container hierarchy, hiding a container window automatically hides all its contained windows too. The same for show. With clever construction and labels with callbacks, this lets one make complex GUI elements that are minimizable or maximizable or ...<br />
* However, there is always some overhead for automation systems and Geyser is no exception. Fortunately, most of the overhead is during window creation and resize events - not things that happen frequently.<br />
<br />
=== Getting pictures for your stuff ===<br />
You can find good, freely-available assets for your UI here:<br />
* [https://kenney.nl/assets?q=2d kenney.nl]<br />
* [https://opengameart.org/ opengameart.org]<br />
* [https://game-icons.net/ game-icons.net]<br />
<br />
=== Constraints format ===<br />
<br />
Geyser position constraints are a string composed of a number and a format type. For example, "10px" means 10 pixels, either pixels from the origin (e.g. x or y) or a value for the width or height. A negative number indicates distance from a container's right or bottom border depending on whether is a constraint for x/width or y/height, respectively. Percentages for width and height are in terms of the container's dimensions and negative values are converted to the equivalent positive value. A 100% width subwindow with an x-coordinate of 10 will have part of itself displayed outside the confines of its container. There is no hard limit on maximum window size, just as with regular Mudlet windows. If a number, n, is passed as a constraint instead of a string, it is assumed to be equivalent to "npx". Any Lua table that contains entries for x, y, width and height in the proper format can be used for Geyser constructors and setting constraints. Just like in Mudlet, 0,0 coordinates mean the top-left corner.<br />
<br />
The following is a valid example for coordinates of a Geyser object:<br />
<br />
<syntaxhighlight lang="lua"><br />
{x = "20px", y = "-10c", width = "40%", height = 30}<br />
</syntaxhighlight><br />
<br />
= Geyser elements =<br />
The purpose of this document is to go through every Geyser element and provide practical examples on how they are used. Read it from top to bottom, preferably doing all of the examples to understand how they work!<br />
<br />
See also: https://www.mudlet.org/geyser/files/index.html for a brief and technical overview of all elements and their functions.<br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html Geyser.Container]==<br />
An invisible, organizing object in Geyser - use it to divide your screen and position elements accordingly. '''[http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html See here]''' for all of the functions that are available to you to use.<br />
<br />
A container is also the base class - which means that everything (labels, miniconsoles and gauges) can use its functions, since everything else is at heart a container.<br />
<br />
=== Creating a container ===<br />
To get started with a container, here's an example that'll create a 200px border on the left side of Mudlet for you, and make a container cover all of it - so you can place other visual elements inside it:<br />
<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(200)<br />
left_container = Geyser.Container:new({<br />
name = "left_container", -- give it a unique name here<br />
x=0, y=0, -- have it start at the top-left corner of mudlet<br />
width = 200, height="100%", -- with a width of 200, and a height of the full screen, hence 100%<br />
})<br />
</syntaxhighlight><br />
<br />
Right away, you'll see space appear on the left side. It'll be black, as the container is an invisible unit by itself. You can make sure it's there by making it flash by doing this from the input line:<br />
<br />
<syntaxhighlight lang="lua">lua left_container:flash()</syntaxhighlight><br />
<br />
The command will cause your container to flash for a moment for you, revealing itself.<br />
<br />
{{Note}} If you hide a container and create new Geyser elements within it, they'll be shown automatically for you.<br />
<br />
=== Container within a container ===<br />
You can place containers within other containers by specifying which "parent" the new container should have when you create one. Given our [[#Creating a container|previous example]], you can split the left side into two halves like this:<br />
<br />
<syntaxhighlight lang="lua"><br />
left_container_top = Geyser.Container:new({<br />
name = "left_container_top",<br />
x=0, y=0, -- this container occupies the top, so it starts top-left as well<br />
width = "100%", height="50%", -- but only uses up half of the height<br />
}, left_container) -- this is the important bit - it says that left_container_top should be inside left_container<br />
<br />
left_container_bottom = Geyser.Container:new({<br />
name = "left_container_bottom",<br />
x=0, y="50%", -- this container starts halfway down the first one<br />
width = "100%", height="50%", -- and has the same half height of the original container<br />
}, left_container) <br />
</syntaxhighlight><br />
<br />
=== Aligning relative to bottom or right sides ===<br />
The aligning point within Mudlet is the top-left corner, and it's the same for the elements they are aligned - the position you specify is used by the top-left corner of the element.<br />
<br />
Using Geyser, you can align to the opposite side as well, using the coordinates in negatives, while keeping the dimensions of the object in mind. For example, if you want to align a box that's 20px wide on the usual left side, you'd give it a width of 20 and an x value of 0. If you'd like to align it on the right side, then you'd give it an x value of -20. The box will spawn 20px away from the right side and "grow" to the right by 20px.<br />
<br />
<syntaxhighlight lang="lua"><br />
right_container = Geyser.Container:new({<br />
name = "right_container",<br />
x="-20%", y=0, -- makes the container start 20% of the screen away from the right side<br />
width = "20%", height="50%", -- filling it up until the end<br />
}) <br />
</syntaxhighlight><br />
<br />
Do make sure to account for the scrollbar, as Mudlet UI elements can overlap it. You can also move the scrollbar with [[Manual:UI_Functions#setBorderRight|setBorderRight()]].<br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html Geyser.Label]==<br />
Labels allow you to use pictures in your interface, as well as nicely-formatted text - see docs for label [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html functions].<br />
<br />
=== Basic label ===<br />
<br />
Here's an example to get you started with:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "50%", y = 0,<br />
width = "50%", height = "100%",<br />
fgColor = "black",<br />
color = "SeaGreen",<br />
message = [[<center>heey</center>]]<br />
})<br />
</syntaxhighlight><br />
<br />
This labels '''x''' coordinate is specified as 50% - and because it's not attached to any container, this implies that the window will start halfway at the main window. You can tell it's not attached to a container because there's nothing in between the last ''}'' and '')'', the place where the container goes.<br />
<br />
The '''y''' coordinate is 0 - which means that the label will start at the top of the screen. With the width being 50%, the label will occupy 50% of the screen - and since it starts at the halfway point, it means it'll occupy the entire right side. A height of 100% means that it'll stretch from the top to the full bottom.<br />
<br />
Here's what that'll look like:<br />
<br />
[[File:Simple-label.png|center|600px]]<br />
<br />
<br />
Playing around with the starting location and dimensions, we can also place it in the center of the screen with:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "25%", y = "25%",<br />
width = "50%", height = "50%",<br />
fgColor = "black",<br />
message = [[<center>heey</center>]]<br />
})<br />
testlabel:setColor(0,255,0,150)<br />
</syntaxhighlight><br />
<br />
[[File:Simple_label_centered.png|center|600px]]<br />
<br />
To change the message on a label, you can use the ''mylabel:echo()'' function, where ''mylabel'' is the name of the label you gave it:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:echo("hello!")<br />
</syntaxhighlight><br />
<br />
=== Setting the font size ===<br />
<br />
To set a different font size for your Label, use the ''setFontSize()'' method. For example:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel:setFontSize(14)<br />
</syntaxhighlight><br />
<br />
The font size is set in Pt, so anything above 30 will likely be too large to be useful.<br />
<br />
=== Label inside a container ===<br />
<br />
Once you've got your containers and mastered the basic labels, you can drop labels into your nicely-organized containers. Doing so is similar to nesting containers:<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "25%", y = "25%",<br />
width = "50%", height = "50%",<br />
fgColor = "black",<br />
message = [[<center>heey</center>]]<br />
}, left_container_bottom) -- this is where we tell it what container to go into<br />
testlabel:setColor(0,255,0,150)<br />
</syntaxhighlight><br />
<br />
That label is exactly the same as the one above that goes across the screen, except it's in our bottom-left container - so it looks appropriately different:<br />
<br />
[[File:Label in a container.png|center]]<br />
<br />
=== Image on a label ===<br />
One of the more amazing things labels allow you to do is put pictures anywhere on your Mudlet screen, that blend in very well. To do so, once the label is created, use the [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:setBackgroundImage setBackgroundImage()] function with the exact path to the image ([[File:Skullface.png]]):<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = 0, y = "-14px",<br />
width = "16px", height = "14px",<br />
})<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/skullface.png]]) -- update location to actual image location on your computer<br />
</syntaxhighlight><br />
<br />
This'll plop the picture to the bottom-left of your screen. To make the picture show, download the skullface picture above - save it to your desktop, and adjust the location of the image within [[]]'s to what it is on your computer. For example, if you saved this on your Windows 7 desktop, it would be:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label:setBackgroundImage([[C:/Users/<your user name>/Desktop/skullface.png]])<br />
</syntaxhighlight><br />
<br />
(yes, that's / and not \ - \ has been known not to work)<br />
<br />
If you saved this on your Mac desktop, it would be:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label:setBackgroundImage([[/Users/<your user name>/Desktop/skullface.png]])<br />
</syntaxhighlight><br />
<br />
If you saved this on your Ubuntu desktop, it would be:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label:setBackgroundImage([[/home/<your user name>/Desktop/skullface.png]])<br />
</syntaxhighlight><br />
<br />
Using this basic building block, you can work up to making yourself a UI!<br />
<br />
=== Stretching an image on a label ===<br />
If you'd like your image not to keep its original size, but instead use up the available space of the label - you can use the [http://doc.qt.io/qt-5/stylesheet-reference.html#border-image border-image] stylesheet property to do so.<br />
<br />
<syntaxhighlight lang="lua"><br />
label = Geyser.Label:new({<br />
name = "label",<br />
x = "50%", y = "50%",<br />
width = "50%", height = "50%",<br />
})<br />
<br />
-- change the location to your picture<br />
-- on windows, use / to separate folders still, not \<br />
label:setStyleSheet[[<br />
border-image: url(/home/vadi/Desktop/iso-avatar-draft_0.png);<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}} If you're on a Mudlet earlier than 3.15 and are having difficulty with the image coming up, it may be because of strange differences between Qt's CSS engine which does not affect mudlet's Lua. You may want to try appending :gsub("\\","/") to your string including getMudletHomeDir() (e.g. <code>getMudletHomeDir():gsub("\\","/")</code>). No longer necessary after Mudlet 3.15.<br />
<br />
=== Aligning an image within a label ===<br />
You can use background-image in combination with background-position to align an image within a label (if, say, the image is much smaller than the label).<br />
<br />
<syntaxhighlight lang="lua"><br />
-- this will set and align an image top-right of the label<br />
if stunning then<br />
mylabel:setStyleSheet([[<br />
background-image: url("/home/vadi/Games/Mudlet/Offensive/Artwork/dialog-ok.png");<br />
background-repeat: no-repeat; background-position: top right; background-origin: margin;<br />
]])<br />
else<br />
mylabel:setStyleSheet([[<br />
background-image: url("/home/vadi/Games/Mudlet/Offensive/Artwork/dialog-no.png");<br />
background-repeat: no-repeat; background-position: top right; background-origin: margin;<br />
]])<br />
end<br />
</syntaxhighlight><br />
<br />
=== Showing / hiding a label ===<br />
You can show and hide labels, as you can any container, miniconsole or a gauge in Geyser with [http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html#Geyser.Container:show Geyser.Container:show()] and [http://www.mudlet.org/geyser/files/geyser/GeyserContainer.html#Geyser.Container:hide Geyser.Container:hide()]. Remember that since labels are a type of a container, all container functions work on them.<br />
<br />
Hiding a label will allow you to click through on what is below the label, as well as free up the visual space for something else.<br />
<br />
<syntaxhighlight lang="lua"><br />
testlabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "50%", y = 0,<br />
width = "50%", height = "100%",<br />
fgColor = "black",<br />
color = "SeaGreen",<br />
message = [[<center>heey</center>]]<br />
})<br />
<br />
-- hide the label with:<br />
testlabel:hide()<br />
<br />
-- show the label with:<br />
testlabel:show()<br />
</syntaxhighlight><br />
<br />
=== Clickable images ===<br />
Tacking onto the fact that you can plop images anywhere on your Mudlet screen now, you can also make them react to your clicks. You can do so with the [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:setClickCallback setClickCallback()] function - by giving it a function to call when your label is clicked, you'll make it react.<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = "-215px", y = "0px",<br />
width = "200px", height = "200px",<br />
})<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/qubodup-opengameart-cc0-200px-missile_icon.png]]) -- update location to actual image location on your computer<br />
picture_label:setClickCallback("on_bomb_press")<br />
<br />
function on_bomb_press()<br />
send("say BOOM!")<br />
end<br />
</syntaxhighlight><br />
<br />
That's it! Pressing on the image will make the ''on_bomb_press()'' function go off, which will do its code of ''send("say BOOM!")''. Download the picture for use [http://opengameart.org/content/missile-rts-icon here].<br />
<br />
[[File:Clickable_image.png|500px|center]]<br />
<br />
=== Styling labels ===<br />
Besides putting text or images on labels, you can also style them using Qt's stylesheets feature. Doing so allows you to create various graphics that make the label look more appealing:<br />
<br />
[[File:Label_styling_examples.png|center]]<br />
<br />
To set a stylesheet on a label, use the [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:setStyleSheet Geyser.Label:setStyleSheet()] function on your label, describing the stylesheet you'd like to give it. A stylesheet consists of properties you set - for example the background color, borders, padding, and so forth. You describe properties in the following format: ''property name''''':'''''values''''';'''. See here for a [http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties list of all supported properties]. For example, to make your labels background be yellow, you'd use the background-color property:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel = Geyser.Label:new({<br />
x = "50%", y = "50%",<br />
width = 200, height = 100<br />
})<br />
<br />
mylabel:setStyleSheet([[<br />
background-color: yellow;<br />
]])<br />
</syntaxhighlight><br />
<br />
[[File:Basic_stylesheet.png|center]]<br />
<br />
Which is nice, but not particularly impressive.<br />
<br />
Scrolling down the list of properties, you'll come along a border one. Plopping it into our stylesheet nets the following:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
background-color: yellow;<br />
border: 5px solid white;<br />
]])<br />
</syntaxhighlight><br />
<br />
[[File:Basic_stylesheet_border.png|center]]<br />
<br />
Which gives a border!<br />
<br />
Fiddling with it some more and applying new properties we find on that page, we get a rounded border on our label:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
background-color: grey;<br />
border-width: 15px;<br />
border-style: solid;<br />
border-color: green;<br />
border-radius: 10px;<br />
]])<br />
</syntaxhighlight><br />
<br />
[[File:Basic_stylesheet_border_radius.png|center]]<br />
<br />
Which'll conclude our exploration for now. Try out all of the other possible options available there - there's loads, from [http://doc.qt.io/qt-5/stylesheet-reference.html#border-style funky borders], to tiling images and fancy color combinations using gradients.<br />
<br />
=== Adding a tooltip to a label ===<br />
<br />
Since Mudlet 4.6, you can now add a tooltip to labels and gauges. You can start by making a simple label and echoing some text to it:<br />
<br />
<syntaxhighlight lang="lua"><br />
testLabel = Geyser.Label:new({<br />
name = "testLabel",<br />
x = "50%",<br />
y = "50%",<br />
height = "25%",<br />
width = "25%",<br />
})<br />
testLabel:echo("This is on the label!")<br />
testLabel:setAlignment("center")<br />
-- sets the tooltip text<br />
testLabel:setToolTip("This is the tooltip", "10")<br />
<br />
<br />
-- optionally - you can customise the tooltip, too!<br />
testLabel:setStyleSheet("QToolTip{background: yellow; color: blue; border:none;}")<br />
</syntaxhighlight><br />
<br />
Without tooltip<br />
[[File:TestLabelForTooltips.png|thumb|center]]<br />
<br />
With tooltip<br />
<br />
[[File:LabelTooltip.png|thumb|center]]<br />
<br />
=== Avoid stylesheet inheritance by tooltip ===<br />
<br />
{{note}} If you set a new stylesheet for a label and with that a background image it is possible that through inheritance the tooltip also has this stylesheet image.<br />
<br />
To avoid this specify that the stylesheet is meant for the Label by using QLabel{...} in your Label stylesheet for exampleː<br />
<syntaxhighlight lang="lua"><br />
label = Geyser.Label:new({<br />
name = "label",<br />
x = "50%", y = "50%",<br />
width = "50%", height = "50%",<br />
})<br />
<br />
-- by using QLabel{...} the stylesheet won't be given to the tooltip as well<br />
label:setStyleSheet[[<br />
QLabel{<br />
border-image: url(/home/vadi/Desktop/iso-avatar-draft_0.png);}<br />
]]<br />
</syntaxhighlight><br />
<br />
<br />
=== Aligning text/images inside a label ===<br />
By default, text is [http://qt-project.org/doc/qt-5/qlabel.html#alignment-prop centered vertically and left aligned] in a label. To align it to a specific side, use the stylesheets we learnt about earlier with the qproperty-alignment:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel = Geyser.Label:new({<br />
name = "testlabel",<br />
x = "50%", y = 0,<br />
width = "50%", height = "100%",<br />
fgColor = "black",<br />
color = "SeaGreen",<br />
message = [[<center>heey</center>]]<br />
})<br />
<br />
-- specify one property this way:<br />
mylabel:setStyleSheet([[qproperty-alignment: 'AlignTop';]])<br />
<br />
-- or multiple ones separated with a |, for example this will align text to top-left:<br />
-- specify one property this way:<br />
mylabel:setStyleSheet([[<br />
qproperty-alignment: 'AlignLeft | AlignTop';<br />
]])<br />
<br />
mylabel:echo("hi!")<br />
</syntaxhighlight><br />
<br />
[[File:Text_aligned.png|center]]<br />
<br />
=== Enabling wordwrap in a label ===<br />
If you need to enable word wrapping in a label (which by default is off), add the following line to the labels stylesheet:<br />
<br />
qproperty-wordWrap: true;<br />
<br />
As an example:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
qproperty-wordWrap: true;<br />
]])<br />
</syntaxhighlight><br />
<br />
If you'd like to set multiple properties, set them all at once - not via multiple :setStyleSheet() calls:<br />
<br />
<syntaxhighlight lang="lua"><br />
mylabel:setStyleSheet([[<br />
background: red;<br />
]])<br />
</syntaxhighlight><br />
<br />
=== Adding a hover effect to a label ===<br />
The labels support adding stylesheets for specific cases, such as when a mouse is [http://doc.qt.io/qt-5/stylesheet-reference.html#hover-ps hovering] over them. To make this work, you provide CSS for when the label is in its usual state, and for when it is hovered over:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example will add a border to the label when it is hovered over<br />
mylabell:setStyleSheet([[<br />
QLabel{ border-radius: 4px; }<br />
QLabel::hover{<br />
background-color: rgba(0,0,0,0%);<br />
border: 4px double green;<br />
border-radius: 4px;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
=== Checkboxes ===<br />
Combining the fact that you can click on a label with an image to do something with the fact that you can change pictures on a label at will, you can make an image that changes itself when you click on it.<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = "50%", y = "50%",<br />
width = "21px", height = "19px"<br />
})<br />
-- a little trick we do to make the background of the label be transparent<br />
picture_label:setStyleSheet([[<br />
background-color: rgba(0,0,0,0%);<br />
]])<br />
<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/checkbox_ticked.png]])<br />
picture_label:setClickCallback("on_checkbox_press")<br />
<br />
function on_checkbox_press()<br />
if checkbox_ticked then<br />
checkbox_ticked = false<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/checkbox_unticked.png]])<br />
echo("Checkbox unticked.\n")<br />
else<br />
checkbox_ticked = true<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/checkbox_ticked.png]])<br />
echo("Checkbox TICKED!\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
The ''on_checkbox_press()'' function this time keeps the track of the checkbox with the ''checkbox_ticked'' variable and sets the image appropriately. You can download the ticked ([[File:Checkbox_ticked.png]]) and unticked images ([[File:Checkbox_unticked.png]]) or the [http://wiki.mudlet.org/images/6/6d/Checkbox.mpackage whole package] altogether.<br />
<br />
[[File:Checkbox_demo.png|500px|center]]<br />
<br />
=== Animated labels ===<br />
Using timers and several pictures, you can make your labels change quickly enough and look animated. Here's one such example:<br />
<br />
<syntaxhighlight lang="lua"><br />
picture_label = Geyser.Label:new({<br />
name = "picture_label",<br />
x = 10, y = "-24px",<br />
width = "16px", height = "14px",<br />
})<br />
<br />
santa_counter = nil<br />
<br />
function animate_santa()<br />
santa_counter = (santa_counter or 0) + 1<br />
if santa_counter > 8 then santa_counter = 1 end<br />
<br />
picture_label:setBackgroundImage([[/home/vadi/Desktop/santa/santa]]..santa_counter..[[.png]]) -- update location to actual image location on your computer<br />
santa_timer = tempTimer(.16, animate_santa)<br />
end<br />
<br />
animate_santa()<br />
</syntaxhighlight><br />
<br />
The completed package is available [http://wiki.mudlet.org/images/6/6b/Dancing-santa.mpackage here], install it and do '''start/end animation''' to watch.<br />
<br />
=== Inserting extra spaces and newlines ===<br />
Echoing text into Mudlet and Geyser labels is different from miniconsoles and the main window, due to their nature. One of the differences is that extra spaces in a label, by default, get compressed down to one. '''To add extra spaces in a label''', replace extra spaces with '''&amp;nbsp;''' or by wrapping your text with them inside '''<nowiki><pre>my text here</pre></nowiki>'''.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- this won't work, it'll show as one space:<br />
mylabel:echo("You -> point")<br />
<br />
-- but this would, because it replaces all spaces with &nbsp before echoing<br />
mylabel:echo(string.gsub("You -> point", " ", "&nbsp;"))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- here is another way to go about this - and it additionally makes the font be monospaced:<br />
mylabel:echo("<pre>You -> point</pre>")<br />
</syntaxhighlight><br />
<br />
'''To add a new line in a label''' (aka linebreak), use '''<br>''' (instead of ''\n'' as you are used to in an echo).<br />
<syntaxhighlight lang="lua"><br />
mylabel:echo("These<br>words<br>are<br>split")<br />
</syntaxhighlight><br />
<br />
=== Transparent labels ===<br />
One of the possible ways of achieving transparency on a label is to add <code>background-color: rgba(0,0,0,0%);</code> to its stylesheet. Here's an example:<br />
<br />
<syntaxhighlight lang="lua"><br />
my_transparent_label:setStyleSheet([[<br />
background-color: rgba(0,0,0,0%);<br />
]])<br />
</syntaxhighlight><br />
<br />
=== Custom mouse cursor ===<br />
You can change the shape of the cursor when it's over your label with:<br />
<syntaxhighlight lang="lua"><br />
mylabel:setCursor("Forbidden") -- will change your mouse cursor to "forbidden" (as in "can't do this") cursor<br />
</syntaxhighlight><br />
Possible cursor shapes are [[CursorShapes| available here]], and you can import this [[Media:Cursor grid.zip|demo package]] to try them all out.<br />
<br />
It is also possible to change the mouse cursor to a custom made cursor by:<br />
<syntaxhighlight lang="lua"><br />
mylabel:setCustomCursor(getMudletHomeDir().."/custom_cursor.png")<br />
</syntaxhighlight><br />
It is recommended that the custom cursor is a png with size of 32x32 to be supported on all systems.<br />
<br />
[[File:Changecursoroverlabel.gif]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
=== Flyout Labels ===<br />
<br />
Flyout labels allow you to create 'dropdown' or 'flyout' menus - menus that reveal more items once you hover your mouse over them. To create flyout labels:<br />
# add <code>nestable=true</code> (left click to open menu) or <code>nestflyout=true</code> (mouse hover to open menu) to your main label.<br />
# use [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:addChild :addChild()] on your main label to add flyout labels to it.<br />
## [http://www.mudlet.org/geyser/files/geyser/GeyserLabel.html#Geyser.Label:addChild :addChild()] uses the same arguments as when creating a new label but also takes the '''layoutDir''' option to specify in which direction and axis should the labels align, where 2 letters combine into the option: first letter R for right, L for left, T for top, B for bottom, followed by the orientation: V for vertical or H for horizontal. So options are: <code>layoutDir="RV"</code>, <code>layoutDir="RH"</code>, <code>layoutDir="LV"</code>, <code>layoutDir="LH"</code>, and so on.<br />
# optionally, add <code>flyOut=true</code> to your flyout labels to make the labels dissapear when the mouse isn't hovering over them anymore.<br />
<br />
Note that the main flyout label cannot go into a container and needs to be on its own.<br />
<br />
{{note}} Requires Mudlet 3.0.<br />
<br />
==== Demo ====<br />
Here's an example that follows the steps above:<br />
<br />
<syntaxhighlight lang="lua"><br />
label0 = Geyser.Label:new({name="label0", <br />
x="50%",y="50%",height=50,width=300,nestable=true, <br />
message="<center>Clicky clicky</center>"})<br />
<br />
-- and add 3 labels to it with RV layout - so Right of the label, aligned Vertically<br />
label1 = label0:addChild({name="label1",height=30,width=70, layoutDir="RV", flyOut=true, message="label one"})<br />
label1:setStyleSheet([[background-color: purple; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px; font-size: 7pt;]])<br />
<br />
label2 = label0:addChild({name="label2",height=30,width=70, layoutDir="RV", flyOut=true, message="label two"}) <br />
label2:setStyleSheet([[background-color: green; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px; font-size: 7pt;]])<br />
<br />
label3 = label0:addChild({name="label3",height=30,width=70, layoutDir="RV", flyOut=true, message="label three"})<br />
label3:setStyleSheet([[background-color: red; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px; font-size: 7pt;]])<br />
</syntaxhighlight><br />
<br />
A more thorough example. Try it out to see what you can create with flyout labels:<br />
<syntaxhighlight lang="lua"><br />
-- create a label with a nestable=true property to say that it can nest labels<br />
mainlabel = Geyser.Label:new({name="testa", x=400,y=50,height=50,width=300,nestflyout=true, message="<center>HOVER HERE TO SEE FLY-OUT LABELS!</center>"})<br />
<br />
-- create 15 labels and store them in a table <br />
table_for_flyout_labels = {}<br />
for i=1,15 do<br />
-- options to layoutDir are the direction the window should go (R for right, L for left, T for top, B for bottom), followed by how the nested labels should be oriented (V for vertical or H for horizontal). So "BH" here means it'll go on the bottom of the label, while expanding horizontally<br />
table_for_flyout_labels[i] = mainlabel:addChild({name="test"..tostring(i),height=30,width=70, layoutDir="BH", flyOut=true, message="test"..tostring(i)})<br />
<br />
table_for_flyout_labels[i]:setStyleSheet([[background-color: purple; border-width: 2px; border-style: solid; border-color: blue; border-radius: 2px;]])<br />
end<br />
<br />
-- make the test5 label look a bit special as it has got a surprise<br />
table_for_flyout_labels[5]:echo("Hover here")<br />
<br />
-- add even more nested labels to the 5th label!<br />
even_more_flyout_labels = {}<br />
for i=1,60 do<br />
-- here, the layout will be to the right of it, while expanding vertically<br />
even_more_flyout_labels[i]=table_for_flyout_labels[5]:addChild({name="hover label "..tostring(i),height=30,width=100, layoutDir="RV", flyOut=true, message="label "..tostring(i)})<br />
even_more_flyout_labels[i]:setClickCallback("testFunc", even_more_flyout_labels[i].name)<br />
even_more_flyout_labels[i]:setStyleSheet([[background-color: grey; border-width: 2px; border-style: solid; border-color: green; border-width: 2px; font-size: 7pt;]])<br />
end<br />
<br />
function testFunc(name)<br />
display(name)<br />
end<br />
</syntaxhighlight><br />
<br />
It'll look something like this: <br />
<br />
[[File:Flyout_labels_demo.png|150px]]<br />
<br />
==== Demo of layouts ====<br />
Here's another demo that explains all of the layout styles quite well:<br />
<syntaxhighlight lang="lua"><br />
local directions = {"R", "L", "T", "B"}<br />
local orientations = {"V", "H"}<br />
local mappings = {R = "right", L = "left", T = "top", B = "bottom", V = "vertical", H = "horizontal"}<br />
<br />
local combinations, combination_labels = {}, {}<br />
for _, direction in pairs(directions) do<br />
for _, orientation in pairs(orientations) do<br />
combinations[#combinations+1] = direction..orientation<br />
end<br />
end<br />
<br />
local function get_foreground_text_colour(r,g,b)<br />
local luminosity = (0.2126 * ((r/255)^2.2)) + (0.7152 * ((g/255)^2.2)) + (0.0722 * ((b /255)^2.2))<br />
if luminosity > 0.5 then<br />
return "black"<br />
else<br />
return "white"<br />
end<br />
end<br />
<br />
local function get_random_colour_rgb()<br />
return math.random(1,255), math.random(1,255), math.random(1,255)<br />
end<br />
<br />
-- create a label with a nestable=true property to say that it can nest labels<br />
all_possible_combinations_label = Geyser.Label:new({name="all_possible_combinations_label", x=0,y="-400",height=50,width=500,<br />
nestable = true, message="<center>Click to see a listing of possible combinations</center>"})<br />
<br />
for i = 1, #combinations do<br />
local combination = combinations[i]<br />
combination_labels[i] = all_possible_combinations_label:addChild({name="combo_"..combination,height=30,width=150, nestable = true, flyOut=true, layoutDir="BH", message="<center>Combination "..combination.."</center>"})<br />
<br />
local r,g,b = get_random_colour_rgb()<br />
local text_colour = get_foreground_text_colour(r,g,b)<br />
<br />
local combination_labels_children = {}<br />
for ii = 1, 3 do<br />
combination_labels_children[ii] = combination_labels[i]:addChild({<br />
name="combo_"..combination.."_"..ii, height = 30, width = 150, layoutDir=combination, flyOut = true,<br />
message = string.format("<center><b>%s</b>%s+<b>%s</b>%s layout</center>", <br />
combination:sub(1,1), mappings[combination:sub(1,1)]:sub(2), combination:sub(2,2), mappings[combination:sub(2,2)]:sub(2)),<br />
fgColor = text_colour})<br />
<br />
combination_labels_children[ii]:setStyleSheet(string.format([[background-color:rgb(%d, %d, %d); border-width: 2px; border-style: solid; border-color: green; border-width: 2px; font-size: 7pt;]], r,g,b))<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
It'll look like this:<br />
<br />
[[File:Flyoutlabels-layout-demo.png]]<br />
<br />
=== Geyser.Label right click menu ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
You can create a right click menu for a label just by using the function (assuming your label name is 'myLabel')<br />
<syntaxhighlight lang="lua"> myLabelːcreateRightClickMenu(MenuItems = myMenuTable, other cons) -- see example below for details </syntaxhighlight><br />
<br />
The menu table comprises of all the items and their names. To create a parent menu just create a nested table of names.<br />
Example of a menuTable<br />
<syntaxhighlight lang="lua"> menuTable = {"First Item", "Second Item (Parent)",{"First ChildItem","Second ChildItem"}, "Third Item"} </syntaxhighlight><br />
As menu would look likeː<br />
<br />
[[File:RCDemo1.gif|250px]]<br />
<br />
==== Style your right click menu ====<br />
Your right click menu has 2 default styles integratedː "light" and "dark" which are defined by the constraint "Style".<br />
To set a default style just give the constraint Style the preferred value, for exampleː<br />
<syntaxhighlight lang="lua"> Style = "dark" </syntaxhighlight><br />
To give different levels of your menu different style just add the number of the level to the constraint, for exampleː<br />
<syntaxhighlight lang="lua"> Style2 = "light" -- Gives the second level of your menu the "light" style</syntaxhighlight><br />
<br />
For adding your own stylesheet use the constraint MenuStyle (use the same method as above to define stylesheets for different levels)<br />
<syntaxhighlight lang="lua"> MenuStyle2 = [[QLabel::hover{ background-color: rgba(0,255,150,100%); color: white;} QLabel::!hover{color: brown; background-color: rgba(100,240,240,100%);} ]] <br />
-- Gives the second level of your menu this stylesheet</syntaxhighlight><br />
<br />
The same methods are used for defining the format, width and height for the menu item.<br />
<syntaxhighlight lang="lua"> <br />
MenuWidth = 70 -- standard menu width if nothing else is given<br />
MenuWidth2 = 80 -- menu width for the second level <br />
MenuFormat1 = "c10" -- menu format for the first level (format works like any other label echo format, in this case c is center and 10 is the font-size)<br />
MenuHeight = 30<br />
</syntaxhighlight><br />
<br />
==== Set onClick action for your menu item ====<br />
To set an action if your menu item is clicked use the function (assuming your label name is 'myLabel' and using the same MenuItems as defined above)<br />
<syntaxhighlight lang="lua"> <br />
myLabelːsetMenuAction("First Item", function() echo("Clicked on the first item\n") end<br />
myLabelːsetMenuAction("Second Item (Parent).First ChildItem", function() echo("Clicked on the first child item\n") end) -- To set an action to a child item find it by using "Parent.Child" as name (only one parent is needed to be given the parents parent is not needed)<br />
</syntaxhighlight><br />
<br />
==== Access an menu item directly ====<br />
The simplest way to access a menu item directly is by just using the function (assuming your label name is 'myLabel' and using the same MenuItems as defined above)<br />
For example to change the menu item textː<br />
<syntaxhighlight lang="lua"> <br />
myLabelːfindMenuElement("First Item"):echo([[my first Item]])<br />
</syntaxhighlight><br />
<br />
==== Right click menu example ====<br />
Better then any further explanation is probably this practical example. <br />
<br />
<syntaxhighlight lang="lua"> <br />
-- create the label the right click menu will be in<br />
myRightClickLabel = myRightClickLabel or Geyser.Label:new({<br />
name = "myRightClickLabel", message = "Please right click!", <br />
format = "cb15", x=10, y=10, width ="30%", height = "15%", <br />
color = "purple"})<br />
<br />
-- right click menu creation with custom styleheet on level2 and default "Dark" style <br />
myRightClickLabel:createRightClickMenu(<br />
{MenuItems = {"Emergency", "Drink",{"ManaPotion","HealthPotion"}, "Disappear", "Cast",{"Blindness", "Blink"}}, <br />
Style = "Dark", <br />
MenuWidth2 = 80, <br />
MenuFormat1 = "c10",<br />
MenuStyle2 = [[QLabel::hover{ background-color: rgba(0,255,150,100%); color: white;} QLabel::!hover{color: brown; background-color: rgba(100,240,240,100%);} ]]}<br />
)<br />
<br />
myRightClickLabel:setMenuAction("Emergency", function() <br />
cecho("<red:pink>[Emergency Mode] Run as fast as possible!\n") <br />
send("emergency") <br />
closeAllLevels(myRightClickLabel) -- this can be used to close the right click menu if clicked on this item<br />
end)<br />
<br />
myRightClickLabel:setMenuAction("Drink.ManaPotion", function()<br />
cecho("<blue>Drinking my mana potion.\n") <br />
send("drink mp") <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Drink.HealthPotion", function() <br />
cecho("<red>Drinking my health potion.\n") <br />
send("drink hp") <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Disappear", function() <br />
cecho("<grey>Disappearing.. \n") <br />
send("disappear") <br />
closeAllLevels(myRightClickLabel) <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Cast.Blindness", function() <br />
cecho("<light_blue>Casting blindness \n") <br />
send("cast blindness enemy") <br />
closeAllLevels(myRightClickLabel) <br />
end )<br />
<br />
myRightClickLabel:setMenuAction("Cast.Blink", function() <br />
cecho("<light_blue>Casting blink \n") <br />
send("cast blink") <br />
end )<br />
</syntaxhighlight><br />
<br />
This looks likeː<br />
<br />
<br />
[[File:Right click example demo.gif]]<br />
<br />
=== Add right click menu to label with already existing left click action ===<br />
If your label has an already existing left click action you'll have to create the right click menu<br />
"before" creating the labels "setClickCallBack" action and then just put into your labels onClick function<br />
(assuming your label name is 'myLabel' and 'event' is the last parameter of your onClick function)<br />
<br />
<syntaxhighlight lang="lua"> <br />
myLabel:onRightClick(event)<br />
</syntaxhighlight><br />
<br />
=== Background for Mudlets buttons ===<br />
You can give Mudlets buttons a background to have them blend in with your UI by doing this:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace the /home/vadi/Pictures/tile.png location below with the one of your picture!<br />
-- you can download the sample tile.png from https://opengameart.org/content/bevouliin-free-game-background-for-game-developers<br />
local backgroundpath = [[/home/vadi/Pictures/tile.png]]<br />
-- Windows:<br />
-- local backgroundpath = [[C:/Users/Vadim/Downloads/Free game background/transparent PNG/tile.png]]<br />
<br />
setAppStyleSheet([[<br />
QToolBar {<br />
border-image: url(]]..backgroundpath..[[);<br />
<br />
}<br />
<br />
QToolBar QToolButton:!hover {<br />
color: white;<br />
}<br />
QToolBar QToolButton:hover {<br />
color: black;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
Result:<br />
<br />
[[File:Mudlet tiled buttons.png|frame|left]]<br />
<br clear=all><br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserMiniConsole.html Geyser.MiniConsole]==<br />
This allows you to spawn a Mudlet miniconsole - unlike labels, these aren't as styleable, but they do format text better. They make a good fit for text-based menus, chat and map capture, and other things.<br />
<br />
Spawning one is very similar to other Geyser elements - paste this into a new script:<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
autoWrap = true,<br />
color = "black",<br />
scrollBar = false,<br />
fontSize = 8,<br />
width="30%", height="50%",<br />
})<br />
</syntaxhighlight><br />
<br />
This'll make you one at the bottom-right of the screen. The miniconsole will have a grey background by default, but you can set it to any color you'd like with [http://www.mudlet.org/geyser/files/geyser/GeyserWindow.html#Geyser.Window:setColor miniconsole:setColor()]:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:setColor("black") -- give it a nice black background<br />
</syntaxhighlight><br />
<br />
A special dimension property that MiniConsoles have is a character - instead of specifying a miniconsole to be % of a container or a certain number of pixels, you can specify it as a certain number of characters. You do this by using "c" at the end of a number. This way, you can, for example, specify miniconsole to be 10 letters long and 2 lines high:<br />
<br />
<syntaxhighlight lang="lua"><br />
flatbox = Geyser.MiniConsole:new({<br />
name="flatbox",<br />
x="70%", y="50%",<br />
wrapAt = 10,<br />
width="10c", height="2c",<br />
})<br />
flatbox:setColor("red")<br />
flatbox:echo("ABCDEFGHIJ") -- that is 10 letters<br />
</syntaxhighlight><br />
<br />
=== Adding text ===<br />
You can use [[Manual:Technical_Manual#echo|echo()]] the same way with a miniconsole to add text as to the usual window:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("hello!")<br />
</syntaxhighlight><br />
<br />
As well as [[Manual:Technical_Manual#cecho|cecho]], [[Manual:Technical_Manual#decho|decho]], or [[Manual:Technical_Manual#hecho|hecho]]:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:cecho("<green>hey, <blue>colored <red>text!\n")<br />
</syntaxhighlight><br />
<br />
=== Copying lines with color ===<br />
To copy a line over to the miniconsole, as it is from the game with all colors preserved, you can [[Manual:UI_Functions#selectCurrentLine|select]], [[Manual:UI_Functions#copy|copy]], and [[Manual:UI_Functions#appendBuffer|append]] it. For an example, try making a trigger with this as the ''Lua function'' pattern type:<br />
<br />
<syntaxhighlight lang="lua"><br />
return true<br />
</syntaxhighlight><br />
<br />
That'll make the trigger go off on every line. Then give it the following script (assumed you have made the HelloWorld miniconsole from earlier):<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
copy()<br />
HelloWorld:appendBuffer()<br />
</syntaxhighlight><br />
<br />
... and you'll see all MUD output duplicated exactly as it is to the miniconsole. Amazing! It's very efficient as well, so you can have many miniconsoles, even in spam, not lag you down.<br />
<br />
=== Clearing the miniconsole ===<br />
Clearing the miniconsole just requires using the following script (assumes you have made the HelloWorld miniconsole from earlier):<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:clear()<br />
</syntaxhighlight><br />
<br />
=== Doing edits in copied lines ===<br />
Sometimes you'll want to edit the line before stuffing it into the miniconsole. For example, if you're making a chat capture, you'd want to condense a really long org name into something that's more space-friendly.<br />
<br />
To do so, you'd use the [[Manual:Technical_Manual#selectString|selectString()]] the text you'd like to modify, [[Manual:Technical_Manual#replace|replace()]] it with a different one:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString("Your", 1) -- select the word you'd like to replace - in this case, 'Your'<br />
setBgColor(getBgColor()) -- preserve the background color in the replacement<br />
setFgColor(getFgColor()) -- preserve the foreground color in the replacement<br />
replace("Mine") -- replace the selection with the wird 'Mine'<br />
<br />
selectCurrentLine()<br />
copy()<br />
HelloWorld:appendBuffer()<br />
</syntaxhighlight><br />
<br />
=== Gagging from the main window ===<br />
If you'd like to gag the line from the main window so it only shows up in your miniconsole, [[Manual:Technical_Manual#deleteLine|delete]] it after moving it over:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
copy()<br />
HelloWorld:appendBuffer()<br />
deleteLine()<br />
</syntaxhighlight><br />
<br />
=== Clickable menus ===<br />
Using the [[Manual:Technical_Manual#echoLink|echoLink]], [[Manual:Technical_Manual#insertLink|insertLink]] and [[Manual:Technical_Manual#setLink|setLink]] functions, you can turn text into one that reacts on a click. Combined with your power of placing text anywhere on the screen with a miniconsole, you can make menus with options. Here is one such example, where selecting an item causes an echo to happen:<br />
<br />
<syntaxhighlight lang="lua"><br />
flatbox = Geyser.MiniConsole:new({<br />
name="flatbox",<br />
x="20%", y="80%",<br />
width="40c", height="4c",<br />
})<br />
flatbox:setColor("red")<br />
clearWindow("flatbox")<br />
<br />
flatbox:cecho("<white:red>Choose one of the following options:\n")<br />
<br />
flatbox:fg("white")<br />
flatbox:bg("red")<br />
<br />
for _, fruit in ipairs{"banana", "apple", "orange"} do<br />
echoLink("flatbox", "* "..fruit:title().."\n", [[echo("You picked ]]..fruit..[[\n")]], "The "..fruit.." option", true)<br />
end<br />
<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
This will produce something like the following:<br />
<br />
[[File:Fruit_menu.png|center]]<br />
<br />
=== Change your miniconsole background image ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
To set a custom background image for your miniconsole use (assumes you have made the HelloWorld miniconsole from earlier): <br />
<syntaxhighlight lang="lua"><br />
HelloWorld:setBackgroundImage(getMudletHomeDir().."/myBgImage.png", "center") -- put's your image myBgImage.png which is in your profile folder in the center of the miniconsole<br />
</syntaxhighlight><br />
<br />
For different modes/options see here [[Manual:Lua_Functions#setConsoleBackgroundImage|setConsoleBackgroundImage()]]<br />
<br />
=== Enable and use your miniconsole command line ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
Every miniconsole has a hidden command line.<br />
Enable it with (assumes you have made the HelloWorld miniconsole from earlier): <br />
<syntaxhighlight lang="lua"><br />
HelloWorld:enableCommandLine()<br />
</syntaxhighlight><br />
<br />
=== Set an action to your miniconsole command line ===<br />
If no action is set to your miniconsole command line the commands are send to the game the same way <br />
as for the main command line <br />
<br />
(aliases still work and there is a command echo in your main and miniconsole if not deactivated in the settings)<br />
<br />
It is possible to set an action to your command line which means that it is possible to use the input text and perform an action.<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:enableCommandLine()<br />
local function channelChat(text)<br />
send("chat "..text)<br />
HelloWorld:echo("[chat] " ..text.."\n")<br />
end<br />
<br />
HelloWorld:setCmdAction(channelChat)<br />
</syntaxhighlight><br />
<br />
This will send your miniconsole command line input to the chat channel.<br />
<br />
More complicated/sophisticated actions are possible, setCmdAction works the same way as the Label clickCallback functions.<br />
<br />
==[http://www.mudlet.org/geyser/files/geyser/GeyserGauge.html Geyser.Gauge]==<br />
<!--<br />
This is a composite window. Gauge duplicates the functionality of the built in Mudlet gauges, but in a clean and easily extended way. Internally, a Geyser Gauge is a container holding two Labels, front and back, which are initially scaled to fill the entire Gauge container. Hence, a gauge, g, can be given callbacks with the g.front:setClickCallback() method.<br />
<br />
The backgroundColor parameter initially sets the colors of the gauge, but of course the front and back components can be accessed individually as labels for high control over their looks. Gauges can be horizontal or vertical and decrease in value left to right, right to left, down up or up down depending on the value of the orientation parameter.<br />
--><br />
<br />
A Gauge allows you to represent numbers on a scale - and most typically, you've seen it be used as your standard hp/mana/whatever bar. A basic bar is made similarly to other Geyser elements. To set the value on the gauge that it should represent, use the [http://www.mudlet.org/geyser/files/geyser/GeyserGauge.html#Geyser.Gauge:setValue setValue()] function:<br />
<br />
<syntaxhighlight lang="lua"><br />
hpbar = Geyser.Gauge:new({<br />
name="hpbar",<br />
x="50%", y="85%",<br />
width="45%", height="5%",<br />
})<br />
hpbar:setValue(math.random(1,100),100)<br />
</syntaxhighlight><br />
<br />
That'll spawn you a pretty basic gauge with a horizontal orientation and a grey colour - and as a test, with a random value.<br />
<br />
[[File:Basic_gauge.png|center]]<br />
<br />
=== Updating a gauge ===<br />
You'd want your gauge to stay in sync with your actual values. To make that happen, you want to call [http://www.mudlet.org/geyser/files/geyser/GeyserGauge.html#Geyser.Gauge:setValue setValue()] whenever the value that the gauge is tracking changes.<br />
<br />
So for example, if you make a health bar - wherever you get your new health at (be it prompt, gmcp, atcp or whatever), update the gauge as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- theoretical example<br />
current_health, max_health = tonumber(matches[2]), tonumber(matches[3])<br />
<br />
-- update the bar<br />
hp_bar:setValue(current_health, max_health)<br />
</syntaxhighlight><br />
<br />
You can also write down how much health have you got on the bar with:<br />
<br />
<syntaxhighlight lang="lua"><br />
lua local hp = math.random(1,100) <br />
hpbar:setValue(current_health, max_health, "<b>"..max_health.."hp</b>")<br />
<br />
-- example using GMCP in IRE games:<br />
hpbar:setValue((100/gmcp.Char.Vitals.maxhp)*gmcp.Char.Vitals.hp,100,gmcp.Char.Vitals.hp)<br />
</syntaxhighlight><br />
<br />
[[File:Hpbar_basic.png|center]]<br />
<br />
=== Styling a gauge ===<br />
The Geyser gauge is composed of three labels - one is called ''mygauge.front'', ''mygauge.back'' and ''mygauge.text''. Combining this with Geyser:Label.setStyleSheet, you can improve the visuals of your gauges by using Qt-supported CSS. The syntax for specifying CSS is a bit different - it requires a semicolon after every property, and is done in the format of ''property name''''':'''''values''''';'''. A list of all possible properties you can use is [http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties available here] and you can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create them. Practical example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hpbar = Geyser.Gauge:new({<br />
name="hpbar",<br />
x="50%", y="85%",<br />
width="45%", height="20px",<br />
})<br />
hpbar.front:setStyleSheet([[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #98f041, stop: 0.1 #8cf029, stop: 0.49 #66cc00, stop: 0.5 #52a300, stop: 1 #66cc00);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;<br />
]])<br />
hpbar.back:setStyleSheet([[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #78bd33, stop: 0.1 #6ebd20, stop: 0.49 #4c9900, stop: 0.5 #387000, stop: 1 #4c9900);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;<br />
]])<br />
<br />
hpbar:setValue(math.random(1,100),100)<br />
</syntaxhighlight><br />
<br />
[[File:Fancy_Geyser_gauge.png|center]]<br />
<br />
The same style can be adjusted by colors to red as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
hpbar = Geyser.Gauge:new({<br />
name="hpbar",<br />
x="50%", y="85%",<br />
width="45%", height="20px",<br />
})<br />
hpbar.front:setStyleSheet([[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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
hpbar.back:setStyleSheet([[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
<br />
hpbar:setValue(math.random(1,100),100)<br />
</syntaxhighlight><br />
<br />
[[File:Fancy_Geyser_gauge_red.png|center]]<br />
<br />
=== Updating a gauge ===<br />
The Geyser gauge is composed of three labels - one is called ''mygauge.front'', ''mygauge.back'' and ''mygauge.text''. To make a gauge clickable you can set a ClickCallBack on the top label which is ''mygauge.text'' example: <syntaxhighlight lang="lua">mygauge.text:setClickCallback("functionName", variableToSendToFunctionName)</syntaxhighlight><br><br />
If you would like to have different click events for the top or back of a gauge you can enable clickThrough for the top or ''mygauge.text'' label example<br />
<br />
<syntaxhighlight lang="lua"><br />
mygauge.text:enableClickthrough()<br />
mygauge.front:setClickCallback("functionOne", variableToSendToFunctionOne)<br />
mygauge.back:setClickCallback("functionTwo", variableToSendToFunctionTwo)<br />
</syntaxhighlight><br />
<br />
<br />
=== Tooltips on gauges ===<br />
Tooltips are available since Mudlet 4.6 as explained in above section [[#Adding_a_tooltip_to_a_label]], and as gauges are really only made up of labels as well, you could add a tooltip then by just using <syntaxhighlight lang="lua">mygauge.text:setToolTip("This is the gauge's tooltip", "10")</syntaxhighlight> the same as it's handled for clickback.<br />
<br />
== HBox/VBox ==<br />
<br />
These are special types of containers. Every window in these is horizontally or vertically aligned in the order they were added.<br />
<br />
<sub>Added to Mudlet in 2.0-rc4</sub><br />
<br />
== Geyser.UserWindow ==<br />
Allows you to use Mudlets UserWindows within Geyser. Which allows you to use all the functionality of a MiniConsole in it‘s basic form.<br />
The big advantage is the possibility to add other Geyser Elements like Labels, MiniConsole, Gauges, Mappers to the UserWindow.<br />
The UserWindow then can act as container for those elements with all the perks of dynamic resizing or any other Geyser functionality.<br />
<br />
{{note}} available in Mudlet 4.6.1+<br />
<br />
===Basic floating UserWindow ===<br />
This will create a movable floating UserWindow.<br />
<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "TestUserWindow",<br />
titleText ="My Test UserWindow", -- only available since Mudlet 4.8+<br />
x = "20%", y="20%",<br />
width="30%", height ="40%"<br />
})<br />
</syntaxhighlight><br />
{{note}} Since Mudlet 4.8+ it is possible to change the Title of the UserWindow by using the constraint titleText and the functions belowː<br />
<br />
To revert to the standard title useː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:resetTitle()<br />
</syntaxhighlight><br />
To set a new title after creation useː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:setTitle("My new title Text")<br />
</syntaxhighlight><br />
<br />
=== Docked UserWindow ===<br />
To create the window docked at the right side,<br />
set the variable docked (at creation of the container) to true.<br />
Be aware that with this variable set to true the position and the size at creation of the userwindow will be ignored.<br />
<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "DockedTestUserWindow",<br />
docked = true<br />
<br />
})<br />
</syntaxhighlight><br />
<br />
Since Mudlet 4.8+ it is also possible to choose the docking Position of the UserWindow at creation and by function withː<br />
<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "DockedTestUserWindow",<br />
docked = true,<br />
dockPosition = "top" -- Possible dockPositions are left "l", right "r", top "t", bottom "b" and floating "f" <br />
})<br />
</syntaxhighlight><br />
<br />
To change it for a already created UserWindow use the function setDockPosition(dockPosition) likeː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:setDockPosition("left")<br />
</syntaxhighlight><br />
<br />
=== Disable\Enable UserWindow autoDock ===<br />
{{note}} available in Mudlet 4.8+<br />
<br />
The auto docking feature can be really annoying at times. To disable it use the functionsː<br />
<syntaxhighlight lang="lua"><br />
testuserwindow:disableAutoDock() -- disables autoDock. Docking still possible with ːsetDockPosition<br />
testuserwindow:enableAutoDock() -- reenables autoDock<br />
</syntaxhighlight><br />
<br />
=== Styling the UserWindow border and title area ===<br />
{{note}} available in Mudlet 4.10+<br />
<br />
Geyser.UserWindows can accept a stylesheet to change the appearance of the border and title area and make<br />
the UserWindow look more appealing.<br />
<syntaxhighlight lang="lua"><br />
myUserWindow = myUserWindow or Geyser.UserWindow:new({<br />
name = "myUserWindow", titleText = "myUserWindow", autoDock = false<br />
})<br />
<br />
myUserWindow:setStyleSheet( <br />
[[QDockWidget{<br />
border: 1px solid green; /* UserWindow border style */<br />
font: bold 15pt "Arial"; /* Font of the titleBar */<br />
color: rgb(0,0,150); /* Font color */<br />
}<br />
<br />
QDockWidget::title{ <br />
background-color: rgb(0,255,150); /* TitleBar color */<br />
border: 2px solid red; /* TitleBar border */<br />
border-radius: 2px; /* TitleBar border radius */<br />
text-align: center; /* alignment of the titleText */<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
This looks likeː<br />
<br />
<br />
[[File:UserWindowStyleSheet.png]]<br />
<br />
=== UserWindow as Container ===<br />
This is the feature which shows the versatile nature of Geyser.UserWindows.<br />
The UserWindow act as container and is at that possible to dynamically resize the containing Geyser Elments.<br />
Put a label in the UserWindow resize it as rectangle.<br />
<syntaxhighlight lang="lua"><br />
testuserwindow = Geyser.UserWindow:new({<br />
name = "ParentTestUserWindow",<br />
x = "20%", y="20%",<br />
width="30%", height ="40%"<br />
})<br />
<br />
testuserwindow:setColor("dark_green") -- give the userwindow a bit of color <br />
<br />
labelinuserw = Geyser.Label:new({<br />
name = "LabelinUserWindow",<br />
x=20, y=20,<br />
width = -20, height = -20,<br />
color="light_blue", fontSize=20,<br />
},testuserwindow)<br />
<br />
labelinuserw:echo("This is a label in an userwindow", "black", "c")<br />
</syntaxhighlight><br />
[[File:LabelInUserWindow.png]]<br />
<br />
The same way you are able to add your favorite Geyser Application (like tabbed chat, animated timers, gauges) to an UserWindow.<br />
<br />
Note that you don't need to add MiniConsoles to a UserWindow - as UserWindows already have them built-in.<br />
<br />
[[File:Tabbedchatinuserwindow.png]]<br />
<br />
== Geyser.CommandLine ==<br />
{{note}} available in Mudlet 4.10+<br />
<br />
Allows you to create your custom command lines which can resize/move like any other Geyser object.<br />
<br />
If you just need a command line which is integrated in a miniconsole or userwindow check out [[Manual:Geyser#Enable and use your miniconsole command line|this]].<br />
<br />
=== Creating a Geyser.CommandLine ===<br />
An example to get you startedː<br />
<syntaxhighlight lang="lua"><br />
myCommandLine = myCommandLine or Geyser.CommandLine:new({<br />
name = "myCommandLine", <br />
x = "-20%", y = -40, <br />
width = "20%", height = 40,<br />
stylesheet = "border: 1px solid silver;"})<br />
</syntaxhighlight><br />
This creates a new command line in the right bottom of your screen.<br />
<br />
=== Bind action to your command line input ===<br />
If you use your previous created command line any command will just be send to the game and/or the alias engine.<br />
<br />
To react to any input in a custom manner we can set an action to the command line and use the input as parameter.<br />
<br />
Example of a command line changing the background color of your main console (assumes you have created "myCommandLine" from earlier): <br />
<syntaxhighlight lang="lua"><br />
myCommandLine:setAction(<br />
function(commandLineInput)<br />
r, g, b = Geyser.Color.parse(commandLineInput) -- gets the r, g, b values of the color you input to the command line<br />
if b then -- checks if the color is valid<br />
setBackgroundColor(r, g, b)<br />
else<br />
echo("\n"..commandLineInput.." is not a valid color. Try again.")<br />
end<br />
end)<br />
</syntaxhighlight><br />
<br />
=== Styling a command line ===<br />
You can style your Geyser command line by using Qt-supported CSS. A list of all possible properties you can use is [http://doc.qt.io/qt-5/stylesheet-reference.html#list-of-properties available here]<br />
<br />
Practical example (assuming "myCommandLine" is created)ː<br />
<syntaxhighlight lang="lua"><br />
myCommandLine:setStyleSheet([[<br />
QPlainTextEdit{ /* QPlainTextEdit is used to prevent the styleSheet bleeding to the right click menu*/<br />
border: 1px solid silver; /* Command line border style */<br />
background-color: rgb(0,255,150); /* Command line background color */<br />
font: bold 12pt "Arial"; /* Font and font-size of your command line */<br />
color: rgb(0,0,150); /* Command line text color */<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
== Create an extra command line in Mudlet ==<br />
If your goal is to just have an extra command/input line copy/paste the example below into a new script in Mudletː<br />
<br />
<syntaxhighlight lang="lua"><br />
inputContainer = inputContainer or Adjustable.Container:new({<br />
x = 0, y = "-4c", <br />
name = "InputContainer", padding = 2, <br />
width = "100%", height = "4c", <br />
autoLoad = false})<br />
<br />
extraCmdLine = extraCmdLine or Geyser.CommandLine:new({<br />
name = "extraCmdLine", <br />
x = 0, y = 0, width = "100%", height = "100%"}, inputContainer)<br />
<br />
inputContainer:attachToBorder("bottom")<br />
</syntaxhighlight><br />
<br />
This will look likeː <br />
<br />
[[File:AdditionalCommandLine.png|extra command line]]<br />
<br />
== Adjustable.Container ==<br />
{{note}} available in Mudlet 4.8+<br />
<br />
Adjustable Containers are a new "GeyserClass" which act as containers for Geyser elements, but with more flexible and user configurable features. They are referred to as "adjustable" because they can be minimized, loaded, saved, moved, adjusted in size with the mouse pointer, and attached to borders. <br />
<br />
A brief video of [https://www.youtube.com/watch?v=GT2ScizuM48&feature=youtu.be Introduction to Adjustable Containers] is available.<br />
<br />
=== Creating an Adjustable.Container ===<br />
An Adjustable.Container is created just like any other Geyser Object. For example, we might experiment with creating a new Adjustable.Container by running the following line of lua code:<br />
<syntaxhighlight lang="lua"><br />
testCon = testCon or Adjustable.Container:new({name="testContainer"})<br />
</syntaxhighlight><br />
This will create a new Adjustable.Container with the name ''testContainer''. Specifying the adjustable container's name is important for saving. Defining a variable, such as ''testCon'' in our above example, allows functions to be used with the Adjustable.Container.<br />
<br />
Our newly created Adjustable.Container may be used the same way as any other Geyser.Container might. For example, let's put a Geyser.Label in our new testContainer:<br />
<br />
<syntaxhighlight lang="lua"><br />
testCon = testCon or Adjustable.Container:new({name="testContainer"})<br />
testLabel = Geyser.Label:new({x=0, y=0, height="100%", width="100%", color="green"},testCon)<br />
</syntaxhighlight><br />
<br />
The above code creates a new, green-colored Geyser.Label in the ''testCon'' adjustable.container as shown below:<br />
<br />
[[File:GreenLabelinAdjustableContainer.png]]<br />
<br />
You can also create one for miniconsole:<br />
<br />
<syntaxhighlight lang="lua"><br />
miniconsoleContainer = miniconsoleContainer or Adjustable.Container:new({name="miniconsoleContainer"})<br />
myMiniconsole = Geyser.MiniConsole:new({<br />
name="myMiniconsole",<br />
x=0, y=0,<br />
autoWrap = true,<br />
color = "black",<br />
scrollBar = false,<br />
fontSize = 8,<br />
width="100%", height="100%",<br />
}, miniconsoleContainer)<br />
<br />
myMiniconsole:echo("Hello!\n")<br />
</syntaxhighlight><br />
<br />
That will give you:<br />
<br />
[[File:Adjustable container miniconsole.png]]<br />
<br />
=== Key Functions ===<br />
A listing of key functions for the Adjustable.Container module can be found hereː https://www.mudlet.org/geyser/files/geyser/AdjustableContainer.html<br />
<br />
=== Change Title Text ===<br />
To specify the title text of a new container, use the constraint <code>titleText</code> in the constructor (see [[Manual:Geyser#valid constraints|valid constraints]]).<br />
<br />
To change the title text after a container has already been created, use <code>setTitle</code>. Continuing from the previous example, the title for an existing container named "testCon" might be adjusted in a number of ways: <br />
<br />
<syntaxhighlight lang="lua"><br />
testCon:setTitle("Title") -- changes the container's title to "Title"<br />
</syntaxhighlight><br />
<br />
A container's title text defaults to the color green, but this can also be adjusted by using <code>setTitle</code>: <br />
<br />
<syntaxhighlight lang="lua"><br />
testCon:setTitle("Red Title Test","red") -- changes the container's title text to "Red Title Test" and displays the text in the specified color "red".<br />
</syntaxhighlight><br />
<br />
To restore a container's default title text, <code>setTitle</code> is issued without any specified title or color: <br />
<br />
<syntaxhighlight lang="lua"><br />
testCon:setTitle() -- resets the container's title text<br />
</syntaxhighlight><br />
<br />
=== AutoSave and AutoLoad ===<br />
The following Adjustable.Container settings can be saved and loadedː<br />
<br />
<code>x</code>, <code>y</code>, <code>height</code>, <code>width</code>, <code>minimized</code>, <code>locked</code>, <code>lock Style</code>, <code>padding</code>, and <code>hidden</code>.<br />
<br />
These settings will be automatically saved when the Mudlet profile is closed, and automatically loaded when a previous Adjustable.Container is created within the corresponding profile.<br />
<br />
To prevent automatic saving and/or loading of these settings, the <code>autoLoad</code> and <code>autoSave</code> constraints can be included in the constructor. For example, the following code will prevent the settings of the ''testCon2'' Adjustable.Container from being loaded upon creation:<br />
<br />
<syntaxhighlight lang="lua"><br />
testCon2 = testCon2 or Adjustable.Container:new({name="testCon2", autoLoad=false})<br />
</syntaxhighlight><br />
<br />
To also prevent the ''testCon2'' Adjustable.Container from automatically saving its settings when the Mudlet profile is closed, the <code>autoSave=false</code> constraint would be added at creation as follows:<br />
<br />
<syntaxhighlight lang="lua"><br />
testCont2 = testCont2 or Adjustable.Container:new({name="testCont2", autoLoad=false, autoSave=false})<br />
</syntaxhighlight><br />
<br />
Automatic saving can also be deactivated after an Adjustable.Container has been created, by invoking <code>testCont:disableAutoSave()</code><br />
<br />
Note that even with autoSave and autoLoad disabled, it is still possible to save and load manually through the right-click menu and/or by using <code>testCont:save()</code> or <code>testCont:load()</code> in a script.<br />
<br />
To save/load all your containers manually at the same time, we use <code>Adjustable.Container:saveAll()</code> and/or <code>Adjustable.Container:loadAll()</code><br />
<br />
=== "All" Functions ===<br />
The following functions affect all Adjustable Containers at the same time.<br />
<br />
{{note}} You must create the Adjustable Containers before these functions will have an effect.<br />
<br />
<code>Adjustable.Container.loadAll()</code> loads all the settings from your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container.saveAll()</code> saves all your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container.loadAll()</code> loads all the settings from your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container:showAll()</code> shows all your Adjustable Containers at once.<br />
<br />
<code>Adjustable.Container:doAll(myfunc)</code> creates a function that will affect all your Adjustable Containers. For example:<br />
<syntaxhighlight lang="lua"><br />
Adjustable.Container:doAll(function(self) self:hide() end) -- hides all your adjustable containers<br />
</syntaxhighlight><br />
<br />
===Right-Click Menu===<br />
Your Adjustable Container has also integrated a right-click Menu with the main key functions for easier usability.<br />
<br />
[[File:AdjustableContainerRightClickMenu.png]]<br />
<br />
The right-click menu also automatically shows you the possible attach position (by clicking on Attach to:) <br />
<br />
and possible lockStyles (by clicking on Lockstyle, integrated are 4 standard lockStyles)<br />
<br />
=== Create a Custom Menu with Custom Items ===<br />
To create a new menu element in your right click menu called "Custom" and add an item to it use:<br />
<syntaxhighlight lang="lua"><br />
testcontainer:newCustomItem(name, func)<br />
-- for example<br />
testcontainer:newCustomItem("Hello world", function(self) echo("Hello world\n") self:flash() end)<br />
-- this will write "Hello world" to the main console and flashes your container.<br />
</syntaxhighlight><br />
<br />
=== Add new LockStyles ===<br />
For more advanced users it's possible to add a new Lockstyles by:<br />
<syntaxhighlight lang="lua"><br />
testcontainer:newLockStyle(name, func)<br />
-- for example<br />
testcontainer:newLockStyle("NewLockStyle", function(self) self.Inside:move(40, 40) self.Inside:resize(-40,-40) self:setTitle("") end)<br />
</syntaxhighlight><br />
<br />
=== Change Adjustable Container Style ===<br />
Additionally to the standard container constraints Adjustable Containers allow you to change at creation: the internal Label style, the menu style, min/close buttons, the menu text, title text... <br />
<br />
( see [[Manual:Geyser#valid constraints|valid constraints]])<br />
An example of a Adjustable Container with different style.<br />
<syntaxhighlight lang="lua"><br />
testCont =<br />
testCont or<br />
Adjustable.Container:new(<br />
{<br />
name = "TestNewStyleContainer",<br />
adjLabelstyle = "background-color:rgba(220,220,220,100%); border: 5px groove grey;",<br />
buttonstyle=[[<br />
QLabel{ border-radius: 7px; background-color: rgba(140,140,140,100%);}<br />
QLabel::hover{ background-color: rgba(160,160,160,50%);}<br />
]],<br />
buttonFontSize = 10,<br />
buttonsize = 20,<br />
titleText = "My new Style",<br />
titleTxtColor = "black",<br />
padding = 15,<br />
}<br />
)<br />
</syntaxhighlight><br />
This code creates a container which looks like this:<br />
<br />
[[File:NewStyleAdjustableContainer.png|Adjustable Container with different style]]<br />
<br />
===<div id="valid constraints"> Valid Constraints</div>===<br />
Adjustable Container constraints and their default values. <br />
<br />
These are in addition to the standard Geyser.Container constraints.<br />
<syntaxhighlight lang="lua"><br />
{<br />
ParentMenuWidth = "102" -- menu width of the main right click menu<br />
<br />
ChildMenuWidth = "82" -- menu width of the children in the right click menu (for attached, lockstyles and custom items)<br />
<br />
MenuHeight = "22" -- height of a single menu item<br />
<br />
MenuFontSize = "8" -- font size of the menu items<br />
<br />
buttonsize = "15" -- size of the minimize and close buttons<br />
<br />
buttonFontSize = "8" -- font size of the minimize and close buttons<br />
<br />
padding = 10 -- how far is the inside element placed from the corner (depends also on the lockstyle setting)<br />
<br />
adjLabelstyle = [[ background-color: rgba(0,0,0,100%); border: 4px double green; border-radius: 4px;]] -- style of the main Label where all elements are in<br />
<br />
menustyle = [[QLabel::hover{ background-color: rgba(0,150,255,100%); color: white;} QLabel::!hover{color: black; background-color: rgba(240,240,240,100%);} <br />
QLabel{ font-size:]]..MenuFontSize..[[pt;}]] -- menu items style<br />
<br />
buttonstyle = [[ QLabel{ border-radius: 7px; background-color: rgba(255,30,30,100%);} QLabel::hover{ background-color: rgba(255,0,0,50%);}<br />
]] -- close and minimize buttons style<br />
<br />
minimized = false -- minimized at creation?<br />
<br />
locked = false -- locked at creation?<br />
<br />
lockLabel.txt = [[<font size="5">🔒</font> Lock/Unlock]] -- text of the "lock" menu item<br />
<br />
minLabel.txt = [[<font size="5">🗕</font> Min/Restore]] -- text of the "min/restore" menu item<br />
<br />
saveLabel.txt = [[<font size="5">💾</font> Save]] -- text of the "save" menu item<br />
<br />
loadLabel.txt = [[<font size="5">📁</font> Load]] -- text of the "load" menu item<br />
<br />
attLabel.txt = [[<font size="5">⚓</font> Attach to:]] -- text of the "attached menu" item<br />
<br />
lockStylesLabel.txt = [[<font size="5">🖌</font> Lockstyle:]] -- text of the "lockstyle menu" item<br />
<br />
customItemsLabel.txt = [[<font size="5">🖇</font> Custom:]] -- text of the "custom menu" item<br />
<br />
titleTxtColor = "green" -- color of the title text<br />
<br />
titleText = name.." - Adjustable Container" -- title text<br />
<br />
lockStyle = "standard" -- choose lockstyle at creation. possible integrated lockstyle are: "standard", "border", "light" and "full"<br />
<br />
noLimit = false -- there is a minimum size limit if this constraint is set to false.<br />
<br />
raiseOnClick = true -- raise your container if you click on it with your left mouse button<br />
<br />
autoSave = true -- saves your container settings on exit (sysExitEvent). If set to false it won't autoSave<br />
<br />
autoLoad = true -- loads the container settings (if there are some to load) at creation of the container. If set to false it won't load the settings at creation<br />
}<br />
</syntaxhighlight><br />
<br />
==Change Container==<br />
{{note}} available in Mudlet 4.8+<br />
<br />
With this command it is possible to change an elements or even a containers location to that from another container.<br />
For example:<br />
<syntaxhighlight lang="lua"><br />
mycontainerone:changeContainer(mycontainertwo)<br />
--puts container one into container two which means container two will be the parent of container one<br />
</syntaxhighlight><br />
It is also possible to change to a container which is not located on the main window:<br />
<syntaxhighlight lang="lua"><br />
myEmco:changeContainer(emco_userwindow)<br />
--puts my tabbed chat Emco into my userwindow<br />
--to put it back to the main window change to a container located on the main window<br />
myEmco:changeContainer(mymainwindow_container)<br />
--or if it the element wasn't in a container use the main Geyser Root container called Geyser<br />
myEmco:changeContainer(Geyser)<br />
</syntaxhighlight><br />
<br />
==Create Map Window==<br />
{{note}} available in Mudlet 4.8+<br />
<br />
It‘s possible to create the mapper as a map window (similar to clicking the icon) like this:<br />
<syntaxhighlight lang="lua"><br />
myMapWidget = Geyser.Mapper:new({embedded= false})<br />
</syntaxhighlight><br />
<br />
This will open a map window with your saved layout (if there is one, otherwise it will dock at the right corner)<br />
<br />
To choose the position of the DockWindow at creation use: (this will create a map window docked at the left corner)<br />
<br />
<syntaxhighlight lang="lua"><br />
myMapWidget = Geyser.Mapper:new({embedded= false, dockPosition="left"})<br />
</syntaxhighlight><br />
<br />
Possible dockPositions are "left", "right", "top", "bottom", and "floating".<br><br />
To change the dockPosition after creation use:<br />
<br />
<syntaxhighlight lang="lua"><br />
myMapWidget:setDockPosition("floating")<br />
-- this will change myMapWidget dockPosition to floating <br />
</syntaxhighlight><br />
<br />
= Tutorial =<br />
Note: This tutorial assumes you know how scripts in Mudlet work. If not then you should look at the manual first. Also it only shows how Geyser basically works and explains Geysers special windows. It wont go into detail about the windows that where already in Mudlet.<br />
<br />
=== Hello World ===<br />
Let's start with something simple. A Label.<br />
<br />
<syntaxhighlight lang="lua"><br />
Geyser.Label:new({<br />
name="HelloWorld",<br />
x=50, y=50,<br />
width=200, height=50,<br />
})<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_1.png]]<br />
<br />
This code creates a blank Label with a size of 200x50 at a position of 50 points horizontal and vertical from its parent window - which is the main window since we didn't specify any.<br />
<br />
You can manipulate the Label through the normal functions but Geyser.Label:new() returns an object which can be used to manipulate the label directly. So you should store it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local HelloWorld = Geyser.Label:new({<br />
name="HelloWorld",<br />
x=50, y=50,<br />
width=200, height=50,<br />
})<br />
</syntaxhighlight><br />
<br />
Then you can, for example print a text on it:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("Hello World")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_2.png]]<br />
<br />
You can put a format parameter so that the text is, for example, centered.<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("Hello World", nil, "c")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_3.png]]<br />
<br />
The second parameter is the color. We set it to nil which means the labels foreground color will be used.<br />
<br />
The color parameter either accepts a string ("red"), a hex value("#FF0000" or "0xFF0000" or "|cFF0000"), or a decimal value "&lt;255,0,0&gt;"<br />
<br />
Example:<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:echo("Hello World", "red", "c")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_4.png]]<br />
<br />
{{note}} This will automatically set the foreground color, so any echo, without the color parameter set, after that will use the same color.<br />
<br />
You can also set the foreground color with the setFgColor method:<br />
<br />
<syntaxhighlight lang="lua"><br />
HelloWorld:setFgColor("red")<br />
HelloWorld:echo("Hello World", nil, "c")<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_HW_4.png]]<br />
<br />
=== Containers ===<br />
<br />
Containers are windows that can contain other windows. Actually, since all other Geyser windows subclass container, every window can do that. But containers do not have any visible content by themselves. <br />
<br />
Let's show that by an example:<br />
<syntaxhighlight lang="lua"><br />
local container = Geyser.Container:new({<br />
name="container",<br />
x=50, y=50,<br />
width=250, height=50,<br />
})<br />
</syntaxhighlight><br />
<br />
This will create a container, but if you look at the screen you will see nothing at the positon.<br />
There is a way to make containers visible though:<br />
<syntaxhighlight lang="lua"><br />
container:flash()<br />
</syntaxhighlight><br />
<br />
This will flash the container for a short period of time.<br />
<br />
[[Image:Geyser_Container_1.png]]<br />
<br />
flash() accepts a number as paremeter which defines the time, in seconds, the flash is shown.<br />
<br />
Now, that the container is created, you can add other windows to it. There are 2 ways:<br />
<br />
Directly when creating the window:<br />
<br />
<syntaxhighlight lang="lua"><br />
local container_label = Geyser.Label:new({<br />
name="container_label",<br />
x=0, y=0,<br />
width="100%", height="100%",<br />
},<br />
container)<br />
container_label:echo("This is a label in a container", nil, "c")<br />
</syntaxhighlight><br />
<br />
Later, after the window was created<br />
<syntaxhighlight lang="lua"><br />
local container_label = Geyser.Label:new({<br />
name="container_label",<br />
x=0, y=0,<br />
width="100%", height="100%",<br />
})<br />
container_label:echo("This is a label in a container", nil, "c")<br />
container:add(container_label)<br />
</syntaxhighlight><br />
<br />
Both will lead to the same outcome.<br />
<br />
[[Image:Geyser_Container_2.png]]<br />
<br />
Note that we gave a width and height of "100%" to the constructor of the container. This means that the label will take 100% of the containers width and height. If values are given in percent they will even resize with its parent:<br />
<br />
<syntaxhighlight lang="lua"><br />
container:resize(325, nil)<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_Container_3.png]]<br />
<br />
The first parameter is the width, the second the height. If the value is nil the current value is used.<br />
<br />
As said in the "Hello World" tutorial the position is relative to its parent window. That's why we could set both x and y to 0 and it is at the position we wanted - the position of the container.<br />
<br />
When we now move the container the label moves with it:<br />
<syntaxhighlight lang="lua"><br />
container:move(400, nil)<br />
</syntaxhighlight><br />
<br />
[[Image:Geyser_Container_4.png]]<br />
<br />
The first parameter is the x-, the second the y-position. If the value is nil the current value is used.<br />
<br />
=== VBox and HBox ===<br />
<br />
The VBox and HBox classes are special Containers.<br />
They will automatically align its containing windows vertically or horizontally, respectively, in the order they where added to them.<br />
<br />
<syntaxhighlight lang="lua"><br />
<br />
local HBox = Geyser.HBox:new({<br />
name="HBox",<br />
x=0, y=0,<br />
width=400, height=30,<br />
})<br />
<br />
</syntaxhighlight><br />
<br />
Like containers you won't see them by themselves.<br />
<br />
Adding children works like with containers<br />
<syntaxhighlight lang="lua"><br />
<br />
local label1 = Geyser.Label:new({<br />
name="Label1",<br />
},<br />
HBox)<br />
label1:echo("Label 1", "black", "c")<br />
label1:setColor(255, 0, 0)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_1.png]]<br />
<br />
We didn't set any position or size, but the label gets the same size as the HBox.<br />
<br />
If we add another window:<br />
<syntaxhighlight lang="lua"><br />
<br />
local label2 = Geyser.Label:new({<br />
name="Label2",<br />
},<br />
HBox)<br />
label2:echo("Label 2", "black", "c")<br />
label2:setColor(0, 255, 0)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_2.png]]<br />
<br />
the size will be divided equally between them!<br />
<br />
What if you want a child that takes more or less space than the others?<br />
That's possible too:<br />
<syntaxhighlight lang="lua"><br />
<br />
local label3 = Geyser.Label:new({<br />
name="Label3",<br />
h_stretch_factor=2.0,<br />
},<br />
HBox)<br />
label3:echo("Label 3", nil, "c")<br />
label3:setColor(0, 0, 255)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_3.png]]<br />
<br />
As you can see, Label 3 takes the same space as Label 1 and 2 Together. <br />
That's because we supplied a horizontal stretch factor with "h_stretch_factor=2.0"<br />
<br />
This works also with a vertical stretch factor, just replace "h_stretch_factor" with "v_stretch_factor"<br />
<br />
Now you may have windows that should not be stretched at all.<br />
To accomplish this you have to set the horizontal and/or vertical policy:<br />
<br />
<syntaxhighlight lang="lua"><br />
<br />
local label4 = Geyser.Label:new({<br />
name="Label4",<br />
width="13%",<br />
h_policy=Geyser.Fixed,<br />
},<br />
HBox)<br />
label4:echo("Label 4", "black", "c")<br />
label4:setColor(0, 255, 255)<br />
<br />
</syntaxhighlight><br />
<br />
[[Image:HVBox_4.png]]<br />
<br />
Possible values for the policies are Geyser.Fixed and Geyser.Dynamic (which is the default). They can also be applied to VBox and HBox in exactly the same way.<br />
<br />
Note that, like in the example above, the label will retain relative values (like percent) if used.<br />
<br />
The VBox works like the HBox, only that the child windows are aligned vertically.<br />
<br />
= Walkthroughs =<br />
Here are a few walkthroughs that will show you how to combine Geyser elements to create some simple GUI widgets.<br />
<br />
===Create a Clickable Compass===<br />
[[File: compass.png]]<br />
The following will walk you through the process of creating your own clickable compass using the Geyser framework.<br />
====Setup the image files====<br />
The compass requires a handful of images to work properly. You can find them here: https://www.dropbox.com/sh/53l7xrn4ds35wnq/WpWOziVKmH <br><br />
Download each image and place it in your profile folder. You can find your profile folder with getMudletHomeDir()<br><br />
If you're using Mudlet 2.1+ you can enter '''lua getMudletHomeDir()''' from the command line to return the profile folder path on your computer.<br />
<br />
====Create a new script====<br />
Script Name: '''''compass.resize'''''<br><br />
Registered Event Handlers: '''''sysWindowResizeEvent'''''<p><br />
Every snippet of code will be placed within this script.<br />
====Store the screen size====<br />
We'll want to store the screen size in some local variables so they can be easily referenced to later on.<br />
<syntaxhighlight lang="lua">local mw, mh = getMainWindowSize()</syntaxhighlight><br />
<br />
====Create a global table or namespace====<br />
Creating a global table will make each of your variables unique. Our namespace will be called '''''compass''''' and everything we make from here on out will be stored within the compass table. We'll also add a few values to it: dirs and ratio. '''''compass.dirs''''' will store each direction while '''''compass.ratio''''' will store the ratio of our screen size so you can 'square up' your compass.<br />
<syntaxhighlight lang="lua">compass = compass or {<br />
dirs = {"nw","n","ne","w","center","e","sw","s","se"},<br />
ratio = mw / mh<br />
}</syntaxhighlight><br />
<br />
====Create the parent label====<br />
[[File: grey.png|thumbnail]]<br />
The 'parent label' refers to the label on the bottom layer. The entire compass will be created within this label. It's container is '''main''' for it's parent is the main window.<br />
<syntaxhighlight lang="lua">compass.back = Geyser.Label:new({<br />
name = "compass.back",<br />
x = "25%",<br />
y = "25%",<br />
width = "10%",<br />
height = "10%",<br />
},main)</syntaxhighlight><br />
<br />
====Set the parent label stylesheet====<br />
[[File: blue.png|thumbnail]]<br />
This will create the blue sphere that makes up most of the compass. The background color is a radial gradient that goes from a deep blue to a brighter shade. The border radius rounds the edges. When the radius is exactly half of the label width it forms a circle. The arrows of the compass actually protrude from the sphere so we give it a margin to suck it in a bit for this effect.<br />
<syntaxhighlight lang="lua">compass.back:setStyleSheet([[<br />
background-color: QRadialGradient(cx:.3,cy:1,radius:1,stop:0 rgb(0,0,50),stop:.5 rgb(0,0,100),stop:1 rgb(0,0,255));<br />
border-radius: ]]..tostring(compass.back:get_width()/2-14)..[[px;<br />
margin: 10px;<br />
]])</syntaxhighlight><br />
<br />
====Create a 3x3 grid====<br />
The compass is split into 9 sections. One for each cardinal direction plus an extra space that sits in the center. This 3x3 grid is created by 3 VBoxes that sit within a single HBox (or vice versa but I flipped a coin and this is what it gave me).<br><br />
So first off, we create the HBox. It will be the same size as its parent, ''compass.back''.<br />
<syntaxhighlight lang="lua"> compass.box = Geyser.HBox:new({<br />
name = "compass.box",<br />
x = 0,<br />
y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},compass.back)</syntaxhighlight><br />
Next, we create our 3 VBoxes. You don't need to specify position or size because these are placed within ''compass.box'', an HBox.<br />
<syntaxhighlight lang="lua"> compass.row1 = Geyser.VBox:new({<br />
name = "compass.row1",<br />
},compass.box)<br />
compass.row2 = Geyser.VBox:new({<br />
name = "compass.row2",<br />
},compass.box)<br />
compass.row3 = Geyser.VBox:new({<br />
name = "compass.row3",<br />
},compass.box)</syntaxhighlight><br />
Finally, we add our 9 labels. Take note that they are split up into even groups of 3. Each group is placed into a different ''compass.row#''<br />
<syntaxhighlight lang="lua"> compass.nw = Geyser.Label:new({<br />
name = "compass.nw",<br />
},compass.row1)<br />
<br />
compass.w = Geyser.Label:new({<br />
name = "compass.w",<br />
},compass.row1)<br />
<br />
compass.sw = Geyser.Label:new({<br />
name = "compass.sw",<br />
},compass.row1)<br />
<br />
compass.n = Geyser.Label:new({<br />
name = "compass.n",<br />
},compass.row2)<br />
<br />
compass.center = Geyser.Label:new({<br />
name = "compass.center",<br />
},compass.row2)<br />
<br />
compass.s = Geyser.Label:new({<br />
name = "compass.s",<br />
},compass.row2)<br />
<br />
compass.ne = Geyser.Label:new({<br />
name = "compass.ne",<br />
},compass.row3)<br />
<br />
compass.e = Geyser.Label:new({<br />
name = "compass.e",<br />
},compass.row3)<br />
<br />
compass.se = Geyser.Label:new({<br />
name = "compass.se",<br />
},compass.row3)</syntaxhighlight><br />
====Create a callback function====<br />
We'll want our compass to head in the direction of the arrow we're clicking. This is where we specify so. When the arrow is clicked, this function will be ran with the arrow direction as the argument.<br />
<syntaxhighlight lang="lua">function compass.click(name)<br />
send(name)<br />
end</syntaxhighlight><br />
====Create the hover functions====<br />
We want our arrows to turn yellow when we hover over them. We do so by simply resetting the label's stylesheet and changing the border image. Don't forget to include the margin as we still want that.<br />
<syntaxhighlight lang="lua">function compass.onEnter(name)<br />
compass[name]:setStyleSheet([[<br />
border-image: url("]]..getMudletHomeDir()..[[/]]..name..[[hover.png");<br />
margin: 5px;<br />
]])<br />
end<br />
<br />
function compass.onLeave(name)<br />
compass[name]:setStyleSheet([[<br />
border-image: url("]]..getMudletHomeDir()..[[/]]..name..[[.png");<br />
margin: 5px;<br />
]])<br />
end</syntaxhighlight><br />
====Set the stylesheets in the grid====<br />
[[File: Sample.png|thumb]]<br />
Each of the 9 labels need an image of an arrow. Rather than setting each individually, we'll iterate over the ''compass.dirs'' table we made awhile back and add the respective image to each. The names of images are a reflection of the ''compass.dirs'' table. This keeps it consistent and easy to refer to. During the iteration, the callback, setLabelOnEnter and setLabelOnLeave are also set for each label.<br />
<syntaxhighlight lang="lua">for k,v in pairs(compass.dirs) do<br />
compass[v]:setStyleSheet([[<br />
border-image: url("]]..getMudletHomeDir()..[[/]]..v..[[.png");<br />
margin: 5px;<br />
]])<br />
compass[v]:setClickCallback("compass.click",v)<br />
setLabelOnEnter("compass."..v,"compass.onEnter",v)<br />
setLabelOnLeave("compass."..v,"compass.onLeave",v)<br />
end</syntaxhighlight><br />
<br />
====Resize the compass into a square====<br />
[[File: final.png|thumb]]<br />
Most screen size ratios aren't a perfect 1:1. This will cause a 10% x 10% label to be far from square. By setting our height (the smaller of the two numbers) to our width, we can resize our compass to a near perfect square. This function is also the name of our script because we want it to run each time sysWindowResizeEvent is raised.<br />
<syntaxhighlight lang="lua">function compass.resize()<br />
compass.back:resize(compass.back.width, compass.back:get_width())<br />
end<br />
<br />
compass.resize()</syntaxhighlight><br />
<br />
===Create a Tabbed Window===<br />
[[File: tabwindow.png]]<br />
The following will walk you through the process of creating your own tabbed window using the Geyser framework.<br />
<br />
====Create a new script====<br />
Script Name: '''''Tabbed Window'''''<br><br />
Every snippet of code will be placed within this script.<br />
====Create a global table====<br />
Creating a global table will make each of your variables unique. Our namespace will be called '''''menu''''' and everything we make from here on out will be stored within the menu table. We'll also add a few values to it: tabs, color1, color2, width, height and current. <br><br />
''''tabs'''' will be a table that stores all our tab names. If we want our tabs to have different names, we alter this table.<br><br />
''''color1'''' and ''''color2'''' will store the colors of our tabbed window. If we want to change the color of our tabbed window, we alter these values.<br><br />
''''width'''' and ''''height'''' will store the size of our tabbed window. If we want to change the size of the tabbed window, we alter these values.<br><br />
''''current'''' keeps track of which tab is selected. We will set this to the first tab in the table by default. We do this outside the initial table creation so we can easily access menu.tabs<br><br />
<syntaxhighlight lang="lua">menu = menu or {<br />
tabs = {"Tab1","Tab2","Tab3","Tab4"},<br />
color1 = "rgb(0,0,70)",<br />
color2 = "rgb(0,0,50)",<br />
width = "20%",<br />
height = "40%",<br />
}<br />
menu.current = menu.current or menu.tabs[1]</syntaxhighlight><br />
<br />
====Create the main container====<br />
Our tabbed window will need a container. This will be the bottom layer. Containers are invisible so no need to set a stylesheet.<br />
<syntaxhighlight lang="lua">menu.container = Geyser.Container:new({<br />
name = "menu.back",<br />
x = "50%", y = "25%",<br />
width = menu.width,<br />
height = menu.height,<br />
},main)</syntaxhighlight><br />
====Create an HBox====<br />
All of our tabs will be evenly spaced. So we'll create an HBox to sit at the top of our container.<br />
<syntaxhighlight lang="lua">menu.header = Geyser.HBox:new({<br />
name = "menu.header",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "10%",<br />
},menu.container)</syntaxhighlight><br />
====Create a label====<br />
This label will serve as a container for each window. It sits right underneath the HBox we just created for the tabs.<br />
<syntaxhighlight lang="lua">menu.footer = Geyser.Label:new({<br />
name = "menu.footer",<br />
x = 0, y = "10%",<br />
width = "100%",<br />
height = "90%",<br />
},menu.container)</syntaxhighlight><br />
We don't want this to be a big grey box at startup, so we'll set the stylesheet to appear like the rest of the windows.<br />
<syntaxhighlight lang="lua"><br />
menu.footer:setStyleSheet([[<br />
background-color: ]]..menu.color1..[[;<br />
border-bottom-left-radius: 10px;<br />
border-bottom-right-radius: 10px;<br />
]])</syntaxhighlight><br />
Each window actually has two labels. One for the light blue background, and another for the dark blue center. This will create that dark blue center.<br />
<syntaxhighlight lang="lua">menu.center = Geyser.Label:new({<br />
name = "menu.center",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu.footer)<br />
menu.center:setStyleSheet([[<br />
background-color: ]]..menu.color2..[[;<br />
border-radius: 10px;<br />
margin: 5px;<br />
]])</syntaxhighlight><br />
====Add your tabs and their windows====<br />
Now we'll want to add our tabs and windows. We do this in a single for loop of the ''''menu.tabs'''' table since it holds all our tab names.<br />
<syntaxhighlight lang="lua">for k,v in pairs(menu.tabs) do<br />
</syntaxhighlight><br />
This will create the tabs. Each tab will be named: menu.<tabname>tab<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"] = Geyser.Label:new({<br />
name = "menu."..v.."tab",<br />
},menu.header)<br />
</syntaxhighlight><br />
Here is where we set the tab stylesheet. Each tab has a rounded top, so we set the border-radius of the top-left and top-right to 10px. Each tab has a small space for separation so we give the right and left sides a tiny margin of 1px.<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"]:setStyleSheet([[<br />
background-color: ]]..menu.color1..[[;<br />
border-top-left-radius: 10px;<br />
border-top-right-radius: 10px;<br />
margin-right: 1px;<br />
margin-left: 1px;<br />
]])<br />
</syntaxhighlight><br />
This will display the name of each tab on the tab.<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"]:echo("<center>"..v)<br />
</syntaxhighlight><br />
We need our tabs to do stuff when clicked, so we'll assign it a callback function, '''''menu.click''''', which we'll create later on. Our tab name is the argument.<br />
<syntaxhighlight lang="lua"><br />
menu[v.."tab"]:setClickCallback("menu.click",v)<br />
</syntaxhighlight><br />
Now we create the windows that appear when each tab is clicked. Each window has two labels, one atop the other. The first, which we'll create here, has rounded edges on its bottom.<br />
<syntaxhighlight lang="lua"><br />
menu[v] = Geyser.Label:new({<br />
name = "menu."..v,<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu.footer)<br />
<br />
menu[v]:setStyleSheet([[<br />
background-color: ]]..menu.color1..[[;<br />
border-bottom-left-radius: 10px;<br />
border-bottom-right-radius: 10px;<br />
]])<br />
</syntaxhighlight><br />
The second label serves as the window's center and has rounded edges on all sides. And a margin of 5px from it's parent, the label we just created. When adding stuff to your windows, this is the label you'll want to use. '''''menu.<tabname>center'''''<br />
<syntaxhighlight lang="lua"><br />
menu[v.."center"] = Geyser.Label:new({<br />
name = "menu."..v.."center",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu[v])<br />
</syntaxhighlight><syntaxhighlight lang="lua"><br />
menu[v.."center"]:setStyleSheet([[<br />
background-color: ]]..menu.color2..[[;<br />
border-radius: 10px;<br />
margin: 5px;<br />
]])<br />
</syntaxhighlight><br />
Finally, we hide all the windows and end the for loop.<br />
<syntaxhighlight lang="lua"><br />
menu[v]:hide()<br />
end</syntaxhighlight><br />
====Create a callback function====<br />
The last step is to create our callback function for when a tab is clicked. This will hide that tab that is stored in '''''menu.current''''', set menu.current to the clicked tab, and then show the menu.current tab.<br />
<syntaxhighlight lang="lua">function menu.click(tab)<br />
menu[menu.current]:hide()<br />
menu.current = tab<br />
menu[menu.current]:show()<br />
end</syntaxhighlight><br />
====Adding content to your windows====<br />
Add content to '''menu.<tab name>center'''<br />
So if we wanted to display our gold in a window we could:<syntaxhighlight lang="lua">menu.Tab1center:echo(myGold)</syntaxhighlight><br />
If we wanted to add a map to a window we could:<br />
<syntaxhighlight lang="lua">myMap = Geyser.Mapper:new({<br />
name = "myMap",<br />
x = 0, y = 0,<br />
width = "100%",<br />
height = "100%",<br />
},menu.Tab2center)</syntaxhighlight><br />
<br />
===Create a Window with a resize label===<br />
[[File: resize_window.png]]<br />
This walkthrough will create a window with a smaller label which will let you resize the window.<br />
<br />
====Create a new script====<br />
Script Name: '''''Resize Window'''''<br><br />
Every snippet of code will be placed within this script.<br />
<br />
====Create a window====<br />
Create a window label which will be resizable.<br />
<syntaxhighlight lang="lua">--<br />
-- Create a label that will be resized and contain the drag icon.<br />
---<br />
mLabel = Geyser.Label:new({<br />
name = "mLabel",<br />
x = 400, y = 200,<br />
width = 200, height = 200,<br />
fgColor = "black",<br />
color = "blue",<br />
message = [[<center>drag the white label to resize</center>]]<br />
})<br />
mLabel:setStyleSheet([[qproperty-wordWrap: true]])<br />
</syntaxhighlight><br />
<br />
====Create small icon inside the window====<br />
Create the label that will be used as a drag icon.<br />
<syntaxhighlight lang="lua">--<br />
-- Create the small drag label within the window.<br />
-- The y position is set to "-15px" to align it to<br />
-- the bottom of the main label.<br />
--<br />
mVDrag = Geyser.Label:new({<br />
name = "mVDrag",<br />
x = 85, y = "-15px",<br />
width = 30, height = 15,<br />
fgColor = "black",<br />
color = "white",<br />
}, mLabel)<br />
</syntaxhighlight><br />
<br />
====Create callback functions====<br />
Create the callback functions that will be called by mouse and timer events.<br><br />
<br />
Create a timer function that will be called repeatedly while the mouse button is pressed.<br />
<syntaxhighlight lang="lua"><br />
function onVDragTimer()<br />
local x<br />
local y<br />
local height<br />
<br />
-- Get mouse position<br />
x, y = getMousePosition()<br />
<br />
-- Substract the top of the label to get the new height.<br />
height = y - 200<br />
if height < MIN_HEIGHT then<br />
-- Height is too small.<br />
height = MIN_HEIGHT<br />
end<br />
<br />
-- Set the new size and restart timer.<br />
mLabel:resize(200, height)<br />
vdragtimer = tempTimer(0.2, onVDragTimer)<br />
end<br />
</syntaxhighlight><br><br />
<br />
Create a function which will be called when we first press the icon. The function will create the timer which will trigger as long as the button is pressed.<br />
<syntaxhighlight lang="lua"><br />
function onVDragClick()<br />
-- The user clicked the drag label.<br />
-- Start a temp timer to update the size of the label.<br />
if not exists("vdragtimer", "timer") then<br />
vdragtimer = permTimer("vdragtimer", "", .016, "onVDragTimer()")<br />
end<br />
<br />
enableTimer("vdragtimer")<br />
end<br />
</syntaxhighlight><br><br />
<br />
Create the callback function which will be called when we release the drag icon.<br />
<syntaxhighlight lang="lua"><br />
function onVDragRelease()<br />
-- Button is release so stop timer and updates.<br />
disableTimer("vdragtimer")<br />
end<br />
</syntaxhighlight><br />
<br />
====Set up the callback functions====<br />
Set up the limit how small the window can be, and setup the callback functions.<br />
<syntaxhighlight lang="lua"><br />
MAX_HEIGHT = 100<br />
--<br />
-- Set mouse event callbacks.<br />
--<br />
setLabelClickCallback("mVDrag", "onVDragClick")<br />
setLabelReleaseCallback("mVDrag", "onVDragRelease")<br />
</syntaxhighlight><br />
<br />
====Final result====<br />
The whole script looks like this:<br />
<br />
<syntaxhighlight lang="lua"><br />
--<br />
-- Example: Resize a label.<br />
--<br />
-- Creates a blue label with a smaller white label, which is<br />
-- used to resize the blue label.<br />
--<br />
-- Utilizing:<br />
-- * getMousePosition()<br />
-- * setLabelClickCallback()<br />
-- * setLabelReleaseCallback()<br />
-- * tempTimer().<br />
--<br />
<br />
--<br />
-- Create labels<br />
--<br />
mLabel = Geyser.Label:new({<br />
name = "mLabel",<br />
x = 400, y = 200,<br />
width = 200, height = 200,<br />
})<br />
mLabel:setStyleSheet([[<br />
background-color: rgba(30, 30, 30, 80%);<br />
qproperty-wordWrap: true;<br />
]])<br />
mLabel:setFontSize(10)<br />
mLabel:echo([[<center>Drag the white label to resize.</center>]])<br />
<br />
--<br />
-- Create the small drag label within the window.<br />
-- The y position is set to "-15px" to align it to<br />
-- the bottom of the main label.<br />
mVDrag = Geyser.Label:new({<br />
name = "mVDrag",<br />
x = 85, y = "-15px",<br />
width = 30, height = 15,<br />
fgColor = "black",<br />
color = "white",<br />
}, mLabel)<br />
mVDrag:setStyleSheet([[<br />
border-radius: 6;<br />
background-color: white;<br />
]])<br />
<br />
MIN_HEIGHT = 100<br />
<br />
--<br />
-- Callback functions.<br />
--<br />
function onVDragTimer()<br />
local x<br />
local y<br />
local height<br />
<br />
-- Get mouse position<br />
x, y = getMousePosition()<br />
<br />
-- Substract the top of the label to get the new height.<br />
height = y - 200<br />
if height < MIN_HEIGHT then<br />
-- Height is too small.<br />
height = MIN_HEIGHT<br />
end<br />
<br />
-- Set the new size and restart timer.<br />
mLabel:resize(200, height)<br />
end<br />
<br />
function onVDragClick()<br />
-- The user clicked the drag label.<br />
-- Start a temp timer to update the size of the label.<br />
if not exists("vdragtimer", "timer") then<br />
vdragtimer = permTimer("vdragtimer", "", .016, "onVDragTimer()")<br />
end<br />
<br />
enableTimer("vdragtimer")<br />
end<br />
<br />
function onVDragRelease()<br />
-- Button is release so stop timer and updates.<br />
disableTimer("vdragtimer")<br />
end<br />
<br />
--<br />
-- Set mouse event callbacks.<br />
--<br />
setLabelClickCallback("mVDrag", "onVDragClick")<br />
setLabelReleaseCallback("mVDrag", "onVDragRelease")<br />
</syntaxhighlight><br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Standards:MMP&diff=15632Standards:MMP2020-10-09T08:08:17Z<p>Smurf: de-spaced</p>
<hr />
<div><languages/><br />
<translate><br />
</translate><br />
{{TOC right}}<br />
<translate><br />
</translate><br />
{{Note}}<br />
<translate>This page is a copy of http://www.mudstandards.org/MMP_Specification/ in an effort to preserve the specification as it is implemented in Mudlet.<br />
<br />
= MMP Specification =<br />
<br />
Iron Realms Entertainment (IRE) games are in the process of creating a way to export our in game map data so that clients (or players) can easily access and download this data to use as needed. Rather than creating an IRE specific protocol, it would be much better if this was a universal system for all muds and clients to use and implement.<br />
<br />
This page is barely fleshed out, so hopefully over the next few days we can get this looking much more formalized.<br />
<br />
<br />
== Purpose ==<br />
<br />
Significant testing in the IRE introductory tours has shown a significant drop off of players when they reach portions of the game where movement is involved. This protocol will allow clients to provide quick graphical maps for their users. Of course, this means that introductory clients used for the game (java and flash) should also provide some kind of basic mapping display as this is where new players will first experience your game.<br />
<br />
<br />
== Map Data ==<br />
<br />
IRE is currently exporting the data in the form of a single XML file OR as several XML files. Here are some links to the current files from Imperian.<br />
<br />
<br />
=== What Data? ===<br />
<br />
What data should we be sending out? Here are my initial thoughts:<br />
* Areas<br />
** ID Number<br />
** Name<br />
* Rooms<br />
** ID Number<br />
** Area ID<br />
** Room Title or Brief Desc<br />
** Room Coordinates<br />
** Room Exits and attached room<br />
** Room Features (shop, forge, healer, teacher, etc)<br />
* Environments<br />
** ID Number<br />
** Name<br />
** Color<br />
<br />
Areas will allow clients to<br />
<br />
<br />
=== Format ===<br />
<br />
Should we continue to use XML to do this, we need to make sure the format is standard. Here is an example of what we are currently doing.<br />
<br />
<?xml version="1.0"?><br />
<map><br />
<areas><br />
<area id="1" name="the ruins of Caanae" /><br />
<area id="2" name="the Khuno Acropolis" /><br />
<br />
... areas<br />
<br />
<area id="194" name="Alcine Estate" /><br />
<area id="195" name="Abandoned Tower" /><br />
</areas><br />
<rooms><br />
<room id="8463" area="1" title="Aryana's Spring" environment="8"><br />
<coord x="0" y="0" z="0" /><br />
<exit direction="north" target="8472" /><br />
<exit direction="east" target="8458" /><br />
<exit direction="south" target="8453" /><br />
<exit direction="west" target="8465" /><br />
<exit direction="down" target="8558" /><br />
<exit direction="in" target="17200" /><br />
</room><br />
<br />
... more rooms<br />
<br />
<room id="8472" area="1" title="The empty northern square" environment="8"><br />
<coord x="0" y="1" z="0" /><br />
<exit direction="northeast" target="8519" /><br />
<exit direction="southeast" target="8458" /><br />
<exit direction="south" target="8463" /><br />
<exit direction="southwest" target="8465" /><br />
<exit direction="in" target="7172" /><br />
</room><br />
</rooms><br />
<environments><br />
<environment id="1" name="Dark Forest" color="2" /><br />
<environment id="2" name="Constructed underground" color="3" /><br />
<br />
... more environments<br />
<br />
<environment id="78" name="Scrublands" color="2" /><br />
<environment id="79" name="Tower" color="7" /><br />
</environments><br />
</map><br />
<br />
<br />
=== Examples ===<br />
<br />
All Area, Room, and Environment Data http://www.imperian.com/maps/map.xml<br />
<br />
The Northern Celidon http://www.imperian.com/maps/10.xml<br />
<br />
The Waelin River http://www.imperian.com/maps/12.xml<br />
<br />
Towne of Tirhin http://www.imperian.com/maps/106.xml<br />
<br />
<br />
== Problems ==<br />
<br />
The following may or may not be problems, based on how you feel maps should be displayed.<br />
<br />
<br />
=== Exploration ===<br />
<br />
Part of the fun of playing a new game is exploring the world, learning about new places, and discovering their treasures. One thing we should try to avoid is simply dumping every single room instantly out to the new player. Players who have been around for a while will not mind this, as they know the world already.<br />
<br />
This is probably something that would mainly need to be addressed client side, in how those rooms are hidden, revealed, and displayed.<br />
<br />
<br />
=== Overlapping Rooms ===<br />
<br />
Some people will consider this a problem, others will not. IRE does not like overlapping rooms. It seems most clients do not care. I think it will be up to games to export their data as they want those maps displayed.<br />
</translate></div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=15622Manual:UI Functions2020-10-07T14:36:14Z<p>Smurf: /* getBgColor */</p>
<hr />
<div>{{TOC right}}<br />
= UI Functions =<br />
<br />
All functions that help you customize Mudlet's interface and the game's text.<br />
<br />
==ansi2decho==<br />
;ansi2decho(text, default_colour)<br />
: Converts ANSI colour sequences in <code>text</code> to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.<br />
: See also: [[Manual:Lua_Functions#decho|decho()]]<br />
{{note}}<br />
ANSI bold is available since Mudlet 3.7.1+.<br />
R<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be replaced.<br />
* ''default_colour:''<br />
: Optional - ANSI default colour code (used when handling orphan bold tags).<br />
<br />
;Return values<br />
* ''string text:''<br />
: The decho-valid converted text.<br />
* ''string colour:''<br />
: The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- '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><br />
decho(replaced)<br />
</syntaxhighlight><br />
<br />
Or show a complete colourful squirrel! It's a lotta code to do all the colours, so click the '''Expand''' button on the right to show it:<br />
<div class="toccolours mw-collapsible mw-collapsed"><br />
<syntaxhighlight lang="lua"><br />
decho(ansi2decho([[<br />
�[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m �[0m<br />
╭───────────────────────╮ �[38;5;95m▄▄�[0m �[38;5;95m▄�[48;5;95;38;5;130m▄▄�[48;5;130m█�[38;5;137m▄�[48;5;137;38;5;95m▄�[49m▀�[0m �[0m<br />
│ │ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄▄▄�[48;5;95;38;5;137m▄▄▄�[49;38;5;95m▄▄�[48;5;95;38;5;130m▄�[48;5;130m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[0m �[0m<br />
│ Encrypt everything! │ �[38;5;95m▄�[48;5;187;38;5;16m▄�[48;5;16;38;5;187m▄�[38;5;16m█�[48;5;137;38;5;137m███�[38;5;187m▄�[38;5;16m▄▄�[38;5;137m██�[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[0m �[0m<br />
│ ├──── �[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;16m▄▄▄�[48;5;137m███�[48;5;16;38;5;16m█�[48;5;187m▄�[48;5;16m█�[48;5;137;38;5;137m█�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
╰───────────────────────╯ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;16m▄�[38;5;16m█�[38;5;137m▄�[48;5;137m██████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;95m▀�[48;5;137m▄�[38;5;137m███████�[38;5;95m▄�[49m▀�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[48;5;95;38;5;187m▄▄▄�[38;5;137m▄�[48;5;137m██�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[38;5;95m▀�[48;5;130m▄�[38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;187m████�[48;5;137;38;5;137m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m██�[38;5;95m▄�[38;5;137m█�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;187;38;5;187m████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95m██�[48;5;137m▄▄�[48;5;187;38;5;187m████�[48;5;137;38;5;95m▄▄�[48;5;95;38;5;137m▄�[48;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;187;38;5;187m███�[48;5;95m▄�[38;5;137m▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[49m▄�[48;5;95;38;5;130m▄�[48;5;130m██████�[48;5;137;38;5;137m███�[38;5;95m▄�[49m▀�[0m�[0m<br />
�[48;5;187;38;5;95m▄�[38;5;187m████�[48;5;137;38;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m█████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;137m▄�[38;5;187m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██████�[48;5;95m▄▄�[48;5;130m▄▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▄▄▄�[48;5;95;38;5;137m▄�[48;5;187m▄�[38;5;187m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m█████�[38;5;95m▄�[38;5;137m███████████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀�[48;5;187m▄▄▄�[48;5;95;38;5;137m▄�[48;5;137m██�[38;5;95m▄�[49m▀�[0m �[38;5;95m▀▀�[48;5;137m▄▄▄▄▄▄�[49m▀▀▀�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀▀�[0m �[0m<br />
]]))<br />
</syntaxhighlight><br />
</div><br />
<br />
[[File:Squirrel-in-Mudlet.png|frameless]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.0+<br />
<br />
<br />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be removed.<br />
<br />
;Return values<br />
* ''string text:''<br />
: The plain text without ANSI colour sequences.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10+<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2string('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- 'replaced' should now contain You say in a baritone voice, "Test."<br />
print(replaced)<br />
</syntaxhighlight><br />
<br />
<br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name.<br />
: See also: [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[Manual:Lua_Functions#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</syntaxhighlight><br />
<br />
==bg==<br />
;bg([window, ]colorName)<br />
: Changes the background color of the text. Useful for highlighting text.<br />
: See Also: [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: 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).<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
<br />
-- or echo text with a green background to a miniconsole<br />
bg("my window", "green")<br />
echo("my window", "some green text\n")<br />
</syntaxhighlight><br />
<br />
==calcFontSize==<br />
;calcFontSize(window_or_fontsize, [fontname])<br />
: Returns the average height and width of characters in a particular window, or a font name and size combination. Helpful if you want to size a miniconsole to specific dimensions.<br />
: Returns two numbers, width/height<br />
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
;Parameters<br />
* ''window_or_fontsize:''<br />
: The miniconsole or font size you are wanting to calculate pixel sizes for.<br />
* ''fontname:''<br />
: Specific font name (along with the size as the first argument) to calculate for.<br />
<br />
{{note}}<br />
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide<br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</syntaxhighlight><br />
<br />
==cecho==<br />
;cecho([window], text)<br />
: Echoes text that can be easily formatted with colour tags. You can also include unicode art in it - try some examples from [http://1lineart.kulaone.com/#/ 1lineart].<br />
: See also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cecho("<blue:yellow>Blue on yellow text!")<br />
<br />
-- \n adds a new line<br />
cecho("<red>one line\n<green>another line\n<blue>last line")<br />
<br />
cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
<br />
cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")<br />
<br />
cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")<br />
<br />
cecho([[<br />
██╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗ ████████╗<br />
███║ ██║ ██║████╗ ██║██╔════╝ ██╔══██╗██╔══██╗╚══██╔══╝<br />
╚██║ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝ ██║<br />
██║ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗ ██║<br />
██║ ███████╗██║██║ ╚████║███████╗ ██║ ██║██║ ██║ ██║<br />
╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝<br />
]])<br />
</syntaxhighlight><br />
<br />
==cechoLink==<br />
;cechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#cecho|cecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cechoPopup==<br />
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#cecho|cecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertLink==<br />
;cinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#cinsertText|cinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertPopup==<br />
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#cinsertText|cinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertText==<br />
;cinsertText([window], text)<br />
: inserts text at the current cursor position, with the possibility for color tags.<br />
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cinsertText("<blue:yellow>Blue on yellow text!")<br />
<br />
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
</syntaxhighlight><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].<br />
<br />
==clearWindow==<br />
;clearWindow([windowName])<br />
: Clears the label, mini console, or user window 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 (starting with Mudlet 2.0-test3+)<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this can clear your whole main window - needs Mudlet version >= 2.0<br />
clearWindow()<br />
</syntaxhighlight><br />
<br />
==copy==<br />
; copy([windowName])<br />
: Copies the current selection to the lua virtual clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the lua virtual clipboard until it gets overwritten by another copy operation.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
; Parameters<br />
* ''windowName'' (optional):<br />
: the window from which to copy text - use the main console if not specified.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This script copies the current line on the main screen to a window (miniconsole or userwindow) called 'chat' and gags the output on the main screen.<br />
selectString(line, 1)<br />
copy()<br />
appendBuffer("chat")<br />
replace("This line has been moved to the chat window!")<br />
</syntaxhighlight><br />
<br />
==copy2decho==<br />
; copy2decho([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in decho format.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line.<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and dechos it to a miniconsole named "test"<br />
decho("test", copy2decho())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and decho it to a Geyser miniconsole stored as the variable enemylist<br />
enemylist:decho(copy2decho(matches[2]))<br />
</syntaxhighlight><br />
<br />
==copy2html==<br />
; copy2html([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in html format for echoing to a label.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main"<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and echos it to a label named "TestLabel"<br />
echo("TestLabel", copy2html())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and echo it to a Geyser label stored as the variable enemylist<br />
enemylist:echo(copy2html(matches[2]))<br />
</syntaxhighlight><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: 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.<br />
<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</syntaxhighlight><br />
<br />
==createCommandLine==<br />
;createCommandLine([name of userwindow], name, x, y, width, height)<br />
: Creates a new command line inside the main window of Mudlet. If only a command line inside a miniConsole/UserWindow is needed see [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]].<br />
: You can use [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]] / [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]] and other command line functions to customize the input.<br />
{{note}} [[Manual:UI_Functions#setCmdLineAction|setCmdLineAction]] allows you to attach an action to your command line input.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#disableCommandLine|disableCommandLine()]], [[Manual:Mudlet_Object_Functions#clearCmdLine|clearCmdLine()]], [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]], [[Manual:Mudlet_Object_Functions#printCmdLine|printCmdLine()]], [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the command line is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the command line. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the command line size and location - it is also possible to set them by using [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createCommandLine() will only set them once.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==createConsole==<br />
;createConsole([name of userwindow], consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow your new miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,<br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
''(For Mudlet Makers)'' This function is implemented outside the application's core via the '''GUIUtils.lua''' file of the Mudlet supporting Lua code using [[Manual:UI_Functions#createMiniConsole|createMiniConsole()]] and other functions to position and size the mini-console and configure the font.<br />
<br />
==createGauge==<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the gauge is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: 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<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
* ''orientation:''<br />
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.<br />
<syntaxhighlight lang="lua"><br />
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")<br />
</syntaxhighlight><br />
<br />
==createLabel==<br />
;createLabel([name of userwindow], name, Xpos, Ypos, width, height, fillBackground, [enableClickthrough])<br />
: 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.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]], [[Manual:Lua_Functions#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will display the background color, 0 or false will not.<br />
* ''enableClickthrough:''<br />
: Whether or not enable clickthrough on this label. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will enable clickthrough, 0 or false will not. Optional, defaults to clickthrough not enabled if not provided.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label situated at x=300 y=400 with dimensions 100x200<br />
createLabel("a very basic label",300,400,100,200,1)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle<br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent<br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
<br />
-- you can also make it react to clicks!<br />
mynamespace = {<br />
messageBoxClicked = function()<br />
echo("hey you've clicked the box!\n")<br />
end<br />
}<br />
<br />
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")<br />
<br />
<br />
-- uncomment code below to make it also hide after a short while<br />
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</syntaxhighlight><br />
<br />
==createMiniConsole==<br />
;createMiniConsole([name of userwindow], name, x, y, width, height)<br />
: 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.<br />
: You can use [[Manual:Lua_Functions#clearWindow|clearWindow()]] / [[Manual:Lua_Functions#moveCursor|moveCursor()]] and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. [[Manual:Lua_Functions#setWindowWrap|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 [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent()]], [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|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.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
==creplace==<br />
;creplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, with color names inside angle brackets as with [[Manual:Lua_Functions#cecho|cecho()]]. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
creplace("<magenta>[ALERT!]: <reset>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==creplaceLine==<br />
;creplaceLine (text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''text:''<br />
*: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)<br />
</syntaxhighlight><br />
<br />
==decho==<br />
;decho ([name of console,] text)<br />
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB,[BA]> 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,[BA]>. 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")''.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]]<br />
<br />
;Parameters<br />
* ''name of console''<br />
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.<br />
* ''text:''<br />
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.<br />
<br />
<br />
{{note}}<br />
Optional background transparancy parameter (BA) available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
decho("<50,50,0:0,255,0>test")<br />
<br />
decho("miniconsolename", "<50,50,0:0,255,0>test")<br />
</syntaxhighlight><br />
<br />
==dechoLink==<br />
;dechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#decho|decho()]]. This version allows you to use colours within your link text.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) allows selection between sending the link to a miniconsole or the "main" window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==dechoPopup==<br />
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#decho|decho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertLink==<br />
;dinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#dinsertText|dinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertPopup==<br />
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#dinsertText|dinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
== deleteLabel ==<br />
; deleteLabel(labelName)<br />
<br />
: Deletes and removes a label from the screen. Note that if you'd like to show the label again, it is much more performant to hide/show it instead.<br />
<br />
: Note that you shouldn't use the Geyser label associated with the label you delete afterwards - that doesn't make sense and Geyser right now wouldn't know that it's been deleted, either.<br />
<br />
: See also: [[#hideWindow|hideWindow()]], [[#showWindow|showWindow()]], [[#createLabel|createLabel()]]<br />
<br />
; Parameters<br />
<br />
* ''labelName'': name of the label to delete.<br />
<br />
<syntaxhighlight lang="lua"><br />
createLabel("a very basic label",300,400,100,200,1)<br />
setBackgroundColor("a very basic label", 255, 204, 0, 200)<br />
<br />
-- delete the label after 3 seconds<br />
tempTimer(3, function()<br />
deleteLabel("a very basic label")<br />
end)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 4.5+<br />
<br />
==deleteLine==<br />
;deleteLine([windowName])<br />
: 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. This is purely visual - triggers will still fire on the line as expected.<br />
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.<br />
<br />
{{note}} for replacing text, [[Manual:Lua_Functions#replace|replace()]] is the proper option; doing the following: <code>selectCurrentLine(); replace(""); cecho("new line!\n")</code> is better.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- deletes the line - just put this command into the big script box. Keep the case the same -<br />
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else<br />
deleteLine()<br />
<br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
<br />
-- example of deleting multiple lines:<br />
deleteLine() -- delete the current line<br />
moveCursor(0,getLineNumber()-1) -- move the cursor back one line<br />
deleteLine() -- delete the previous line now<br />
</syntaxhighlight><br />
<br />
==deselect==<br />
;deselect([window name])<br />
: 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.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''window name:''<br />
: (optional) The name of the window to stop having anything selected in. If name is not provided the main window will have its selection cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further<br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</syntaxhighlight><br />
<br />
==disableClickthrough==<br />
; disableClickthrough(label)<br />
: Disables clickthrough for a label - making it act 'normal' again and receive clicks, doubleclicks, onEnter, and onLeave events. This is the default behaviour for labels.<br />
: See also: [[#enableClickthrough|enableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name of the label to restore clickability on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==disableCommandLine==<br />
; disableCommandLine(windowName)<br />
: Disables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableCommandLine|enableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to disable the command line in.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10<br />
<br />
==disableHorizontalScrollBar==<br />
; disableHorizontalScrollBar([windowName])<br />
: Disables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableHorizontalScrollBar|enableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==disableScrollBar==<br />
; disableScrollBar([windowName])<br />
: Disables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==dreplace==<br />
;dreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#decho|decho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
dreplace("<255,0,255>[ALERT!]: <r>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''text:''<br />
: Text to display in the echo. Same as a normal echo().<br />
* ''command:''<br />
: Lua code to do when the link is clicked.<br />
* ''hint:''<br />
: Text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentFormatElseDefault:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
echoLink("press me!", [[send("hi")]], "This is a tooltip")<br />
<br />
-- do the same, but send this link to a miniConsole<br />
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")<br />
</syntaxhighlight><br />
<br />
==echoUserWindow==<br />
;echoUserWindow(windowName)<br />
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.<br />
<br />
==echoPopup==<br />
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==enableClickthrough==<br />
; enableClickthrough(label)<br />
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.<br />
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.<br />
: See also: [[#disableClickthrough|disableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: The name of the label to enable clickthrough on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==enableCommandLine==<br />
; enableCommandLine(windowName)<br />
: Enables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#disableCommandLine|disableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to enable the command line in.<br />
<br />
{{note}} The command line name is the same as the miniConsole name<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableHorizontalScrollBar==<br />
; enableHorizontalScrollBar([windowName])<br />
: Enables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableHorizontalScrollBar|disableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableScrollBar==<br />
; enableScrollBar([windowName])<br />
: Enables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==fg==<br />
; fg([window], colorName)<br />
: 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)<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything or use ''main'' (since Mudlet 3.0).<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
<br />
-- example of working on a miniconsole<br />
fg("my console", "red")<br />
echo("my console", "red text")<br />
</syntaxhighlight><br />
<br />
==getAvailableFonts==<br />
; getAvailableFonts()<br />
: This returns a "font - true" key-value list of available fonts which you can use to verify that Mudlet has access to a given font.<br />
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.<br />
<br />
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]<br />
<br />
{{note}}<br />
Available since Mudlet 3.10<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if Ubuntu Mono is a font we can use<br />
if getAvailableFonts()["Ubuntu Mono"] then<br />
-- make the miniconsole use the font at size 16<br />
setFont("my miniconsole", "Ubuntu Mono")<br />
setFontSize("my miniconsole", 16)<br />
end<br />
</syntaxhighlight><br />
<br />
==getBgColor==<br />
; getBgColor(windowName)<br />
: 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.<br />
<br />
: See also: [[#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r,g,b;<br />
selectString("troll",1)<br />
r,g,b = getBgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
With Mudlet 4.10, '''getBgColor''' returns a fourth integer: the number of (UTF-16) characters with the same color. You can use this length to efficiently split a line into same-color runs.<br />
<br />
==getBorderBottom==<br />
;getBorderBottom()<br />
: Returns the size of the bottom border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
getBorderBottom()<br />
-- returns: 150<br />
</syntaxhighlight><br />
<br />
==getBorderLeft==<br />
;getBorderLeft()<br />
: Returns the size of the left border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
getBorderLeft()<br />
-- returns: 5<br />
</syntaxhighlight><br />
<br />
==getBorderRight==<br />
;getBorderRight()<br />
: Returns the size of the right border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
getBorderRight()<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderSizes==<br />
;getBorderSizes()<br />
: Returns the a named table with the sizes of all borders of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]],[[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0)<br />
getBorderSizes()<br />
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }<br />
getBorderSizes().right<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderTop==<br />
;getBorderTop()<br />
: Returns the size of the top border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
getBorderTop()<br />
-- returns: 100<br />
</syntaxhighlight><br />
<br />
==getClipboardText==<br />
;getClipboardText()<br />
: Returns any text that is currently present in the clipboard. <br />
: See also: [[#setClipboardText | setClipboardText()]]<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local clipboardContents = getClipboardText()<br />
echo("Clipboard: " .. clipboardContents)<br />
</syntaxhighlight><br />
<br />
==getColorWildcard==<br />
; getColorWildcard(ansi color number)<br />
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.<br />
<br />
: See also: [[#isAnsiFgColor|isAnsiFgColor()]], [[#isAnsiBgColor|isAnsiBgColor()]]<br />
<br />
;Parameters<br />
* ''ansi color number:''<br />
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- we can run this script on a line that has the players name coloured differently to easily capture it from<br />
-- anywhere on the line<br />
local match = getColorWildcard(14)<br />
<br />
if match then<br />
echo("\nFound "..match.."!")<br />
else<br />
echo("\nDidn't find anyone.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getColumnCount==<br />
;getColumnCount([windowName])<br />
: Gets the maximum number of columns (characters) that a given window can display on a single row, taking into consideration factors such as window width, font size, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum number of columns on the main window "..getColumnCount())<br />
</syntaxhighlight><br />
<br />
==getColumnNumber==<br />
;getColumnNumber([windowName])<br />
: Gets the absolute column number of the current user cursor.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
<br />
{{note}} the argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
<br />
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
</syntaxhighlight><br />
<br />
==getCurrentLine==<br />
;getCurrentLine([windowName])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Currently selected line: "..getCurrentLine())<br />
</syntaxhighlight><br />
<br />
==getFgColor==<br />
; getFgColor(windowName)<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString("troll",1)<br />
local r,g,b = getFgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is written in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
With Mudlet 4.10, '''getFgColor''' returns a fourth integer: the number of (UTF-16) characters with the same color. You can use this length e.g. to efficiently split a line into same-color runs.<br />
<br />
==getFont==<br />
;getFont(windowName)<br />
: Gets the current font of the given window or console name. Can be used to get font of the main console, dockable userwindows and miniconsoles.<br />
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
display("Font in the main window: "..getFont())<br />
<br />
display("Font in the main window: "..getFont("main"))<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
display("Font size: " .. getFont("user window awesome"))<br />
</syntaxhighlight><br />
<br />
==getFontSize==<br />
;getFontSize(windowName)<br />
: Gets the current font size of the given window or console name. Can be used to get font size of the Main console as well as dockable UserWindows.<br />
: See also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
local mainWindowFontSize = getFontSize()<br />
if mainWindowFontSize then<br />
display("Font size: " .. mainWindowFontSize)<br />
end<br />
<br />
local mainWindowFontSize = getFontSize("main")<br />
if mainWindowFontSize then<br />
display("Font size: " .. fs2)<br />
end<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
local awesomeWindowFontSize = getFontSize("user window awesome")<br />
if awesomeWindowFontSize then<br />
display("Font size: " .. awesomeWindowFontSize)<br />
end<br />
</syntaxhighlight><br />
<br />
==getImageSize==<br />
;getImageSize(imageLocation)<br />
: Returns the width and the height of the given image. If the image can't be found, loaded, or isn't a valid image file - nil+error message will be returned instead.<br />
: See also: [[#createLabel|createLabel()]]<br />
<br />
;Parameters<br />
* ''imageLocation:''<br />
: Path to the image.<br />
<br />
{{note}}<br />
Available in Mudlet 4.5+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local path = getMudletHomeDir().."/my-image.png"<br />
<br />
cecho("Showing dimensions of the picture in: "..path.."\n")<br />
<br />
local width, height = getImageSize(path)<br />
<br />
if not width then<br />
-- in case of an problem, we don't get a height back - but the error message<br />
cecho("error: "..height.."\n")<br />
else<br />
cecho(string.format("They are: %sx%s", width, height))<br />
end<br />
</syntaxhighlight><br />
<br />
==getLastLineNumber==<br />
;getLastLineNumber(windowName)<br />
:Returns the latest line's number in the main window or the miniconsole. This could be different from [[Manual:UI_Functions#getLineNumber|getLineNumber()]] if the cursor was moved around.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the latest line's # in the buffer<br />
local latestline = getLastLineNumber("main")<br />
</syntaxhighlight><br />
<br />
==getLineCount==<br />
;getLineCount()<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
''Need example''<br />
<br />
==getLines==<br />
;getLines([windowName,] from_line_number, to_line_number)<br />
: 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}''.<br />
<br />
:Absolute line numbers are used.<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)<br />
* ''from_line_number:''<br />
: First line number<br />
* ''to_line_number:''<br />
: End line number<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- retrieve & echo the last line:<br />
echo(getLines(getLineNumber()-1, getLineNumber())[1])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- find out which server and port you are connected to (as per Mudlet settings dialog):<br />
local t = getLines(0, getLineNumber())<br />
<br />
local server, port<br />
<br />
for i = 1, #t do<br />
local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")<br />
if s then server, port = s, p break end<br />
end<br />
<br />
display(server)<br />
display(port)<br />
</syntaxhighlight><br />
<br />
==getLineNumber==<br />
;getLineNumber([windowName])<br />
: 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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#moveCursorEnd|moveCursorEnd()]]. This function can come in handy in combination when using with [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#getLines|getLines()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.<br />
<br />
{{note}}<br />
The argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word<br />
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end<br />
<br />
-- check how many lines you've got in your miniconsole after echoing some text.<br />
-- Note the use of moveCursorEnd() to update getLineNumber()'s output<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
print(getLineNumber("HelloWorld"))<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
-- update the cursors position, as it seems to be necessary to do<br />
moveCursorEnd("HelloWorld")<br />
print(getLineNumber("HelloWorld"))<br />
</syntaxhighlight><br />
<br />
==getMainConsoleWidth==<br />
;getMainConsoleWidth()<br />
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.<br />
<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Save width of the main console to a variable for future use.<br />
consoleWidth = getMainConsoleWidth()<br />
</syntaxhighlight><br />
<br />
==getMousePosition==<br />
;getMousePosition()<br />
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{note}} Available since Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- 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<br />
local x, y = getMousePosition()<br />
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)<br />
-- if the label already exists, just move it<br />
moveWindow("clickGeneratedLabel", x, y)<br />
-- and make it easier to notice<br />
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)<br />
</syntaxhighlight><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getUserWindowSize|getUserWindowSize()]], [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your main mudlet window and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</syntaxhighlight><br />
<br />
==getRowCount==<br />
;getRowCount([windowName])<br />
: Gets the maximum number of rows that a given window can display at once, taking into consideration factors such as window height, font type, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum of rows on the main window "..getRowCount())<br />
</syntaxhighlight><br />
<br />
==getSelection==<br />
;getSelection([windowName])<br />
: Returns the text currently selected with [[#selectString|selectString()]], [[#selectSection|selectSection()]], or [[#selectCurrentLine|selectCurrentLine()]]. Note that this isn't the text currently selected with the mouse.<br />
: Also returns the start offset and length of the selection as second and third value.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window to get the selection from. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.16.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
print("Current line contains: "..getSelection())<br />
</syntaxhighlight><br />
<br />
;retrieving the selection<br />
<syntaxhighlight lang="lua"><br />
text,offset,len = getSelection()<br />
-- manipulate the selection, e.g. to discover the color of characters other than the first<br />
-- then restore it<br />
selectSection(offset, len)<br />
</syntaxhighlight><br />
<br />
==getTextFormat==<br />
;getTextFormat([windowName])<br />
: Gets the current text format of the currently selected text. May be used with other console windows. The returned values come in a table containing text attribute names and their values. The values given will be booleans for: bold, italics, underline, overline, strikeout, and reverse - followed by color triplet tables for the foreground and background colors.<br />
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.<br />
<br />
{{note}} Available since Mudlet 3.20.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- A suitable test for getTextFormat()<br />
-- (copy it into an alias or a script)<br />
<br />
clearWindow()<br />
<br />
echo("\n")<br />
<br />
local SGR = string.char(27)..'['<br />
feedTriggers("Format attributes: '"..SGR.."1mBold"..SGR.."0m' '"..SGR.."3mItalic"..SGR.."0m' '"..SGR.."4mUnderline"..SGR.."0m' '"..SGR.."5mBlink"..SGR.."0m' '"..SGR.."6mF.Blink"..SGR.."0m' '"..SGR.."7mReverse"..SGR.."0m' '"..SGR.."9mStruckout"..SGR.."0m' '"..SGR.."53mOverline"..SGR.."0m'.\n")<br />
<br />
moveCursor(1,1)<br />
selectSection(1,1)<br />
<br />
local results = getTextFormat()<br />
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))<br />
echo("\nItalic detected: " .. tostring(results["italic"]))<br />
echo("\nUnderline detected: " .. tostring(results["underline"]))<br />
echo("\nReverse detected: " .. tostring(results["reverse"]))<br />
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))<br />
echo("\nOverline detected: " .. tostring(results["overline"]))<br />
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")<br />
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")<br />
<br />
selectSection(21,1)<br />
echo("\n\nFor individual parts of test text:")<br />
echo("\nBold detected (character 21): " .. tostring(results["bold"]))<br />
<br />
selectSection(28,1)<br />
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))<br />
<br />
selectSection(37,1)<br />
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))<br />
<br />
selectSection(67,1)<br />
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))<br />
<br />
selectSection(77,1)<br />
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))<br />
<br />
selectSection(89,1)<br />
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))<br />
echo("\n")<br />
</syntaxhighlight><br />
<br />
==getUserWindowSize==<br />
{{note}} available in Mudlet 4.6.1+<br />
;getUserWindowSize(windowName)<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the given userwindow dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''windowName''<br />
:the name of the userwindow we will get the dimensions from<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your userwindow named "ChatWindow" and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getUserWindowSize("ChatWindow")<br />
</syntaxhighlight><br />
<br />
==handleWindowResizeEvent==<br />
;handleWindowResizeEvent()<br />
: (''depreciated'') This function is depreciated and should not be used; it's only documented here for historical reference - use the [[Manual:Technical_Manual#sysWindowResizeEvent|sysWindowResizeEvent]] event instead.<br />
<br />
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.<br />
<br />
; Parameters<br />
:None<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
function handleWindowResizeEvent()<br />
-- determine the size of your screen<br />
WindowWidth=0;<br />
WindowHeight=0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
-- move mini console "sys" to the far right side of the screen whenever the screen gets resized<br />
moveWindow("sys",WindowWidth-300,0)<br />
end<br />
</syntaxhighlight><br />
<br />
==hasFocus==<br />
;hasFocus()<br />
: 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). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if attacked and not hasFocus() then<br />
runaway()<br />
else<br />
fight()<br />
end<br />
</syntaxhighlight><br />
<br />
==hecho==<br />
;hecho([windowName], text)<br />
: Echoes text that can be easily formatted with colour tags in the hexadecimal format.<br />
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.<br />
* ''text:''<br />
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #FRFGFB,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 or #r can be used within the string to reset the colors to default. Hexadecimal color codes can be found here: https://www.color-hex.com/<br />
<br />
{{note}}<br />
Transparency for background in hex-format available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hecho("\n#ffffff White text!")<br />
-- your text in white<br />
hecho("\n#ca0004 Red text! And now reset #rit to the default color")<br />
-- your text in red, then reset to default using #r<br />
hecho("\n#ffffff,ca0004 White text with a red background!")<br />
-- your text in white, against a red background<br />
hecho("\n|c0000ff Blue text, this time using |c instead of #")<br />
-- your text in blue, activated with |c vs #.<br />
</syntaxhighlight><br />
<br />
==hechoLink==<br />
;hechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#hecho|hecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
-- # format also works<br />
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==hechoPopup==<br />
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#hecho|hecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertLink==<br />
;hinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#hinsertText|hinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertPopup==<br />
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#hinsertText|hinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hreplace==<br />
;hreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#hecho|hecho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
hreplace("#EE00EE[ALERT!]: #r"..matches[2])<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.5+<br />
<br />
==hideToolBar==<br />
;hideToolBar(name)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to hide<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hideToolBar("my offensive buttons")<br />
</syntaxhighlight><br />
<br />
==hideWindow==<br />
;hideWindow(name)<br />
: This function hides a '''mini console''', a '''user window''' or a '''label''' with the given name. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].<br />
<br />
: See also: [[#createMiniConsole|createMiniConsole()]], [[#createLabel|createLabel()]], [[#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name''<br />
: specifies the label or console you want to hide.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function miniconsoleTest()<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
print("created red window top-right")<br />
<br />
tempTimer(1, function()<br />
hideWindow("sys")<br />
print("hid red window top-right")<br />
end)<br />
<br />
tempTimer(3, function()<br />
showWindow("sys")<br />
print("showed red window top-right")<br />
end)<br />
end<br />
<br />
miniconsoleTest()<br />
</syntaxhighlight><br />
<br />
==insertLink==<br />
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])<br />
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) the window to insert the link in - use either "main" or omit for the main window.<br />
* ''text:''<br />
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) true or false. 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- link with the default blue on white colors<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")<br />
<br />
-- use current cursor colors by adding true at the end<br />
fg("red")<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==insertPopup==<br />
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])<br />
: Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to [[Manual:Lua_Functions#insertText|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''name:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.<br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==insertText==<br />
;insertText([windowName], text)<br />
: Inserts text at cursor postion in window - unlike [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] to move the cursor into position first.<br />
<br />
: insertHTML() also does the same thing as insertText, if you ever come across it.<br />
<br />
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) The window to insert the text to.<br />
* ''text:''<br />
: The text you will insert into the current cursor position.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the cursor to the end of the previous line and insert some text<br />
<br />
-- move to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
-- move the end the of the previous line<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
<br />
fg("dark_slate_gray")<br />
insertText(' <- that looks nice.')<br />
<br />
deselect()<br />
resetFormat()<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
==ioprint==<br />
;ioprint(text, some more text, ...)<br />
:Prints text to the to the stdout. This is only available if you [http://www.wikihow.com/Run-a-Program-on-Command-Prompt launched Mudlet from cmd.exe] on Windows, [http://www.wikihow.com/Open-Applications-Using-Terminal-on-Mac from the terminal] on Mac, or from the terminal on a Linux OS (launch the terminal program, type ''mudlet'' and press enter).<br />
<br />
Similar to [[Manual:Lua_Functions#echo|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.<br />
<br />
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.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
ioprint("hi!")<br />
ioprint(1,2,3)<br />
ioprint(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==isAnsiBgColor==<br />
; isAnsiBgColor(bgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the background color specified by bgColorCode.<br />
<br />
;Parameters<br />
* ''bgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiBgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the background of the text is light green" )<br />
else<br />
echo( "no sorry, some other background color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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 getBgColor() and then handling the color comparison in Lua.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default background color in the zeroth position.''<br />
<br />
==isAnsiFgColor==<br />
; isAnsiFgColor(fgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the foreground color specified by fgColorCode.<br />
<br />
;Parameters<br />
* ''fgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiFgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the text is light green" )<br />
else<br />
echo( "no sorry, some other foreground color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default foreground color in the zeroth position.''<br />
<br />
==lowerWindow==<br />
;lowerWindow(labelName)<br />
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to move below the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top<br />
</syntaxhighlight><br />
<br />
==moveCursor==<br />
;moveCursor([windowName], x, y)<br />
: 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 [[Manual:Lua_Functions#getLineNumber|getLineNumber()]], [[Manual:Lua_Functions#getColumnNumber|getColumnNumber()]] and [[Manual:Lua_Functions#getLastLineNumber|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.<br />
<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The window you are going to move the cursor in.<br />
* ''x:''<br />
: The horizontal axis in the window - that is, the letter position within the line.<br />
* ''y:''<br />
: The vertical axis in the window - that is, the line number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move cursor to the start of the previous line and insert -<(<br />
-- the first 0 means we want the cursor right at the start of the line,<br />
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which<br />
-- equals to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
insertText("-<(")<br />
<br />
-- now we move the cursor at the end of the previous line. Because the<br />
-- cursor is on the previous line already, we can use #getCurrentLine()<br />
-- to see how long it is. We also just do getLineNumber() because getLineNumber()<br />
-- returns the current line # the cursor is on<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
insertText(")>-")<br />
<br />
-- finally, reset it to the end where it was after our shenaningans - other scripts<br />
-- could expect the cursor to be at the end<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a more complicated example showing how to work with Mudlet functions<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
local WindowWidth, WindowHeight = getMainWindowSize()<br />
<br />
-- define a mini console named "sys" and set its background color<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
<br />
-- you *must* set the font size, otherwise mini windows will not work properly<br />
setMiniConsoleFontSize("sys", 12)<br />
-- wrap lines in window "sys" at 65 characters per line<br />
setWindowWrap("sys", 60)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
-- clear the window<br />
clearUserWindow("sys")<br />
<br />
moveCursorEnd("sys")<br />
setFgColor("sys", 10,10,0)<br />
setBgColor("sys", 0,0,255)<br />
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")<br />
echo("sys", "test1---line2\n")<br />
echo("sys", "test1---line3\n")<br />
setTextFormat("sys",158,0,255,255,0,255,0,0,0);<br />
--setFgColor("sys",255,0,0);<br />
echo("sys", "test1---line4\n")<br />
echo("sys", "test1---line5\n")<br />
moveCursor("sys", 1,1)<br />
<br />
-- deleting lines 2+3<br />
deleteLine("sys")<br />
deleteLine("sys")<br />
<br />
-- inserting a line at pos 5,2<br />
moveCursor("sys", 5,2)<br />
setFgColor("sys", 100,100,0)<br />
setBgColor("sys", 255,100,0)<br />
insertText("sys","############## line inserted at pos 5/2 ##############")<br />
<br />
-- inserting a line at pos 0,0<br />
moveCursor("sys", 0,0)<br />
selectCurrentLine("sys")<br />
setFgColor("sys", 255,155,255)<br />
setBold( "sys", true );<br />
setUnderline( "sys", true )<br />
setItalics( "sys", true )<br />
insertText("sys", "------- line inserted at: 0/0 -----\n")<br />
<br />
setBold( "sys", true )<br />
setUnderline( "sys", false )<br />
setItalics( "sys", false )<br />
setFgColor("sys", 255,100,0)<br />
setBgColor("sys", 155,155,0)<br />
echo("sys", "*** This is the end. ***\n")<br />
</syntaxhighlight><br />
<br />
==moveCursorDown==<br />
;moveCursorDown([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window down a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor down by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorUp==<br />
;moveCursorUp([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window up a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor up by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorEnd==<br />
;moveCursorEnd([windowName])<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
: Returns true or false<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveGauge==<br />
;moveGauge(gaugeName, newX, newY)<br />
: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.<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: The name of your gauge<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would move the health bar gauge to the location 1200, 400<br />
moveGauge("healthBar", 1200, 400)<br />
</syntaxhighlight><br />
<br />
==moveWindow==<br />
;moveWindow(name, x, y)<br />
: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.<br />
<br />
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of your window<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles.<br />
<br />
==openUserWindow==<br />
;openUserWindow(windowName, [restoreLayout], [autoDock], [dockingArea])<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).<br />
* ''restoreLayout:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.<br />
* ''autoDock:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't dock automatically at the corners.<br />
* ''dockingArea:''<br />
: (optional) - the area your UserWindow will be docked at. possible docking areas your UserWindow will be created in (f" floating "t" top "b" bottom "r" right and "l" left). Docking area is "right" if not given any value.<br />
<br />
{{note}}<br />
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.<br />
<br />
{{note}}<br />
The parameters autoDock and dockingArea are available since Mudlet 4.7+ <br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
openUserWindow("My floating window")<br />
cecho("My floating window", "<red>hello <blue>bob!")<br />
<br />
-- if you don't want Mudlet to remember its last position:<br />
openUserWindow("My floating window", false)<br />
</syntaxhighlight><br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]]<br />
<br />
==paste==<br />
;paste(windowName)<br />
: Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The [[#copy | copy()]] and [[#paste | 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
<br />
==prefix==<br />
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
:Prefixes text at the beginning of the current line when used in a trigger.<br />
<br />
;Parameters<br />
* ''text:''<br />
: the information you want to prefix<br />
* "writingFunction:"<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* "foregroundColor:"<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* "backgroundColor:"<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* "windowName:"<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that<br />
prefix(os.date("%H:%M:%S "))<br />
-- Prefix the time in red into a miniconsole named "my_console"<br />
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#suffix | suffix()]]<br />
<br />
==print==<br />
;print(text, some more text, ...)<br />
:Prints text to the main window. Similar to [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#display|display()]] for those. This function works similarly to the print() you will see in guides for Lua.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
print("hi!")<br />
print(1,2,3)<br />
print(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==raiseWindow==<br />
;raiseWindow(labelName)<br />
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to bring to the top of the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel<br />
</syntaxhighlight><br />
<br />
==replace==<br />
;replace([windowName], with, [keepcolor])<br />
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.<br />
<br />
{{note}}<br />
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.<br />
<br />
{{note}}<br />
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 | insertText()]] does.<br />
<br />
See also: [[#creplace|creplace]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of window (a miniconsole)<br />
* ''with:''<br />
: the new text to display.<br />
* ''keepcolor:''<br />
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
-- replace word "troll" with "cute trolly"<br />
selectString("troll",1)<br />
replace("cute trolly")<br />
<br />
-- replace the whole line<br />
selectCurrentLine()<br />
replace("Out with the old, in with the new!")<br />
</syntaxhighlight><br />
<br />
==replaceAll==<br />
;replaceAll(what, with, [keepcolor])<br />
: Replaces all occurrences of ''what'' in the current line with ''with''.<br />
<br />
;Parameters<br />
* ''what:''<br />
: the text to replace<br />
{{note}}<br />
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]<br />
* ''with:''<br />
: the new text to have in place<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors.<br />
{{note}} keepcolor available in Mudlet 4.10+, is not in previous versions.<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the word "south" in the line with "north"<br />
replaceAll("south", "north")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the text that the variable "target" has<br />
replaceAll(target, "The Bad Guy")<br />
</syntaxhighlight><br />
<br />
==replaceWildcard==<br />
;replaceWildcard(which, replacement, [keepcolor])<br />
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString(matches[2], 1)<br />
replace("text")<br />
</syntaxhighlight><br />
<br />
;Parameters<br />
* ''which:''<br />
: Wildcard to replace.<br />
* ''replacement:''<br />
: Text to replace the wildcard with.<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors<br />
{{note}} keepcolor available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello<br />
</syntaxhighlight><br />
<br />
==resetCmdLineAction==<br />
;resetCmdLineAction(commandLineName)<br />
: Resets the action on the command line so the it behaves like the main command line again.<br />
;Parameters<br />
<br />
* ''commandLineName''<br />
: The name of the command line the action will be resetet.<br />
: See also: [[#setCmdLineAction | setCmdLineAction()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetConsoleBackgroundImage==<br />
;resetConsoleBackgroundImage([windowName])<br />
: Resets the console background-image<br />
;Parameters<br />
<br />
* ''windowName''<br />
: (optional) name of the console the image will be reset<br />
: See also: [[#setConsoleBackgroundImage | setConsoleBackgroundImage()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: 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.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==resetLabelCursor==<br />
;resetLabelCursor(labelName)<br />
: Resets your mouse cursor to the default one.<br />
<br />
: See also: [[#setLabelCursor|setLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName'': label for which to reset the cursor for.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetLabelCursor("myLabel")<br />
-- This will reset the mouse cursor over myLabel to the default one<br />
</syntaxhighlight><br />
<br />
==resetLabelToolTip==<br />
;resetLabelToolTip(labelName)<br />
: Resets the tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label the tooltip will be reseted.<br />
: See also: [[#setLabelToolTip | setLabelToolTip()]]<br />
<br />
==resetMapWindowTitle==<br />
;resetMapWindowTitle()<br />
: resets the title of the popped out map window to default.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setMapWindowTitle|setMapWindowTitle()]]<br />
<br />
==resetUserWindowTitle==<br />
;resetUserWindowTitle(windowName)<br />
: resets the title of the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow for which the title will be resetet<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setUserWindowTitle|setUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==resizeWindow==<br />
;resizeWindow(windowName, width, height)<br />
: Resizes a mini console, label, or floating User Windows.<br />
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
* ''width:''<br />
: The new width you want<br />
* ''height:''<br />
: The new height you want<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.<br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumber:''<br />
: number of the capture group you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".<br />
--If you want to color the amount of money you have green you do:<br />
<br />
selectCaptureGroup(1)<br />
setFgColor(0,255,0)<br />
</syntaxhighlight><br />
<br />
==selectCurrentLine==<br />
; selectCurrentLine([windowName])<br />
: 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.<br />
<br />
{{note}}<br />
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.<br />
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- color the whole line green!<br />
selectCurrentLine()<br />
fg("green")<br />
deselect()<br />
resetFormat()<br />
<br />
-- to select the previous line, you can do this:<br />
moveCursor(0, getLineNumber()-1)<br />
selectCurrentLine()<br />
<br />
-- to select two lines back, this:<br />
moveCursor(0, getLineNumber()-2)<br />
selectCurrentLine()<br />
<br />
</syntaxhighlight><br />
<br />
==selectSection==<br />
;selectSection( [windowName], fromPosition, length )<br />
: 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.<br />
: 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.<br />
<br />
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]<br />
<br />
;Parameters<br />
* "windowName:"<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.<br />
: Will not work if "main" is given as the windowName to try to select from the main window.<br />
* ''fromPosition:''<br />
: number to specify at which position in the line to begin selecting<br />
* ''length:''<br />
: number to specify the amount of characters you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and colour the first character in the line red<br />
if selectSection(0,1) then fg("red") end<br />
<br />
-- select and colour the second character green (start selecting from the first character, and select 1 character)<br />
if selectSection(1,1) then fg("green") end<br />
<br />
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)<br />
if selectSection(2,3) then fg("grey") end<br />
</syntaxhighlight><br />
<br />
==selectString==<br />
;selectString( [windowName], text, number_of_match )<br />
: 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).<br />
<br />
{{note}}<br />
You can move the user cursor with [[#moveCursor | 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 | deselect()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.<br />
* ''text:''<br />
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).<br />
* ''number_of_match:''<br />
: 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.<br />
<br />
: Returns position in line or -1 on error (text not found in line)<br />
<br />
{{note}}<br />
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if selectString( "big monster", 1 ) > -1 then fg("red") end<br />
</syntaxhighlight><br />
<br />
==setAppStyleSheet==<br />
;setAppStyleSheet(stylesheet [, tag])<br />
: Sets a stylesheet for the entire Mudlet application and every open profile. Because it affects other profiles that might not be related to yours, it's better to use [[#setProfileStyleSheet|setProfileStyleSheet()]] instead of this function.<br />
<br />
: Raises the sysAppStyleSheetChange event which comes with two arguments in addition to the event name. The first is the optional tag which was passed into the function, or "" if nothing was given. The second is the profile which made the stylesheet changes.<br />
<br />
: See also: [[#setProfileStyleSheet|setProfileStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use.<br />
<br />
* ''tag:'' (with Mudlet 3.19+)<br />
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.<br />
<br />
;References<br />
: See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setAppStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
]])<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 3.0.<br />
<br />
Enhanced in Mudlet version 3.19.0 to generate an event that profiles/packages can utilise to redraw any parts of the UI that they themselves had previously styled so their effects can be re-applied to the new application style.<br />
<br />
It is anticipated that the Mudlet application itself will make further use of application styling effects and two strings are provisionally planned for the second parameter in the ''sysAppStyleSheetChange'' event: "''mudlet-theme-dark''" and "''mudlet-theme-light''"; it will also set the third parameter to "''system''".<br />
<br />
==setBackgroundColor==<br />
;setBackgroundColor([windowName], r, g, b, transparency)<br />
: Sets the background for the given label, miniconsole, or userwindow. Colors are from 0 to 255 (0 being black), and transparency is from 0 to 255 (0 being completely transparent).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.<br />
* ''r:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''g:''<br />
: Amount of green to use, from 0 (none) to 255 (full).<br />
* ''b:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).<br />
<br />
{{note}}<br />
Transparency also available for main/miniconsoles in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red label that's somewhat transparent<br />
setBackgroundColor("some label",255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setBackgroundImage==<br />
;setBackgroundImage(labelName, imageLocation)<br />
: Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.<br />
<br />
{{note}}<br />
You can only do this for labels, not miniconsoles.<br />
<br />
{{note}}<br />
You can also load images via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to change it's background color.<br />
* ''imageLocation:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give the top border a nice look<br />
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])<br />
</syntaxhighlight><br />
<br />
==setBgColor==<br />
;setBgColor([windowName], r, g, b, transparency)<br />
: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.<br />
<br />
: ''See also:'' [[#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Optional, if not used color is fully opaque<br />
<br />
<br />
<br />
{{note}}<br />
Transparency parameter available in Mudlet 4.10+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red background color.<br />
selectString( "Tom", 1 )<br />
setBgColor( 255,0,0 )<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--prints "Hello" on red background and "You" on blue.<br />
setBgColor(255,0,0)<br />
echo("Hello")<br />
setBgColor(0,0,255)<br />
echo(" You!")<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBold==<br />
;setBold(windowName, boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
<br />
* ''boolean:''<br />
: A <code>true</code> or <code>false</code> that enables or disables bolding of text<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- enable bold formatting<br />
setBold(true)<br />
-- the following echo will be bolded<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBorderBottom==<br />
;setBorderBottom(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
</syntaxhighlight><br />
<br />
==setBorderColor==<br />
;setBorderColor(red, green, blue)<br />
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]<br />
<br />
;Parameters<br />
* ''red:''<br />
: Amount of red color to use, from 0 to 255.<br />
* ''green:''<br />
: Amount of green color to use, from 0 to 255.<br />
* ''blue:''<br />
: Amount of blue color to use, from 0 to 255.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set the border to be completely blue<br />
setBorderColor(0, 0, 255)<br />
<br />
-- or red, using a name<br />
setBorderColor( unpack(color_table.red) )<br />
</syntaxhighlight><br />
<br />
==setBorderLeft==<br />
;setBorderLeft(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
</syntaxhighlight><br />
<br />
==setBorderRight==<br />
;setBorderRight(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
</syntaxhighlight><br />
<br />
==setBorderSizes==<br />
;setBorderSizes(top, right, bottom, left)<br />
: Sets the size of all borders 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.<br />
: The exact result of this function depends on how many numbers you give to it as arguments.<br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Arguments<br />
* '''setBorderSizes(top, right, bottom, left)'''<br />
: ''4 arguments:'' All borders will be set to their new given size.<br />
* '''setBorderSizes(top, width, bottom)''' <br />
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width. <br />
* '''setBorderSizes(height, width)'''<br />
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width. <br />
* '''setBorderSizes(size)'''<br />
: ''1 argument:'' All borders will be set to the same size.<br />
* '''setBorderSizes()'''<br />
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0) <br />
-- big border at the top, bigger at the bottom, small at the right, none at the left<br />
<br />
setBorderSizes(100, 50, 150) <br />
-- big border at the top, bigger at the bottom, small at the right and the left<br />
<br />
setBorderSizes(100, 50) <br />
-- big border at the top and the bottom, small at the right and the left<br />
<br />
setBorderSizes(100) <br />
-- big borders at all four sides<br />
<br />
setBorderSizes() <br />
-- no borders at all four sides<br />
</syntaxhighlight><br />
<br />
==setBorderTop==<br />
;setBorderTop(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
</syntaxhighlight><br />
<br />
==setFgColor==<br />
;setFgColor([windowName], red, green, blue)<br />
:Sets the current text foreground color in the main window unless windowName parameter given.<br />
<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''red:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''green:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''blue:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]], [[#setHexBgColor | setHexBgColor()]], [[#resetFormat | resetFormat()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setFgColor( 255, 0, 0 )<br />
</syntaxhighlight><br />
<br />
==setButtonStyleSheet==<br />
;setButtonStyleSheet(button, markup)<br />
: Applies Qt style formatting to a button via a special markup language.<br />
<br />
; Parameters<br />
* ''button:''<br />
: The name of the button to be formatted.<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note: You can instead use QWidget { markup }. QWidget will reference 'button', allowing the use of pseudostates like QWidget:hover and QWidget:selected<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setButtonStyleSheet("my test button", [[<br />
QWidget {<br />
background-color: #999999;<br />
border: 3px #777777;<br />
}<br />
QWidget:hover {<br />
background-color: #bbbbbb;<br />
}<br />
QWidget:checked {<br />
background-color: #77bb77;<br />
border: 3px #559955;<br />
}<br />
QWidget:hover:checked {<br />
background-color: #99dd99;<br />
} ]])</syntaxhighlight><br />
<br />
==setClipboardText==<br />
;setClipboardText(textContent)<br />
: Sets the value of the computer's clipboard to the string data provided.<br />
: See also: [[#getClipboardText | getClipboardText()]]<br />
<br />
; Parameters<br />
* ''textContent:''<br />
: The text to be put into the clipboard.<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setClipboardText("New Clipboard Contents")<br />
echo("Clipboard: " .. getClipboardText()) -- should echo "Clipboard: New Clipboard Contents"<br />
</syntaxhighlight><br />
<br />
==setCmdLineAction==<br />
;setCmdLineAction(commandLineName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user sends text to the command line. 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 command line action. Additionally, this function passes the command line input text as the final argument.<br />
{{note}} If no action is set the command line behaves like the main command line and sends commands directly to the game or alias engine.<br />
<br />
The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, text)<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#resetCmdLineAction|resetCmdLineAction()]]<br />
<br />
;Parameters<br />
<br />
* ''commandLineName:''<br />
: The name of the command line to attach the action function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} You can also pass a function directly instead of using a string<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function sendTextToMiniConsole(miniConsoleName, cmdLineText)<br />
echo(miniConsoleName, cmdLineText.."\n")<br />
end<br />
<br />
setCmdLineAction("myCmdLine", "sendTextToMiniConsole", "myMiniConsole")<br />
<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setCmdLineStyleSheet==<br />
;setCmdLineStyleSheet([commandLineName], markup)<br />
: Applies Qt style formatting to a command line via a special markup language.<br />
<br />
;Parameters<br />
* ''commandLineName:''<br />
: (optional) Name of the command line (or miniconsole the command line is in). If not given the stylesheet will be applied to the main command line.<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#createCommandLine|createCommandLine()]]<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- move the main command line over to the right<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
padding-left: 100px; /* change 100 to your number */<br />
background-color: black; /* change it to your background color */<br />
}<br />
]])<br />
<br />
--only change font-size of your main command line<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
font-sizeː20pt; <br />
}<br />
]])<br />
<br />
--change bg/fg color of your miniconsole command line (name of the miniconsole is 'myMiniconsole'<br />
--the command line in the miniconsole has to be enabled<br />
setCmdLineStyleSheet("myMiniConsole", [[<br />
QPlainTextEdit {<br />
background: rgb(0,100,0);<br />
color: rgb(0,200,255);<br />
font-size: 10pt;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
<br />
==setConsoleBackgroundImage==<br />
;setConsoleBackgroundImage([windowname], imageLocation, [mode])<br />
: Loads an image file (for example png) as a background image for a console (main/miniconsole and userwindows).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow to change the background image on, or "main" for the main window.<br />
* ''imageLocation:''<br />
: 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.<br />
* ''mode:''<br />
: (optional) allows different modes for drawing the background image<br />
possible modes areː "border" (the background image is stretched) , 2 "center" (the background image is in the center), <br />
3 "tile" (the background image is 'tiled'), 4 "style" (choose your own background image stylesheet. see example below) <br />
<br />
: See also: [[#resetConsoleBackgroundImage | resetConsoleBackgroundImage()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give my_miniconsole a nice background image and put it in the center<br />
setConsoleBackgroundImage("my_miniconsole", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image with own stylesheet option<br />
setConsoleBackgroundImage("my_miniconsole", [[background-image: url(:/Mudlet_splashscreen_development.png); background-repeat: no-repeat; background-position: right;]], "style")<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setFont==<br />
;setFont(name, font)<br />
: Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Prefer a monospaced font - those work best with text games. See here [https://doc.qt.io/qt-5/qfont.html#setFamily for more].<br />
: See also: [[#getFont|getFont()]], [[#setFontSize|setFontSize()]], [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''font:''<br />
: The font to use.<br />
<br />
{{note}}<br />
Available in Mudlet 3.9+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.<br />
setFont("Ubuntu Mono")<br />
setFont("main", "Ubuntu Mono")<br />
<br />
-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.<br />
setFont("combat", "Ubuntu Mono")<br />
</syntaxhighlight><br />
<br />
==setFontSize==<br />
;setFontSize(name, size)<br />
: Sets a font size on the given window or console name. Can be used to change font size of the Main console as well as dockable UserWindows.<br />
: See Also: [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
* ''size:''<br />
: The font size to apply to the window.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to 12-point font.<br />
setFontSize(12)<br />
setFontSize("main", 12)<br />
<br />
-- This will set the font size of a user window named "uw1" to 12-point font.<br />
setFontSize("uw1", 12)<br />
</syntaxhighlight><br />
<br />
==setGauge==<br />
;setGauge(gaugeName, currentValue, maxValue, gaugeText)<br />
: 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.<br />
<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#createGauge|createGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a gauge<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
--Change the looks of the gauge named healthBar and make it<br />
--fill to half of its capacity. The height is always remembered.<br />
setGauge("healthBar", 200, 400)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
--If you wish to change the text on your gauge, you’d do the following:<br />
setGauge("healthBar", 200, 400, "some text")<br />
</syntaxhighlight><br />
<br />
==setGaugeStyleSheet==<br />
;setGaugeStyleSheet(gaugeName, css, cssback, csstext)<br />
: 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. You can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create stylesheets.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]],<br />
[[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
</syntaxhighlight><br />
<br />
==setGaugeText==<br />
;setGaugeText(gaugename, css, ccstext )<br />
: Set the formatting of the text used inside the inserted gaugename.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
setGaugeText("healthBar", [[<p style="font-weight:bold;color:#C9C9C9;letter-spacing:1pt;word-spacing:2pt;font-size:12px;text-align:center;font-family:arial black, sans-serif;">]]..MY_NUMERIC_VARIABLE_HERE..[[</p>]])</syntaxhighlight><br />
<br />
;Useful resources:<br />
:http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.<br />
:https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!<br />
<br />
==setHexBgColor==<br />
;setHexBgColor([windowName], hexColorString)<br />
:Sets the current text nackground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.<br />
selectString( "Tom", 1 )<br />
setHexBgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setHexFgColor==<br />
;setHexFgColor([windowName], hexColorString)<br />
:Sets the current text foreground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text foreground color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setFgColor | setFgColor()]], [[#setHexBgColor | setHexBgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setHexFgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setItalics==<br />
;setItalics(windowName, bool)<br />
: Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setLabelToolTip==<br />
;setLabelToolTip(labelName, [duration])<br />
: Sets a tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to set the tooltip to.<br />
* ''duration:''<br />
: Duration of the tooltip timeout in seconds. Optional, if not set the default duration will be set.<br />
<br />
: See also: [[Manual:UI_Functions#resetLabelToolTip|resetLabelToolTip()]]<br />
<br />
==setLabelClickCallback==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument. This table contains information about the mouse button clicked, other buttons that were pressed at the time, and the mouse cursor's local (relative to the label) and global (relative to the Mudlet window) position. The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, event)<br />
</syntaxhighlight><br />
<br />
where '''event''' has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
button = "LeftButton",<br />
buttons = {"RightButton", "MidButton"},<br />
}<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]],[[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} Event argument is available in 3.6+, and in 4.8+ you can pass a function directly instead of a string.<br />
<br />
{{note}}<br />
While '''event.button''' may contain a single string of any listed below, '''event.buttons''' will only ever contain some combination of "LeftButton", "MidButton", and "RightButton"<br />
:The following mouse button strings are defined:<br />
<pre><br />
"LeftButton" "RightButton" "MidButton"<br />
"BackButton" "ForwardButton" "TaskButton"<br />
"ExtraButton4" "ExtraButton5" "ExtraButton6"<br />
"ExtraButton7" "ExtraButton8" "ExtraButton9"<br />
"ExtraButton10" "ExtraButton11" "ExtraButton12"<br />
"ExtraButton13" "ExtraButton14" "ExtraButton15"<br />
"ExtraButton16" "ExtraButton17" "ExtraButton18"<br />
"ExtraButton19" "ExtraButton20" "ExtraButton21"<br />
"ExtraButton22" "ExtraButton23" "ExtraButton24"<br />
</pre><br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
else if event.button == "RightButton" then<br />
send("swim north")<br />
else if event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )<br />
<br />
-- you can also use them within tables now:<br />
mynamespace = {<br />
onClickGoNorth = function()<br />
echo("the north button was clicked!")<br />
end<br />
}<br />
<br />
setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )<br />
<br />
</syntaxhighlight><br />
<br />
==setLabelDoubleClickCallback==<br />
;setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user double 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.6+<br />
<br />
: See also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
==setLabelMoveCallback==<br />
;setLabelMoveCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse moves while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
==setLabelOnEnter==<br />
;setLabelOnEnter(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the '''event''' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
}<br />
</syntaxhighlight><br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseOver()<br />
echo("The mouse is hovering over the label!\n")<br />
end<br />
<br />
setLabelOnEnter( "compassNorthImage", "onMouseOver" )<br />
</syntaxhighlight><br />
<br />
==setLabelOnLeave==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseLeft(argument)<br />
echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)<br />
end<br />
<br />
setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )<br />
</syntaxhighlight><br />
<br />
==setLabelReleaseCallback==<br />
;setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
This command was added in version 3.0.0<br />
<br />
{{note}}<br />
The ''event'' argument only available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onReleaseNorth()<br />
echo("the north button was released!")<br />
end<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onReleaseNorth = function()<br />
echo("the north button was released!")<br />
end<br />
}<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )<br />
</syntaxhighlight><br />
<br />
==setLabelStyleSheet==<br />
;setLabelStyleSheet(label, markup)<br />
: Applies Qt style formatting to a label via a special markup language.<br />
<br />
; Parameters<br />
* ''label:''<br />
: The name of the label to be formatted (passed when calling createLabel).<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a white background and a green border, with the text "test"<br />
-- inside.<br />
createLabel("test", 50, 50, 100, 100, 0)<br />
setLabelStyleSheet("test", [[<br />
background-color: white;<br />
border: 10px solid green;<br />
font-size: 12px;<br />
]])<br />
echo("test", "test")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that will tile or clip depending on the<br />
-- size of the label. To use this example, please supply your own image.<br />
createLabel("test5", 50, 353, 164, 55, 0)<br />
setLabelStyleSheet("test5", [[<br />
background-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that can be resized (such as during a<br />
-- sysWindowResizeEvent). To use this example, please supply your own image.<br />
createLabel("test9", 215, 353, 100, 100, 0)<br />
setLabelStyleSheet("test9", [[<br />
border-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--This creates a label whose background changes when the users mouse hovers over it.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
local ourLabelStyle = [[<br />
QLabel{<br />
background-color: ]]..labelBackgroundColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
QLabel::hover{<br />
background-color: ]]..labelHoverColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--Using QLabel::hover mentioned above. Lets "trick" the label into changing it's text.<br />
--Please keep in mind that the setLabelMoveCallback allows for much more control over not just your label but your entire project.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
--Notice we are adding a string returned from a function. In this case, the users profile directory.<br />
local ourLabelStyle = [[<br />
QLabel{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithtext.png");<br />
}<br />
QLabel::hover{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithhovertext.png");<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
--This is just to example that echos draw on top of the label. You would not want to echo onto a label you were drawing text on with images, because echos would draw on top of them.<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<br />
==setLabelCursor==<br />
;setLabelCursor(labelName, cursorShape)<br />
: Changes how the mouse cursor looks like when over the label. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''cursorShape''<br />
: Shape of the mouse cursor. List of possible cursor shapes is [[CursorShapes| available here]].<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCursor("myLabel", "Cross")<br />
-- This will change the mouse cursor to a cross if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelCustomCursor==<br />
;setLabelCustomCursor(labelName, custom cursor, [hotX, hotY])<br />
: Changes the mouse cursor shape over your label to a custom cursor. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCursor|setLabelCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''custom cursor''<br />
: Location of your custom cursor file. To be compatible with all systems it is recommended to use png files with size of 32x32.<br />
* ''hotX''<br />
: X-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
* ''hotY''<br />
: Y-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCustomCursor("myLabel", getMudletHomeDir().."/custom_cursor.png")<br />
-- This will change the mouse cursor to your custom cursor if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelWheelCallback==<br />
;setLabelWheelCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse wheel is scrolled while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the ''event'' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
buttons = {"RightButton", "MidButton"},<br />
angleDeltaX = 0,<br />
angleDeltaY = 120<br />
}<br />
</syntaxhighlight><br />
<br />
: Keys ''angleDeltaX'' and ''angleDeltaY'' correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onWheelNorth(event)<br />
if event.angleDeltaY > 0 then<br />
echo("the north button was wheeled forwards over!")<br />
else<br />
echo("the north button was wheeled backwards over!")<br />
end<br />
end<br />
<br />
setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onWheelNorth = function()<br />
echo("the north button was wheeled over!")<br />
end<br />
}<br />
<br />
setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )<br />
</syntaxhighlight><br />
<br />
==setLink==<br />
;setLink([windowName], command, tooltip)<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of a miniconsole or a userwindow in which to select the text in.<br />
* ''command:''<br />
: command to do when the text is clicked.<br />
* ''tooltip:''<br />
: tooltip to show when the mouse is over the text - explaining what would clicking do.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can clickify a lot of things to save yourself some time - for example, you can change<br />
-- the line where you receive a message to be clickable to read it!<br />
-- prel regex trigger:<br />
-- ^You just received message #(\w+) from \w+\.$<br />
-- script:<br />
selectString(matches[2], 1)<br />
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])<br />
resetFormat()<br />
<br />
-- an example of selecting text in a miniconsole and turning it into a link:<br />
<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
HelloWorld:echo("hi")<br />
selectString("HelloWorld", "hi", 1)<br />
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")<br />
</syntaxhighlight><br />
<br />
==setMainWindowSize==<br />
;setMainWindowSize(mainWidth, mainHeight)<br />
: Changes the size of your main Mudlet window to the values given.<br />
: See Also: [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''mainWidth:''<br />
: The new width in pixels.<br />
* ''mainHeight:''<br />
: The new height in pixels.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will resize your main Mudlet window<br />
setMainWindowSize(1024, 768)<br />
</syntaxhighlight><br />
<br />
==setMapWindowTitle==<br />
;setMapWindowTitle(text)<br />
: Changes the title shown in the mapper window when it's popped out.<br />
: See also: [[#resetMapWindowTitle|resetMapWindowTitle()]]<br />
<br />
; Parameters<br />
* ''text:''<br />
: New window title to set.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapWindowTitle("my cool game map")<br />
</syntaxhighlight><br />
<br />
==setMiniConsoleFontSize==<br />
;setMiniConsoleFontSize(name, fontSize)<br />
: Sets the font size of the mini console. see also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]]<br />
<br />
==setOverline==<br />
;setOverline([windowName], boolean)<br />
: Sets the current text font to be overlined (true) or not overlined (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 overlined. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be overlined until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be overlined or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables overlining of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable overlined text<br />
setOverline(true)<br />
-- the following echo will be have an overline<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and reverse have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==setPopup==<br />
;setPopup(windowName, {lua code}, {hints})<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,<br />
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking<br />
-- will show some commands you can do.<br />
<br />
selectString("Hello", 1)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})<br />
</syntaxhighlight><br />
<br />
==setProfileStyleSheet==<br />
;setProfileStyleSheet(stylesheet)<br />
: Sets a stylesheet for the current Mudlet profile - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). This function is better than setAppStyleSheet() because it affects only the current profile and not every other one as well.<br />
<br />
: See also: [[#setAppStyleSheet|setAppStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use. See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setProfileStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
<br />
QTreeView {<br />
background: ]]..background_color..[[;<br />
color: white;<br />
}<br />
<br />
QMenuBar{ background-color: ]]..background_color..[[;}<br />
<br />
QMenuBar::item{ background-color: ]]..background_color..[[;}<br />
<br />
QDockWidget::title {<br />
background: ]]..border_color..[[;<br />
}<br />
QStatusBar {<br />
background: ]]..border_color..[[;<br />
}<br />
QScrollBar:vertical {<br />
background: ]]..background_color..[[;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background-color: ]]..background_color..[[;<br />
min-height: 20px;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 7px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-bottom-left-radius: 7px;<br />
border-bottom-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-top-left-radius: 7px;<br />
border-top-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
background: white;<br />
width: 4px;<br />
height: 3px;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]])<br />
<br />
-- if you'd like to reset it, use:<br />
setProfileStyleSheet("")<br />
<br />
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':<br />
setProfileStyleSheet[[<br />
TConsole QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
TConsole QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
TConsole QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 4.6.<br />
<br />
==setReverse==<br />
;setReverse([windowName], boolean)<br />
: Sets the current text to swap foreground and background color settings (true) or not (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 have it's colors swapped. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will have their foreground and background colors swapped until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text colors to be reversed or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables reversing of the fore- and back-ground colors of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable fore/back-ground color reversal of text<br />
setReverse(true)<br />
-- the following echo will have the text colors reversed<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and overline have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
{{note}} Although the visual effect on-screen is the same as that of text being selected if both apply to a piece of text they neutralise each other - however the effect of the reversal ''will'' be carried over in copies made by the "Copy to HTML" and in logs made in HTML format log file mode.<br />
<br />
==setStrikeOut==<br />
;setStrikeOut([windowName], boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be striken out until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be stricken out or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables striking out of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable striken-out text<br />
setStrikeOut(true)<br />
-- the following echo will be have a strikethrough<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setTextFormat==<br />
;setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])<br />
: Sets current text format of selected window. This is a more convenient means to set all the individual features at once compared to using [[#setFgColor|setFgColor]]( windowName, r,g,b ), [[#setBold|setBold]]( windowName, true ), [[#setItalics|setItalics]]( windowName, true ), [[#setUnderline|setUnderline]]( windowName, true ), [[#setStrikeOut|setStrikeOut]]( windowName, true ).<br />
: See Also: [[Manual:Lua_Functions#getTextFormat|getTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: Specify name of selected window. If empty string "" or "main" format will be applied to the main console<br />
* ''r1,g1,b1''<br />
: To color text background, give number values in RBG style<br />
* ''r2,g2,b2''<br />
: To color text foreground, give number values in RBG style<br />
* ''bold''<br />
: To format text bold, set to 1 or true, otherwise 0 or false<br />
* ''underline''<br />
: To underline text, set to 1 or true, otherwise 0 or false<br />
* ''italics''<br />
: To format text italic, set to 1 or true, otherwise 0 or false<br />
* ''strikeout<br />
: (optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''overline<br />
: (optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''reverse<br />
: (optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This script would create a mini text console and write with bold, struck-out, yellow foreground color and blue background color "This is a test".<br />
createMiniConsole( "con1", 0,0,300,100);<br />
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);<br />
echo("con1","This is a test")<br />
</syntaxhighlight><br />
<br />
{{note}} In versions prior to 3.7.0 the error messages ''and this wiki'' were wrong in that they had the foreground color parameters as r1, g1 and b1 and the background ones as r2, g2 and b2.<br />
<br />
==setUnderline==<br />
;setUnderline(windowName, bool)<br />
: Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setUserWindowTitle==<br />
;setUserWindowTitle(windowName, text)<br />
: sets a new title text for the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''text''<br />
: new title text<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==setUserWindowStyleSheet==<br />
;setUserWindowStyleSheet(windowName, markup)<br />
: Applies Qt style formatting to the border/title area of a userwindow via a special markup language.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when you dock the userwindow the border style is not provided by this<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- changes the title area style of the UserWindow 'myUserWindow'<br />
setUserWindowStyleSheet("myUserWindow", [[QDockWidget::title{ <br />
background-color: rgb(0,255,150);<br />
border: 2px solid red;<br />
border-radius: 8px;<br />
text-align: center; <br />
}]])<br />
</syntaxhighlight><br />
<br />
: See also: [[#openUserWindow|openUserWindow()]]<br />
<br />
==setWindow==<br />
;setWindow(windowName, name, [Xpos, Ypos, show])<br />
: Changes the parent window of an element.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow which you want the element put in. If you want to put the element into the main window, use windowName "main".<br />
* ''name''<br />
: Name of the element which you want to switch the parent from. Elements can be labels, miniconsoles and the embedded mapper. If you want to move the mapper use the name "mapper"<br />
* ''Xpos:''<br />
: X position of the element. Measured in pixels, with 0 being the very left. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''Ypos:''<br />
: Y position of the element. Measured in pixels, with 0 being the very top. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''show:''<br />
: true or false to decide if the element will be shown or not in the new parent window. Optional, if not given it will be true.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindow("myuserwindow", "mapper")<br />
-- This will put your embedded mapper in your userwindow "myuserwindow".<br />
</syntaxhighlight><br />
<br />
==setWindowWrap==<br />
;setWindowWrap(windowName, wrapAt)<br />
: sets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapAt:''<br />
: Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==setWindowWrapIndent==<br />
;setWindowWrapIndent(windowName, wrapTo)<br />
: sets how many spaces wrapped text will be indented with (after the first line of course).<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapTo:''<br />
: Number of spaces which wrapped lines are prefixed with.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
setWindowWrapIndent("main", 3)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==showCaptureGroups==<br />
;showCaptureGroups()<br />
:Lua debug function that highlights in random colors 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.<br />
<br />
;Example:<br />
: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.<br />
<br />
==showMultimatches==<br />
;showMultimatches()<br />
: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.<br />
<br />
==showWindow==<br />
;showWindow(name)<br />
: Makes a hidden window (label or miniconsole) be shown again.<br />
<br />
: See also: [[#hideWindow | hideWindow()]]<br />
<br />
==showColors==<br />
;showColors([columns], [filterColor], [sort])<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in '''color_table''', in table form. The format is ''color_table.colorName = {r, g, b}''.<br />
<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: (optional) number of columns to print the color table in.<br />
* ''filterColor:''<br />
: (optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.<br />
* ''sort:''<br />
: (optional) sort colors alphabetically.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- display as four columns:<br />
showColors(4)<br />
<br />
-- show only red colours:<br />
showColors("red")<br />
</syntaxhighlight><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)|thumb|center]]<br />
<br />
==showToolBar==<br />
;showToolBar(name)<br />
: Makes a toolbar (a button group) appear on the screen.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
showToolBar("my attack buttons")<br />
</syntaxhighlight><br />
<br />
==suffix==<br />
;suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
: Suffixes text at the end of the current line. This is similar to [[Manual:Lua_Functions#echo | echo()]], which also suffixes text at the end of the line, but different - [[Manual:Lua_Functions#echo | 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.<br />
<br />
;Parameters<br />
* ''text''<br />
: the information you want to prefix<br />
* ''writingFunction''<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* ''foregroundColor''<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* ''backgroundColor''<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* ''windowName''<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
<br />
: See also: [[#prefix | prefix()]], [[Manual:Lua_Functions#echo | echo()]]<br />
<br />
==wrapLine==<br />
;wrapLine(windowName, lineNumber)<br />
: 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.:<br />
<br />
<syntaxhighlight lang="lua">selectString(line,1)<br />
replace("")</syntaxhighlight><br />
<br />
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.<br />
<br />
: See Also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#deleteLine|deleteLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The miniconsole or the main window (use ''main'' for the main window)<br />
* ''lineNumber:''<br />
: The line number which you'd like re-wrapped.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- re-wrap the last line in the main window<br />
wrapLine("main", getLineCount())<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=15621Manual:UI Functions2020-10-07T14:35:55Z<p>Smurf: /* getFgColor */ add length</p>
<hr />
<div>{{TOC right}}<br />
= UI Functions =<br />
<br />
All functions that help you customize Mudlet's interface and the game's text.<br />
<br />
==ansi2decho==<br />
;ansi2decho(text, default_colour)<br />
: Converts ANSI colour sequences in <code>text</code> to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.<br />
: See also: [[Manual:Lua_Functions#decho|decho()]]<br />
{{note}}<br />
ANSI bold is available since Mudlet 3.7.1+.<br />
R<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be replaced.<br />
* ''default_colour:''<br />
: Optional - ANSI default colour code (used when handling orphan bold tags).<br />
<br />
;Return values<br />
* ''string text:''<br />
: The decho-valid converted text.<br />
* ''string colour:''<br />
: The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- '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><br />
decho(replaced)<br />
</syntaxhighlight><br />
<br />
Or show a complete colourful squirrel! It's a lotta code to do all the colours, so click the '''Expand''' button on the right to show it:<br />
<div class="toccolours mw-collapsible mw-collapsed"><br />
<syntaxhighlight lang="lua"><br />
decho(ansi2decho([[<br />
�[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m �[0m<br />
╭───────────────────────╮ �[38;5;95m▄▄�[0m �[38;5;95m▄�[48;5;95;38;5;130m▄▄�[48;5;130m█�[38;5;137m▄�[48;5;137;38;5;95m▄�[49m▀�[0m �[0m<br />
│ │ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄▄▄�[48;5;95;38;5;137m▄▄▄�[49;38;5;95m▄▄�[48;5;95;38;5;130m▄�[48;5;130m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[0m �[0m<br />
│ Encrypt everything! │ �[38;5;95m▄�[48;5;187;38;5;16m▄�[48;5;16;38;5;187m▄�[38;5;16m█�[48;5;137;38;5;137m███�[38;5;187m▄�[38;5;16m▄▄�[38;5;137m██�[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[0m �[0m<br />
│ ├──── �[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;16m▄▄▄�[48;5;137m███�[48;5;16;38;5;16m█�[48;5;187m▄�[48;5;16m█�[48;5;137;38;5;137m█�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
╰───────────────────────╯ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;16m▄�[38;5;16m█�[38;5;137m▄�[48;5;137m██████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;95m▀�[48;5;137m▄�[38;5;137m███████�[38;5;95m▄�[49m▀�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[48;5;95;38;5;187m▄▄▄�[38;5;137m▄�[48;5;137m██�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[38;5;95m▀�[48;5;130m▄�[38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;187m████�[48;5;137;38;5;137m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m██�[38;5;95m▄�[38;5;137m█�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;187;38;5;187m████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95m██�[48;5;137m▄▄�[48;5;187;38;5;187m████�[48;5;137;38;5;95m▄▄�[48;5;95;38;5;137m▄�[48;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;187;38;5;187m███�[48;5;95m▄�[38;5;137m▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[49m▄�[48;5;95;38;5;130m▄�[48;5;130m██████�[48;5;137;38;5;137m███�[38;5;95m▄�[49m▀�[0m�[0m<br />
�[48;5;187;38;5;95m▄�[38;5;187m████�[48;5;137;38;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m█████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;137m▄�[38;5;187m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██████�[48;5;95m▄▄�[48;5;130m▄▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▄▄▄�[48;5;95;38;5;137m▄�[48;5;187m▄�[38;5;187m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m█████�[38;5;95m▄�[38;5;137m███████████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀�[48;5;187m▄▄▄�[48;5;95;38;5;137m▄�[48;5;137m██�[38;5;95m▄�[49m▀�[0m �[38;5;95m▀▀�[48;5;137m▄▄▄▄▄▄�[49m▀▀▀�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀▀�[0m �[0m<br />
]]))<br />
</syntaxhighlight><br />
</div><br />
<br />
[[File:Squirrel-in-Mudlet.png|frameless]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.0+<br />
<br />
<br />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be removed.<br />
<br />
;Return values<br />
* ''string text:''<br />
: The plain text without ANSI colour sequences.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10+<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2string('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- 'replaced' should now contain You say in a baritone voice, "Test."<br />
print(replaced)<br />
</syntaxhighlight><br />
<br />
<br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name.<br />
: See also: [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[Manual:Lua_Functions#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</syntaxhighlight><br />
<br />
==bg==<br />
;bg([window, ]colorName)<br />
: Changes the background color of the text. Useful for highlighting text.<br />
: See Also: [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: 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).<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
<br />
-- or echo text with a green background to a miniconsole<br />
bg("my window", "green")<br />
echo("my window", "some green text\n")<br />
</syntaxhighlight><br />
<br />
==calcFontSize==<br />
;calcFontSize(window_or_fontsize, [fontname])<br />
: Returns the average height and width of characters in a particular window, or a font name and size combination. Helpful if you want to size a miniconsole to specific dimensions.<br />
: Returns two numbers, width/height<br />
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
;Parameters<br />
* ''window_or_fontsize:''<br />
: The miniconsole or font size you are wanting to calculate pixel sizes for.<br />
* ''fontname:''<br />
: Specific font name (along with the size as the first argument) to calculate for.<br />
<br />
{{note}}<br />
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide<br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</syntaxhighlight><br />
<br />
==cecho==<br />
;cecho([window], text)<br />
: Echoes text that can be easily formatted with colour tags. You can also include unicode art in it - try some examples from [http://1lineart.kulaone.com/#/ 1lineart].<br />
: See also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cecho("<blue:yellow>Blue on yellow text!")<br />
<br />
-- \n adds a new line<br />
cecho("<red>one line\n<green>another line\n<blue>last line")<br />
<br />
cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
<br />
cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")<br />
<br />
cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")<br />
<br />
cecho([[<br />
██╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗ ████████╗<br />
███║ ██║ ██║████╗ ██║██╔════╝ ██╔══██╗██╔══██╗╚══██╔══╝<br />
╚██║ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝ ██║<br />
██║ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗ ██║<br />
██║ ███████╗██║██║ ╚████║███████╗ ██║ ██║██║ ██║ ██║<br />
╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝<br />
]])<br />
</syntaxhighlight><br />
<br />
==cechoLink==<br />
;cechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#cecho|cecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cechoPopup==<br />
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#cecho|cecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertLink==<br />
;cinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#cinsertText|cinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertPopup==<br />
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#cinsertText|cinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertText==<br />
;cinsertText([window], text)<br />
: inserts text at the current cursor position, with the possibility for color tags.<br />
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cinsertText("<blue:yellow>Blue on yellow text!")<br />
<br />
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
</syntaxhighlight><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].<br />
<br />
==clearWindow==<br />
;clearWindow([windowName])<br />
: Clears the label, mini console, or user window 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 (starting with Mudlet 2.0-test3+)<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this can clear your whole main window - needs Mudlet version >= 2.0<br />
clearWindow()<br />
</syntaxhighlight><br />
<br />
==copy==<br />
; copy([windowName])<br />
: Copies the current selection to the lua virtual clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the lua virtual clipboard until it gets overwritten by another copy operation.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
; Parameters<br />
* ''windowName'' (optional):<br />
: the window from which to copy text - use the main console if not specified.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This script copies the current line on the main screen to a window (miniconsole or userwindow) called 'chat' and gags the output on the main screen.<br />
selectString(line, 1)<br />
copy()<br />
appendBuffer("chat")<br />
replace("This line has been moved to the chat window!")<br />
</syntaxhighlight><br />
<br />
==copy2decho==<br />
; copy2decho([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in decho format.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line.<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and dechos it to a miniconsole named "test"<br />
decho("test", copy2decho())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and decho it to a Geyser miniconsole stored as the variable enemylist<br />
enemylist:decho(copy2decho(matches[2]))<br />
</syntaxhighlight><br />
<br />
==copy2html==<br />
; copy2html([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in html format for echoing to a label.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main"<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and echos it to a label named "TestLabel"<br />
echo("TestLabel", copy2html())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and echo it to a Geyser label stored as the variable enemylist<br />
enemylist:echo(copy2html(matches[2]))<br />
</syntaxhighlight><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: 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.<br />
<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</syntaxhighlight><br />
<br />
==createCommandLine==<br />
;createCommandLine([name of userwindow], name, x, y, width, height)<br />
: Creates a new command line inside the main window of Mudlet. If only a command line inside a miniConsole/UserWindow is needed see [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]].<br />
: You can use [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]] / [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]] and other command line functions to customize the input.<br />
{{note}} [[Manual:UI_Functions#setCmdLineAction|setCmdLineAction]] allows you to attach an action to your command line input.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#disableCommandLine|disableCommandLine()]], [[Manual:Mudlet_Object_Functions#clearCmdLine|clearCmdLine()]], [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]], [[Manual:Mudlet_Object_Functions#printCmdLine|printCmdLine()]], [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the command line is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the command line. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the command line size and location - it is also possible to set them by using [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createCommandLine() will only set them once.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==createConsole==<br />
;createConsole([name of userwindow], consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow your new miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,<br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
''(For Mudlet Makers)'' This function is implemented outside the application's core via the '''GUIUtils.lua''' file of the Mudlet supporting Lua code using [[Manual:UI_Functions#createMiniConsole|createMiniConsole()]] and other functions to position and size the mini-console and configure the font.<br />
<br />
==createGauge==<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the gauge is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: 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<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
* ''orientation:''<br />
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.<br />
<syntaxhighlight lang="lua"><br />
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")<br />
</syntaxhighlight><br />
<br />
==createLabel==<br />
;createLabel([name of userwindow], name, Xpos, Ypos, width, height, fillBackground, [enableClickthrough])<br />
: 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.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]], [[Manual:Lua_Functions#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will display the background color, 0 or false will not.<br />
* ''enableClickthrough:''<br />
: Whether or not enable clickthrough on this label. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will enable clickthrough, 0 or false will not. Optional, defaults to clickthrough not enabled if not provided.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label situated at x=300 y=400 with dimensions 100x200<br />
createLabel("a very basic label",300,400,100,200,1)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle<br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent<br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
<br />
-- you can also make it react to clicks!<br />
mynamespace = {<br />
messageBoxClicked = function()<br />
echo("hey you've clicked the box!\n")<br />
end<br />
}<br />
<br />
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")<br />
<br />
<br />
-- uncomment code below to make it also hide after a short while<br />
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</syntaxhighlight><br />
<br />
==createMiniConsole==<br />
;createMiniConsole([name of userwindow], name, x, y, width, height)<br />
: 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.<br />
: You can use [[Manual:Lua_Functions#clearWindow|clearWindow()]] / [[Manual:Lua_Functions#moveCursor|moveCursor()]] and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. [[Manual:Lua_Functions#setWindowWrap|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 [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent()]], [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|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.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
==creplace==<br />
;creplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, with color names inside angle brackets as with [[Manual:Lua_Functions#cecho|cecho()]]. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
creplace("<magenta>[ALERT!]: <reset>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==creplaceLine==<br />
;creplaceLine (text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''text:''<br />
*: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)<br />
</syntaxhighlight><br />
<br />
==decho==<br />
;decho ([name of console,] text)<br />
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB,[BA]> 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,[BA]>. 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")''.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]]<br />
<br />
;Parameters<br />
* ''name of console''<br />
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.<br />
* ''text:''<br />
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.<br />
<br />
<br />
{{note}}<br />
Optional background transparancy parameter (BA) available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
decho("<50,50,0:0,255,0>test")<br />
<br />
decho("miniconsolename", "<50,50,0:0,255,0>test")<br />
</syntaxhighlight><br />
<br />
==dechoLink==<br />
;dechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#decho|decho()]]. This version allows you to use colours within your link text.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) allows selection between sending the link to a miniconsole or the "main" window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==dechoPopup==<br />
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#decho|decho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertLink==<br />
;dinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#dinsertText|dinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertPopup==<br />
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#dinsertText|dinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
== deleteLabel ==<br />
; deleteLabel(labelName)<br />
<br />
: Deletes and removes a label from the screen. Note that if you'd like to show the label again, it is much more performant to hide/show it instead.<br />
<br />
: Note that you shouldn't use the Geyser label associated with the label you delete afterwards - that doesn't make sense and Geyser right now wouldn't know that it's been deleted, either.<br />
<br />
: See also: [[#hideWindow|hideWindow()]], [[#showWindow|showWindow()]], [[#createLabel|createLabel()]]<br />
<br />
; Parameters<br />
<br />
* ''labelName'': name of the label to delete.<br />
<br />
<syntaxhighlight lang="lua"><br />
createLabel("a very basic label",300,400,100,200,1)<br />
setBackgroundColor("a very basic label", 255, 204, 0, 200)<br />
<br />
-- delete the label after 3 seconds<br />
tempTimer(3, function()<br />
deleteLabel("a very basic label")<br />
end)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 4.5+<br />
<br />
==deleteLine==<br />
;deleteLine([windowName])<br />
: 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. This is purely visual - triggers will still fire on the line as expected.<br />
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.<br />
<br />
{{note}} for replacing text, [[Manual:Lua_Functions#replace|replace()]] is the proper option; doing the following: <code>selectCurrentLine(); replace(""); cecho("new line!\n")</code> is better.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- deletes the line - just put this command into the big script box. Keep the case the same -<br />
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else<br />
deleteLine()<br />
<br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
<br />
-- example of deleting multiple lines:<br />
deleteLine() -- delete the current line<br />
moveCursor(0,getLineNumber()-1) -- move the cursor back one line<br />
deleteLine() -- delete the previous line now<br />
</syntaxhighlight><br />
<br />
==deselect==<br />
;deselect([window name])<br />
: 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.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''window name:''<br />
: (optional) The name of the window to stop having anything selected in. If name is not provided the main window will have its selection cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further<br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</syntaxhighlight><br />
<br />
==disableClickthrough==<br />
; disableClickthrough(label)<br />
: Disables clickthrough for a label - making it act 'normal' again and receive clicks, doubleclicks, onEnter, and onLeave events. This is the default behaviour for labels.<br />
: See also: [[#enableClickthrough|enableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name of the label to restore clickability on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==disableCommandLine==<br />
; disableCommandLine(windowName)<br />
: Disables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableCommandLine|enableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to disable the command line in.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10<br />
<br />
==disableHorizontalScrollBar==<br />
; disableHorizontalScrollBar([windowName])<br />
: Disables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableHorizontalScrollBar|enableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==disableScrollBar==<br />
; disableScrollBar([windowName])<br />
: Disables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the window to disable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==dreplace==<br />
;dreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#decho|decho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
dreplace("<255,0,255>[ALERT!]: <r>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''text:''<br />
: Text to display in the echo. Same as a normal echo().<br />
* ''command:''<br />
: Lua code to do when the link is clicked.<br />
* ''hint:''<br />
: Text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentFormatElseDefault:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
echoLink("press me!", [[send("hi")]], "This is a tooltip")<br />
<br />
-- do the same, but send this link to a miniConsole<br />
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")<br />
</syntaxhighlight><br />
<br />
==echoUserWindow==<br />
;echoUserWindow(windowName)<br />
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.<br />
<br />
==echoPopup==<br />
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==enableClickthrough==<br />
; enableClickthrough(label)<br />
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.<br />
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.<br />
: See also: [[#disableClickthrough|disableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: The name of the label to enable clickthrough on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==enableCommandLine==<br />
; enableCommandLine(windowName)<br />
: Enables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#disableCommandLine|disableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to enable the command line in.<br />
<br />
{{note}} The command line name is the same as the miniConsole name<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableHorizontalScrollBar==<br />
; enableHorizontalScrollBar([windowName])<br />
: Enables the horizontal scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableHorizontalScrollBar|disableHorizontalScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableScrollBar==<br />
; enableScrollBar([windowName])<br />
: Enables the scroll bar for the miniConsole/userwindow ''windowName'' or the main window<br />
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in. If "main" or not provided it is the main console.<br />
<br />
==fg==<br />
; fg([window], colorName)<br />
: 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)<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything or use ''main'' (since Mudlet 3.0).<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
<br />
-- example of working on a miniconsole<br />
fg("my console", "red")<br />
echo("my console", "red text")<br />
</syntaxhighlight><br />
<br />
==getAvailableFonts==<br />
; getAvailableFonts()<br />
: This returns a "font - true" key-value list of available fonts which you can use to verify that Mudlet has access to a given font.<br />
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.<br />
<br />
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]<br />
<br />
{{note}}<br />
Available since Mudlet 3.10<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if Ubuntu Mono is a font we can use<br />
if getAvailableFonts()["Ubuntu Mono"] then<br />
-- make the miniconsole use the font at size 16<br />
setFont("my miniconsole", "Ubuntu Mono")<br />
setFontSize("my miniconsole", 16)<br />
end<br />
</syntaxhighlight><br />
<br />
==getBgColor==<br />
; getBgColor(windowName)<br />
: 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.<br />
<br />
: See also: [[#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r,g,b;<br />
selectString("troll",1)<br />
r,g,b = getBgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getBorderBottom==<br />
;getBorderBottom()<br />
: Returns the size of the bottom border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
getBorderBottom()<br />
-- returns: 150<br />
</syntaxhighlight><br />
<br />
==getBorderLeft==<br />
;getBorderLeft()<br />
: Returns the size of the left border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
getBorderLeft()<br />
-- returns: 5<br />
</syntaxhighlight><br />
<br />
==getBorderRight==<br />
;getBorderRight()<br />
: Returns the size of the right border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
getBorderRight()<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderSizes==<br />
;getBorderSizes()<br />
: Returns the a named table with the sizes of all borders of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]],[[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0)<br />
getBorderSizes()<br />
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }<br />
getBorderSizes().right<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderTop==<br />
;getBorderTop()<br />
: Returns the size of the top border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
getBorderTop()<br />
-- returns: 100<br />
</syntaxhighlight><br />
<br />
==getClipboardText==<br />
;getClipboardText()<br />
: Returns any text that is currently present in the clipboard. <br />
: See also: [[#setClipboardText | setClipboardText()]]<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local clipboardContents = getClipboardText()<br />
echo("Clipboard: " .. clipboardContents)<br />
</syntaxhighlight><br />
<br />
==getColorWildcard==<br />
; getColorWildcard(ansi color number)<br />
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.<br />
<br />
: See also: [[#isAnsiFgColor|isAnsiFgColor()]], [[#isAnsiBgColor|isAnsiBgColor()]]<br />
<br />
;Parameters<br />
* ''ansi color number:''<br />
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- we can run this script on a line that has the players name coloured differently to easily capture it from<br />
-- anywhere on the line<br />
local match = getColorWildcard(14)<br />
<br />
if match then<br />
echo("\nFound "..match.."!")<br />
else<br />
echo("\nDidn't find anyone.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getColumnCount==<br />
;getColumnCount([windowName])<br />
: Gets the maximum number of columns (characters) that a given window can display on a single row, taking into consideration factors such as window width, font size, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum number of columns on the main window "..getColumnCount())<br />
</syntaxhighlight><br />
<br />
==getColumnNumber==<br />
;getColumnNumber([windowName])<br />
: Gets the absolute column number of the current user cursor.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
<br />
{{note}} the argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
<br />
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
</syntaxhighlight><br />
<br />
==getCurrentLine==<br />
;getCurrentLine([windowName])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Currently selected line: "..getCurrentLine())<br />
</syntaxhighlight><br />
<br />
==getFgColor==<br />
; getFgColor(windowName)<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString("troll",1)<br />
local r,g,b = getFgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is written in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
With Mudlet 4.10, '''getFgColor''' returns a fourth integer: the number of (UTF-16) characters with the same color. You can use this length e.g. to efficiently split a line into same-color runs.<br />
<br />
==getFont==<br />
;getFont(windowName)<br />
: Gets the current font of the given window or console name. Can be used to get font of the main console, dockable userwindows and miniconsoles.<br />
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
display("Font in the main window: "..getFont())<br />
<br />
display("Font in the main window: "..getFont("main"))<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
display("Font size: " .. getFont("user window awesome"))<br />
</syntaxhighlight><br />
<br />
==getFontSize==<br />
;getFontSize(windowName)<br />
: Gets the current font size of the given window or console name. Can be used to get font size of the Main console as well as dockable UserWindows.<br />
: See also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
local mainWindowFontSize = getFontSize()<br />
if mainWindowFontSize then<br />
display("Font size: " .. mainWindowFontSize)<br />
end<br />
<br />
local mainWindowFontSize = getFontSize("main")<br />
if mainWindowFontSize then<br />
display("Font size: " .. fs2)<br />
end<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
local awesomeWindowFontSize = getFontSize("user window awesome")<br />
if awesomeWindowFontSize then<br />
display("Font size: " .. awesomeWindowFontSize)<br />
end<br />
</syntaxhighlight><br />
<br />
==getImageSize==<br />
;getImageSize(imageLocation)<br />
: Returns the width and the height of the given image. If the image can't be found, loaded, or isn't a valid image file - nil+error message will be returned instead.<br />
: See also: [[#createLabel|createLabel()]]<br />
<br />
;Parameters<br />
* ''imageLocation:''<br />
: Path to the image.<br />
<br />
{{note}}<br />
Available in Mudlet 4.5+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local path = getMudletHomeDir().."/my-image.png"<br />
<br />
cecho("Showing dimensions of the picture in: "..path.."\n")<br />
<br />
local width, height = getImageSize(path)<br />
<br />
if not width then<br />
-- in case of an problem, we don't get a height back - but the error message<br />
cecho("error: "..height.."\n")<br />
else<br />
cecho(string.format("They are: %sx%s", width, height))<br />
end<br />
</syntaxhighlight><br />
<br />
==getLastLineNumber==<br />
;getLastLineNumber(windowName)<br />
:Returns the latest line's number in the main window or the miniconsole. This could be different from [[Manual:UI_Functions#getLineNumber|getLineNumber()]] if the cursor was moved around.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the latest line's # in the buffer<br />
local latestline = getLastLineNumber("main")<br />
</syntaxhighlight><br />
<br />
==getLineCount==<br />
;getLineCount()<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
''Need example''<br />
<br />
==getLines==<br />
;getLines([windowName,] from_line_number, to_line_number)<br />
: 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}''.<br />
<br />
:Absolute line numbers are used.<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)<br />
* ''from_line_number:''<br />
: First line number<br />
* ''to_line_number:''<br />
: End line number<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- retrieve & echo the last line:<br />
echo(getLines(getLineNumber()-1, getLineNumber())[1])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- find out which server and port you are connected to (as per Mudlet settings dialog):<br />
local t = getLines(0, getLineNumber())<br />
<br />
local server, port<br />
<br />
for i = 1, #t do<br />
local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")<br />
if s then server, port = s, p break end<br />
end<br />
<br />
display(server)<br />
display(port)<br />
</syntaxhighlight><br />
<br />
==getLineNumber==<br />
;getLineNumber([windowName])<br />
: 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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#moveCursorEnd|moveCursorEnd()]]. This function can come in handy in combination when using with [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#getLines|getLines()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.<br />
<br />
{{note}}<br />
The argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word<br />
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end<br />
<br />
-- check how many lines you've got in your miniconsole after echoing some text.<br />
-- Note the use of moveCursorEnd() to update getLineNumber()'s output<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
print(getLineNumber("HelloWorld"))<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
-- update the cursors position, as it seems to be necessary to do<br />
moveCursorEnd("HelloWorld")<br />
print(getLineNumber("HelloWorld"))<br />
</syntaxhighlight><br />
<br />
==getMainConsoleWidth==<br />
;getMainConsoleWidth()<br />
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.<br />
<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Save width of the main console to a variable for future use.<br />
consoleWidth = getMainConsoleWidth()<br />
</syntaxhighlight><br />
<br />
==getMousePosition==<br />
;getMousePosition()<br />
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{note}} Available since Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- 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<br />
local x, y = getMousePosition()<br />
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)<br />
-- if the label already exists, just move it<br />
moveWindow("clickGeneratedLabel", x, y)<br />
-- and make it easier to notice<br />
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)<br />
</syntaxhighlight><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getUserWindowSize|getUserWindowSize()]], [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your main mudlet window and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</syntaxhighlight><br />
<br />
==getRowCount==<br />
;getRowCount([windowName])<br />
: Gets the maximum number of rows that a given window can display at once, taking into consideration factors such as window height, font type, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum of rows on the main window "..getRowCount())<br />
</syntaxhighlight><br />
<br />
==getSelection==<br />
;getSelection([windowName])<br />
: Returns the text currently selected with [[#selectString|selectString()]], [[#selectSection|selectSection()]], or [[#selectCurrentLine|selectCurrentLine()]]. Note that this isn't the text currently selected with the mouse.<br />
: Also returns the start offset and length of the selection as second and third value.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window to get the selection from. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.16.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
print("Current line contains: "..getSelection())<br />
</syntaxhighlight><br />
<br />
;retrieving the selection<br />
<syntaxhighlight lang="lua"><br />
text,offset,len = getSelection()<br />
-- manipulate the selection, e.g. to discover the color of characters other than the first<br />
-- then restore it<br />
selectSection(offset, len)<br />
</syntaxhighlight><br />
<br />
==getTextFormat==<br />
;getTextFormat([windowName])<br />
: Gets the current text format of the currently selected text. May be used with other console windows. The returned values come in a table containing text attribute names and their values. The values given will be booleans for: bold, italics, underline, overline, strikeout, and reverse - followed by color triplet tables for the foreground and background colors.<br />
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.<br />
<br />
{{note}} Available since Mudlet 3.20.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- A suitable test for getTextFormat()<br />
-- (copy it into an alias or a script)<br />
<br />
clearWindow()<br />
<br />
echo("\n")<br />
<br />
local SGR = string.char(27)..'['<br />
feedTriggers("Format attributes: '"..SGR.."1mBold"..SGR.."0m' '"..SGR.."3mItalic"..SGR.."0m' '"..SGR.."4mUnderline"..SGR.."0m' '"..SGR.."5mBlink"..SGR.."0m' '"..SGR.."6mF.Blink"..SGR.."0m' '"..SGR.."7mReverse"..SGR.."0m' '"..SGR.."9mStruckout"..SGR.."0m' '"..SGR.."53mOverline"..SGR.."0m'.\n")<br />
<br />
moveCursor(1,1)<br />
selectSection(1,1)<br />
<br />
local results = getTextFormat()<br />
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))<br />
echo("\nItalic detected: " .. tostring(results["italic"]))<br />
echo("\nUnderline detected: " .. tostring(results["underline"]))<br />
echo("\nReverse detected: " .. tostring(results["reverse"]))<br />
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))<br />
echo("\nOverline detected: " .. tostring(results["overline"]))<br />
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")<br />
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")<br />
<br />
selectSection(21,1)<br />
echo("\n\nFor individual parts of test text:")<br />
echo("\nBold detected (character 21): " .. tostring(results["bold"]))<br />
<br />
selectSection(28,1)<br />
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))<br />
<br />
selectSection(37,1)<br />
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))<br />
<br />
selectSection(67,1)<br />
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))<br />
<br />
selectSection(77,1)<br />
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))<br />
<br />
selectSection(89,1)<br />
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))<br />
echo("\n")<br />
</syntaxhighlight><br />
<br />
==getUserWindowSize==<br />
{{note}} available in Mudlet 4.6.1+<br />
;getUserWindowSize(windowName)<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the given userwindow dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''windowName''<br />
:the name of the userwindow we will get the dimensions from<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your userwindow named "ChatWindow" and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getUserWindowSize("ChatWindow")<br />
</syntaxhighlight><br />
<br />
==handleWindowResizeEvent==<br />
;handleWindowResizeEvent()<br />
: (''depreciated'') This function is depreciated and should not be used; it's only documented here for historical reference - use the [[Manual:Technical_Manual#sysWindowResizeEvent|sysWindowResizeEvent]] event instead.<br />
<br />
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.<br />
<br />
; Parameters<br />
:None<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
function handleWindowResizeEvent()<br />
-- determine the size of your screen<br />
WindowWidth=0;<br />
WindowHeight=0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
-- move mini console "sys" to the far right side of the screen whenever the screen gets resized<br />
moveWindow("sys",WindowWidth-300,0)<br />
end<br />
</syntaxhighlight><br />
<br />
==hasFocus==<br />
;hasFocus()<br />
: 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). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if attacked and not hasFocus() then<br />
runaway()<br />
else<br />
fight()<br />
end<br />
</syntaxhighlight><br />
<br />
==hecho==<br />
;hecho([windowName], text)<br />
: Echoes text that can be easily formatted with colour tags in the hexadecimal format.<br />
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.<br />
* ''text:''<br />
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #FRFGFB,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 or #r can be used within the string to reset the colors to default. Hexadecimal color codes can be found here: https://www.color-hex.com/<br />
<br />
{{note}}<br />
Transparency for background in hex-format available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hecho("\n#ffffff White text!")<br />
-- your text in white<br />
hecho("\n#ca0004 Red text! And now reset #rit to the default color")<br />
-- your text in red, then reset to default using #r<br />
hecho("\n#ffffff,ca0004 White text with a red background!")<br />
-- your text in white, against a red background<br />
hecho("\n|c0000ff Blue text, this time using |c instead of #")<br />
-- your text in blue, activated with |c vs #.<br />
</syntaxhighlight><br />
<br />
==hechoLink==<br />
;hechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#hecho|hecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
-- # format also works<br />
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==hechoPopup==<br />
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#hecho|hecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertLink==<br />
;hinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#hinsertText|hinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertPopup==<br />
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#hinsertText|hinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hreplace==<br />
;hreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#hecho|hecho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
hreplace("#EE00EE[ALERT!]: #r"..matches[2])<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.5+<br />
<br />
==hideToolBar==<br />
;hideToolBar(name)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to hide<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hideToolBar("my offensive buttons")<br />
</syntaxhighlight><br />
<br />
==hideWindow==<br />
;hideWindow(name)<br />
: This function hides a '''mini console''', a '''user window''' or a '''label''' with the given name. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].<br />
<br />
: See also: [[#createMiniConsole|createMiniConsole()]], [[#createLabel|createLabel()]], [[#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name''<br />
: specifies the label or console you want to hide.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function miniconsoleTest()<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
print("created red window top-right")<br />
<br />
tempTimer(1, function()<br />
hideWindow("sys")<br />
print("hid red window top-right")<br />
end)<br />
<br />
tempTimer(3, function()<br />
showWindow("sys")<br />
print("showed red window top-right")<br />
end)<br />
end<br />
<br />
miniconsoleTest()<br />
</syntaxhighlight><br />
<br />
==insertLink==<br />
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])<br />
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) the window to insert the link in - use either "main" or omit for the main window.<br />
* ''text:''<br />
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) true or false. 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- link with the default blue on white colors<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")<br />
<br />
-- use current cursor colors by adding true at the end<br />
fg("red")<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==insertPopup==<br />
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])<br />
: Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to [[Manual:Lua_Functions#insertText|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''name:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.<br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==insertText==<br />
;insertText([windowName], text)<br />
: Inserts text at cursor postion in window - unlike [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] to move the cursor into position first.<br />
<br />
: insertHTML() also does the same thing as insertText, if you ever come across it.<br />
<br />
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) The window to insert the text to.<br />
* ''text:''<br />
: The text you will insert into the current cursor position.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the cursor to the end of the previous line and insert some text<br />
<br />
-- move to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
-- move the end the of the previous line<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
<br />
fg("dark_slate_gray")<br />
insertText(' <- that looks nice.')<br />
<br />
deselect()<br />
resetFormat()<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
==ioprint==<br />
;ioprint(text, some more text, ...)<br />
:Prints text to the to the stdout. This is only available if you [http://www.wikihow.com/Run-a-Program-on-Command-Prompt launched Mudlet from cmd.exe] on Windows, [http://www.wikihow.com/Open-Applications-Using-Terminal-on-Mac from the terminal] on Mac, or from the terminal on a Linux OS (launch the terminal program, type ''mudlet'' and press enter).<br />
<br />
Similar to [[Manual:Lua_Functions#echo|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.<br />
<br />
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.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
ioprint("hi!")<br />
ioprint(1,2,3)<br />
ioprint(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==isAnsiBgColor==<br />
; isAnsiBgColor(bgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the background color specified by bgColorCode.<br />
<br />
;Parameters<br />
* ''bgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiBgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the background of the text is light green" )<br />
else<br />
echo( "no sorry, some other background color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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 getBgColor() and then handling the color comparison in Lua.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default background color in the zeroth position.''<br />
<br />
==isAnsiFgColor==<br />
; isAnsiFgColor(fgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the foreground color specified by fgColorCode.<br />
<br />
;Parameters<br />
* ''fgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiFgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the text is light green" )<br />
else<br />
echo( "no sorry, some other foreground color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default foreground color in the zeroth position.''<br />
<br />
==lowerWindow==<br />
;lowerWindow(labelName)<br />
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to move below the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top<br />
</syntaxhighlight><br />
<br />
==moveCursor==<br />
;moveCursor([windowName], x, y)<br />
: 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 [[Manual:Lua_Functions#getLineNumber|getLineNumber()]], [[Manual:Lua_Functions#getColumnNumber|getColumnNumber()]] and [[Manual:Lua_Functions#getLastLineNumber|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.<br />
<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The window you are going to move the cursor in.<br />
* ''x:''<br />
: The horizontal axis in the window - that is, the letter position within the line.<br />
* ''y:''<br />
: The vertical axis in the window - that is, the line number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move cursor to the start of the previous line and insert -<(<br />
-- the first 0 means we want the cursor right at the start of the line,<br />
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which<br />
-- equals to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
insertText("-<(")<br />
<br />
-- now we move the cursor at the end of the previous line. Because the<br />
-- cursor is on the previous line already, we can use #getCurrentLine()<br />
-- to see how long it is. We also just do getLineNumber() because getLineNumber()<br />
-- returns the current line # the cursor is on<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
insertText(")>-")<br />
<br />
-- finally, reset it to the end where it was after our shenaningans - other scripts<br />
-- could expect the cursor to be at the end<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a more complicated example showing how to work with Mudlet functions<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
local WindowWidth, WindowHeight = getMainWindowSize()<br />
<br />
-- define a mini console named "sys" and set its background color<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
<br />
-- you *must* set the font size, otherwise mini windows will not work properly<br />
setMiniConsoleFontSize("sys", 12)<br />
-- wrap lines in window "sys" at 65 characters per line<br />
setWindowWrap("sys", 60)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
-- clear the window<br />
clearUserWindow("sys")<br />
<br />
moveCursorEnd("sys")<br />
setFgColor("sys", 10,10,0)<br />
setBgColor("sys", 0,0,255)<br />
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")<br />
echo("sys", "test1---line2\n")<br />
echo("sys", "test1---line3\n")<br />
setTextFormat("sys",158,0,255,255,0,255,0,0,0);<br />
--setFgColor("sys",255,0,0);<br />
echo("sys", "test1---line4\n")<br />
echo("sys", "test1---line5\n")<br />
moveCursor("sys", 1,1)<br />
<br />
-- deleting lines 2+3<br />
deleteLine("sys")<br />
deleteLine("sys")<br />
<br />
-- inserting a line at pos 5,2<br />
moveCursor("sys", 5,2)<br />
setFgColor("sys", 100,100,0)<br />
setBgColor("sys", 255,100,0)<br />
insertText("sys","############## line inserted at pos 5/2 ##############")<br />
<br />
-- inserting a line at pos 0,0<br />
moveCursor("sys", 0,0)<br />
selectCurrentLine("sys")<br />
setFgColor("sys", 255,155,255)<br />
setBold( "sys", true );<br />
setUnderline( "sys", true )<br />
setItalics( "sys", true )<br />
insertText("sys", "------- line inserted at: 0/0 -----\n")<br />
<br />
setBold( "sys", true )<br />
setUnderline( "sys", false )<br />
setItalics( "sys", false )<br />
setFgColor("sys", 255,100,0)<br />
setBgColor("sys", 155,155,0)<br />
echo("sys", "*** This is the end. ***\n")<br />
</syntaxhighlight><br />
<br />
==moveCursorDown==<br />
;moveCursorDown([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window down a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor down by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorUp==<br />
;moveCursorUp([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window up a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor up by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorEnd==<br />
;moveCursorEnd([windowName])<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
: Returns true or false<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveGauge==<br />
;moveGauge(gaugeName, newX, newY)<br />
: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.<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: The name of your gauge<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would move the health bar gauge to the location 1200, 400<br />
moveGauge("healthBar", 1200, 400)<br />
</syntaxhighlight><br />
<br />
==moveWindow==<br />
;moveWindow(name, x, y)<br />
: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.<br />
<br />
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of your window<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles.<br />
<br />
==openUserWindow==<br />
;openUserWindow(windowName, [restoreLayout], [autoDock], [dockingArea])<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).<br />
* ''restoreLayout:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.<br />
* ''autoDock:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't dock automatically at the corners.<br />
* ''dockingArea:''<br />
: (optional) - the area your UserWindow will be docked at. possible docking areas your UserWindow will be created in (f" floating "t" top "b" bottom "r" right and "l" left). Docking area is "right" if not given any value.<br />
<br />
{{note}}<br />
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.<br />
<br />
{{note}}<br />
The parameters autoDock and dockingArea are available since Mudlet 4.7+ <br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
openUserWindow("My floating window")<br />
cecho("My floating window", "<red>hello <blue>bob!")<br />
<br />
-- if you don't want Mudlet to remember its last position:<br />
openUserWindow("My floating window", false)<br />
</syntaxhighlight><br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]]<br />
<br />
==paste==<br />
;paste(windowName)<br />
: Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The [[#copy | copy()]] and [[#paste | 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
<br />
==prefix==<br />
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
:Prefixes text at the beginning of the current line when used in a trigger.<br />
<br />
;Parameters<br />
* ''text:''<br />
: the information you want to prefix<br />
* "writingFunction:"<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* "foregroundColor:"<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* "backgroundColor:"<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* "windowName:"<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that<br />
prefix(os.date("%H:%M:%S "))<br />
-- Prefix the time in red into a miniconsole named "my_console"<br />
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#suffix | suffix()]]<br />
<br />
==print==<br />
;print(text, some more text, ...)<br />
:Prints text to the main window. Similar to [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#display|display()]] for those. This function works similarly to the print() you will see in guides for Lua.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
print("hi!")<br />
print(1,2,3)<br />
print(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==raiseWindow==<br />
;raiseWindow(labelName)<br />
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to bring to the top of the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel<br />
</syntaxhighlight><br />
<br />
==replace==<br />
;replace([windowName], with, [keepcolor])<br />
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.<br />
<br />
{{note}}<br />
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.<br />
<br />
{{note}}<br />
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 | insertText()]] does.<br />
<br />
See also: [[#creplace|creplace]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of window (a miniconsole)<br />
* ''with:''<br />
: the new text to display.<br />
* ''keepcolor:''<br />
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
-- replace word "troll" with "cute trolly"<br />
selectString("troll",1)<br />
replace("cute trolly")<br />
<br />
-- replace the whole line<br />
selectCurrentLine()<br />
replace("Out with the old, in with the new!")<br />
</syntaxhighlight><br />
<br />
==replaceAll==<br />
;replaceAll(what, with, [keepcolor])<br />
: Replaces all occurrences of ''what'' in the current line with ''with''.<br />
<br />
;Parameters<br />
* ''what:''<br />
: the text to replace<br />
{{note}}<br />
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]<br />
* ''with:''<br />
: the new text to have in place<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors.<br />
{{note}} keepcolor available in Mudlet 4.10+, is not in previous versions.<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the word "south" in the line with "north"<br />
replaceAll("south", "north")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the text that the variable "target" has<br />
replaceAll(target, "The Bad Guy")<br />
</syntaxhighlight><br />
<br />
==replaceWildcard==<br />
;replaceWildcard(which, replacement, [keepcolor])<br />
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString(matches[2], 1)<br />
replace("text")<br />
</syntaxhighlight><br />
<br />
;Parameters<br />
* ''which:''<br />
: Wildcard to replace.<br />
* ''replacement:''<br />
: Text to replace the wildcard with.<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors<br />
{{note}} keepcolor available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello<br />
</syntaxhighlight><br />
<br />
==resetCmdLineAction==<br />
;resetCmdLineAction(commandLineName)<br />
: Resets the action on the command line so the it behaves like the main command line again.<br />
;Parameters<br />
<br />
* ''commandLineName''<br />
: The name of the command line the action will be resetet.<br />
: See also: [[#setCmdLineAction | setCmdLineAction()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetConsoleBackgroundImage==<br />
;resetConsoleBackgroundImage([windowName])<br />
: Resets the console background-image<br />
;Parameters<br />
<br />
* ''windowName''<br />
: (optional) name of the console the image will be reset<br />
: See also: [[#setConsoleBackgroundImage | setConsoleBackgroundImage()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: 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.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==resetLabelCursor==<br />
;resetLabelCursor(labelName)<br />
: Resets your mouse cursor to the default one.<br />
<br />
: See also: [[#setLabelCursor|setLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName'': label for which to reset the cursor for.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetLabelCursor("myLabel")<br />
-- This will reset the mouse cursor over myLabel to the default one<br />
</syntaxhighlight><br />
<br />
==resetLabelToolTip==<br />
;resetLabelToolTip(labelName)<br />
: Resets the tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label the tooltip will be reseted.<br />
: See also: [[#setLabelToolTip | setLabelToolTip()]]<br />
<br />
==resetMapWindowTitle==<br />
;resetMapWindowTitle()<br />
: resets the title of the popped out map window to default.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setMapWindowTitle|setMapWindowTitle()]]<br />
<br />
==resetUserWindowTitle==<br />
;resetUserWindowTitle(windowName)<br />
: resets the title of the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow for which the title will be resetet<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setUserWindowTitle|setUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==resizeWindow==<br />
;resizeWindow(windowName, width, height)<br />
: Resizes a mini console, label, or floating User Windows.<br />
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
* ''width:''<br />
: The new width you want<br />
* ''height:''<br />
: The new height you want<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.<br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumber:''<br />
: number of the capture group you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".<br />
--If you want to color the amount of money you have green you do:<br />
<br />
selectCaptureGroup(1)<br />
setFgColor(0,255,0)<br />
</syntaxhighlight><br />
<br />
==selectCurrentLine==<br />
; selectCurrentLine([windowName])<br />
: 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.<br />
<br />
{{note}}<br />
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.<br />
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- color the whole line green!<br />
selectCurrentLine()<br />
fg("green")<br />
deselect()<br />
resetFormat()<br />
<br />
-- to select the previous line, you can do this:<br />
moveCursor(0, getLineNumber()-1)<br />
selectCurrentLine()<br />
<br />
-- to select two lines back, this:<br />
moveCursor(0, getLineNumber()-2)<br />
selectCurrentLine()<br />
<br />
</syntaxhighlight><br />
<br />
==selectSection==<br />
;selectSection( [windowName], fromPosition, length )<br />
: 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.<br />
: 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.<br />
<br />
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]<br />
<br />
;Parameters<br />
* "windowName:"<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.<br />
: Will not work if "main" is given as the windowName to try to select from the main window.<br />
* ''fromPosition:''<br />
: number to specify at which position in the line to begin selecting<br />
* ''length:''<br />
: number to specify the amount of characters you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and colour the first character in the line red<br />
if selectSection(0,1) then fg("red") end<br />
<br />
-- select and colour the second character green (start selecting from the first character, and select 1 character)<br />
if selectSection(1,1) then fg("green") end<br />
<br />
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)<br />
if selectSection(2,3) then fg("grey") end<br />
</syntaxhighlight><br />
<br />
==selectString==<br />
;selectString( [windowName], text, number_of_match )<br />
: 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).<br />
<br />
{{note}}<br />
You can move the user cursor with [[#moveCursor | 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 | deselect()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.<br />
* ''text:''<br />
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).<br />
* ''number_of_match:''<br />
: 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.<br />
<br />
: Returns position in line or -1 on error (text not found in line)<br />
<br />
{{note}}<br />
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if selectString( "big monster", 1 ) > -1 then fg("red") end<br />
</syntaxhighlight><br />
<br />
==setAppStyleSheet==<br />
;setAppStyleSheet(stylesheet [, tag])<br />
: Sets a stylesheet for the entire Mudlet application and every open profile. Because it affects other profiles that might not be related to yours, it's better to use [[#setProfileStyleSheet|setProfileStyleSheet()]] instead of this function.<br />
<br />
: Raises the sysAppStyleSheetChange event which comes with two arguments in addition to the event name. The first is the optional tag which was passed into the function, or "" if nothing was given. The second is the profile which made the stylesheet changes.<br />
<br />
: See also: [[#setProfileStyleSheet|setProfileStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use.<br />
<br />
* ''tag:'' (with Mudlet 3.19+)<br />
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.<br />
<br />
;References<br />
: See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setAppStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
]])<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 3.0.<br />
<br />
Enhanced in Mudlet version 3.19.0 to generate an event that profiles/packages can utilise to redraw any parts of the UI that they themselves had previously styled so their effects can be re-applied to the new application style.<br />
<br />
It is anticipated that the Mudlet application itself will make further use of application styling effects and two strings are provisionally planned for the second parameter in the ''sysAppStyleSheetChange'' event: "''mudlet-theme-dark''" and "''mudlet-theme-light''"; it will also set the third parameter to "''system''".<br />
<br />
==setBackgroundColor==<br />
;setBackgroundColor([windowName], r, g, b, transparency)<br />
: Sets the background for the given label, miniconsole, or userwindow. Colors are from 0 to 255 (0 being black), and transparency is from 0 to 255 (0 being completely transparent).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.<br />
* ''r:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''g:''<br />
: Amount of green to use, from 0 (none) to 255 (full).<br />
* ''b:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).<br />
<br />
{{note}}<br />
Transparency also available for main/miniconsoles in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red label that's somewhat transparent<br />
setBackgroundColor("some label",255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setBackgroundImage==<br />
;setBackgroundImage(labelName, imageLocation)<br />
: Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.<br />
<br />
{{note}}<br />
You can only do this for labels, not miniconsoles.<br />
<br />
{{note}}<br />
You can also load images via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to change it's background color.<br />
* ''imageLocation:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give the top border a nice look<br />
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])<br />
</syntaxhighlight><br />
<br />
==setBgColor==<br />
;setBgColor([windowName], r, g, b, transparency)<br />
: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.<br />
<br />
: ''See also:'' [[#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Optional, if not used color is fully opaque<br />
<br />
<br />
<br />
{{note}}<br />
Transparency parameter available in Mudlet 4.10+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red background color.<br />
selectString( "Tom", 1 )<br />
setBgColor( 255,0,0 )<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--prints "Hello" on red background and "You" on blue.<br />
setBgColor(255,0,0)<br />
echo("Hello")<br />
setBgColor(0,0,255)<br />
echo(" You!")<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBold==<br />
;setBold(windowName, boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
<br />
* ''boolean:''<br />
: A <code>true</code> or <code>false</code> that enables or disables bolding of text<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- enable bold formatting<br />
setBold(true)<br />
-- the following echo will be bolded<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBorderBottom==<br />
;setBorderBottom(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
</syntaxhighlight><br />
<br />
==setBorderColor==<br />
;setBorderColor(red, green, blue)<br />
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]<br />
<br />
;Parameters<br />
* ''red:''<br />
: Amount of red color to use, from 0 to 255.<br />
* ''green:''<br />
: Amount of green color to use, from 0 to 255.<br />
* ''blue:''<br />
: Amount of blue color to use, from 0 to 255.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set the border to be completely blue<br />
setBorderColor(0, 0, 255)<br />
<br />
-- or red, using a name<br />
setBorderColor( unpack(color_table.red) )<br />
</syntaxhighlight><br />
<br />
==setBorderLeft==<br />
;setBorderLeft(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
</syntaxhighlight><br />
<br />
==setBorderRight==<br />
;setBorderRight(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
</syntaxhighlight><br />
<br />
==setBorderSizes==<br />
;setBorderSizes(top, right, bottom, left)<br />
: Sets the size of all borders 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.<br />
: The exact result of this function depends on how many numbers you give to it as arguments.<br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Arguments<br />
* '''setBorderSizes(top, right, bottom, left)'''<br />
: ''4 arguments:'' All borders will be set to their new given size.<br />
* '''setBorderSizes(top, width, bottom)''' <br />
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width. <br />
* '''setBorderSizes(height, width)'''<br />
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width. <br />
* '''setBorderSizes(size)'''<br />
: ''1 argument:'' All borders will be set to the same size.<br />
* '''setBorderSizes()'''<br />
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0) <br />
-- big border at the top, bigger at the bottom, small at the right, none at the left<br />
<br />
setBorderSizes(100, 50, 150) <br />
-- big border at the top, bigger at the bottom, small at the right and the left<br />
<br />
setBorderSizes(100, 50) <br />
-- big border at the top and the bottom, small at the right and the left<br />
<br />
setBorderSizes(100) <br />
-- big borders at all four sides<br />
<br />
setBorderSizes() <br />
-- no borders at all four sides<br />
</syntaxhighlight><br />
<br />
==setBorderTop==<br />
;setBorderTop(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
</syntaxhighlight><br />
<br />
==setFgColor==<br />
;setFgColor([windowName], red, green, blue)<br />
:Sets the current text foreground color in the main window unless windowName parameter given.<br />
<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''red:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''green:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''blue:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]], [[#setHexBgColor | setHexBgColor()]], [[#resetFormat | resetFormat()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setFgColor( 255, 0, 0 )<br />
</syntaxhighlight><br />
<br />
==setButtonStyleSheet==<br />
;setButtonStyleSheet(button, markup)<br />
: Applies Qt style formatting to a button via a special markup language.<br />
<br />
; Parameters<br />
* ''button:''<br />
: The name of the button to be formatted.<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note: You can instead use QWidget { markup }. QWidget will reference 'button', allowing the use of pseudostates like QWidget:hover and QWidget:selected<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setButtonStyleSheet("my test button", [[<br />
QWidget {<br />
background-color: #999999;<br />
border: 3px #777777;<br />
}<br />
QWidget:hover {<br />
background-color: #bbbbbb;<br />
}<br />
QWidget:checked {<br />
background-color: #77bb77;<br />
border: 3px #559955;<br />
}<br />
QWidget:hover:checked {<br />
background-color: #99dd99;<br />
} ]])</syntaxhighlight><br />
<br />
==setClipboardText==<br />
;setClipboardText(textContent)<br />
: Sets the value of the computer's clipboard to the string data provided.<br />
: See also: [[#getClipboardText | getClipboardText()]]<br />
<br />
; Parameters<br />
* ''textContent:''<br />
: The text to be put into the clipboard.<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setClipboardText("New Clipboard Contents")<br />
echo("Clipboard: " .. getClipboardText()) -- should echo "Clipboard: New Clipboard Contents"<br />
</syntaxhighlight><br />
<br />
==setCmdLineAction==<br />
;setCmdLineAction(commandLineName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user sends text to the command line. 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 command line action. Additionally, this function passes the command line input text as the final argument.<br />
{{note}} If no action is set the command line behaves like the main command line and sends commands directly to the game or alias engine.<br />
<br />
The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, text)<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#resetCmdLineAction|resetCmdLineAction()]]<br />
<br />
;Parameters<br />
<br />
* ''commandLineName:''<br />
: The name of the command line to attach the action function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} You can also pass a function directly instead of using a string<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function sendTextToMiniConsole(miniConsoleName, cmdLineText)<br />
echo(miniConsoleName, cmdLineText.."\n")<br />
end<br />
<br />
setCmdLineAction("myCmdLine", "sendTextToMiniConsole", "myMiniConsole")<br />
<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setCmdLineStyleSheet==<br />
;setCmdLineStyleSheet([commandLineName], markup)<br />
: Applies Qt style formatting to a command line via a special markup language.<br />
<br />
;Parameters<br />
* ''commandLineName:''<br />
: (optional) Name of the command line (or miniconsole the command line is in). If not given the stylesheet will be applied to the main command line.<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#createCommandLine|createCommandLine()]]<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- move the main command line over to the right<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
padding-left: 100px; /* change 100 to your number */<br />
background-color: black; /* change it to your background color */<br />
}<br />
]])<br />
<br />
--only change font-size of your main command line<br />
setCmdLineStyleSheet("main", [[<br />
QPlainTextEdit {<br />
font-sizeː20pt; <br />
}<br />
]])<br />
<br />
--change bg/fg color of your miniconsole command line (name of the miniconsole is 'myMiniconsole'<br />
--the command line in the miniconsole has to be enabled<br />
setCmdLineStyleSheet("myMiniConsole", [[<br />
QPlainTextEdit {<br />
background: rgb(0,100,0);<br />
color: rgb(0,200,255);<br />
font-size: 10pt;<br />
}<br />
]])<br />
</syntaxhighlight><br />
<br />
<br />
==setConsoleBackgroundImage==<br />
;setConsoleBackgroundImage([windowname], imageLocation, [mode])<br />
: Loads an image file (for example png) as a background image for a console (main/miniconsole and userwindows).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow to change the background image on, or "main" for the main window.<br />
* ''imageLocation:''<br />
: 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.<br />
* ''mode:''<br />
: (optional) allows different modes for drawing the background image<br />
possible modes areː "border" (the background image is stretched) , 2 "center" (the background image is in the center), <br />
3 "tile" (the background image is 'tiled'), 4 "style" (choose your own background image stylesheet. see example below) <br />
<br />
: See also: [[#resetConsoleBackgroundImage | resetConsoleBackgroundImage()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give my_miniconsole a nice background image and put it in the center<br />
setConsoleBackgroundImage("my_miniconsole", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image with own stylesheet option<br />
setConsoleBackgroundImage("my_miniconsole", [[background-image: url(:/Mudlet_splashscreen_development.png); background-repeat: no-repeat; background-position: right;]], "style")<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setFont==<br />
;setFont(name, font)<br />
: Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Prefer a monospaced font - those work best with text games. See here [https://doc.qt.io/qt-5/qfont.html#setFamily for more].<br />
: See also: [[#getFont|getFont()]], [[#setFontSize|setFontSize()]], [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''font:''<br />
: The font to use.<br />
<br />
{{note}}<br />
Available in Mudlet 3.9+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.<br />
setFont("Ubuntu Mono")<br />
setFont("main", "Ubuntu Mono")<br />
<br />
-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.<br />
setFont("combat", "Ubuntu Mono")<br />
</syntaxhighlight><br />
<br />
==setFontSize==<br />
;setFontSize(name, size)<br />
: Sets a font size on the given window or console name. Can be used to change font size of the Main console as well as dockable UserWindows.<br />
: See Also: [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
* ''size:''<br />
: The font size to apply to the window.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to 12-point font.<br />
setFontSize(12)<br />
setFontSize("main", 12)<br />
<br />
-- This will set the font size of a user window named "uw1" to 12-point font.<br />
setFontSize("uw1", 12)<br />
</syntaxhighlight><br />
<br />
==setGauge==<br />
;setGauge(gaugeName, currentValue, maxValue, gaugeText)<br />
: 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.<br />
<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#createGauge|createGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a gauge<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
--Change the looks of the gauge named healthBar and make it<br />
--fill to half of its capacity. The height is always remembered.<br />
setGauge("healthBar", 200, 400)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
--If you wish to change the text on your gauge, you’d do the following:<br />
setGauge("healthBar", 200, 400, "some text")<br />
</syntaxhighlight><br />
<br />
==setGaugeStyleSheet==<br />
;setGaugeStyleSheet(gaugeName, css, cssback, csstext)<br />
: 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. You can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create stylesheets.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]],<br />
[[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
</syntaxhighlight><br />
<br />
==setGaugeText==<br />
;setGaugeText(gaugename, css, ccstext )<br />
: Set the formatting of the text used inside the inserted gaugename.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
setGaugeText("healthBar", [[<p style="font-weight:bold;color:#C9C9C9;letter-spacing:1pt;word-spacing:2pt;font-size:12px;text-align:center;font-family:arial black, sans-serif;">]]..MY_NUMERIC_VARIABLE_HERE..[[</p>]])</syntaxhighlight><br />
<br />
;Useful resources:<br />
:http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.<br />
:https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!<br />
<br />
==setHexBgColor==<br />
;setHexBgColor([windowName], hexColorString)<br />
:Sets the current text nackground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.<br />
selectString( "Tom", 1 )<br />
setHexBgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setHexFgColor==<br />
;setHexFgColor([windowName], hexColorString)<br />
:Sets the current text foreground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text foreground color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setFgColor | setFgColor()]], [[#setHexBgColor | setHexBgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setHexFgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setItalics==<br />
;setItalics(windowName, bool)<br />
: Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setLabelToolTip==<br />
;setLabelToolTip(labelName, [duration])<br />
: Sets a tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to set the tooltip to.<br />
* ''duration:''<br />
: Duration of the tooltip timeout in seconds. Optional, if not set the default duration will be set.<br />
<br />
: See also: [[Manual:UI_Functions#resetLabelToolTip|resetLabelToolTip()]]<br />
<br />
==setLabelClickCallback==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument. This table contains information about the mouse button clicked, other buttons that were pressed at the time, and the mouse cursor's local (relative to the label) and global (relative to the Mudlet window) position. The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, event)<br />
</syntaxhighlight><br />
<br />
where '''event''' has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
button = "LeftButton",<br />
buttons = {"RightButton", "MidButton"},<br />
}<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]],[[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} Event argument is available in 3.6+, and in 4.8+ you can pass a function directly instead of a string.<br />
<br />
{{note}}<br />
While '''event.button''' may contain a single string of any listed below, '''event.buttons''' will only ever contain some combination of "LeftButton", "MidButton", and "RightButton"<br />
:The following mouse button strings are defined:<br />
<pre><br />
"LeftButton" "RightButton" "MidButton"<br />
"BackButton" "ForwardButton" "TaskButton"<br />
"ExtraButton4" "ExtraButton5" "ExtraButton6"<br />
"ExtraButton7" "ExtraButton8" "ExtraButton9"<br />
"ExtraButton10" "ExtraButton11" "ExtraButton12"<br />
"ExtraButton13" "ExtraButton14" "ExtraButton15"<br />
"ExtraButton16" "ExtraButton17" "ExtraButton18"<br />
"ExtraButton19" "ExtraButton20" "ExtraButton21"<br />
"ExtraButton22" "ExtraButton23" "ExtraButton24"<br />
</pre><br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
else if event.button == "RightButton" then<br />
send("swim north")<br />
else if event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )<br />
<br />
-- you can also use them within tables now:<br />
mynamespace = {<br />
onClickGoNorth = function()<br />
echo("the north button was clicked!")<br />
end<br />
}<br />
<br />
setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )<br />
<br />
</syntaxhighlight><br />
<br />
==setLabelDoubleClickCallback==<br />
;setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user double 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.6+<br />
<br />
: See also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
==setLabelMoveCallback==<br />
;setLabelMoveCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse moves while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
==setLabelOnEnter==<br />
;setLabelOnEnter(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the '''event''' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
}<br />
</syntaxhighlight><br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseOver()<br />
echo("The mouse is hovering over the label!\n")<br />
end<br />
<br />
setLabelOnEnter( "compassNorthImage", "onMouseOver" )<br />
</syntaxhighlight><br />
<br />
==setLabelOnLeave==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseLeft(argument)<br />
echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)<br />
end<br />
<br />
setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )<br />
</syntaxhighlight><br />
<br />
==setLabelReleaseCallback==<br />
;setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
This command was added in version 3.0.0<br />
<br />
{{note}}<br />
The ''event'' argument only available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onReleaseNorth()<br />
echo("the north button was released!")<br />
end<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onReleaseNorth = function()<br />
echo("the north button was released!")<br />
end<br />
}<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )<br />
</syntaxhighlight><br />
<br />
==setLabelStyleSheet==<br />
;setLabelStyleSheet(label, markup)<br />
: Applies Qt style formatting to a label via a special markup language.<br />
<br />
; Parameters<br />
* ''label:''<br />
: The name of the label to be formatted (passed when calling createLabel).<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a white background and a green border, with the text "test"<br />
-- inside.<br />
createLabel("test", 50, 50, 100, 100, 0)<br />
setLabelStyleSheet("test", [[<br />
background-color: white;<br />
border: 10px solid green;<br />
font-size: 12px;<br />
]])<br />
echo("test", "test")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that will tile or clip depending on the<br />
-- size of the label. To use this example, please supply your own image.<br />
createLabel("test5", 50, 353, 164, 55, 0)<br />
setLabelStyleSheet("test5", [[<br />
background-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that can be resized (such as during a<br />
-- sysWindowResizeEvent). To use this example, please supply your own image.<br />
createLabel("test9", 215, 353, 100, 100, 0)<br />
setLabelStyleSheet("test9", [[<br />
border-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--This creates a label whose background changes when the users mouse hovers over it.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
local ourLabelStyle = [[<br />
QLabel{<br />
background-color: ]]..labelBackgroundColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
QLabel::hover{<br />
background-color: ]]..labelHoverColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--Using QLabel::hover mentioned above. Lets "trick" the label into changing it's text.<br />
--Please keep in mind that the setLabelMoveCallback allows for much more control over not just your label but your entire project.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
--Notice we are adding a string returned from a function. In this case, the users profile directory.<br />
local ourLabelStyle = [[<br />
QLabel{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithtext.png");<br />
}<br />
QLabel::hover{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithhovertext.png");<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
--This is just to example that echos draw on top of the label. You would not want to echo onto a label you were drawing text on with images, because echos would draw on top of them.<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<br />
==setLabelCursor==<br />
;setLabelCursor(labelName, cursorShape)<br />
: Changes how the mouse cursor looks like when over the label. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''cursorShape''<br />
: Shape of the mouse cursor. List of possible cursor shapes is [[CursorShapes| available here]].<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCursor("myLabel", "Cross")<br />
-- This will change the mouse cursor to a cross if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelCustomCursor==<br />
;setLabelCustomCursor(labelName, custom cursor, [hotX, hotY])<br />
: Changes the mouse cursor shape over your label to a custom cursor. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCursor|setLabelCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''custom cursor''<br />
: Location of your custom cursor file. To be compatible with all systems it is recommended to use png files with size of 32x32.<br />
* ''hotX''<br />
: X-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
* ''hotY''<br />
: Y-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCustomCursor("myLabel", getMudletHomeDir().."/custom_cursor.png")<br />
-- This will change the mouse cursor to your custom cursor if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelWheelCallback==<br />
;setLabelWheelCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse wheel is scrolled while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the ''event'' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
buttons = {"RightButton", "MidButton"},<br />
angleDeltaX = 0,<br />
angleDeltaY = 120<br />
}<br />
</syntaxhighlight><br />
<br />
: Keys ''angleDeltaX'' and ''angleDeltaY'' correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onWheelNorth(event)<br />
if event.angleDeltaY > 0 then<br />
echo("the north button was wheeled forwards over!")<br />
else<br />
echo("the north button was wheeled backwards over!")<br />
end<br />
end<br />
<br />
setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onWheelNorth = function()<br />
echo("the north button was wheeled over!")<br />
end<br />
}<br />
<br />
setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )<br />
</syntaxhighlight><br />
<br />
==setLink==<br />
;setLink([windowName], command, tooltip)<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of a miniconsole or a userwindow in which to select the text in.<br />
* ''command:''<br />
: command to do when the text is clicked.<br />
* ''tooltip:''<br />
: tooltip to show when the mouse is over the text - explaining what would clicking do.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can clickify a lot of things to save yourself some time - for example, you can change<br />
-- the line where you receive a message to be clickable to read it!<br />
-- prel regex trigger:<br />
-- ^You just received message #(\w+) from \w+\.$<br />
-- script:<br />
selectString(matches[2], 1)<br />
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])<br />
resetFormat()<br />
<br />
-- an example of selecting text in a miniconsole and turning it into a link:<br />
<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
HelloWorld:echo("hi")<br />
selectString("HelloWorld", "hi", 1)<br />
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")<br />
</syntaxhighlight><br />
<br />
==setMainWindowSize==<br />
;setMainWindowSize(mainWidth, mainHeight)<br />
: Changes the size of your main Mudlet window to the values given.<br />
: See Also: [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''mainWidth:''<br />
: The new width in pixels.<br />
* ''mainHeight:''<br />
: The new height in pixels.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will resize your main Mudlet window<br />
setMainWindowSize(1024, 768)<br />
</syntaxhighlight><br />
<br />
==setMapWindowTitle==<br />
;setMapWindowTitle(text)<br />
: Changes the title shown in the mapper window when it's popped out.<br />
: See also: [[#resetMapWindowTitle|resetMapWindowTitle()]]<br />
<br />
; Parameters<br />
* ''text:''<br />
: New window title to set.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapWindowTitle("my cool game map")<br />
</syntaxhighlight><br />
<br />
==setMiniConsoleFontSize==<br />
;setMiniConsoleFontSize(name, fontSize)<br />
: Sets the font size of the mini console. see also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]]<br />
<br />
==setOverline==<br />
;setOverline([windowName], boolean)<br />
: Sets the current text font to be overlined (true) or not overlined (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 overlined. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be overlined until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be overlined or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables overlining of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable overlined text<br />
setOverline(true)<br />
-- the following echo will be have an overline<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and reverse have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==setPopup==<br />
;setPopup(windowName, {lua code}, {hints})<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,<br />
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking<br />
-- will show some commands you can do.<br />
<br />
selectString("Hello", 1)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})<br />
</syntaxhighlight><br />
<br />
==setProfileStyleSheet==<br />
;setProfileStyleSheet(stylesheet)<br />
: Sets a stylesheet for the current Mudlet profile - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). This function is better than setAppStyleSheet() because it affects only the current profile and not every other one as well.<br />
<br />
: See also: [[#setAppStyleSheet|setAppStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use. See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setProfileStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
<br />
QTreeView {<br />
background: ]]..background_color..[[;<br />
color: white;<br />
}<br />
<br />
QMenuBar{ background-color: ]]..background_color..[[;}<br />
<br />
QMenuBar::item{ background-color: ]]..background_color..[[;}<br />
<br />
QDockWidget::title {<br />
background: ]]..border_color..[[;<br />
}<br />
QStatusBar {<br />
background: ]]..border_color..[[;<br />
}<br />
QScrollBar:vertical {<br />
background: ]]..background_color..[[;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background-color: ]]..background_color..[[;<br />
min-height: 20px;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 7px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-bottom-left-radius: 7px;<br />
border-bottom-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-top-left-radius: 7px;<br />
border-top-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
background: white;<br />
width: 4px;<br />
height: 3px;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]])<br />
<br />
-- if you'd like to reset it, use:<br />
setProfileStyleSheet("")<br />
<br />
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':<br />
setProfileStyleSheet[[<br />
TConsole QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
TConsole QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
TConsole QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 4.6.<br />
<br />
==setReverse==<br />
;setReverse([windowName], boolean)<br />
: Sets the current text to swap foreground and background color settings (true) or not (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 have it's colors swapped. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will have their foreground and background colors swapped until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text colors to be reversed or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables reversing of the fore- and back-ground colors of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable fore/back-ground color reversal of text<br />
setReverse(true)<br />
-- the following echo will have the text colors reversed<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and overline have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
{{note}} Although the visual effect on-screen is the same as that of text being selected if both apply to a piece of text they neutralise each other - however the effect of the reversal ''will'' be carried over in copies made by the "Copy to HTML" and in logs made in HTML format log file mode.<br />
<br />
==setStrikeOut==<br />
;setStrikeOut([windowName], boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be striken out until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be stricken out or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables striking out of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable striken-out text<br />
setStrikeOut(true)<br />
-- the following echo will be have a strikethrough<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setTextFormat==<br />
;setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])<br />
: Sets current text format of selected window. This is a more convenient means to set all the individual features at once compared to using [[#setFgColor|setFgColor]]( windowName, r,g,b ), [[#setBold|setBold]]( windowName, true ), [[#setItalics|setItalics]]( windowName, true ), [[#setUnderline|setUnderline]]( windowName, true ), [[#setStrikeOut|setStrikeOut]]( windowName, true ).<br />
: See Also: [[Manual:Lua_Functions#getTextFormat|getTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: Specify name of selected window. If empty string "" or "main" format will be applied to the main console<br />
* ''r1,g1,b1''<br />
: To color text background, give number values in RBG style<br />
* ''r2,g2,b2''<br />
: To color text foreground, give number values in RBG style<br />
* ''bold''<br />
: To format text bold, set to 1 or true, otherwise 0 or false<br />
* ''underline''<br />
: To underline text, set to 1 or true, otherwise 0 or false<br />
* ''italics''<br />
: To format text italic, set to 1 or true, otherwise 0 or false<br />
* ''strikeout<br />
: (optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''overline<br />
: (optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''reverse<br />
: (optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This script would create a mini text console and write with bold, struck-out, yellow foreground color and blue background color "This is a test".<br />
createMiniConsole( "con1", 0,0,300,100);<br />
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);<br />
echo("con1","This is a test")<br />
</syntaxhighlight><br />
<br />
{{note}} In versions prior to 3.7.0 the error messages ''and this wiki'' were wrong in that they had the foreground color parameters as r1, g1 and b1 and the background ones as r2, g2 and b2.<br />
<br />
==setUnderline==<br />
;setUnderline(windowName, bool)<br />
: Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setUserWindowTitle==<br />
;setUserWindowTitle(windowName, text)<br />
: sets a new title text for the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''text''<br />
: new title text<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==setUserWindowStyleSheet==<br />
;setUserWindowStyleSheet(windowName, markup)<br />
: Applies Qt style formatting to the border/title area of a userwindow via a special markup language.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when you dock the userwindow the border style is not provided by this<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- changes the title area style of the UserWindow 'myUserWindow'<br />
setUserWindowStyleSheet("myUserWindow", [[QDockWidget::title{ <br />
background-color: rgb(0,255,150);<br />
border: 2px solid red;<br />
border-radius: 8px;<br />
text-align: center; <br />
}]])<br />
</syntaxhighlight><br />
<br />
: See also: [[#openUserWindow|openUserWindow()]]<br />
<br />
==setWindow==<br />
;setWindow(windowName, name, [Xpos, Ypos, show])<br />
: Changes the parent window of an element.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow which you want the element put in. If you want to put the element into the main window, use windowName "main".<br />
* ''name''<br />
: Name of the element which you want to switch the parent from. Elements can be labels, miniconsoles and the embedded mapper. If you want to move the mapper use the name "mapper"<br />
* ''Xpos:''<br />
: X position of the element. Measured in pixels, with 0 being the very left. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''Ypos:''<br />
: Y position of the element. Measured in pixels, with 0 being the very top. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''show:''<br />
: true or false to decide if the element will be shown or not in the new parent window. Optional, if not given it will be true.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindow("myuserwindow", "mapper")<br />
-- This will put your embedded mapper in your userwindow "myuserwindow".<br />
</syntaxhighlight><br />
<br />
==setWindowWrap==<br />
;setWindowWrap(windowName, wrapAt)<br />
: sets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapAt:''<br />
: Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==setWindowWrapIndent==<br />
;setWindowWrapIndent(windowName, wrapTo)<br />
: sets how many spaces wrapped text will be indented with (after the first line of course).<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapTo:''<br />
: Number of spaces which wrapped lines are prefixed with.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
setWindowWrapIndent("main", 3)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==showCaptureGroups==<br />
;showCaptureGroups()<br />
:Lua debug function that highlights in random colors 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.<br />
<br />
;Example:<br />
: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.<br />
<br />
==showMultimatches==<br />
;showMultimatches()<br />
: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.<br />
<br />
==showWindow==<br />
;showWindow(name)<br />
: Makes a hidden window (label or miniconsole) be shown again.<br />
<br />
: See also: [[#hideWindow | hideWindow()]]<br />
<br />
==showColors==<br />
;showColors([columns], [filterColor], [sort])<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in '''color_table''', in table form. The format is ''color_table.colorName = {r, g, b}''.<br />
<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: (optional) number of columns to print the color table in.<br />
* ''filterColor:''<br />
: (optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.<br />
* ''sort:''<br />
: (optional) sort colors alphabetically.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- display as four columns:<br />
showColors(4)<br />
<br />
-- show only red colours:<br />
showColors("red")<br />
</syntaxhighlight><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)|thumb|center]]<br />
<br />
==showToolBar==<br />
;showToolBar(name)<br />
: Makes a toolbar (a button group) appear on the screen.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
showToolBar("my attack buttons")<br />
</syntaxhighlight><br />
<br />
==suffix==<br />
;suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
: Suffixes text at the end of the current line. This is similar to [[Manual:Lua_Functions#echo | echo()]], which also suffixes text at the end of the line, but different - [[Manual:Lua_Functions#echo | 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.<br />
<br />
;Parameters<br />
* ''text''<br />
: the information you want to prefix<br />
* ''writingFunction''<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* ''foregroundColor''<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* ''backgroundColor''<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* ''windowName''<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
<br />
: See also: [[#prefix | prefix()]], [[Manual:Lua_Functions#echo | echo()]]<br />
<br />
==wrapLine==<br />
;wrapLine(windowName, lineNumber)<br />
: 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.:<br />
<br />
<syntaxhighlight lang="lua">selectString(line,1)<br />
replace("")</syntaxhighlight><br />
<br />
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.<br />
<br />
: See Also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#deleteLine|deleteLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The miniconsole or the main window (use ''main'' for the main window)<br />
* ''lineNumber:''<br />
: The line number which you'd like re-wrapped.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- re-wrap the last line in the main window<br />
wrapLine("main", getLineCount())<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=15593Manual:UI Functions2020-09-30T15:17:06Z<p>Smurf: /* getSelection */ clarify example</p>
<hr />
<div>{{TOC right}}<br />
= UI Functions =<br />
<br />
All functions that help you customize Mudlet's interface and the game's text.<br />
<br />
==ansi2decho==<br />
;ansi2decho(text, default_colour)<br />
: Converts ANSI colour sequences in <code>text</code> to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.<br />
: See also: [[Manual:Lua_Functions#decho|decho()]]<br />
{{note}}<br />
ANSI bold is available since Mudlet 3.7.1+.<br />
R<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be replaced.<br />
* ''default_colour:''<br />
: Optional - ANSI default colour code (used when handling orphan bold tags).<br />
<br />
;Return values<br />
* ''string text:''<br />
: The decho-valid converted text.<br />
* ''string colour:''<br />
: The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- '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><br />
decho(replaced)<br />
</syntaxhighlight><br />
<br />
Or show a complete colourful squirrel! It's a lotta code to do all the colours, so click the '''Expand''' button on the right to show it:<br />
<div class="toccolours mw-collapsible mw-collapsed"><br />
<syntaxhighlight lang="lua"><br />
decho(ansi2decho([[<br />
�[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m �[0m<br />
╭───────────────────────╮ �[38;5;95m▄▄�[0m �[38;5;95m▄�[48;5;95;38;5;130m▄▄�[48;5;130m█�[38;5;137m▄�[48;5;137;38;5;95m▄�[49m▀�[0m �[0m<br />
│ │ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄▄▄�[48;5;95;38;5;137m▄▄▄�[49;38;5;95m▄▄�[48;5;95;38;5;130m▄�[48;5;130m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[0m �[0m<br />
│ Encrypt everything! │ �[38;5;95m▄�[48;5;187;38;5;16m▄�[48;5;16;38;5;187m▄�[38;5;16m█�[48;5;137;38;5;137m███�[38;5;187m▄�[38;5;16m▄▄�[38;5;137m██�[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[0m �[0m<br />
│ ├──── �[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;16m▄▄▄�[48;5;137m███�[48;5;16;38;5;16m█�[48;5;187m▄�[48;5;16m█�[48;5;137;38;5;137m█�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
╰───────────────────────╯ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;16m▄�[38;5;16m█�[38;5;137m▄�[48;5;137m██████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;95m▀�[48;5;137m▄�[38;5;137m███████�[38;5;95m▄�[49m▀�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[48;5;95;38;5;187m▄▄▄�[38;5;137m▄�[48;5;137m██�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[38;5;95m▀�[48;5;130m▄�[38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;187m████�[48;5;137;38;5;137m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m██�[38;5;95m▄�[38;5;137m█�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;187;38;5;187m████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95m██�[48;5;137m▄▄�[48;5;187;38;5;187m████�[48;5;137;38;5;95m▄▄�[48;5;95;38;5;137m▄�[48;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;187;38;5;187m███�[48;5;95m▄�[38;5;137m▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[49m▄�[48;5;95;38;5;130m▄�[48;5;130m██████�[48;5;137;38;5;137m███�[38;5;95m▄�[49m▀�[0m�[0m<br />
�[48;5;187;38;5;95m▄�[38;5;187m████�[48;5;137;38;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m█████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;137m▄�[38;5;187m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██████�[48;5;95m▄▄�[48;5;130m▄▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▄▄▄�[48;5;95;38;5;137m▄�[48;5;187m▄�[38;5;187m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m█████�[38;5;95m▄�[38;5;137m███████████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀�[48;5;187m▄▄▄�[48;5;95;38;5;137m▄�[48;5;137m██�[38;5;95m▄�[49m▀�[0m �[38;5;95m▀▀�[48;5;137m▄▄▄▄▄▄�[49m▀▀▀�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀▀�[0m �[0m<br />
]]))<br />
</syntaxhighlight><br />
</div><br />
<br />
[[File:Squirrel-in-Mudlet.png|frameless]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.0+<br />
<br />
<br />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be removed.<br />
<br />
;Return values<br />
* ''string text:''<br />
: The plain text without ANSI colour sequences.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10+<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2string('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- 'replaced' should now contain You say in a baritone voice, "Test."<br />
print(replaced)<br />
</syntaxhighlight><br />
<br />
<br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name.<br />
: See also: [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[Manual:Lua_Functions#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</syntaxhighlight><br />
<br />
==bg==<br />
;bg([window, ]colorName)<br />
: Changes the background color of the text. Useful for highlighting text.<br />
: See Also: [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: 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).<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
<br />
-- or echo text with a green background to a miniconsole<br />
bg("my window", "green")<br />
echo("my window", "some green text\n")<br />
</syntaxhighlight><br />
<br />
==calcFontSize==<br />
;calcFontSize(window_or_fontsize, [fontname])<br />
: Returns the average height and width of characters in a particular window, or a font name and size combination. Helpful if you want to size a miniconsole to specific dimensions.<br />
: Returns two numbers, width/height<br />
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
;Parameters<br />
* ''window_or_fontsize:''<br />
: The miniconsole or font size you are wanting to calculate pixel sizes for.<br />
* ''fontname:''<br />
: Specific font name (along with the size as the first argument) to calculate for.<br />
<br />
{{note}}<br />
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide<br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</syntaxhighlight><br />
<br />
==cecho==<br />
;cecho([window], text)<br />
: Echoes text that can be easily formatted with colour tags. You can also include unicode art in it - try some examples from [http://1lineart.kulaone.com/#/ 1lineart].<br />
: See also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cecho("<blue:yellow>Blue on yellow text!")<br />
<br />
-- \n adds a new line<br />
cecho("<red>one line\n<green>another line\n<blue>last line")<br />
<br />
cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
<br />
cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")<br />
<br />
cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")<br />
<br />
cecho([[<br />
██╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗ ████████╗<br />
███║ ██║ ██║████╗ ██║██╔════╝ ██╔══██╗██╔══██╗╚══██╔══╝<br />
╚██║ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝ ██║<br />
██║ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗ ██║<br />
██║ ███████╗██║██║ ╚████║███████╗ ██║ ██║██║ ██║ ██║<br />
╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝<br />
]])<br />
</syntaxhighlight><br />
<br />
==cechoLink==<br />
;cechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#cecho|cecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cechoPopup==<br />
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#cecho|cecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertLink==<br />
;cinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#cinsertText|cinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertPopup==<br />
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#cinsertText|cinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertText==<br />
;cinsertText([window], text)<br />
: inserts text at the current cursor position, with the possibility for color tags.<br />
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cinsertText("<blue:yellow>Blue on yellow text!")<br />
<br />
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
</syntaxhighlight><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].<br />
<br />
==clearWindow==<br />
;clearWindow([windowName])<br />
: Clears the label, mini console, or user window 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 (starting with Mudlet 2.0-test3+)<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this can clear your whole main window - needs Mudlet version >= 2.0<br />
clearWindow()<br />
</syntaxhighlight><br />
<br />
==copy==<br />
; copy([windowName])<br />
: Copies the current selection to the lua virtual clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the lua virtual clipboard until it gets overwritten by another copy operation.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
; Parameters<br />
* ''windowName'' (optional):<br />
: the window from which to copy text - use the main console if not specified.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This script copies the current line on the main screen to a window (miniconsole or userwindow) called 'chat' and gags the output on the main screen.<br />
selectString(line, 1)<br />
copy()<br />
appendBuffer("chat")<br />
replace("This line has been moved to the chat window!")<br />
</syntaxhighlight><br />
<br />
==copy2decho==<br />
; copy2decho([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in decho format.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line.<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and dechos it to a miniconsole named "test"<br />
decho("test", copy2decho())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and decho it to a Geyser miniconsole stored as the variable enemylist<br />
enemylist:decho(copy2decho(matches[2]))<br />
</syntaxhighlight><br />
<br />
==copy2html==<br />
; copy2html([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in html format for echoing to a label.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main"<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and echos it to a label named "TestLabel"<br />
echo("TestLabel", copy2html())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and echo it to a Geyser label stored as the variable enemylist<br />
enemylist:echo(copy2html(matches[2]))<br />
</syntaxhighlight><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: 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.<br />
<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</syntaxhighlight><br />
<br />
==createCommandLine==<br />
;createCommandLine([name of userwindow], name, x, y, width, height)<br />
: Creates a new command line inside the main window of Mudlet. If only a command line inside a miniConsole/UserWindow is needed see [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]].<br />
: You can use [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]] / [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]] and other command line functions to customize the input.<br />
{{note}} [[Manual:UI_Functions#setCmdLineAction|setCmdLineAction]] allows you to attach an action to your command line input.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#disableCommandLine|disableCommandLine()]], [[Manual:Mudlet_Object_Functions#clearCmdLine|clearCmdLine()]], [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]], [[Manual:Mudlet_Object_Functions#printCmdLine|printCmdLine()]], [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the command line is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the command line. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the command line size and location - it is also possible to set them by using [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createCommandLine() will only set them once.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==createConsole==<br />
;createConsole([name of userwindow], consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow your new miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,<br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
''(For Mudlet Makers)'' This function is implemented outside the application's core via the '''GUIUtils.lua''' file of the Mudlet supporting Lua code using [[Manual:UI_Functions#createMiniConsole|createMiniConsole()]] and other functions to position and size the mini-console and configure the font.<br />
<br />
==createGauge==<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the gauge is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: 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<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
* ''orientation:''<br />
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.<br />
<syntaxhighlight lang="lua"><br />
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")<br />
</syntaxhighlight><br />
<br />
==createLabel==<br />
;createLabel([name of userwindow], name, Xpos, Ypos, width, height, fillBackground, [enableClickthrough])<br />
: 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.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]], [[Manual:Lua_Functions#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will display the background color, 0 or false will not.<br />
* ''enableClickthrough:''<br />
: Whether or not enable clickthrough on this label. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will enable clickthrough, 0 or false will not. Optional, defaults to clickthrough not enabled if not provided.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label situated at x=300 y=400 with dimensions 100x200<br />
createLabel("a very basic label",300,400,100,200,1)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle<br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent<br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
<br />
-- you can also make it react to clicks!<br />
mynamespace = {<br />
messageBoxClicked = function()<br />
echo("hey you've clicked the box!\n")<br />
end<br />
}<br />
<br />
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")<br />
<br />
<br />
-- uncomment code below to make it also hide after a short while<br />
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</syntaxhighlight><br />
<br />
==createMiniConsole==<br />
;createMiniConsole([name of userwindow], name, x, y, width, height)<br />
: 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.<br />
: You can use [[Manual:Lua_Functions#clearWindow|clearWindow()]] / [[Manual:Lua_Functions#moveCursor|moveCursor()]] and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. [[Manual:Lua_Functions#setWindowWrap|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 [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent()]], [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|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.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
==creplace==<br />
;creplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, with color names inside angle brackets as with [[Manual:Lua_Functions#cecho|cecho()]]. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
creplace("<magenta>[ALERT!]: <reset>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==creplaceLine==<br />
;creplaceLine (text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''text:''<br />
*: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)<br />
</syntaxhighlight><br />
<br />
==decho==<br />
;decho ([name of console,] text)<br />
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB,[BA]> 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,[BA]>. 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")''.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]]<br />
<br />
;Parameters<br />
* ''name of console''<br />
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.<br />
* ''text:''<br />
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.<br />
<br />
<br />
{{note}}<br />
Optional background transparancy parameter (BA) available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
decho("<50,50,0:0,255,0>test")<br />
<br />
decho("miniconsolename", "<50,50,0:0,255,0>test")<br />
</syntaxhighlight><br />
<br />
==dechoLink==<br />
;dechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#decho|decho()]]. This version allows you to use colours within your link text.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) allows selection between sending the link to a miniconsole or the "main" window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==dechoPopup==<br />
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#decho|decho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertLink==<br />
;dinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#dinsertText|dinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertPopup==<br />
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#dinsertText|dinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
== deleteLabel ==<br />
; deleteLabel(labelName)<br />
<br />
: Deletes and removes a label from the screen. Note that if you'd like to show the label again, it is much more performant to hide/show it instead.<br />
<br />
: Note that you shouldn't use the Geyser label associated with the label you delete afterwards - that doesn't make sense and Geyser right now wouldn't know that it's been deleted, either.<br />
<br />
: See also: [[#hideWindow|hideWindow()]], [[#showWindow|showWindow()]], [[#createLabel|createLabel()]]<br />
<br />
; Parameters<br />
<br />
* ''labelName'': name of the label to delete.<br />
<br />
<syntaxhighlight lang="lua"><br />
createLabel("a very basic label",300,400,100,200,1)<br />
setBackgroundColor("a very basic label", 255, 204, 0, 200)<br />
<br />
-- delete the label after 3 seconds<br />
tempTimer(3, function()<br />
deleteLabel("a very basic label")<br />
end)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 4.5+<br />
<br />
==deleteLine==<br />
;deleteLine([windowName])<br />
: 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. This is purely visual - triggers will still fire on the line as expected.<br />
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.<br />
<br />
{{note}} for replacing text, [[Manual:Lua_Functions#replace|replace()]] is the proper option; doing the following: <code>selectCurrentLine(); replace(""); cecho("new line!\n")</code> is better.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- deletes the line - just put this command into the big script box. Keep the case the same -<br />
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else<br />
deleteLine()<br />
<br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
<br />
-- example of deleting multiple lines:<br />
deleteLine() -- delete the current line<br />
moveCursor(0,getLineNumber()-1) -- move the cursor back one line<br />
deleteLine() -- delete the previous line now<br />
</syntaxhighlight><br />
<br />
==deselect==<br />
;deselect([window name])<br />
: 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.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''window name:''<br />
: (optional) The name of the window to stop having anything selected in. If name is not provided the main window will have its selection cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further<br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</syntaxhighlight><br />
<br />
==disableClickthrough==<br />
; disableClickthrough(label)<br />
: Disables clickthrough for a label - making it act 'normal' again and receive clicks, doubleclicks, onEnter, and onLeave events. This is the default behaviour for labels.<br />
: See also: [[#enableClickthrough|enableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name of the label to restore clickability on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==disableCommandLine==<br />
; disableCommandLine(windowName)<br />
: Disables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableCommandLine|enableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to disable the command line in.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10<br />
<br />
==disableScrollBar==<br />
; disableScrollBar(windowName)<br />
: Disables the scroll bar for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to disable the scroll bar in.<br />
<br />
==dreplace==<br />
;dreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#decho|decho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
dreplace("<255,0,255>[ALERT!]: <r>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''text:''<br />
: Text to display in the echo. Same as a normal echo().<br />
* ''command:''<br />
: Lua code to do when the link is clicked.<br />
* ''hint:''<br />
: Text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentFormatElseDefault:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
echoLink("press me!", [[send("hi")]], "This is a tooltip")<br />
<br />
-- do the same, but send this link to a miniConsole<br />
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")<br />
</syntaxhighlight><br />
<br />
==echoUserWindow==<br />
;echoUserWindow(windowName)<br />
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.<br />
<br />
==echoPopup==<br />
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==enableClickthrough==<br />
; enableClickthrough(label)<br />
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.<br />
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.<br />
: See also: [[#disableClickthrough|disableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: The name of the label to enable clickthrough on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==enableCommandLine==<br />
; enableCommandLine(windowName)<br />
: Enables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#disableCommandLine|disableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to enable the command line in.<br />
<br />
{{note}} The command line name is the same as the miniConsole name<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableScrollBar==<br />
; enableScrollBar(windowName)<br />
: Enables the scrollbar for the miniConsole named ''windowName''.<br />
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in.<br />
<br />
==fg==<br />
; fg([window], colorName)<br />
: 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)<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything or use ''main'' (since Mudlet 3.0).<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
<br />
-- example of working on a miniconsole<br />
fg("my console", "red")<br />
echo("my console", "red text")<br />
</syntaxhighlight><br />
<br />
==getAvailableFonts==<br />
; getAvailableFonts()<br />
: This returns a "font - true" key-value list of available fonts which you can use to verify that Mudlet has access to a given font.<br />
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.<br />
<br />
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]<br />
<br />
{{note}}<br />
Available since Mudlet 3.10<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if Ubuntu Mono is a font we can use<br />
if getAvailableFonts()["Ubuntu Mono"] then<br />
-- make the miniconsole use the font at size 16<br />
setFont("my miniconsole", "Ubuntu Mono")<br />
setFontSize("my miniconsole", 16)<br />
end<br />
</syntaxhighlight><br />
<br />
==getBgColor==<br />
; getBgColor(windowName)<br />
: 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.<br />
<br />
: See also: [[#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r,g,b;<br />
selectString("troll",1)<br />
r,g,b = getBgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getBorderBottom==<br />
;getBorderBottom()<br />
: Returns the size of the bottom border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
getBorderBottom()<br />
-- returns: 150<br />
</syntaxhighlight><br />
<br />
==getBorderLeft==<br />
;getBorderLeft()<br />
: Returns the size of the left border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
getBorderLeft()<br />
-- returns: 5<br />
</syntaxhighlight><br />
<br />
==getBorderRight==<br />
;getBorderRight()<br />
: Returns the size of the right border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
getBorderRight()<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderSizes==<br />
;getBorderSizes()<br />
: Returns the a named table with the sizes of all borders of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]],[[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0)<br />
getBorderSizes()<br />
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }<br />
getBorderSizes().right<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderTop==<br />
;getBorderTop()<br />
: Returns the size of the top border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
getBorderTop()<br />
-- returns: 100<br />
</syntaxhighlight><br />
<br />
==getClipboardText==<br />
;getClipboardText()<br />
: Returns any text that is currently present in the clipboard. <br />
: See also: [[#setClipboardText | setClipboardText()]]<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local clipboardContents = getClipboardText()<br />
echo("Clipboard: " .. clipboardContents)<br />
</syntaxhighlight><br />
<br />
==getColorWildcard==<br />
; getColorWildcard(ansi color number)<br />
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.<br />
<br />
: See also: [[#isAnsiFgColor|isAnsiFgColor()]], [[#isAnsiBgColor|isAnsiBgColor()]]<br />
<br />
;Parameters<br />
* ''ansi color number:''<br />
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- we can run this script on a line that has the players name coloured differently to easily capture it from<br />
-- anywhere on the line<br />
local match = getColorWildcard(14)<br />
<br />
if match then<br />
echo("\nFound "..match.."!")<br />
else<br />
echo("\nDidn't find anyone.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getColumnCount==<br />
;getColumnCount([windowName])<br />
: Gets the maximum number of columns (characters) that a given window can display on a single row, taking into consideration factors such as window width, font size, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum number of columns on the main window "..getColumnCount())<br />
</syntaxhighlight><br />
<br />
==getColumnNumber==<br />
;getColumnNumber([windowName])<br />
: Gets the absolute column number of the current user cursor.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
<br />
{{note}} the argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
<br />
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
</syntaxhighlight><br />
<br />
==getCurrentLine==<br />
;getCurrentLine([windowName])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Currently selected line: "..getCurrentLine())<br />
</syntaxhighlight><br />
<br />
==getFgColor==<br />
; getFgColor(windowName)<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString("troll",1)<br />
local r,g,b = getFgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is written in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getFont==<br />
;getFont(windowName)<br />
: Gets the current font of the given window or console name. Can be used to get font of the main console, dockable userwindows and miniconsoles.<br />
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
display("Font in the main window: "..getFont())<br />
<br />
display("Font in the main window: "..getFont("main"))<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
display("Font size: " .. getFont("user window awesome"))<br />
</syntaxhighlight><br />
<br />
==getFontSize==<br />
;getFontSize(windowName)<br />
: Gets the current font size of the given window or console name. Can be used to get font size of the Main console as well as dockable UserWindows.<br />
: See also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
local mainWindowFontSize = getFontSize()<br />
if mainWindowFontSize then<br />
display("Font size: " .. mainWindowFontSize)<br />
end<br />
<br />
local mainWindowFontSize = getFontSize("main")<br />
if mainWindowFontSize then<br />
display("Font size: " .. fs2)<br />
end<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
local awesomeWindowFontSize = getFontSize("user window awesome")<br />
if awesomeWindowFontSize then<br />
display("Font size: " .. awesomeWindowFontSize)<br />
end<br />
</syntaxhighlight><br />
<br />
==getImageSize==<br />
;getImageSize(imageLocation)<br />
: Returns the width and the height of the given image. If the image can't be found, loaded, or isn't a valid image file - nil+error message will be returned instead.<br />
: See also: [[#createLabel|createLabel()]]<br />
<br />
;Parameters<br />
* ''imageLocation:''<br />
: Path to the image.<br />
<br />
{{note}}<br />
Available in Mudlet 4.5+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local path = getMudletHomeDir().."/my-image.png"<br />
<br />
cecho("Showing dimensions of the picture in: "..path.."\n")<br />
<br />
local width, height = getImageSize(path)<br />
<br />
if not width then<br />
-- in case of an problem, we don't get a height back - but the error message<br />
cecho("error: "..height.."\n")<br />
else<br />
cecho(string.format("They are: %sx%s", width, height))<br />
end<br />
</syntaxhighlight><br />
<br />
==getLastLineNumber==<br />
;getLastLineNumber(windowName)<br />
:Returns the latest line's number in the main window or the miniconsole. This could be different from [[Manual:UI_Functions#getLineNumber|getLineNumber()]] if the cursor was moved around.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the latest line's # in the buffer<br />
local latestline = getLastLineNumber("main")<br />
</syntaxhighlight><br />
<br />
==getLineCount==<br />
;getLineCount()<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
''Need example''<br />
<br />
==getLines==<br />
;getLines([windowName,] from_line_number, to_line_number)<br />
: 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}''.<br />
<br />
:Absolute line numbers are used.<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)<br />
* ''from_line_number:''<br />
: First line number<br />
* ''to_line_number:''<br />
: End line number<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- retrieve & echo the last line:<br />
echo(getLines(getLineNumber()-1, getLineNumber())[1])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- find out which server and port you are connected to (as per Mudlet settings dialog):<br />
local t = getLines(0, getLineNumber())<br />
<br />
local server, port<br />
<br />
for i = 1, #t do<br />
local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")<br />
if s then server, port = s, p break end<br />
end<br />
<br />
display(server)<br />
display(port)<br />
</syntaxhighlight><br />
<br />
==getLineNumber==<br />
;getLineNumber([windowName])<br />
: 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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#moveCursorEnd|moveCursorEnd()]]. This function can come in handy in combination when using with [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#getLines|getLines()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.<br />
<br />
{{note}}<br />
The argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word<br />
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end<br />
<br />
-- check how many lines you've got in your miniconsole after echoing some text.<br />
-- Note the use of moveCursorEnd() to update getLineNumber()'s output<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
print(getLineNumber("HelloWorld"))<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
-- update the cursors position, as it seems to be necessary to do<br />
moveCursorEnd("HelloWorld")<br />
print(getLineNumber("HelloWorld"))<br />
</syntaxhighlight><br />
<br />
==getMainConsoleWidth==<br />
;getMainConsoleWidth()<br />
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.<br />
<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Save width of the main console to a variable for future use.<br />
consoleWidth = getMainConsoleWidth()<br />
</syntaxhighlight><br />
<br />
==getMousePosition==<br />
;getMousePosition()<br />
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{note}} Available since Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- 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<br />
local x, y = getMousePosition()<br />
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)<br />
-- if the label already exists, just move it<br />
moveWindow("clickGeneratedLabel", x, y)<br />
-- and make it easier to notice<br />
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)<br />
</syntaxhighlight><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getUserWindowSize|getUserWindowSize()]], [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your main mudlet window and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</syntaxhighlight><br />
<br />
==getRowCount==<br />
;getRowCount([windowName])<br />
: Gets the maximum number of rows that a given window can display at once, taking into consideration factors such as window height, font type, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum of rows on the main window "..getRowCount())<br />
</syntaxhighlight><br />
<br />
==getSelection==<br />
;getSelection([windowName])<br />
: Returns the text currently selected with [[#selectString|selectString()]], [[#selectSection|selectSection()]], or [[#selectCurrentLine|selectCurrentLine()]]. Note that this isn't the text currently selected with the mouse.<br />
: Also returns the start offset and length of the selection as second and third value.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window to get the selection from. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.16.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
print("Current line contains: "..getSelection())<br />
</syntaxhighlight><br />
<br />
;retrieving the selection<br />
<syntaxhighlight lang="lua"><br />
text,offset,len = getSelection()<br />
-- manipulate the selection, e.g. to discover the color of characters other than the first<br />
-- then restore it<br />
selectSection(offset, len)<br />
</syntaxhighlight><br />
<br />
==getTextFormat==<br />
;getTextFormat([windowName])<br />
: Gets the current text format of the currently selected text. May be used with other console windows. The returned values come in a table containing text attribute names and their values. The values given will be booleans for: bold, italics, underline, overline, strikeout, and reverse - followed by color triplet tables for the foreground and background colors.<br />
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.<br />
<br />
{{note}} Available since Mudlet 3.20.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- A suitable test for getTextFormat()<br />
-- (copy it into an alias or a script)<br />
<br />
clearWindow()<br />
<br />
echo("\n")<br />
<br />
local SGR = string.char(27)..'['<br />
feedTriggers("Format attributes: '"..SGR.."1mBold"..SGR.."0m' '"..SGR.."3mItalic"..SGR.."0m' '"..SGR.."4mUnderline"..SGR.."0m' '"..SGR.."5mBlink"..SGR.."0m' '"..SGR.."6mF.Blink"..SGR.."0m' '"..SGR.."7mReverse"..SGR.."0m' '"..SGR.."9mStruckout"..SGR.."0m' '"..SGR.."53mOverline"..SGR.."0m'.\n")<br />
<br />
moveCursor(1,1)<br />
selectSection(1,1)<br />
<br />
local results = getTextFormat()<br />
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))<br />
echo("\nItalic detected: " .. tostring(results["italic"]))<br />
echo("\nUnderline detected: " .. tostring(results["underline"]))<br />
echo("\nReverse detected: " .. tostring(results["reverse"]))<br />
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))<br />
echo("\nOverline detected: " .. tostring(results["overline"]))<br />
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")<br />
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")<br />
<br />
selectSection(21,1)<br />
echo("\n\nFor individual parts of test text:")<br />
echo("\nBold detected (character 21): " .. tostring(results["bold"]))<br />
<br />
selectSection(28,1)<br />
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))<br />
<br />
selectSection(37,1)<br />
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))<br />
<br />
selectSection(67,1)<br />
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))<br />
<br />
selectSection(77,1)<br />
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))<br />
<br />
selectSection(89,1)<br />
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))<br />
echo("\n")<br />
</syntaxhighlight><br />
<br />
==getUserWindowSize==<br />
{{note}} available in Mudlet 4.6.1+<br />
;getUserWindowSize(windowName)<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the given userwindow dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''windowName''<br />
:the name of the userwindow we will get the dimensions from<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your userwindow named "ChatWindow" and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getUserWindowSize("ChatWindow")<br />
</syntaxhighlight><br />
<br />
==handleWindowResizeEvent==<br />
;handleWindowResizeEvent()<br />
: (''depreciated'') This function is depreciated and should not be used; it's only documented here for historical reference - use the [[Manual:Technical_Manual#sysWindowResizeEvent|sysWindowResizeEvent]] event instead.<br />
<br />
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.<br />
<br />
; Parameters<br />
:None<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
function handleWindowResizeEvent()<br />
-- determine the size of your screen<br />
WindowWidth=0;<br />
WindowHeight=0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
-- move mini console "sys" to the far right side of the screen whenever the screen gets resized<br />
moveWindow("sys",WindowWidth-300,0)<br />
end<br />
</syntaxhighlight><br />
<br />
==hasFocus==<br />
;hasFocus()<br />
: 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). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if attacked and not hasFocus() then<br />
runaway()<br />
else<br />
fight()<br />
end<br />
</syntaxhighlight><br />
<br />
==hecho==<br />
;hecho([windowName], text)<br />
: Echoes text that can be easily formatted with colour tags in the hexadecimal format.<br />
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.<br />
* ''text:''<br />
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #FRFGFB,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 or #r can be used within the string to reset the colors to default. Hexadecimal color codes can be found here: https://www.color-hex.com/<br />
<br />
{{note}}<br />
Transparency for background in hex-format available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hecho("\n#ffffff White text!")<br />
-- your text in white<br />
hecho("\n#ca0004 Red text! And now reset #rit to the default color")<br />
-- your text in red, then reset to default using #r<br />
hecho("\n#ffffff,ca0004 White text with a red background!")<br />
-- your text in white, against a red background<br />
hecho("\n|c0000ff Blue text, this time using |c instead of #")<br />
-- your text in blue, activated with |c vs #.<br />
</syntaxhighlight><br />
<br />
==hechoLink==<br />
;hechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#hecho|hecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
-- # format also works<br />
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==hechoPopup==<br />
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#hecho|hecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertLink==<br />
;hinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#hinsertText|hinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertPopup==<br />
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#hinsertText|hinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hreplace==<br />
;hreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#hecho|hecho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
hreplace("#EE00EE[ALERT!]: #r"..matches[2])<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.5+<br />
<br />
==hideToolBar==<br />
;hideToolBar(name)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to hide<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hideToolBar("my offensive buttons")<br />
</syntaxhighlight><br />
<br />
==hideWindow==<br />
;hideWindow(name)<br />
: This function hides a '''mini console''', a '''user window''' or a '''label''' with the given name. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].<br />
<br />
: See also: [[#createMiniConsole|createMiniConsole()]], [[#createLabel|createLabel()]], [[#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name''<br />
: specifies the label or console you want to hide.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function miniconsoleTest()<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
print("created red window top-right")<br />
<br />
tempTimer(1, function()<br />
hideWindow("sys")<br />
print("hid red window top-right")<br />
end)<br />
<br />
tempTimer(3, function()<br />
showWindow("sys")<br />
print("showed red window top-right")<br />
end)<br />
end<br />
<br />
miniconsoleTest()<br />
</syntaxhighlight><br />
<br />
==insertLink==<br />
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])<br />
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) the window to insert the link in - use either "main" or omit for the main window.<br />
* ''text:''<br />
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) true or false. 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- link with the default blue on white colors<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")<br />
<br />
-- use current cursor colors by adding true at the end<br />
fg("red")<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==insertPopup==<br />
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])<br />
: Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to [[Manual:Lua_Functions#insertText|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''name:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.<br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==insertText==<br />
;insertText([windowName], text)<br />
: Inserts text at cursor postion in window - unlike [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] to move the cursor into position first.<br />
<br />
: insertHTML() also does the same thing as insertText, if you ever come across it.<br />
<br />
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) The window to insert the text to.<br />
* ''text:''<br />
: The text you will insert into the current cursor position.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the cursor to the end of the previous line and insert some text<br />
<br />
-- move to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
-- move the end the of the previous line<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
<br />
fg("dark_slate_gray")<br />
insertText(' <- that looks nice.')<br />
<br />
deselect()<br />
resetFormat()<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
==ioprint==<br />
;ioprint(text, some more text, ...)<br />
:Prints text to the to the stdout. This is only available if you [http://www.wikihow.com/Run-a-Program-on-Command-Prompt launched Mudlet from cmd.exe] on Windows, [http://www.wikihow.com/Open-Applications-Using-Terminal-on-Mac from the terminal] on Mac, or from the terminal on a Linux OS (launch the terminal program, type ''mudlet'' and press enter).<br />
<br />
Similar to [[Manual:Lua_Functions#echo|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.<br />
<br />
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.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
ioprint("hi!")<br />
ioprint(1,2,3)<br />
ioprint(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==isAnsiBgColor==<br />
; isAnsiBgColor(bgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the background color specified by bgColorCode.<br />
<br />
;Parameters<br />
* ''bgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiBgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the background of the text is light green" )<br />
else<br />
echo( "no sorry, some other background color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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 getBgColor() and then handling the color comparison in Lua.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default background color in the zeroth position.''<br />
<br />
==isAnsiFgColor==<br />
; isAnsiFgColor(fgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the foreground color specified by fgColorCode.<br />
<br />
;Parameters<br />
* ''fgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiFgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the text is light green" )<br />
else<br />
echo( "no sorry, some other foreground color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default foreground color in the zeroth position.''<br />
<br />
==lowerWindow==<br />
;lowerWindow(labelName)<br />
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to move below the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top<br />
</syntaxhighlight><br />
<br />
==moveCursor==<br />
;moveCursor([windowName], x, y)<br />
: 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 [[Manual:Lua_Functions#getLineNumber|getLineNumber()]], [[Manual:Lua_Functions#getColumnNumber|getColumnNumber()]] and [[Manual:Lua_Functions#getLastLineNumber|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.<br />
<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The window you are going to move the cursor in.<br />
* ''x:''<br />
: The horizontal axis in the window - that is, the letter position within the line.<br />
* ''y:''<br />
: The vertical axis in the window - that is, the line number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move cursor to the start of the previous line and insert -<(<br />
-- the first 0 means we want the cursor right at the start of the line,<br />
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which<br />
-- equals to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
insertText("-<(")<br />
<br />
-- now we move the cursor at the end of the previous line. Because the<br />
-- cursor is on the previous line already, we can use #getCurrentLine()<br />
-- to see how long it is. We also just do getLineNumber() because getLineNumber()<br />
-- returns the current line # the cursor is on<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
insertText(")>-")<br />
<br />
-- finally, reset it to the end where it was after our shenaningans - other scripts<br />
-- could expect the cursor to be at the end<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a more complicated example showing how to work with Mudlet functions<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
local WindowWidth, WindowHeight = getMainWindowSize()<br />
<br />
-- define a mini console named "sys" and set its background color<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
<br />
-- you *must* set the font size, otherwise mini windows will not work properly<br />
setMiniConsoleFontSize("sys", 12)<br />
-- wrap lines in window "sys" at 65 characters per line<br />
setWindowWrap("sys", 60)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
-- clear the window<br />
clearUserWindow("sys")<br />
<br />
moveCursorEnd("sys")<br />
setFgColor("sys", 10,10,0)<br />
setBgColor("sys", 0,0,255)<br />
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")<br />
echo("sys", "test1---line2\n")<br />
echo("sys", "test1---line3\n")<br />
setTextFormat("sys",158,0,255,255,0,255,0,0,0);<br />
--setFgColor("sys",255,0,0);<br />
echo("sys", "test1---line4\n")<br />
echo("sys", "test1---line5\n")<br />
moveCursor("sys", 1,1)<br />
<br />
-- deleting lines 2+3<br />
deleteLine("sys")<br />
deleteLine("sys")<br />
<br />
-- inserting a line at pos 5,2<br />
moveCursor("sys", 5,2)<br />
setFgColor("sys", 100,100,0)<br />
setBgColor("sys", 255,100,0)<br />
insertText("sys","############## line inserted at pos 5/2 ##############")<br />
<br />
-- inserting a line at pos 0,0<br />
moveCursor("sys", 0,0)<br />
selectCurrentLine("sys")<br />
setFgColor("sys", 255,155,255)<br />
setBold( "sys", true );<br />
setUnderline( "sys", true )<br />
setItalics( "sys", true )<br />
insertText("sys", "------- line inserted at: 0/0 -----\n")<br />
<br />
setBold( "sys", true )<br />
setUnderline( "sys", false )<br />
setItalics( "sys", false )<br />
setFgColor("sys", 255,100,0)<br />
setBgColor("sys", 155,155,0)<br />
echo("sys", "*** This is the end. ***\n")<br />
</syntaxhighlight><br />
<br />
==moveCursorDown==<br />
;moveCursorDown([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window down a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor down by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorUp==<br />
;moveCursorUp([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window up a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor up by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorEnd==<br />
;moveCursorEnd([windowName])<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
: Returns true or false<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveGauge==<br />
;moveGauge(gaugeName, newX, newY)<br />
: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.<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: The name of your gauge<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would move the health bar gauge to the location 1200, 400<br />
moveGauge("healthBar", 1200, 400)<br />
</syntaxhighlight><br />
<br />
==moveWindow==<br />
;moveWindow(name, x, y)<br />
: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.<br />
<br />
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of your window<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles.<br />
<br />
==openUserWindow==<br />
;openUserWindow(windowName, [restoreLayout], [autoDock], [dockingArea])<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).<br />
* ''restoreLayout:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.<br />
* ''autoDock:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't dock automatically at the corners.<br />
* ''dockingArea:''<br />
: (optional) - the area your UserWindow will be docked at. possible docking areas your UserWindow will be created in (f" floating "t" top "b" bottom "r" right and "l" left). Docking area is "right" if not given any value.<br />
<br />
{{note}}<br />
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.<br />
<br />
{{note}}<br />
The parameters autoDock and dockingArea are available since Mudlet 4.7+ <br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
openUserWindow("My floating window")<br />
cecho("My floating window", "<red>hello <blue>bob!")<br />
<br />
-- if you don't want Mudlet to remember its last position:<br />
openUserWindow("My floating window", false)<br />
</syntaxhighlight><br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]]<br />
<br />
==paste==<br />
;paste(windowName)<br />
: Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The [[#copy | copy()]] and [[#paste | 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
<br />
==prefix==<br />
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
:Prefixes text at the beginning of the current line when used in a trigger.<br />
<br />
;Parameters<br />
* ''text:''<br />
: the information you want to prefix<br />
* "writingFunction:"<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* "foregroundColor:"<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* "backgroundColor:"<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* "windowName:"<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that<br />
prefix(os.date("%H:%M:%S "))<br />
-- Prefix the time in red into a miniconsole named "my_console"<br />
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#suffix | suffix()]]<br />
<br />
==print==<br />
;print(text, some more text, ...)<br />
:Prints text to the main window. Similar to [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#display|display()]] for those. This function works similarly to the print() you will see in guides for Lua.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
print("hi!")<br />
print(1,2,3)<br />
print(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==raiseWindow==<br />
;raiseWindow(labelName)<br />
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to bring to the top of the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel<br />
</syntaxhighlight><br />
<br />
==replace==<br />
;replace([windowName], with, [keepcolor])<br />
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.<br />
<br />
{{note}}<br />
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.<br />
<br />
{{note}}<br />
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 | insertText()]] does.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of window (a miniconsole)<br />
* ''with:''<br />
: the new text to display.<br />
* ''keepcolor:''<br />
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
-- replace word "troll" with "cute trolly"<br />
selectString("troll",1)<br />
replace("cute trolly")<br />
<br />
-- replace the whole line<br />
selectCurrentLine()<br />
replace("Out with the old, in with the new!")<br />
</syntaxhighlight><br />
<br />
==replaceAll==<br />
;replaceAll(what, with, [keepcolor])<br />
: Replaces all occurrences of ''what'' in the current line with ''with''.<br />
<br />
;Parameters<br />
* ''what:''<br />
: the text to replace<br />
{{note}}<br />
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]<br />
* ''with:''<br />
: the new text to have in place<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors.<br />
{{note}} keepcolor available in Mudlet 4.10+, is not in previous versions.<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the word "south" in the line with "north"<br />
replaceAll("south", "north")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the text that the variable "target" has<br />
replaceAll(target, "The Bad Guy")<br />
</syntaxhighlight><br />
<br />
==replaceWildcard==<br />
;replaceWildcard(which, replacement, [keepcolor])<br />
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString(matches[2], 1)<br />
replace("text")<br />
</syntaxhighlight><br />
<br />
;Parameters<br />
* ''which:''<br />
: Wildcard to replace.<br />
* ''replacement:''<br />
: Text to replace the wildcard with.<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors<br />
{{note}} keepcolor available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello<br />
</syntaxhighlight><br />
<br />
==resetCmdLineAction==<br />
;resetCmdLineAction(commandLineName)<br />
: Resets the action on the command line so the it behaves like the main command line again.<br />
;Parameters<br />
<br />
* ''commandLineName''<br />
: The name of the command line the action will be resetet.<br />
: See also: [[#setCmdLineAction | setCmdLineAction()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetConsoleBackgroundImage==<br />
;resetConsoleBackgroundImage([windowName])<br />
: Resets the console background-image<br />
;Parameters<br />
<br />
* ''windowName''<br />
: (optional) name of the console the image will be reset<br />
: See also: [[#setConsoleBackgroundImage | setConsoleBackgroundImage()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: 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.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==resetLabelCursor==<br />
;resetLabelCursor(labelName)<br />
: Resets your mouse cursor to the default one.<br />
<br />
: See also: [[#setLabelCursor|setLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName'': label for which to reset the cursor for.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetLabelCursor("myLabel")<br />
-- This will reset the mouse cursor over myLabel to the default one<br />
</syntaxhighlight><br />
<br />
==resetLabelToolTip==<br />
;resetLabelToolTip(labelName)<br />
: Resets the tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label the tooltip will be reseted.<br />
: See also: [[#setLabelToolTip | setLabelToolTip()]]<br />
<br />
==resetMapWindowTitle==<br />
;resetMapWindowTitle()<br />
: resets the title of the popped out map window to default.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setMapWindowTitle|setMapWindowTitle()]]<br />
<br />
==resetUserWindowTitle==<br />
;resetUserWindowTitle(windowName)<br />
: resets the title of the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow for which the title will be resetet<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setUserWindowTitle|setUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==resizeWindow==<br />
;resizeWindow(windowName, width, height)<br />
: Resizes a mini console, label, or floating User Windows.<br />
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
* ''width:''<br />
: The new width you want<br />
* ''height:''<br />
: The new height you want<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.<br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumber:''<br />
: number of the capture group you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".<br />
--If you want to color the amount of money you have green you do:<br />
<br />
selectCaptureGroup(1)<br />
setFgColor(0,255,0)<br />
</syntaxhighlight><br />
<br />
==selectCurrentLine==<br />
; selectCurrentLine([windowName])<br />
: 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.<br />
<br />
{{note}}<br />
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.<br />
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- color the whole line green!<br />
selectCurrentLine()<br />
fg("green")<br />
deselect()<br />
resetFormat()<br />
<br />
-- to select the previous line, you can do this:<br />
moveCursor(0, getLineNumber()-1)<br />
selectCurrentLine()<br />
<br />
-- to select two lines back, this:<br />
moveCursor(0, getLineNumber()-2)<br />
selectCurrentLine()<br />
<br />
</syntaxhighlight><br />
<br />
==selectSection==<br />
;selectSection( [windowName], fromPosition, length )<br />
: 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.<br />
: 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.<br />
<br />
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]<br />
<br />
;Parameters<br />
* "windowName:"<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.<br />
: Will not work if "main" is given as the windowName to try to select from the main window.<br />
* ''fromPosition:''<br />
: number to specify at which position in the line to begin selecting<br />
* ''length:''<br />
: number to specify the amount of characters you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and colour the first character in the line red<br />
if selectSection(0,1) then fg("red") end<br />
<br />
-- select and colour the second character green (start selecting from the first character, and select 1 character)<br />
if selectSection(1,1) then fg("green") end<br />
<br />
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)<br />
if selectSection(2,3) then fg("grey") end<br />
</syntaxhighlight><br />
<br />
==selectString==<br />
;selectString( [windowName], text, number_of_match )<br />
: 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).<br />
<br />
{{note}}<br />
You can move the user cursor with [[#moveCursor | 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 | deselect()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.<br />
* ''text:''<br />
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).<br />
* ''number_of_match:''<br />
: 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.<br />
<br />
: Returns position in line or -1 on error (text not found in line)<br />
<br />
{{note}}<br />
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if selectString( "big monster", 1 ) > -1 then fg("red") end<br />
</syntaxhighlight><br />
<br />
==setAppStyleSheet==<br />
;setAppStyleSheet(stylesheet [, tag])<br />
: Sets a stylesheet for the entire Mudlet application and every open profile. Because it affects other profiles that might not be related to yours, it's better to use [[#setProfileStyleSheet|setProfileStyleSheet()]] instead of this function.<br />
<br />
: Raises the sysAppStyleSheetChange event which comes with two arguments in addition to the event name. The first is the optional tag which was passed into the function, or "" if nothing was given. The second is the profile which made the stylesheet changes.<br />
<br />
: See also: [[#setProfileStyleSheet|setProfileStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use.<br />
<br />
* ''tag:'' (with Mudlet 3.19+)<br />
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.<br />
<br />
;References<br />
: See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setAppStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
]])<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 3.0.<br />
<br />
Enhanced in Mudlet version 3.19.0 to generate an event that profiles/packages can utilise to redraw any parts of the UI that they themselves had previously styled so their effects can be re-applied to the new application style.<br />
<br />
It is anticipated that the Mudlet application itself will make further use of application styling effects and two strings are provisionally planned for the second parameter in the ''sysAppStyleSheetChange'' event: "''mudlet-theme-dark''" and "''mudlet-theme-light''"; it will also set the third parameter to "''system''".<br />
<br />
==setBackgroundColor==<br />
;setBackgroundColor([windowName], r, g, b, transparency)<br />
: Sets the background for the given label, miniconsole, or userwindow. Colors are from 0 to 255 (0 being black), and transparency is from 0 to 255 (0 being completely transparent).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.<br />
* ''r:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''g:''<br />
: Amount of green to use, from 0 (none) to 255 (full).<br />
* ''b:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).<br />
<br />
{{note}}<br />
Transparency also available for main/miniconsoles in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red label that's somewhat transparent<br />
setBackgroundColor("some label",255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setBackgroundImage==<br />
;setBackgroundImage(labelName, imageLocation)<br />
: Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.<br />
<br />
{{note}}<br />
You can only do this for labels, not miniconsoles.<br />
<br />
{{note}}<br />
You can also load images via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to change it's background color.<br />
* ''imageLocation:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give the top border a nice look<br />
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])<br />
</syntaxhighlight><br />
<br />
==setBgColor==<br />
;setBgColor([windowName], r, g, b, transparency)<br />
: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.<br />
<br />
: ''See also:'' [[#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Optional, if not used color is fully opaque<br />
<br />
<br />
<br />
{{note}}<br />
Transparency parameter available in Mudlet 4.10+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red background color.<br />
selectString( "Tom", 1 )<br />
setBgColor( 255,0,0 )<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--prints "Hello" on red background and "You" on blue.<br />
setBgColor(255,0,0)<br />
echo("Hello")<br />
setBgColor(0,0,255)<br />
echo(" You!")<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBold==<br />
;setBold(windowName, boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
<br />
* ''boolean:''<br />
: A <code>true</code> or <code>false</code> that enables or disables bolding of text<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- enable bold formatting<br />
setBold(true)<br />
-- the following echo will be bolded<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBorderBottom==<br />
;setBorderBottom(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
</syntaxhighlight><br />
<br />
==setBorderColor==<br />
;setBorderColor(red, green, blue)<br />
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]<br />
<br />
;Parameters<br />
* ''red:''<br />
: Amount of red color to use, from 0 to 255.<br />
* ''green:''<br />
: Amount of green color to use, from 0 to 255.<br />
* ''blue:''<br />
: Amount of blue color to use, from 0 to 255.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set the border to be completely blue<br />
setBorderColor(0, 0, 255)<br />
<br />
-- or red, using a name<br />
setBorderColor( unpack(color_table.red) )<br />
</syntaxhighlight><br />
<br />
==setBorderLeft==<br />
;setBorderLeft(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
</syntaxhighlight><br />
<br />
==setBorderRight==<br />
;setBorderRight(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
</syntaxhighlight><br />
<br />
==setBorderSizes==<br />
;setBorderSizes(top, right, bottom, left)<br />
: Sets the size of all borders 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.<br />
: The exact result of this function depends on how many numbers you give to it as arguments.<br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Arguments<br />
* '''setBorderSizes(top, right, bottom, left)'''<br />
: ''4 arguments:'' All borders will be set to their new given size.<br />
* '''setBorderSizes(top, width, bottom)''' <br />
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width. <br />
* '''setBorderSizes(height, width)'''<br />
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width. <br />
* '''setBorderSizes(size)'''<br />
: ''1 argument:'' All borders will be set to the same size.<br />
* '''setBorderSizes()'''<br />
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0) <br />
-- big border at the top, bigger at the bottom, small at the right, none at the left<br />
<br />
setBorderSizes(100, 50, 150) <br />
-- big border at the top, bigger at the bottom, small at the right and the left<br />
<br />
setBorderSizes(100, 50) <br />
-- big border at the top and the bottom, small at the right and the left<br />
<br />
setBorderSizes(100) <br />
-- big borders at all four sides<br />
<br />
setBorderSizes() <br />
-- no borders at all four sides<br />
</syntaxhighlight><br />
<br />
==setBorderTop==<br />
;setBorderTop(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
</syntaxhighlight><br />
<br />
==setFgColor==<br />
;setFgColor([windowName], red, green, blue)<br />
:Sets the current text foreground color in the main window unless windowName parameter given.<br />
<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''red:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''green:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''blue:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]], [[#setHexBgColor | setHexBgColor()]], [[#resetFormat | resetFormat()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setFgColor( 255, 0, 0 )<br />
</syntaxhighlight><br />
<br />
==setButtonStyleSheet==<br />
;setButtonStyleSheet(button, markup)<br />
: Applies Qt style formatting to a button via a special markup language.<br />
<br />
; Parameters<br />
* ''button:''<br />
: The name of the button to be formatted.<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note: You can instead use QWidget { markup }. QWidget will reference 'button', allowing the use of pseudostates like QWidget:hover and QWidget:selected<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setButtonStyleSheet("my test button", [[<br />
QWidget {<br />
background-color: #999999;<br />
border: 3px #777777;<br />
}<br />
QWidget:hover {<br />
background-color: #bbbbbb;<br />
}<br />
QWidget:checked {<br />
background-color: #77bb77;<br />
border: 3px #559955;<br />
}<br />
QWidget:hover:checked {<br />
background-color: #99dd99;<br />
} ]])</syntaxhighlight><br />
<br />
==setClipboardText==<br />
;setClipboardText(textContent)<br />
: Sets the value of the computer's clipboard to the string data provided.<br />
: See also: [[#getClipboardText | getClipboardText()]]<br />
<br />
; Parameters<br />
* ''textContent:''<br />
: The text to be put into the clipboard.<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setClipboardText("New Clipboard Contents")<br />
echo("Clipboard: " .. getClipboardText()) -- should echo "Clipboard: New Clipboard Contents"<br />
</syntaxhighlight><br />
<br />
==setCmdLineAction==<br />
;setCmdLineAction(commandLineName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user sends text to the command line. 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 command line action. Additionally, this function passes the command line input text as the final argument.<br />
{{note}} If no action is set the command line behaves like the main command line and sends commands directly to the game or alias engine.<br />
<br />
The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, text)<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#resetCmdLineAction|resetCmdLineAction()]]<br />
<br />
;Parameters<br />
<br />
* ''commandLineName:''<br />
: The name of the command line to attach the action function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} You can also pass a function directly instead of using a string<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function sendTextToMiniConsole(miniConsoleName, cmdLineText)<br />
echo(miniConsoleName, cmdLineText.."\n")<br />
end<br />
<br />
setCmdLineAction("myCmdLine", "sendTextToMiniConsole", "myMiniConsole")<br />
<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setConsoleBackgroundImage==<br />
;setConsoleBackgroundImage([windowname], imageLocation, [mode])<br />
: Loads an image file (for example png) as a background image for a console (main/miniconsole and userwindows).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow to change the background image on, or "main" for the main window.<br />
* ''imageLocation:''<br />
: 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.<br />
* ''mode:''<br />
: (optional) allows different modes for drawing the background image<br />
possible modes areː "border" (the background image is stretched) , 2 "center" (the background image is in the center), <br />
3 "tile" (the background image is 'tiled'), 4 "style" (choose your own background image stylesheet. see example below) <br />
<br />
: See also: [[#resetConsoleBackgroundImage | resetConsoleBackgroundImage()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give my_miniconsole a nice background image and put it in the center<br />
setConsoleBackgroundImage("my_miniconsole", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image with own stylesheet option<br />
setConsoleBackgroundImage("my_miniconsole", [[background-image: url(:/Mudlet_splashscreen_development.png); background-repeat: no-repeat; background-position: right;]], "style")<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setFont==<br />
;setFont(name, font)<br />
: Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Prefer a monospaced font - those work best with text games. See here [https://doc.qt.io/qt-5/qfont.html#setFamily for more].<br />
: See also: [[#getFont|getFont()]], [[#setFontSize|setFontSize()]], [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''font:''<br />
: The font to use.<br />
<br />
{{note}}<br />
Available in Mudlet 3.9+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.<br />
setFont("Ubuntu Mono")<br />
setFont("main", "Ubuntu Mono")<br />
<br />
-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.<br />
setFont("combat", "Ubuntu Mono")<br />
</syntaxhighlight><br />
<br />
==setFontSize==<br />
;setFontSize(name, size)<br />
: Sets a font size on the given window or console name. Can be used to change font size of the Main console as well as dockable UserWindows.<br />
: See Also: [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
* ''size:''<br />
: The font size to apply to the window.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to 12-point font.<br />
setFontSize(12)<br />
setFontSize("main", 12)<br />
<br />
-- This will set the font size of a user window named "uw1" to 12-point font.<br />
setFontSize("uw1", 12)<br />
</syntaxhighlight><br />
<br />
==setGauge==<br />
;setGauge(gaugeName, currentValue, maxValue, gaugeText)<br />
: 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.<br />
<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#createGauge|createGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a gauge<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
--Change the looks of the gauge named healthBar and make it<br />
--fill to half of its capacity. The height is always remembered.<br />
setGauge("healthBar", 200, 400)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
--If you wish to change the text on your gauge, you’d do the following:<br />
setGauge("healthBar", 200, 400, "some text")<br />
</syntaxhighlight><br />
<br />
==setGaugeStyleSheet==<br />
;setGaugeStyleSheet(gaugeName, css, cssback, csstext)<br />
: 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. You can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create stylesheets.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]],<br />
[[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
</syntaxhighlight><br />
<br />
==setGaugeText==<br />
;setGaugeText(gaugename, css, ccstext )<br />
: Set the formatting of the text used inside the inserted gaugename.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
setGaugeText("healthBar", [[<p style="font-weight:bold;color:#C9C9C9;letter-spacing:1pt;word-spacing:2pt;font-size:12px;text-align:center;font-family:arial black, sans-serif;">]]..MY_NUMERIC_VARIABLE_HERE..[[</p>]])</syntaxhighlight><br />
<br />
;Useful resources:<br />
:http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.<br />
:https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!<br />
<br />
==setHexBgColor==<br />
;setHexBgColor([windowName], hexColorString)<br />
:Sets the current text nackground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.<br />
selectString( "Tom", 1 )<br />
setHexBgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setHexFgColor==<br />
;setHexFgColor([windowName], hexColorString)<br />
:Sets the current text foreground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text foreground color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setFgColor | setFgColor()]], [[#setHexBgColor | setHexBgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setHexFgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setItalics==<br />
;setItalics(windowName, bool)<br />
: Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setLabelToolTip==<br />
;setLabelToolTip(labelName, [duration])<br />
: Sets a tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to set the tooltip to.<br />
* ''duration:''<br />
: Duration of the tooltip timeout in seconds. Optional, if not set the default duration will be set.<br />
<br />
: See also: [[Manual:UI_Functions#resetLabelToolTip|resetLabelToolTip()]]<br />
<br />
==setLabelClickCallback==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument. This table contains information about the mouse button clicked, other buttons that were pressed at the time, and the mouse cursor's local (relative to the label) and global (relative to the Mudlet window) position. The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, event)<br />
</syntaxhighlight><br />
<br />
where '''event''' has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
button = "LeftButton",<br />
buttons = {"RightButton", "MidButton"},<br />
}<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]],[[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} Event argument is available in 3.6+, and in 4.8+ you can pass a function directly instead of a string.<br />
<br />
{{note}}<br />
While '''event.button''' may contain a single string of any listed below, '''event.buttons''' will only ever contain some combination of "LeftButton", "MidButton", and "RightButton"<br />
:The following mouse button strings are defined:<br />
<pre><br />
"LeftButton" "RightButton" "MidButton"<br />
"BackButton" "ForwardButton" "TaskButton"<br />
"ExtraButton4" "ExtraButton5" "ExtraButton6"<br />
"ExtraButton7" "ExtraButton8" "ExtraButton9"<br />
"ExtraButton10" "ExtraButton11" "ExtraButton12"<br />
"ExtraButton13" "ExtraButton14" "ExtraButton15"<br />
"ExtraButton16" "ExtraButton17" "ExtraButton18"<br />
"ExtraButton19" "ExtraButton20" "ExtraButton21"<br />
"ExtraButton22" "ExtraButton23" "ExtraButton24"<br />
</pre><br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
else if event.button == "RightButton" then<br />
send("swim north")<br />
else if event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )<br />
<br />
-- you can also use them within tables now:<br />
mynamespace = {<br />
onClickGoNorth = function()<br />
echo("the north button was clicked!")<br />
end<br />
}<br />
<br />
setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )<br />
<br />
</syntaxhighlight><br />
<br />
==setLabelDoubleClickCallback==<br />
;setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user double 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.6+<br />
<br />
: See also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
==setLabelMoveCallback==<br />
;setLabelMoveCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse moves while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
==setLabelOnEnter==<br />
;setLabelOnEnter(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the '''event''' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
}<br />
</syntaxhighlight><br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseOver()<br />
echo("The mouse is hovering over the label!\n")<br />
end<br />
<br />
setLabelOnEnter( "compassNorthImage", "onMouseOver" )<br />
</syntaxhighlight><br />
<br />
==setLabelOnLeave==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseLeft(argument)<br />
echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)<br />
end<br />
<br />
setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )<br />
</syntaxhighlight><br />
<br />
==setLabelReleaseCallback==<br />
;setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
This command was added in version 3.0.0<br />
<br />
{{note}}<br />
The ''event'' argument only available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onReleaseNorth()<br />
echo("the north button was released!")<br />
end<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onReleaseNorth = function()<br />
echo("the north button was released!")<br />
end<br />
}<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )<br />
</syntaxhighlight><br />
<br />
==setLabelStyleSheet==<br />
;setLabelStyleSheet(label, markup)<br />
: Applies Qt style formatting to a label via a special markup language.<br />
<br />
; Parameters<br />
* ''label:''<br />
: The name of the label to be formatted (passed when calling createLabel).<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a white background and a green border, with the text "test"<br />
-- inside.<br />
createLabel("test", 50, 50, 100, 100, 0)<br />
setLabelStyleSheet("test", [[<br />
background-color: white;<br />
border: 10px solid green;<br />
font-size: 12px;<br />
]])<br />
echo("test", "test")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that will tile or clip depending on the<br />
-- size of the label. To use this example, please supply your own image.<br />
createLabel("test5", 50, 353, 164, 55, 0)<br />
setLabelStyleSheet("test5", [[<br />
background-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that can be resized (such as during a<br />
-- sysWindowResizeEvent). To use this example, please supply your own image.<br />
createLabel("test9", 215, 353, 100, 100, 0)<br />
setLabelStyleSheet("test9", [[<br />
border-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--This creates a label whose background changes when the users mouse hovers over it.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
local ourLabelStyle = [[<br />
QLabel{<br />
background-color: ]]..labelBackgroundColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
QLabel::hover{<br />
background-color: ]]..labelHoverColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--Using QLabel::hover mentioned above. Lets "trick" the label into changing it's text.<br />
--Please keep in mind that the setLabelMoveCallback allows for much more control over not just your label but your entire project.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
--Notice we are adding a string returned from a function. In this case, the users profile directory.<br />
local ourLabelStyle = [[<br />
QLabel{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithtext.png");<br />
}<br />
QLabel::hover{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithhovertext.png");<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
--This is just to example that echos draw on top of the label. You would not want to echo onto a label you were drawing text on with images, because echos would draw on top of them.<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<br />
==setLabelCursor==<br />
;setLabelCursor(labelName, cursorShape)<br />
: Changes how the mouse cursor looks like when over the label. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''cursorShape''<br />
: Shape of the mouse cursor. List of possible cursor shapes is [[CursorShapes| available here]].<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCursor("myLabel", "Cross")<br />
-- This will change the mouse cursor to a cross if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelCustomCursor==<br />
;setLabelCustomCursor(labelName, custom cursor, [hotX, hotY])<br />
: Changes the mouse cursor shape over your label to a custom cursor. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCursor|setLabelCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''custom cursor''<br />
: Location of your custom cursor file. To be compatible with all systems it is recommended to use png files with size of 32x32.<br />
* ''hotX''<br />
: X-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
* ''hotY''<br />
: Y-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCustomCursor("myLabel", getMudletHomeDir().."/custom_cursor.png")<br />
-- This will change the mouse cursor to your custom cursor if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelWheelCallback==<br />
;setLabelWheelCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse wheel is scrolled while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the ''event'' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
buttons = {"RightButton", "MidButton"},<br />
angleDeltaX = 0,<br />
angleDeltaY = 120<br />
}<br />
</syntaxhighlight><br />
<br />
: Keys ''angleDeltaX'' and ''angleDeltaY'' correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onWheelNorth(event)<br />
if event.angleDeltaY > 0 then<br />
echo("the north button was wheeled forwards over!")<br />
else<br />
echo("the north button was wheeled backwards over!")<br />
end<br />
end<br />
<br />
setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onWheelNorth = function()<br />
echo("the north button was wheeled over!")<br />
end<br />
}<br />
<br />
setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )<br />
</syntaxhighlight><br />
<br />
==setLink==<br />
;setLink([windowName], command, tooltip)<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of a miniconsole or a userwindow in which to select the text in.<br />
* ''command:''<br />
: command to do when the text is clicked.<br />
* ''tooltip:''<br />
: tooltip to show when the mouse is over the text - explaining what would clicking do.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can clickify a lot of things to save yourself some time - for example, you can change<br />
-- the line where you receive a message to be clickable to read it!<br />
-- prel regex trigger:<br />
-- ^You just received message #(\w+) from \w+\.$<br />
-- script:<br />
selectString(matches[2], 1)<br />
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])<br />
resetFormat()<br />
<br />
-- an example of selecting text in a miniconsole and turning it into a link:<br />
<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
HelloWorld:echo("hi")<br />
selectString("HelloWorld", "hi", 1)<br />
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")<br />
</syntaxhighlight><br />
<br />
==setMainWindowSize==<br />
;setMainWindowSize(mainWidth, mainHeight)<br />
: Changes the size of your main Mudlet window to the values given.<br />
: See Also: [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''mainWidth:''<br />
: The new width in pixels.<br />
* ''mainHeight:''<br />
: The new height in pixels.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will resize your main Mudlet window<br />
setMainWindowSize(1024, 768)<br />
</syntaxhighlight><br />
<br />
==setMapWindowTitle==<br />
;setMapWindowTitle(text)<br />
: Changes the title shown in the mapper window when it's popped out.<br />
: See also: [[#resetMapWindowTitle|resetMapWindowTitle()]]<br />
<br />
; Parameters<br />
* ''text:''<br />
: New window title to set.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapWindowTitle("my cool game map")<br />
</syntaxhighlight><br />
<br />
==setMiniConsoleFontSize==<br />
;setMiniConsoleFontSize(name, fontSize)<br />
: Sets the font size of the mini console. see also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]]<br />
<br />
==setOverline==<br />
;setOverline([windowName], boolean)<br />
: Sets the current text font to be overlined (true) or not overlined (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 overlined. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be overlined until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be overlined or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables overlining of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable overlined text<br />
setOverline(true)<br />
-- the following echo will be have an overline<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and reverse have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==setPopup==<br />
;setPopup(windowName, {lua code}, {hints})<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,<br />
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking<br />
-- will show some commands you can do.<br />
<br />
selectString("Hello", 1)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})<br />
</syntaxhighlight><br />
<br />
==setProfileStyleSheet==<br />
;setProfileStyleSheet(stylesheet)<br />
: Sets a stylesheet for the current Mudlet profile - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). This function is better than setAppStyleSheet() because it affects only the current profile and not every other one as well.<br />
<br />
: See also: [[#setAppStyleSheet|setAppStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use. See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setProfileStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
<br />
QTreeView {<br />
background: ]]..background_color..[[;<br />
color: white;<br />
}<br />
<br />
QMenuBar{ background-color: ]]..background_color..[[;}<br />
<br />
QMenuBar::item{ background-color: ]]..background_color..[[;}<br />
<br />
QDockWidget::title {<br />
background: ]]..border_color..[[;<br />
}<br />
QStatusBar {<br />
background: ]]..border_color..[[;<br />
}<br />
QScrollBar:vertical {<br />
background: ]]..background_color..[[;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background-color: ]]..background_color..[[;<br />
min-height: 20px;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 7px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-bottom-left-radius: 7px;<br />
border-bottom-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-top-left-radius: 7px;<br />
border-top-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
background: white;<br />
width: 4px;<br />
height: 3px;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]])<br />
<br />
-- if you'd like to reset it, use:<br />
setProfileStyleSheet("")<br />
<br />
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':<br />
setProfileStyleSheet[[<br />
TConsole QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
TConsole QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
TConsole QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 4.6.<br />
<br />
==setReverse==<br />
;setReverse([windowName], boolean)<br />
: Sets the current text to swap foreground and background color settings (true) or not (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 have it's colors swapped. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will have their foreground and background colors swapped until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text colors to be reversed or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables reversing of the fore- and back-ground colors of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable fore/back-ground color reversal of text<br />
setReverse(true)<br />
-- the following echo will have the text colors reversed<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and overline have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
{{note}} Although the visual effect on-screen is the same as that of text being selected if both apply to a piece of text they neutralise each other - however the effect of the reversal ''will'' be carried over in copies made by the "Copy to HTML" and in logs made in HTML format log file mode.<br />
<br />
==setStrikeOut==<br />
;setStrikeOut([windowName], boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be striken out until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be stricken out or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables striking out of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable striken-out text<br />
setStrikeOut(true)<br />
-- the following echo will be have a strikethrough<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setTextFormat==<br />
;setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])<br />
: Sets current text format of selected window. This is a more convenient means to set all the individual features at once compared to using [[#setFgColor|setFgColor]]( windowName, r,g,b ), [[#setBold|setBold]]( windowName, true ), [[#setItalics|setItalics]]( windowName, true ), [[#setUnderline|setUnderline]]( windowName, true ), [[#setStrikeOut|setStrikeOut]]( windowName, true ).<br />
: See Also: [[Manual:Lua_Functions#getTextFormat|getTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: Specify name of selected window. If empty string "" or "main" format will be applied to the main console<br />
* ''r1,g1,b1''<br />
: To color text background, give number values in RBG style<br />
* ''r2,g2,b2''<br />
: To color text foreground, give number values in RBG style<br />
* ''bold''<br />
: To format text bold, set to 1 or true, otherwise 0 or false<br />
* ''underline''<br />
: To underline text, set to 1 or true, otherwise 0 or false<br />
* ''italics''<br />
: To format text italic, set to 1 or true, otherwise 0 or false<br />
* ''strikeout<br />
: (optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''overline<br />
: (optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''reverse<br />
: (optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This script would create a mini text console and write with bold, struck-out, yellow foreground color and blue background color "This is a test".<br />
createMiniConsole( "con1", 0,0,300,100);<br />
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);<br />
echo("con1","This is a test")<br />
</syntaxhighlight><br />
<br />
{{note}} In versions prior to 3.7.0 the error messages ''and this wiki'' were wrong in that they had the foreground color parameters as r1, g1 and b1 and the background ones as r2, g2 and b2.<br />
<br />
==setUnderline==<br />
;setUnderline(windowName, bool)<br />
: Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setUserWindowTitle==<br />
;setUserWindowTitle(windowName, text)<br />
: sets a new title text for the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''text''<br />
: new title text<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==setUserWindowStyleSheet==<br />
;setUserWindowStyleSheet(windowName, markup)<br />
: Applies Qt style formatting to the border/title area of a userwindow via a special markup language.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when you dock the userwindow the border style is not provided by this<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- changes the title area style of the UserWindow 'myUserWindow'<br />
setUserWindowStyleSheet("myUserWindow", [[QDockWidget::title{ <br />
background-color: rgb(0,255,150);<br />
border: 2px solid red;<br />
border-radius: 8px;<br />
text-align: center; <br />
}]])<br />
</syntaxhighlight><br />
<br />
: See also: [[#openUserWindow|openUserWindow()]]<br />
<br />
==setWindow==<br />
;setWindow(windowName, name, [Xpos, Ypos, show])<br />
: Changes the parent window of an element.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow which you want the element put in. If you want to put the element into the main window, use windowName "main".<br />
* ''name''<br />
: Name of the element which you want to switch the parent from. Elements can be labels, miniconsoles and the embedded mapper. If you want to move the mapper use the name "mapper"<br />
* ''Xpos:''<br />
: X position of the element. Measured in pixels, with 0 being the very left. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''Ypos:''<br />
: Y position of the element. Measured in pixels, with 0 being the very top. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''show:''<br />
: true or false to decide if the element will be shown or not in the new parent window. Optional, if not given it will be true.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindow("myuserwindow", "mapper")<br />
-- This will put your embedded mapper in your userwindow "myuserwindow".<br />
</syntaxhighlight><br />
<br />
==setWindowWrap==<br />
;setWindowWrap(windowName, wrapAt)<br />
: sets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapAt:''<br />
: Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==setWindowWrapIndent==<br />
;setWindowWrapIndent(windowName, wrapTo)<br />
: sets how many spaces wrapped text will be indented with (after the first line of course).<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapTo:''<br />
: Number of spaces which wrapped lines are prefixed with.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
setWindowWrapIndent("main", 3)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==showCaptureGroups==<br />
;showCaptureGroups()<br />
:Lua debug function that highlights in random colors 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.<br />
<br />
;Example:<br />
: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.<br />
<br />
==showMultimatches==<br />
;showMultimatches()<br />
: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.<br />
<br />
==showWindow==<br />
;showWindow(name)<br />
: Makes a hidden window (label or miniconsole) be shown again.<br />
<br />
: See also: [[#hideWindow | hideWindow()]]<br />
<br />
==showColors==<br />
;showColors([columns], [filterColor], [sort])<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in '''color_table''', in table form. The format is ''color_table.colorName = {r, g, b}''.<br />
<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: (optional) number of columns to print the color table in.<br />
* ''filterColor:''<br />
: (optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.<br />
* ''sort:''<br />
: (optional) sort colors alphabetically.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- display as four columns:<br />
showColors(4)<br />
<br />
-- show only red colours:<br />
showColors("red")<br />
</syntaxhighlight><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)|thumb|center]]<br />
<br />
==showToolBar==<br />
;showToolBar(name)<br />
: Makes a toolbar (a button group) appear on the screen.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
showToolBar("my attack buttons")<br />
</syntaxhighlight><br />
<br />
==suffix==<br />
;suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
: Suffixes text at the end of the current line. This is similar to [[Manual:Lua_Functions#echo | echo()]], which also suffixes text at the end of the line, but different - [[Manual:Lua_Functions#echo | 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.<br />
<br />
;Parameters<br />
* ''text''<br />
: the information you want to prefix<br />
* ''writingFunction''<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* ''foregroundColor''<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* ''backgroundColor''<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* ''windowName''<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
<br />
: See also: [[#prefix | prefix()]], [[Manual:Lua_Functions#echo | echo()]]<br />
<br />
==wrapLine==<br />
;wrapLine(windowName, lineNumber)<br />
: 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.:<br />
<br />
<syntaxhighlight lang="lua">selectString(line,1)<br />
replace("")</syntaxhighlight><br />
<br />
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.<br />
<br />
: See Also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#deleteLine|deleteLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The miniconsole or the main window (use ''main'' for the main window)<br />
* ''lineNumber:''<br />
: The line number which you'd like re-wrapped.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- re-wrap the last line in the main window<br />
wrapLine("main", getLineCount())<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=15592Manual:UI Functions2020-09-30T15:16:37Z<p>Smurf: /* getSelection */ returns three values if you let it</p>
<hr />
<div>{{TOC right}}<br />
= UI Functions =<br />
<br />
All functions that help you customize Mudlet's interface and the game's text.<br />
<br />
==ansi2decho==<br />
;ansi2decho(text, default_colour)<br />
: Converts ANSI colour sequences in <code>text</code> to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.<br />
: See also: [[Manual:Lua_Functions#decho|decho()]]<br />
{{note}}<br />
ANSI bold is available since Mudlet 3.7.1+.<br />
R<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be replaced.<br />
* ''default_colour:''<br />
: Optional - ANSI default colour code (used when handling orphan bold tags).<br />
<br />
;Return values<br />
* ''string text:''<br />
: The decho-valid converted text.<br />
* ''string colour:''<br />
: The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- '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><br />
decho(replaced)<br />
</syntaxhighlight><br />
<br />
Or show a complete colourful squirrel! It's a lotta code to do all the colours, so click the '''Expand''' button on the right to show it:<br />
<div class="toccolours mw-collapsible mw-collapsed"><br />
<syntaxhighlight lang="lua"><br />
decho(ansi2decho([[<br />
�[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m �[0m<br />
╭───────────────────────╮ �[38;5;95m▄▄�[0m �[38;5;95m▄�[48;5;95;38;5;130m▄▄�[48;5;130m█�[38;5;137m▄�[48;5;137;38;5;95m▄�[49m▀�[0m �[0m<br />
│ │ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄▄▄�[48;5;95;38;5;137m▄▄▄�[49;38;5;95m▄▄�[48;5;95;38;5;130m▄�[48;5;130m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[0m �[0m<br />
│ Encrypt everything! │ �[38;5;95m▄�[48;5;187;38;5;16m▄�[48;5;16;38;5;187m▄�[38;5;16m█�[48;5;137;38;5;137m███�[38;5;187m▄�[38;5;16m▄▄�[38;5;137m██�[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[0m �[0m<br />
│ ├──── �[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;16m▄▄▄�[48;5;137m███�[48;5;16;38;5;16m█�[48;5;187m▄�[48;5;16m█�[48;5;137;38;5;137m█�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
╰───────────────────────╯ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;16m▄�[38;5;16m█�[38;5;137m▄�[48;5;137m██████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;95m▀�[48;5;137m▄�[38;5;137m███████�[38;5;95m▄�[49m▀�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[48;5;95;38;5;187m▄▄▄�[38;5;137m▄�[48;5;137m██�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[38;5;95m▀�[48;5;130m▄�[38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;187m████�[48;5;137;38;5;137m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m██�[38;5;95m▄�[38;5;137m█�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;187;38;5;187m████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95m██�[48;5;137m▄▄�[48;5;187;38;5;187m████�[48;5;137;38;5;95m▄▄�[48;5;95;38;5;137m▄�[48;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;187;38;5;187m███�[48;5;95m▄�[38;5;137m▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[49m▄�[48;5;95;38;5;130m▄�[48;5;130m██████�[48;5;137;38;5;137m███�[38;5;95m▄�[49m▀�[0m�[0m<br />
�[48;5;187;38;5;95m▄�[38;5;187m████�[48;5;137;38;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m█████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;137m▄�[38;5;187m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██████�[48;5;95m▄▄�[48;5;130m▄▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▄▄▄�[48;5;95;38;5;137m▄�[48;5;187m▄�[38;5;187m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m█████�[38;5;95m▄�[38;5;137m███████████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀�[48;5;187m▄▄▄�[48;5;95;38;5;137m▄�[48;5;137m██�[38;5;95m▄�[49m▀�[0m �[38;5;95m▀▀�[48;5;137m▄▄▄▄▄▄�[49m▀▀▀�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀▀�[0m �[0m<br />
]]))<br />
</syntaxhighlight><br />
</div><br />
<br />
[[File:Squirrel-in-Mudlet.png|frameless]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.0+<br />
<br />
<br />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be removed.<br />
<br />
;Return values<br />
* ''string text:''<br />
: The plain text without ANSI colour sequences.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10+<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2string('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- 'replaced' should now contain You say in a baritone voice, "Test."<br />
print(replaced)<br />
</syntaxhighlight><br />
<br />
<br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name.<br />
: See also: [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[Manual:Lua_Functions#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</syntaxhighlight><br />
<br />
==bg==<br />
;bg([window, ]colorName)<br />
: Changes the background color of the text. Useful for highlighting text.<br />
: See Also: [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: 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).<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
<br />
-- or echo text with a green background to a miniconsole<br />
bg("my window", "green")<br />
echo("my window", "some green text\n")<br />
</syntaxhighlight><br />
<br />
==calcFontSize==<br />
;calcFontSize(window_or_fontsize, [fontname])<br />
: Returns the average height and width of characters in a particular window, or a font name and size combination. Helpful if you want to size a miniconsole to specific dimensions.<br />
: Returns two numbers, width/height<br />
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
;Parameters<br />
* ''window_or_fontsize:''<br />
: The miniconsole or font size you are wanting to calculate pixel sizes for.<br />
* ''fontname:''<br />
: Specific font name (along with the size as the first argument) to calculate for.<br />
<br />
{{note}}<br />
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide<br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</syntaxhighlight><br />
<br />
==cecho==<br />
;cecho([window], text)<br />
: Echoes text that can be easily formatted with colour tags. You can also include unicode art in it - try some examples from [http://1lineart.kulaone.com/#/ 1lineart].<br />
: See also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cecho("<blue:yellow>Blue on yellow text!")<br />
<br />
-- \n adds a new line<br />
cecho("<red>one line\n<green>another line\n<blue>last line")<br />
<br />
cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
<br />
cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")<br />
<br />
cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")<br />
<br />
cecho([[<br />
██╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗ ████████╗<br />
███║ ██║ ██║████╗ ██║██╔════╝ ██╔══██╗██╔══██╗╚══██╔══╝<br />
╚██║ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝ ██║<br />
██║ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗ ██║<br />
██║ ███████╗██║██║ ╚████║███████╗ ██║ ██║██║ ██║ ██║<br />
╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝<br />
]])<br />
</syntaxhighlight><br />
<br />
==cechoLink==<br />
;cechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#cecho|cecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cechoPopup==<br />
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#cecho|cecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertLink==<br />
;cinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#cinsertText|cinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertPopup==<br />
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#cinsertText|cinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertText==<br />
;cinsertText([window], text)<br />
: inserts text at the current cursor position, with the possibility for color tags.<br />
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cinsertText("<blue:yellow>Blue on yellow text!")<br />
<br />
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
</syntaxhighlight><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].<br />
<br />
==clearWindow==<br />
;clearWindow([windowName])<br />
: Clears the label, mini console, or user window 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 (starting with Mudlet 2.0-test3+)<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this can clear your whole main window - needs Mudlet version >= 2.0<br />
clearWindow()<br />
</syntaxhighlight><br />
<br />
==copy==<br />
; copy([windowName])<br />
: Copies the current selection to the lua virtual clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the lua virtual clipboard until it gets overwritten by another copy operation.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
; Parameters<br />
* ''windowName'' (optional):<br />
: the window from which to copy text - use the main console if not specified.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This script copies the current line on the main screen to a window (miniconsole or userwindow) called 'chat' and gags the output on the main screen.<br />
selectString(line, 1)<br />
copy()<br />
appendBuffer("chat")<br />
replace("This line has been moved to the chat window!")<br />
</syntaxhighlight><br />
<br />
==copy2decho==<br />
; copy2decho([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in decho format.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line.<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and dechos it to a miniconsole named "test"<br />
decho("test", copy2decho())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and decho it to a Geyser miniconsole stored as the variable enemylist<br />
enemylist:decho(copy2decho(matches[2]))<br />
</syntaxhighlight><br />
<br />
==copy2html==<br />
; copy2html([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in html format for echoing to a label.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main"<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and echos it to a label named "TestLabel"<br />
echo("TestLabel", copy2html())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and echo it to a Geyser label stored as the variable enemylist<br />
enemylist:echo(copy2html(matches[2]))<br />
</syntaxhighlight><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: 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.<br />
<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</syntaxhighlight><br />
<br />
==createCommandLine==<br />
;createCommandLine([name of userwindow], name, x, y, width, height)<br />
: Creates a new command line inside the main window of Mudlet. If only a command line inside a miniConsole/UserWindow is needed see [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]].<br />
: You can use [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]] / [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]] and other command line functions to customize the input.<br />
{{note}} [[Manual:UI_Functions#setCmdLineAction|setCmdLineAction]] allows you to attach an action to your command line input.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#disableCommandLine|disableCommandLine()]], [[Manual:Mudlet_Object_Functions#clearCmdLine|clearCmdLine()]], [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]], [[Manual:Mudlet_Object_Functions#printCmdLine|printCmdLine()]], [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the command line is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the command line. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the command line size and location - it is also possible to set them by using [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createCommandLine() will only set them once.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==createConsole==<br />
;createConsole([name of userwindow], consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow your new miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,<br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
''(For Mudlet Makers)'' This function is implemented outside the application's core via the '''GUIUtils.lua''' file of the Mudlet supporting Lua code using [[Manual:UI_Functions#createMiniConsole|createMiniConsole()]] and other functions to position and size the mini-console and configure the font.<br />
<br />
==createGauge==<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the gauge is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: 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<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
* ''orientation:''<br />
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.<br />
<syntaxhighlight lang="lua"><br />
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")<br />
</syntaxhighlight><br />
<br />
==createLabel==<br />
;createLabel([name of userwindow], name, Xpos, Ypos, width, height, fillBackground, [enableClickthrough])<br />
: 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.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]], [[Manual:Lua_Functions#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will display the background color, 0 or false will not.<br />
* ''enableClickthrough:''<br />
: Whether or not enable clickthrough on this label. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will enable clickthrough, 0 or false will not. Optional, defaults to clickthrough not enabled if not provided.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label situated at x=300 y=400 with dimensions 100x200<br />
createLabel("a very basic label",300,400,100,200,1)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle<br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent<br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
<br />
-- you can also make it react to clicks!<br />
mynamespace = {<br />
messageBoxClicked = function()<br />
echo("hey you've clicked the box!\n")<br />
end<br />
}<br />
<br />
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")<br />
<br />
<br />
-- uncomment code below to make it also hide after a short while<br />
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</syntaxhighlight><br />
<br />
==createMiniConsole==<br />
;createMiniConsole([name of userwindow], name, x, y, width, height)<br />
: 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.<br />
: You can use [[Manual:Lua_Functions#clearWindow|clearWindow()]] / [[Manual:Lua_Functions#moveCursor|moveCursor()]] and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. [[Manual:Lua_Functions#setWindowWrap|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 [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent()]], [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|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.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
==creplace==<br />
;creplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, with color names inside angle brackets as with [[Manual:Lua_Functions#cecho|cecho()]]. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
creplace("<magenta>[ALERT!]: <reset>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==creplaceLine==<br />
;creplaceLine (text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''text:''<br />
*: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)<br />
</syntaxhighlight><br />
<br />
==decho==<br />
;decho ([name of console,] text)<br />
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB,[BA]> 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,[BA]>. 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")''.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]]<br />
<br />
;Parameters<br />
* ''name of console''<br />
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.<br />
* ''text:''<br />
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.<br />
<br />
<br />
{{note}}<br />
Optional background transparancy parameter (BA) available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
decho("<50,50,0:0,255,0>test")<br />
<br />
decho("miniconsolename", "<50,50,0:0,255,0>test")<br />
</syntaxhighlight><br />
<br />
==dechoLink==<br />
;dechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#decho|decho()]]. This version allows you to use colours within your link text.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) allows selection between sending the link to a miniconsole or the "main" window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==dechoPopup==<br />
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#decho|decho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertLink==<br />
;dinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#dinsertText|dinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertPopup==<br />
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#dinsertText|dinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
== deleteLabel ==<br />
; deleteLabel(labelName)<br />
<br />
: Deletes and removes a label from the screen. Note that if you'd like to show the label again, it is much more performant to hide/show it instead.<br />
<br />
: Note that you shouldn't use the Geyser label associated with the label you delete afterwards - that doesn't make sense and Geyser right now wouldn't know that it's been deleted, either.<br />
<br />
: See also: [[#hideWindow|hideWindow()]], [[#showWindow|showWindow()]], [[#createLabel|createLabel()]]<br />
<br />
; Parameters<br />
<br />
* ''labelName'': name of the label to delete.<br />
<br />
<syntaxhighlight lang="lua"><br />
createLabel("a very basic label",300,400,100,200,1)<br />
setBackgroundColor("a very basic label", 255, 204, 0, 200)<br />
<br />
-- delete the label after 3 seconds<br />
tempTimer(3, function()<br />
deleteLabel("a very basic label")<br />
end)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 4.5+<br />
<br />
==deleteLine==<br />
;deleteLine([windowName])<br />
: 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. This is purely visual - triggers will still fire on the line as expected.<br />
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.<br />
<br />
{{note}} for replacing text, [[Manual:Lua_Functions#replace|replace()]] is the proper option; doing the following: <code>selectCurrentLine(); replace(""); cecho("new line!\n")</code> is better.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- deletes the line - just put this command into the big script box. Keep the case the same -<br />
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else<br />
deleteLine()<br />
<br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
<br />
-- example of deleting multiple lines:<br />
deleteLine() -- delete the current line<br />
moveCursor(0,getLineNumber()-1) -- move the cursor back one line<br />
deleteLine() -- delete the previous line now<br />
</syntaxhighlight><br />
<br />
==deselect==<br />
;deselect([window name])<br />
: 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.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''window name:''<br />
: (optional) The name of the window to stop having anything selected in. If name is not provided the main window will have its selection cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further<br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</syntaxhighlight><br />
<br />
==disableClickthrough==<br />
; disableClickthrough(label)<br />
: Disables clickthrough for a label - making it act 'normal' again and receive clicks, doubleclicks, onEnter, and onLeave events. This is the default behaviour for labels.<br />
: See also: [[#enableClickthrough|enableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name of the label to restore clickability on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==disableCommandLine==<br />
; disableCommandLine(windowName)<br />
: Disables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableCommandLine|enableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to disable the command line in.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10<br />
<br />
==disableScrollBar==<br />
; disableScrollBar(windowName)<br />
: Disables the scroll bar for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to disable the scroll bar in.<br />
<br />
==dreplace==<br />
;dreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#decho|decho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
dreplace("<255,0,255>[ALERT!]: <r>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''text:''<br />
: Text to display in the echo. Same as a normal echo().<br />
* ''command:''<br />
: Lua code to do when the link is clicked.<br />
* ''hint:''<br />
: Text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentFormatElseDefault:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
echoLink("press me!", [[send("hi")]], "This is a tooltip")<br />
<br />
-- do the same, but send this link to a miniConsole<br />
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")<br />
</syntaxhighlight><br />
<br />
==echoUserWindow==<br />
;echoUserWindow(windowName)<br />
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.<br />
<br />
==echoPopup==<br />
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==enableClickthrough==<br />
; enableClickthrough(label)<br />
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.<br />
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.<br />
: See also: [[#disableClickthrough|disableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: The name of the label to enable clickthrough on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==enableCommandLine==<br />
; enableCommandLine(windowName)<br />
: Enables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#disableCommandLine|disableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to enable the command line in.<br />
<br />
{{note}} The command line name is the same as the miniConsole name<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableScrollBar==<br />
; enableScrollBar(windowName)<br />
: Enables the scrollbar for the miniConsole named ''windowName''.<br />
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in.<br />
<br />
==fg==<br />
; fg([window], colorName)<br />
: 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)<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything or use ''main'' (since Mudlet 3.0).<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
<br />
-- example of working on a miniconsole<br />
fg("my console", "red")<br />
echo("my console", "red text")<br />
</syntaxhighlight><br />
<br />
==getAvailableFonts==<br />
; getAvailableFonts()<br />
: This returns a "font - true" key-value list of available fonts which you can use to verify that Mudlet has access to a given font.<br />
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.<br />
<br />
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]<br />
<br />
{{note}}<br />
Available since Mudlet 3.10<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if Ubuntu Mono is a font we can use<br />
if getAvailableFonts()["Ubuntu Mono"] then<br />
-- make the miniconsole use the font at size 16<br />
setFont("my miniconsole", "Ubuntu Mono")<br />
setFontSize("my miniconsole", 16)<br />
end<br />
</syntaxhighlight><br />
<br />
==getBgColor==<br />
; getBgColor(windowName)<br />
: 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.<br />
<br />
: See also: [[#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r,g,b;<br />
selectString("troll",1)<br />
r,g,b = getBgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getBorderBottom==<br />
;getBorderBottom()<br />
: Returns the size of the bottom border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
getBorderBottom()<br />
-- returns: 150<br />
</syntaxhighlight><br />
<br />
==getBorderLeft==<br />
;getBorderLeft()<br />
: Returns the size of the left border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
getBorderLeft()<br />
-- returns: 5<br />
</syntaxhighlight><br />
<br />
==getBorderRight==<br />
;getBorderRight()<br />
: Returns the size of the right border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
getBorderRight()<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderSizes==<br />
;getBorderSizes()<br />
: Returns the a named table with the sizes of all borders of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]],[[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0)<br />
getBorderSizes()<br />
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }<br />
getBorderSizes().right<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderTop==<br />
;getBorderTop()<br />
: Returns the size of the top border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
getBorderTop()<br />
-- returns: 100<br />
</syntaxhighlight><br />
<br />
==getClipboardText==<br />
;getClipboardText()<br />
: Returns any text that is currently present in the clipboard. <br />
: See also: [[#setClipboardText | setClipboardText()]]<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local clipboardContents = getClipboardText()<br />
echo("Clipboard: " .. clipboardContents)<br />
</syntaxhighlight><br />
<br />
==getColorWildcard==<br />
; getColorWildcard(ansi color number)<br />
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.<br />
<br />
: See also: [[#isAnsiFgColor|isAnsiFgColor()]], [[#isAnsiBgColor|isAnsiBgColor()]]<br />
<br />
;Parameters<br />
* ''ansi color number:''<br />
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- we can run this script on a line that has the players name coloured differently to easily capture it from<br />
-- anywhere on the line<br />
local match = getColorWildcard(14)<br />
<br />
if match then<br />
echo("\nFound "..match.."!")<br />
else<br />
echo("\nDidn't find anyone.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getColumnCount==<br />
;getColumnCount([windowName])<br />
: Gets the maximum number of columns (characters) that a given window can display on a single row, taking into consideration factors such as window width, font size, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum number of columns on the main window "..getColumnCount())<br />
</syntaxhighlight><br />
<br />
==getColumnNumber==<br />
;getColumnNumber([windowName])<br />
: Gets the absolute column number of the current user cursor.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
<br />
{{note}} the argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
<br />
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
</syntaxhighlight><br />
<br />
==getCurrentLine==<br />
;getCurrentLine([windowName])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Currently selected line: "..getCurrentLine())<br />
</syntaxhighlight><br />
<br />
==getFgColor==<br />
; getFgColor(windowName)<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString("troll",1)<br />
local r,g,b = getFgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is written in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getFont==<br />
;getFont(windowName)<br />
: Gets the current font of the given window or console name. Can be used to get font of the main console, dockable userwindows and miniconsoles.<br />
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
display("Font in the main window: "..getFont())<br />
<br />
display("Font in the main window: "..getFont("main"))<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
display("Font size: " .. getFont("user window awesome"))<br />
</syntaxhighlight><br />
<br />
==getFontSize==<br />
;getFontSize(windowName)<br />
: Gets the current font size of the given window or console name. Can be used to get font size of the Main console as well as dockable UserWindows.<br />
: See also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
local mainWindowFontSize = getFontSize()<br />
if mainWindowFontSize then<br />
display("Font size: " .. mainWindowFontSize)<br />
end<br />
<br />
local mainWindowFontSize = getFontSize("main")<br />
if mainWindowFontSize then<br />
display("Font size: " .. fs2)<br />
end<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
local awesomeWindowFontSize = getFontSize("user window awesome")<br />
if awesomeWindowFontSize then<br />
display("Font size: " .. awesomeWindowFontSize)<br />
end<br />
</syntaxhighlight><br />
<br />
==getImageSize==<br />
;getImageSize(imageLocation)<br />
: Returns the width and the height of the given image. If the image can't be found, loaded, or isn't a valid image file - nil+error message will be returned instead.<br />
: See also: [[#createLabel|createLabel()]]<br />
<br />
;Parameters<br />
* ''imageLocation:''<br />
: Path to the image.<br />
<br />
{{note}}<br />
Available in Mudlet 4.5+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local path = getMudletHomeDir().."/my-image.png"<br />
<br />
cecho("Showing dimensions of the picture in: "..path.."\n")<br />
<br />
local width, height = getImageSize(path)<br />
<br />
if not width then<br />
-- in case of an problem, we don't get a height back - but the error message<br />
cecho("error: "..height.."\n")<br />
else<br />
cecho(string.format("They are: %sx%s", width, height))<br />
end<br />
</syntaxhighlight><br />
<br />
==getLastLineNumber==<br />
;getLastLineNumber(windowName)<br />
:Returns the latest line's number in the main window or the miniconsole. This could be different from [[Manual:UI_Functions#getLineNumber|getLineNumber()]] if the cursor was moved around.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the latest line's # in the buffer<br />
local latestline = getLastLineNumber("main")<br />
</syntaxhighlight><br />
<br />
==getLineCount==<br />
;getLineCount()<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
''Need example''<br />
<br />
==getLines==<br />
;getLines([windowName,] from_line_number, to_line_number)<br />
: 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}''.<br />
<br />
:Absolute line numbers are used.<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)<br />
* ''from_line_number:''<br />
: First line number<br />
* ''to_line_number:''<br />
: End line number<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- retrieve & echo the last line:<br />
echo(getLines(getLineNumber()-1, getLineNumber())[1])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- find out which server and port you are connected to (as per Mudlet settings dialog):<br />
local t = getLines(0, getLineNumber())<br />
<br />
local server, port<br />
<br />
for i = 1, #t do<br />
local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")<br />
if s then server, port = s, p break end<br />
end<br />
<br />
display(server)<br />
display(port)<br />
</syntaxhighlight><br />
<br />
==getLineNumber==<br />
;getLineNumber([windowName])<br />
: 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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#moveCursorEnd|moveCursorEnd()]]. This function can come in handy in combination when using with [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#getLines|getLines()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.<br />
<br />
{{note}}<br />
The argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word<br />
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end<br />
<br />
-- check how many lines you've got in your miniconsole after echoing some text.<br />
-- Note the use of moveCursorEnd() to update getLineNumber()'s output<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
print(getLineNumber("HelloWorld"))<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
-- update the cursors position, as it seems to be necessary to do<br />
moveCursorEnd("HelloWorld")<br />
print(getLineNumber("HelloWorld"))<br />
</syntaxhighlight><br />
<br />
==getMainConsoleWidth==<br />
;getMainConsoleWidth()<br />
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.<br />
<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Save width of the main console to a variable for future use.<br />
consoleWidth = getMainConsoleWidth()<br />
</syntaxhighlight><br />
<br />
==getMousePosition==<br />
;getMousePosition()<br />
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{note}} Available since Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- 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<br />
local x, y = getMousePosition()<br />
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)<br />
-- if the label already exists, just move it<br />
moveWindow("clickGeneratedLabel", x, y)<br />
-- and make it easier to notice<br />
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)<br />
</syntaxhighlight><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getUserWindowSize|getUserWindowSize()]], [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your main mudlet window and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</syntaxhighlight><br />
<br />
==getRowCount==<br />
;getRowCount([windowName])<br />
: Gets the maximum number of rows that a given window can display at once, taking into consideration factors such as window height, font type, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum of rows on the main window "..getRowCount())<br />
</syntaxhighlight><br />
<br />
==getSelection==<br />
;getSelection([windowName])<br />
: Returns the text currently selected with [[#selectString|selectString()]], [[#selectSection|selectSection()]], or [[#selectCurrentLine|selectCurrentLine()]]. Note that this isn't the text currently selected with the mouse.<br />
: Also returns the start offset and length of the selection as second and third value.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window to get the selection from. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.16.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
print("Current selection is: "..getSelection())<br />
</syntaxhighlight><br />
<br />
;retrieving the selection<br />
<syntaxhighlight lang="lua"><br />
text,offset,len = getSelection()<br />
-- manipulate the selection, e.g. to discover the color of characters other than the first<br />
-- then restore it<br />
selectSection(offset, len)<br />
</syntaxhighlight><br />
<br />
==getTextFormat==<br />
;getTextFormat([windowName])<br />
: Gets the current text format of the currently selected text. May be used with other console windows. The returned values come in a table containing text attribute names and their values. The values given will be booleans for: bold, italics, underline, overline, strikeout, and reverse - followed by color triplet tables for the foreground and background colors.<br />
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.<br />
<br />
{{note}} Available since Mudlet 3.20.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- A suitable test for getTextFormat()<br />
-- (copy it into an alias or a script)<br />
<br />
clearWindow()<br />
<br />
echo("\n")<br />
<br />
local SGR = string.char(27)..'['<br />
feedTriggers("Format attributes: '"..SGR.."1mBold"..SGR.."0m' '"..SGR.."3mItalic"..SGR.."0m' '"..SGR.."4mUnderline"..SGR.."0m' '"..SGR.."5mBlink"..SGR.."0m' '"..SGR.."6mF.Blink"..SGR.."0m' '"..SGR.."7mReverse"..SGR.."0m' '"..SGR.."9mStruckout"..SGR.."0m' '"..SGR.."53mOverline"..SGR.."0m'.\n")<br />
<br />
moveCursor(1,1)<br />
selectSection(1,1)<br />
<br />
local results = getTextFormat()<br />
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))<br />
echo("\nItalic detected: " .. tostring(results["italic"]))<br />
echo("\nUnderline detected: " .. tostring(results["underline"]))<br />
echo("\nReverse detected: " .. tostring(results["reverse"]))<br />
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))<br />
echo("\nOverline detected: " .. tostring(results["overline"]))<br />
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")<br />
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")<br />
<br />
selectSection(21,1)<br />
echo("\n\nFor individual parts of test text:")<br />
echo("\nBold detected (character 21): " .. tostring(results["bold"]))<br />
<br />
selectSection(28,1)<br />
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))<br />
<br />
selectSection(37,1)<br />
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))<br />
<br />
selectSection(67,1)<br />
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))<br />
<br />
selectSection(77,1)<br />
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))<br />
<br />
selectSection(89,1)<br />
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))<br />
echo("\n")<br />
</syntaxhighlight><br />
<br />
==getUserWindowSize==<br />
{{note}} available in Mudlet 4.6.1+<br />
;getUserWindowSize(windowName)<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the given userwindow dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''windowName''<br />
:the name of the userwindow we will get the dimensions from<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your userwindow named "ChatWindow" and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getUserWindowSize("ChatWindow")<br />
</syntaxhighlight><br />
<br />
==handleWindowResizeEvent==<br />
;handleWindowResizeEvent()<br />
: (''depreciated'') This function is depreciated and should not be used; it's only documented here for historical reference - use the [[Manual:Technical_Manual#sysWindowResizeEvent|sysWindowResizeEvent]] event instead.<br />
<br />
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.<br />
<br />
; Parameters<br />
:None<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
function handleWindowResizeEvent()<br />
-- determine the size of your screen<br />
WindowWidth=0;<br />
WindowHeight=0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
-- move mini console "sys" to the far right side of the screen whenever the screen gets resized<br />
moveWindow("sys",WindowWidth-300,0)<br />
end<br />
</syntaxhighlight><br />
<br />
==hasFocus==<br />
;hasFocus()<br />
: 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). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if attacked and not hasFocus() then<br />
runaway()<br />
else<br />
fight()<br />
end<br />
</syntaxhighlight><br />
<br />
==hecho==<br />
;hecho([windowName], text)<br />
: Echoes text that can be easily formatted with colour tags in the hexadecimal format.<br />
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.<br />
* ''text:''<br />
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #FRFGFB,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 or #r can be used within the string to reset the colors to default. Hexadecimal color codes can be found here: https://www.color-hex.com/<br />
<br />
{{note}}<br />
Transparency for background in hex-format available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hecho("\n#ffffff White text!")<br />
-- your text in white<br />
hecho("\n#ca0004 Red text! And now reset #rit to the default color")<br />
-- your text in red, then reset to default using #r<br />
hecho("\n#ffffff,ca0004 White text with a red background!")<br />
-- your text in white, against a red background<br />
hecho("\n|c0000ff Blue text, this time using |c instead of #")<br />
-- your text in blue, activated with |c vs #.<br />
</syntaxhighlight><br />
<br />
==hechoLink==<br />
;hechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#hecho|hecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
-- # format also works<br />
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==hechoPopup==<br />
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#hecho|hecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertLink==<br />
;hinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#hinsertText|hinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertPopup==<br />
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#hinsertText|hinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hreplace==<br />
;hreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#hecho|hecho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
hreplace("#EE00EE[ALERT!]: #r"..matches[2])<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.5+<br />
<br />
==hideToolBar==<br />
;hideToolBar(name)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to hide<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hideToolBar("my offensive buttons")<br />
</syntaxhighlight><br />
<br />
==hideWindow==<br />
;hideWindow(name)<br />
: This function hides a '''mini console''', a '''user window''' or a '''label''' with the given name. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].<br />
<br />
: See also: [[#createMiniConsole|createMiniConsole()]], [[#createLabel|createLabel()]], [[#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name''<br />
: specifies the label or console you want to hide.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function miniconsoleTest()<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
print("created red window top-right")<br />
<br />
tempTimer(1, function()<br />
hideWindow("sys")<br />
print("hid red window top-right")<br />
end)<br />
<br />
tempTimer(3, function()<br />
showWindow("sys")<br />
print("showed red window top-right")<br />
end)<br />
end<br />
<br />
miniconsoleTest()<br />
</syntaxhighlight><br />
<br />
==insertLink==<br />
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])<br />
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) the window to insert the link in - use either "main" or omit for the main window.<br />
* ''text:''<br />
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) true or false. 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- link with the default blue on white colors<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")<br />
<br />
-- use current cursor colors by adding true at the end<br />
fg("red")<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==insertPopup==<br />
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])<br />
: Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to [[Manual:Lua_Functions#insertText|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''name:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.<br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==insertText==<br />
;insertText([windowName], text)<br />
: Inserts text at cursor postion in window - unlike [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] to move the cursor into position first.<br />
<br />
: insertHTML() also does the same thing as insertText, if you ever come across it.<br />
<br />
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) The window to insert the text to.<br />
* ''text:''<br />
: The text you will insert into the current cursor position.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the cursor to the end of the previous line and insert some text<br />
<br />
-- move to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
-- move the end the of the previous line<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
<br />
fg("dark_slate_gray")<br />
insertText(' <- that looks nice.')<br />
<br />
deselect()<br />
resetFormat()<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
==ioprint==<br />
;ioprint(text, some more text, ...)<br />
:Prints text to the to the stdout. This is only available if you [http://www.wikihow.com/Run-a-Program-on-Command-Prompt launched Mudlet from cmd.exe] on Windows, [http://www.wikihow.com/Open-Applications-Using-Terminal-on-Mac from the terminal] on Mac, or from the terminal on a Linux OS (launch the terminal program, type ''mudlet'' and press enter).<br />
<br />
Similar to [[Manual:Lua_Functions#echo|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.<br />
<br />
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.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
ioprint("hi!")<br />
ioprint(1,2,3)<br />
ioprint(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==isAnsiBgColor==<br />
; isAnsiBgColor(bgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the background color specified by bgColorCode.<br />
<br />
;Parameters<br />
* ''bgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiBgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the background of the text is light green" )<br />
else<br />
echo( "no sorry, some other background color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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 getBgColor() and then handling the color comparison in Lua.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default background color in the zeroth position.''<br />
<br />
==isAnsiFgColor==<br />
; isAnsiFgColor(fgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the foreground color specified by fgColorCode.<br />
<br />
;Parameters<br />
* ''fgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiFgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the text is light green" )<br />
else<br />
echo( "no sorry, some other foreground color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default foreground color in the zeroth position.''<br />
<br />
==lowerWindow==<br />
;lowerWindow(labelName)<br />
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to move below the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top<br />
</syntaxhighlight><br />
<br />
==moveCursor==<br />
;moveCursor([windowName], x, y)<br />
: 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 [[Manual:Lua_Functions#getLineNumber|getLineNumber()]], [[Manual:Lua_Functions#getColumnNumber|getColumnNumber()]] and [[Manual:Lua_Functions#getLastLineNumber|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.<br />
<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The window you are going to move the cursor in.<br />
* ''x:''<br />
: The horizontal axis in the window - that is, the letter position within the line.<br />
* ''y:''<br />
: The vertical axis in the window - that is, the line number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move cursor to the start of the previous line and insert -<(<br />
-- the first 0 means we want the cursor right at the start of the line,<br />
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which<br />
-- equals to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
insertText("-<(")<br />
<br />
-- now we move the cursor at the end of the previous line. Because the<br />
-- cursor is on the previous line already, we can use #getCurrentLine()<br />
-- to see how long it is. We also just do getLineNumber() because getLineNumber()<br />
-- returns the current line # the cursor is on<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
insertText(")>-")<br />
<br />
-- finally, reset it to the end where it was after our shenaningans - other scripts<br />
-- could expect the cursor to be at the end<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a more complicated example showing how to work with Mudlet functions<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
local WindowWidth, WindowHeight = getMainWindowSize()<br />
<br />
-- define a mini console named "sys" and set its background color<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
<br />
-- you *must* set the font size, otherwise mini windows will not work properly<br />
setMiniConsoleFontSize("sys", 12)<br />
-- wrap lines in window "sys" at 65 characters per line<br />
setWindowWrap("sys", 60)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
-- clear the window<br />
clearUserWindow("sys")<br />
<br />
moveCursorEnd("sys")<br />
setFgColor("sys", 10,10,0)<br />
setBgColor("sys", 0,0,255)<br />
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")<br />
echo("sys", "test1---line2\n")<br />
echo("sys", "test1---line3\n")<br />
setTextFormat("sys",158,0,255,255,0,255,0,0,0);<br />
--setFgColor("sys",255,0,0);<br />
echo("sys", "test1---line4\n")<br />
echo("sys", "test1---line5\n")<br />
moveCursor("sys", 1,1)<br />
<br />
-- deleting lines 2+3<br />
deleteLine("sys")<br />
deleteLine("sys")<br />
<br />
-- inserting a line at pos 5,2<br />
moveCursor("sys", 5,2)<br />
setFgColor("sys", 100,100,0)<br />
setBgColor("sys", 255,100,0)<br />
insertText("sys","############## line inserted at pos 5/2 ##############")<br />
<br />
-- inserting a line at pos 0,0<br />
moveCursor("sys", 0,0)<br />
selectCurrentLine("sys")<br />
setFgColor("sys", 255,155,255)<br />
setBold( "sys", true );<br />
setUnderline( "sys", true )<br />
setItalics( "sys", true )<br />
insertText("sys", "------- line inserted at: 0/0 -----\n")<br />
<br />
setBold( "sys", true )<br />
setUnderline( "sys", false )<br />
setItalics( "sys", false )<br />
setFgColor("sys", 255,100,0)<br />
setBgColor("sys", 155,155,0)<br />
echo("sys", "*** This is the end. ***\n")<br />
</syntaxhighlight><br />
<br />
==moveCursorDown==<br />
;moveCursorDown([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window down a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor down by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorUp==<br />
;moveCursorUp([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window up a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor up by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorEnd==<br />
;moveCursorEnd([windowName])<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
: Returns true or false<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveGauge==<br />
;moveGauge(gaugeName, newX, newY)<br />
: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.<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: The name of your gauge<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would move the health bar gauge to the location 1200, 400<br />
moveGauge("healthBar", 1200, 400)<br />
</syntaxhighlight><br />
<br />
==moveWindow==<br />
;moveWindow(name, x, y)<br />
: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.<br />
<br />
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of your window<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles.<br />
<br />
==openUserWindow==<br />
;openUserWindow(windowName, [restoreLayout], [autoDock], [dockingArea])<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).<br />
* ''restoreLayout:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.<br />
* ''autoDock:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't dock automatically at the corners.<br />
* ''dockingArea:''<br />
: (optional) - the area your UserWindow will be docked at. possible docking areas your UserWindow will be created in (f" floating "t" top "b" bottom "r" right and "l" left). Docking area is "right" if not given any value.<br />
<br />
{{note}}<br />
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.<br />
<br />
{{note}}<br />
The parameters autoDock and dockingArea are available since Mudlet 4.7+ <br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
openUserWindow("My floating window")<br />
cecho("My floating window", "<red>hello <blue>bob!")<br />
<br />
-- if you don't want Mudlet to remember its last position:<br />
openUserWindow("My floating window", false)<br />
</syntaxhighlight><br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]]<br />
<br />
==paste==<br />
;paste(windowName)<br />
: Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The [[#copy | copy()]] and [[#paste | 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
<br />
==prefix==<br />
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
:Prefixes text at the beginning of the current line when used in a trigger.<br />
<br />
;Parameters<br />
* ''text:''<br />
: the information you want to prefix<br />
* "writingFunction:"<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* "foregroundColor:"<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* "backgroundColor:"<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* "windowName:"<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that<br />
prefix(os.date("%H:%M:%S "))<br />
-- Prefix the time in red into a miniconsole named "my_console"<br />
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#suffix | suffix()]]<br />
<br />
==print==<br />
;print(text, some more text, ...)<br />
:Prints text to the main window. Similar to [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#display|display()]] for those. This function works similarly to the print() you will see in guides for Lua.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
print("hi!")<br />
print(1,2,3)<br />
print(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==raiseWindow==<br />
;raiseWindow(labelName)<br />
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to bring to the top of the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel<br />
</syntaxhighlight><br />
<br />
==replace==<br />
;replace([windowName], with, [keepcolor])<br />
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.<br />
<br />
{{note}}<br />
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.<br />
<br />
{{note}}<br />
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 | insertText()]] does.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of window (a miniconsole)<br />
* ''with:''<br />
: the new text to display.<br />
* ''keepcolor:''<br />
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
-- replace word "troll" with "cute trolly"<br />
selectString("troll",1)<br />
replace("cute trolly")<br />
<br />
-- replace the whole line<br />
selectCurrentLine()<br />
replace("Out with the old, in with the new!")<br />
</syntaxhighlight><br />
<br />
==replaceAll==<br />
;replaceAll(what, with, [keepcolor])<br />
: Replaces all occurrences of ''what'' in the current line with ''with''.<br />
<br />
;Parameters<br />
* ''what:''<br />
: the text to replace<br />
{{note}}<br />
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]<br />
* ''with:''<br />
: the new text to have in place<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors.<br />
{{note}} keepcolor available in Mudlet 4.10+, is not in previous versions.<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the word "south" in the line with "north"<br />
replaceAll("south", "north")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the text that the variable "target" has<br />
replaceAll(target, "The Bad Guy")<br />
</syntaxhighlight><br />
<br />
==replaceWildcard==<br />
;replaceWildcard(which, replacement, [keepcolor])<br />
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString(matches[2], 1)<br />
replace("text")<br />
</syntaxhighlight><br />
<br />
;Parameters<br />
* ''which:''<br />
: Wildcard to replace.<br />
* ''replacement:''<br />
: Text to replace the wildcard with.<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors<br />
{{note}} keepcolor available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello<br />
</syntaxhighlight><br />
<br />
==resetCmdLineAction==<br />
;resetCmdLineAction(commandLineName)<br />
: Resets the action on the command line so the it behaves like the main command line again.<br />
;Parameters<br />
<br />
* ''commandLineName''<br />
: The name of the command line the action will be resetet.<br />
: See also: [[#setCmdLineAction | setCmdLineAction()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetConsoleBackgroundImage==<br />
;resetConsoleBackgroundImage([windowName])<br />
: Resets the console background-image<br />
;Parameters<br />
<br />
* ''windowName''<br />
: (optional) name of the console the image will be reset<br />
: See also: [[#setConsoleBackgroundImage | setConsoleBackgroundImage()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: 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.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==resetLabelCursor==<br />
;resetLabelCursor(labelName)<br />
: Resets your mouse cursor to the default one.<br />
<br />
: See also: [[#setLabelCursor|setLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName'': label for which to reset the cursor for.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetLabelCursor("myLabel")<br />
-- This will reset the mouse cursor over myLabel to the default one<br />
</syntaxhighlight><br />
<br />
==resetLabelToolTip==<br />
;resetLabelToolTip(labelName)<br />
: Resets the tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label the tooltip will be reseted.<br />
: See also: [[#setLabelToolTip | setLabelToolTip()]]<br />
<br />
==resetMapWindowTitle==<br />
;resetMapWindowTitle()<br />
: resets the title of the popped out map window to default.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setMapWindowTitle|setMapWindowTitle()]]<br />
<br />
==resetUserWindowTitle==<br />
;resetUserWindowTitle(windowName)<br />
: resets the title of the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow for which the title will be resetet<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setUserWindowTitle|setUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==resizeWindow==<br />
;resizeWindow(windowName, width, height)<br />
: Resizes a mini console, label, or floating User Windows.<br />
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
* ''width:''<br />
: The new width you want<br />
* ''height:''<br />
: The new height you want<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.<br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumber:''<br />
: number of the capture group you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".<br />
--If you want to color the amount of money you have green you do:<br />
<br />
selectCaptureGroup(1)<br />
setFgColor(0,255,0)<br />
</syntaxhighlight><br />
<br />
==selectCurrentLine==<br />
; selectCurrentLine([windowName])<br />
: 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.<br />
<br />
{{note}}<br />
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.<br />
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- color the whole line green!<br />
selectCurrentLine()<br />
fg("green")<br />
deselect()<br />
resetFormat()<br />
<br />
-- to select the previous line, you can do this:<br />
moveCursor(0, getLineNumber()-1)<br />
selectCurrentLine()<br />
<br />
-- to select two lines back, this:<br />
moveCursor(0, getLineNumber()-2)<br />
selectCurrentLine()<br />
<br />
</syntaxhighlight><br />
<br />
==selectSection==<br />
;selectSection( [windowName], fromPosition, length )<br />
: 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.<br />
: 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.<br />
<br />
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]<br />
<br />
;Parameters<br />
* "windowName:"<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.<br />
: Will not work if "main" is given as the windowName to try to select from the main window.<br />
* ''fromPosition:''<br />
: number to specify at which position in the line to begin selecting<br />
* ''length:''<br />
: number to specify the amount of characters you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and colour the first character in the line red<br />
if selectSection(0,1) then fg("red") end<br />
<br />
-- select and colour the second character green (start selecting from the first character, and select 1 character)<br />
if selectSection(1,1) then fg("green") end<br />
<br />
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)<br />
if selectSection(2,3) then fg("grey") end<br />
</syntaxhighlight><br />
<br />
==selectString==<br />
;selectString( [windowName], text, number_of_match )<br />
: 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).<br />
<br />
{{note}}<br />
You can move the user cursor with [[#moveCursor | 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 | deselect()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.<br />
* ''text:''<br />
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).<br />
* ''number_of_match:''<br />
: 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.<br />
<br />
: Returns position in line or -1 on error (text not found in line)<br />
<br />
{{note}}<br />
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if selectString( "big monster", 1 ) > -1 then fg("red") end<br />
</syntaxhighlight><br />
<br />
==setAppStyleSheet==<br />
;setAppStyleSheet(stylesheet [, tag])<br />
: Sets a stylesheet for the entire Mudlet application and every open profile. Because it affects other profiles that might not be related to yours, it's better to use [[#setProfileStyleSheet|setProfileStyleSheet()]] instead of this function.<br />
<br />
: Raises the sysAppStyleSheetChange event which comes with two arguments in addition to the event name. The first is the optional tag which was passed into the function, or "" if nothing was given. The second is the profile which made the stylesheet changes.<br />
<br />
: See also: [[#setProfileStyleSheet|setProfileStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use.<br />
<br />
* ''tag:'' (with Mudlet 3.19+)<br />
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.<br />
<br />
;References<br />
: See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setAppStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
]])<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 3.0.<br />
<br />
Enhanced in Mudlet version 3.19.0 to generate an event that profiles/packages can utilise to redraw any parts of the UI that they themselves had previously styled so their effects can be re-applied to the new application style.<br />
<br />
It is anticipated that the Mudlet application itself will make further use of application styling effects and two strings are provisionally planned for the second parameter in the ''sysAppStyleSheetChange'' event: "''mudlet-theme-dark''" and "''mudlet-theme-light''"; it will also set the third parameter to "''system''".<br />
<br />
==setBackgroundColor==<br />
;setBackgroundColor([windowName], r, g, b, transparency)<br />
: Sets the background for the given label, miniconsole, or userwindow. Colors are from 0 to 255 (0 being black), and transparency is from 0 to 255 (0 being completely transparent).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.<br />
* ''r:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''g:''<br />
: Amount of green to use, from 0 (none) to 255 (full).<br />
* ''b:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).<br />
<br />
{{note}}<br />
Transparency also available for main/miniconsoles in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red label that's somewhat transparent<br />
setBackgroundColor("some label",255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setBackgroundImage==<br />
;setBackgroundImage(labelName, imageLocation)<br />
: Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.<br />
<br />
{{note}}<br />
You can only do this for labels, not miniconsoles.<br />
<br />
{{note}}<br />
You can also load images via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to change it's background color.<br />
* ''imageLocation:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give the top border a nice look<br />
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])<br />
</syntaxhighlight><br />
<br />
==setBgColor==<br />
;setBgColor([windowName], r, g, b, transparency)<br />
: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.<br />
<br />
: ''See also:'' [[#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Optional, if not used color is fully opaque<br />
<br />
<br />
<br />
{{note}}<br />
Transparency parameter available in Mudlet 4.10+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red background color.<br />
selectString( "Tom", 1 )<br />
setBgColor( 255,0,0 )<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--prints "Hello" on red background and "You" on blue.<br />
setBgColor(255,0,0)<br />
echo("Hello")<br />
setBgColor(0,0,255)<br />
echo(" You!")<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBold==<br />
;setBold(windowName, boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
<br />
* ''boolean:''<br />
: A <code>true</code> or <code>false</code> that enables or disables bolding of text<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- enable bold formatting<br />
setBold(true)<br />
-- the following echo will be bolded<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBorderBottom==<br />
;setBorderBottom(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
</syntaxhighlight><br />
<br />
==setBorderColor==<br />
;setBorderColor(red, green, blue)<br />
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]<br />
<br />
;Parameters<br />
* ''red:''<br />
: Amount of red color to use, from 0 to 255.<br />
* ''green:''<br />
: Amount of green color to use, from 0 to 255.<br />
* ''blue:''<br />
: Amount of blue color to use, from 0 to 255.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set the border to be completely blue<br />
setBorderColor(0, 0, 255)<br />
<br />
-- or red, using a name<br />
setBorderColor( unpack(color_table.red) )<br />
</syntaxhighlight><br />
<br />
==setBorderLeft==<br />
;setBorderLeft(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
</syntaxhighlight><br />
<br />
==setBorderRight==<br />
;setBorderRight(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
</syntaxhighlight><br />
<br />
==setBorderSizes==<br />
;setBorderSizes(top, right, bottom, left)<br />
: Sets the size of all borders 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.<br />
: The exact result of this function depends on how many numbers you give to it as arguments.<br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Arguments<br />
* '''setBorderSizes(top, right, bottom, left)'''<br />
: ''4 arguments:'' All borders will be set to their new given size.<br />
* '''setBorderSizes(top, width, bottom)''' <br />
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width. <br />
* '''setBorderSizes(height, width)'''<br />
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width. <br />
* '''setBorderSizes(size)'''<br />
: ''1 argument:'' All borders will be set to the same size.<br />
* '''setBorderSizes()'''<br />
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0) <br />
-- big border at the top, bigger at the bottom, small at the right, none at the left<br />
<br />
setBorderSizes(100, 50, 150) <br />
-- big border at the top, bigger at the bottom, small at the right and the left<br />
<br />
setBorderSizes(100, 50) <br />
-- big border at the top and the bottom, small at the right and the left<br />
<br />
setBorderSizes(100) <br />
-- big borders at all four sides<br />
<br />
setBorderSizes() <br />
-- no borders at all four sides<br />
</syntaxhighlight><br />
<br />
==setBorderTop==<br />
;setBorderTop(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
</syntaxhighlight><br />
<br />
==setFgColor==<br />
;setFgColor([windowName], red, green, blue)<br />
:Sets the current text foreground color in the main window unless windowName parameter given.<br />
<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''red:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''green:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''blue:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]], [[#setHexBgColor | setHexBgColor()]], [[#resetFormat | resetFormat()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setFgColor( 255, 0, 0 )<br />
</syntaxhighlight><br />
<br />
==setButtonStyleSheet==<br />
;setButtonStyleSheet(button, markup)<br />
: Applies Qt style formatting to a button via a special markup language.<br />
<br />
; Parameters<br />
* ''button:''<br />
: The name of the button to be formatted.<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note: You can instead use QWidget { markup }. QWidget will reference 'button', allowing the use of pseudostates like QWidget:hover and QWidget:selected<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setButtonStyleSheet("my test button", [[<br />
QWidget {<br />
background-color: #999999;<br />
border: 3px #777777;<br />
}<br />
QWidget:hover {<br />
background-color: #bbbbbb;<br />
}<br />
QWidget:checked {<br />
background-color: #77bb77;<br />
border: 3px #559955;<br />
}<br />
QWidget:hover:checked {<br />
background-color: #99dd99;<br />
} ]])</syntaxhighlight><br />
<br />
==setClipboardText==<br />
;setClipboardText(textContent)<br />
: Sets the value of the computer's clipboard to the string data provided.<br />
: See also: [[#getClipboardText | getClipboardText()]]<br />
<br />
; Parameters<br />
* ''textContent:''<br />
: The text to be put into the clipboard.<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setClipboardText("New Clipboard Contents")<br />
echo("Clipboard: " .. getClipboardText()) -- should echo "Clipboard: New Clipboard Contents"<br />
</syntaxhighlight><br />
<br />
==setCmdLineAction==<br />
;setCmdLineAction(commandLineName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user sends text to the command line. 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 command line action. Additionally, this function passes the command line input text as the final argument.<br />
{{note}} If no action is set the command line behaves like the main command line and sends commands directly to the game or alias engine.<br />
<br />
The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, text)<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#resetCmdLineAction|resetCmdLineAction()]]<br />
<br />
;Parameters<br />
<br />
* ''commandLineName:''<br />
: The name of the command line to attach the action function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} You can also pass a function directly instead of using a string<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function sendTextToMiniConsole(miniConsoleName, cmdLineText)<br />
echo(miniConsoleName, cmdLineText.."\n")<br />
end<br />
<br />
setCmdLineAction("myCmdLine", "sendTextToMiniConsole", "myMiniConsole")<br />
<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setConsoleBackgroundImage==<br />
;setConsoleBackgroundImage([windowname], imageLocation, [mode])<br />
: Loads an image file (for example png) as a background image for a console (main/miniconsole and userwindows).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow to change the background image on, or "main" for the main window.<br />
* ''imageLocation:''<br />
: 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.<br />
* ''mode:''<br />
: (optional) allows different modes for drawing the background image<br />
possible modes areː "border" (the background image is stretched) , 2 "center" (the background image is in the center), <br />
3 "tile" (the background image is 'tiled'), 4 "style" (choose your own background image stylesheet. see example below) <br />
<br />
: See also: [[#resetConsoleBackgroundImage | resetConsoleBackgroundImage()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give my_miniconsole a nice background image and put it in the center<br />
setConsoleBackgroundImage("my_miniconsole", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image with own stylesheet option<br />
setConsoleBackgroundImage("my_miniconsole", [[background-image: url(:/Mudlet_splashscreen_development.png); background-repeat: no-repeat; background-position: right;]], "style")<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setFont==<br />
;setFont(name, font)<br />
: Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Prefer a monospaced font - those work best with text games. See here [https://doc.qt.io/qt-5/qfont.html#setFamily for more].<br />
: See also: [[#getFont|getFont()]], [[#setFontSize|setFontSize()]], [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''font:''<br />
: The font to use.<br />
<br />
{{note}}<br />
Available in Mudlet 3.9+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.<br />
setFont("Ubuntu Mono")<br />
setFont("main", "Ubuntu Mono")<br />
<br />
-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.<br />
setFont("combat", "Ubuntu Mono")<br />
</syntaxhighlight><br />
<br />
==setFontSize==<br />
;setFontSize(name, size)<br />
: Sets a font size on the given window or console name. Can be used to change font size of the Main console as well as dockable UserWindows.<br />
: See Also: [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
* ''size:''<br />
: The font size to apply to the window.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to 12-point font.<br />
setFontSize(12)<br />
setFontSize("main", 12)<br />
<br />
-- This will set the font size of a user window named "uw1" to 12-point font.<br />
setFontSize("uw1", 12)<br />
</syntaxhighlight><br />
<br />
==setGauge==<br />
;setGauge(gaugeName, currentValue, maxValue, gaugeText)<br />
: 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.<br />
<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#createGauge|createGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a gauge<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
--Change the looks of the gauge named healthBar and make it<br />
--fill to half of its capacity. The height is always remembered.<br />
setGauge("healthBar", 200, 400)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
--If you wish to change the text on your gauge, you’d do the following:<br />
setGauge("healthBar", 200, 400, "some text")<br />
</syntaxhighlight><br />
<br />
==setGaugeStyleSheet==<br />
;setGaugeStyleSheet(gaugeName, css, cssback, csstext)<br />
: 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. You can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create stylesheets.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]],<br />
[[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
</syntaxhighlight><br />
<br />
==setGaugeText==<br />
;setGaugeText(gaugename, css, ccstext )<br />
: Set the formatting of the text used inside the inserted gaugename.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
setGaugeText("healthBar", [[<p style="font-weight:bold;color:#C9C9C9;letter-spacing:1pt;word-spacing:2pt;font-size:12px;text-align:center;font-family:arial black, sans-serif;">]]..MY_NUMERIC_VARIABLE_HERE..[[</p>]])</syntaxhighlight><br />
<br />
;Useful resources:<br />
:http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.<br />
:https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!<br />
<br />
==setHexBgColor==<br />
;setHexBgColor([windowName], hexColorString)<br />
:Sets the current text nackground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.<br />
selectString( "Tom", 1 )<br />
setHexBgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setHexFgColor==<br />
;setHexFgColor([windowName], hexColorString)<br />
:Sets the current text foreground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text foreground color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setFgColor | setFgColor()]], [[#setHexBgColor | setHexBgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setHexFgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setItalics==<br />
;setItalics(windowName, bool)<br />
: Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setLabelToolTip==<br />
;setLabelToolTip(labelName, [duration])<br />
: Sets a tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to set the tooltip to.<br />
* ''duration:''<br />
: Duration of the tooltip timeout in seconds. Optional, if not set the default duration will be set.<br />
<br />
: See also: [[Manual:UI_Functions#resetLabelToolTip|resetLabelToolTip()]]<br />
<br />
==setLabelClickCallback==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument. This table contains information about the mouse button clicked, other buttons that were pressed at the time, and the mouse cursor's local (relative to the label) and global (relative to the Mudlet window) position. The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, event)<br />
</syntaxhighlight><br />
<br />
where '''event''' has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
button = "LeftButton",<br />
buttons = {"RightButton", "MidButton"},<br />
}<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]],[[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} Event argument is available in 3.6+, and in 4.8+ you can pass a function directly instead of a string.<br />
<br />
{{note}}<br />
While '''event.button''' may contain a single string of any listed below, '''event.buttons''' will only ever contain some combination of "LeftButton", "MidButton", and "RightButton"<br />
:The following mouse button strings are defined:<br />
<pre><br />
"LeftButton" "RightButton" "MidButton"<br />
"BackButton" "ForwardButton" "TaskButton"<br />
"ExtraButton4" "ExtraButton5" "ExtraButton6"<br />
"ExtraButton7" "ExtraButton8" "ExtraButton9"<br />
"ExtraButton10" "ExtraButton11" "ExtraButton12"<br />
"ExtraButton13" "ExtraButton14" "ExtraButton15"<br />
"ExtraButton16" "ExtraButton17" "ExtraButton18"<br />
"ExtraButton19" "ExtraButton20" "ExtraButton21"<br />
"ExtraButton22" "ExtraButton23" "ExtraButton24"<br />
</pre><br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
else if event.button == "RightButton" then<br />
send("swim north")<br />
else if event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )<br />
<br />
-- you can also use them within tables now:<br />
mynamespace = {<br />
onClickGoNorth = function()<br />
echo("the north button was clicked!")<br />
end<br />
}<br />
<br />
setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )<br />
<br />
</syntaxhighlight><br />
<br />
==setLabelDoubleClickCallback==<br />
;setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user double 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.6+<br />
<br />
: See also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
==setLabelMoveCallback==<br />
;setLabelMoveCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse moves while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
==setLabelOnEnter==<br />
;setLabelOnEnter(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the '''event''' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
}<br />
</syntaxhighlight><br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseOver()<br />
echo("The mouse is hovering over the label!\n")<br />
end<br />
<br />
setLabelOnEnter( "compassNorthImage", "onMouseOver" )<br />
</syntaxhighlight><br />
<br />
==setLabelOnLeave==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseLeft(argument)<br />
echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)<br />
end<br />
<br />
setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )<br />
</syntaxhighlight><br />
<br />
==setLabelReleaseCallback==<br />
;setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
This command was added in version 3.0.0<br />
<br />
{{note}}<br />
The ''event'' argument only available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onReleaseNorth()<br />
echo("the north button was released!")<br />
end<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onReleaseNorth = function()<br />
echo("the north button was released!")<br />
end<br />
}<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )<br />
</syntaxhighlight><br />
<br />
==setLabelStyleSheet==<br />
;setLabelStyleSheet(label, markup)<br />
: Applies Qt style formatting to a label via a special markup language.<br />
<br />
; Parameters<br />
* ''label:''<br />
: The name of the label to be formatted (passed when calling createLabel).<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a white background and a green border, with the text "test"<br />
-- inside.<br />
createLabel("test", 50, 50, 100, 100, 0)<br />
setLabelStyleSheet("test", [[<br />
background-color: white;<br />
border: 10px solid green;<br />
font-size: 12px;<br />
]])<br />
echo("test", "test")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that will tile or clip depending on the<br />
-- size of the label. To use this example, please supply your own image.<br />
createLabel("test5", 50, 353, 164, 55, 0)<br />
setLabelStyleSheet("test5", [[<br />
background-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that can be resized (such as during a<br />
-- sysWindowResizeEvent). To use this example, please supply your own image.<br />
createLabel("test9", 215, 353, 100, 100, 0)<br />
setLabelStyleSheet("test9", [[<br />
border-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--This creates a label whose background changes when the users mouse hovers over it.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
local ourLabelStyle = [[<br />
QLabel{<br />
background-color: ]]..labelBackgroundColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
QLabel::hover{<br />
background-color: ]]..labelHoverColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--Using QLabel::hover mentioned above. Lets "trick" the label into changing it's text.<br />
--Please keep in mind that the setLabelMoveCallback allows for much more control over not just your label but your entire project.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
--Notice we are adding a string returned from a function. In this case, the users profile directory.<br />
local ourLabelStyle = [[<br />
QLabel{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithtext.png");<br />
}<br />
QLabel::hover{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithhovertext.png");<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
--This is just to example that echos draw on top of the label. You would not want to echo onto a label you were drawing text on with images, because echos would draw on top of them.<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<br />
==setLabelCursor==<br />
;setLabelCursor(labelName, cursorShape)<br />
: Changes how the mouse cursor looks like when over the label. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''cursorShape''<br />
: Shape of the mouse cursor. List of possible cursor shapes is [[CursorShapes| available here]].<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCursor("myLabel", "Cross")<br />
-- This will change the mouse cursor to a cross if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelCustomCursor==<br />
;setLabelCustomCursor(labelName, custom cursor, [hotX, hotY])<br />
: Changes the mouse cursor shape over your label to a custom cursor. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCursor|setLabelCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''custom cursor''<br />
: Location of your custom cursor file. To be compatible with all systems it is recommended to use png files with size of 32x32.<br />
* ''hotX''<br />
: X-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
* ''hotY''<br />
: Y-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCustomCursor("myLabel", getMudletHomeDir().."/custom_cursor.png")<br />
-- This will change the mouse cursor to your custom cursor if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelWheelCallback==<br />
;setLabelWheelCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse wheel is scrolled while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the ''event'' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
buttons = {"RightButton", "MidButton"},<br />
angleDeltaX = 0,<br />
angleDeltaY = 120<br />
}<br />
</syntaxhighlight><br />
<br />
: Keys ''angleDeltaX'' and ''angleDeltaY'' correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onWheelNorth(event)<br />
if event.angleDeltaY > 0 then<br />
echo("the north button was wheeled forwards over!")<br />
else<br />
echo("the north button was wheeled backwards over!")<br />
end<br />
end<br />
<br />
setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onWheelNorth = function()<br />
echo("the north button was wheeled over!")<br />
end<br />
}<br />
<br />
setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )<br />
</syntaxhighlight><br />
<br />
==setLink==<br />
;setLink([windowName], command, tooltip)<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of a miniconsole or a userwindow in which to select the text in.<br />
* ''command:''<br />
: command to do when the text is clicked.<br />
* ''tooltip:''<br />
: tooltip to show when the mouse is over the text - explaining what would clicking do.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can clickify a lot of things to save yourself some time - for example, you can change<br />
-- the line where you receive a message to be clickable to read it!<br />
-- prel regex trigger:<br />
-- ^You just received message #(\w+) from \w+\.$<br />
-- script:<br />
selectString(matches[2], 1)<br />
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])<br />
resetFormat()<br />
<br />
-- an example of selecting text in a miniconsole and turning it into a link:<br />
<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
HelloWorld:echo("hi")<br />
selectString("HelloWorld", "hi", 1)<br />
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")<br />
</syntaxhighlight><br />
<br />
==setMainWindowSize==<br />
;setMainWindowSize(mainWidth, mainHeight)<br />
: Changes the size of your main Mudlet window to the values given.<br />
: See Also: [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''mainWidth:''<br />
: The new width in pixels.<br />
* ''mainHeight:''<br />
: The new height in pixels.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will resize your main Mudlet window<br />
setMainWindowSize(1024, 768)<br />
</syntaxhighlight><br />
<br />
==setMapWindowTitle==<br />
;setMapWindowTitle(text)<br />
: Changes the title shown in the mapper window when it's popped out.<br />
: See also: [[#resetMapWindowTitle|resetMapWindowTitle()]]<br />
<br />
; Parameters<br />
* ''text:''<br />
: New window title to set.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapWindowTitle("my cool game map")<br />
</syntaxhighlight><br />
<br />
==setMiniConsoleFontSize==<br />
;setMiniConsoleFontSize(name, fontSize)<br />
: Sets the font size of the mini console. see also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]]<br />
<br />
==setOverline==<br />
;setOverline([windowName], boolean)<br />
: Sets the current text font to be overlined (true) or not overlined (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 overlined. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be overlined until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be overlined or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables overlining of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable overlined text<br />
setOverline(true)<br />
-- the following echo will be have an overline<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and reverse have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==setPopup==<br />
;setPopup(windowName, {lua code}, {hints})<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,<br />
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking<br />
-- will show some commands you can do.<br />
<br />
selectString("Hello", 1)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})<br />
</syntaxhighlight><br />
<br />
==setProfileStyleSheet==<br />
;setProfileStyleSheet(stylesheet)<br />
: Sets a stylesheet for the current Mudlet profile - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). This function is better than setAppStyleSheet() because it affects only the current profile and not every other one as well.<br />
<br />
: See also: [[#setAppStyleSheet|setAppStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use. See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setProfileStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
<br />
QTreeView {<br />
background: ]]..background_color..[[;<br />
color: white;<br />
}<br />
<br />
QMenuBar{ background-color: ]]..background_color..[[;}<br />
<br />
QMenuBar::item{ background-color: ]]..background_color..[[;}<br />
<br />
QDockWidget::title {<br />
background: ]]..border_color..[[;<br />
}<br />
QStatusBar {<br />
background: ]]..border_color..[[;<br />
}<br />
QScrollBar:vertical {<br />
background: ]]..background_color..[[;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background-color: ]]..background_color..[[;<br />
min-height: 20px;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 7px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-bottom-left-radius: 7px;<br />
border-bottom-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-top-left-radius: 7px;<br />
border-top-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
background: white;<br />
width: 4px;<br />
height: 3px;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]])<br />
<br />
-- if you'd like to reset it, use:<br />
setProfileStyleSheet("")<br />
<br />
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':<br />
setProfileStyleSheet[[<br />
TConsole QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
TConsole QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
TConsole QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 4.6.<br />
<br />
==setReverse==<br />
;setReverse([windowName], boolean)<br />
: Sets the current text to swap foreground and background color settings (true) or not (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 have it's colors swapped. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will have their foreground and background colors swapped until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text colors to be reversed or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables reversing of the fore- and back-ground colors of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable fore/back-ground color reversal of text<br />
setReverse(true)<br />
-- the following echo will have the text colors reversed<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and overline have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
{{note}} Although the visual effect on-screen is the same as that of text being selected if both apply to a piece of text they neutralise each other - however the effect of the reversal ''will'' be carried over in copies made by the "Copy to HTML" and in logs made in HTML format log file mode.<br />
<br />
==setStrikeOut==<br />
;setStrikeOut([windowName], boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be striken out until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be stricken out or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables striking out of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable striken-out text<br />
setStrikeOut(true)<br />
-- the following echo will be have a strikethrough<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setTextFormat==<br />
;setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])<br />
: Sets current text format of selected window. This is a more convenient means to set all the individual features at once compared to using [[#setFgColor|setFgColor]]( windowName, r,g,b ), [[#setBold|setBold]]( windowName, true ), [[#setItalics|setItalics]]( windowName, true ), [[#setUnderline|setUnderline]]( windowName, true ), [[#setStrikeOut|setStrikeOut]]( windowName, true ).<br />
: See Also: [[Manual:Lua_Functions#getTextFormat|getTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: Specify name of selected window. If empty string "" or "main" format will be applied to the main console<br />
* ''r1,g1,b1''<br />
: To color text background, give number values in RBG style<br />
* ''r2,g2,b2''<br />
: To color text foreground, give number values in RBG style<br />
* ''bold''<br />
: To format text bold, set to 1 or true, otherwise 0 or false<br />
* ''underline''<br />
: To underline text, set to 1 or true, otherwise 0 or false<br />
* ''italics''<br />
: To format text italic, set to 1 or true, otherwise 0 or false<br />
* ''strikeout<br />
: (optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''overline<br />
: (optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''reverse<br />
: (optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This script would create a mini text console and write with bold, struck-out, yellow foreground color and blue background color "This is a test".<br />
createMiniConsole( "con1", 0,0,300,100);<br />
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);<br />
echo("con1","This is a test")<br />
</syntaxhighlight><br />
<br />
{{note}} In versions prior to 3.7.0 the error messages ''and this wiki'' were wrong in that they had the foreground color parameters as r1, g1 and b1 and the background ones as r2, g2 and b2.<br />
<br />
==setUnderline==<br />
;setUnderline(windowName, bool)<br />
: Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setUserWindowTitle==<br />
;setUserWindowTitle(windowName, text)<br />
: sets a new title text for the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''text''<br />
: new title text<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==setUserWindowStyleSheet==<br />
;setUserWindowStyleSheet(windowName, markup)<br />
: Applies Qt style formatting to the border/title area of a userwindow via a special markup language.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when you dock the userwindow the border style is not provided by this<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- changes the title area style of the UserWindow 'myUserWindow'<br />
setUserWindowStyleSheet("myUserWindow", [[QDockWidget::title{ <br />
background-color: rgb(0,255,150);<br />
border: 2px solid red;<br />
border-radius: 8px;<br />
text-align: center; <br />
}]])<br />
</syntaxhighlight><br />
<br />
: See also: [[#openUserWindow|openUserWindow()]]<br />
<br />
==setWindow==<br />
;setWindow(windowName, name, [Xpos, Ypos, show])<br />
: Changes the parent window of an element.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow which you want the element put in. If you want to put the element into the main window, use windowName "main".<br />
* ''name''<br />
: Name of the element which you want to switch the parent from. Elements can be labels, miniconsoles and the embedded mapper. If you want to move the mapper use the name "mapper"<br />
* ''Xpos:''<br />
: X position of the element. Measured in pixels, with 0 being the very left. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''Ypos:''<br />
: Y position of the element. Measured in pixels, with 0 being the very top. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''show:''<br />
: true or false to decide if the element will be shown or not in the new parent window. Optional, if not given it will be true.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindow("myuserwindow", "mapper")<br />
-- This will put your embedded mapper in your userwindow "myuserwindow".<br />
</syntaxhighlight><br />
<br />
==setWindowWrap==<br />
;setWindowWrap(windowName, wrapAt)<br />
: sets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapAt:''<br />
: Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==setWindowWrapIndent==<br />
;setWindowWrapIndent(windowName, wrapTo)<br />
: sets how many spaces wrapped text will be indented with (after the first line of course).<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapTo:''<br />
: Number of spaces which wrapped lines are prefixed with.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
setWindowWrapIndent("main", 3)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==showCaptureGroups==<br />
;showCaptureGroups()<br />
:Lua debug function that highlights in random colors 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.<br />
<br />
;Example:<br />
: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.<br />
<br />
==showMultimatches==<br />
;showMultimatches()<br />
: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.<br />
<br />
==showWindow==<br />
;showWindow(name)<br />
: Makes a hidden window (label or miniconsole) be shown again.<br />
<br />
: See also: [[#hideWindow | hideWindow()]]<br />
<br />
==showColors==<br />
;showColors([columns], [filterColor], [sort])<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in '''color_table''', in table form. The format is ''color_table.colorName = {r, g, b}''.<br />
<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: (optional) number of columns to print the color table in.<br />
* ''filterColor:''<br />
: (optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.<br />
* ''sort:''<br />
: (optional) sort colors alphabetically.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- display as four columns:<br />
showColors(4)<br />
<br />
-- show only red colours:<br />
showColors("red")<br />
</syntaxhighlight><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)|thumb|center]]<br />
<br />
==showToolBar==<br />
;showToolBar(name)<br />
: Makes a toolbar (a button group) appear on the screen.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
showToolBar("my attack buttons")<br />
</syntaxhighlight><br />
<br />
==suffix==<br />
;suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
: Suffixes text at the end of the current line. This is similar to [[Manual:Lua_Functions#echo | echo()]], which also suffixes text at the end of the line, but different - [[Manual:Lua_Functions#echo | 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.<br />
<br />
;Parameters<br />
* ''text''<br />
: the information you want to prefix<br />
* ''writingFunction''<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* ''foregroundColor''<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* ''backgroundColor''<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* ''windowName''<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
<br />
: See also: [[#prefix | prefix()]], [[Manual:Lua_Functions#echo | echo()]]<br />
<br />
==wrapLine==<br />
;wrapLine(windowName, lineNumber)<br />
: 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.:<br />
<br />
<syntaxhighlight lang="lua">selectString(line,1)<br />
replace("")</syntaxhighlight><br />
<br />
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.<br />
<br />
: See Also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#deleteLine|deleteLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The miniconsole or the main window (use ''main'' for the main window)<br />
* ''lineNumber:''<br />
: The line number which you'd like re-wrapped.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- re-wrap the last line in the main window<br />
wrapLine("main", getLineCount())<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=15591Manual:UI Functions2020-09-30T11:24:20Z<p>Smurf: /* setWindowWrapIndent */ wording</p>
<hr />
<div>{{TOC right}}<br />
= UI Functions =<br />
<br />
All functions that help you customize Mudlet's interface and the game's text.<br />
<br />
==ansi2decho==<br />
;ansi2decho(text, default_colour)<br />
: Converts ANSI colour sequences in <code>text</code> to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.<br />
: See also: [[Manual:Lua_Functions#decho|decho()]]<br />
{{note}}<br />
ANSI bold is available since Mudlet 3.7.1+.<br />
R<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be replaced.<br />
* ''default_colour:''<br />
: Optional - ANSI default colour code (used when handling orphan bold tags).<br />
<br />
;Return values<br />
* ''string text:''<br />
: The decho-valid converted text.<br />
* ''string colour:''<br />
: The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- '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><br />
decho(replaced)<br />
</syntaxhighlight><br />
<br />
Or show a complete colourful squirrel! It's a lotta code to do all the colours, so click the '''Expand''' button on the right to show it:<br />
<div class="toccolours mw-collapsible mw-collapsed"><br />
<syntaxhighlight lang="lua"><br />
decho(ansi2decho([[<br />
�[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m �[0m<br />
╭───────────────────────╮ �[38;5;95m▄▄�[0m �[38;5;95m▄�[48;5;95;38;5;130m▄▄�[48;5;130m█�[38;5;137m▄�[48;5;137;38;5;95m▄�[49m▀�[0m �[0m<br />
│ │ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄▄▄�[48;5;95;38;5;137m▄▄▄�[49;38;5;95m▄▄�[48;5;95;38;5;130m▄�[48;5;130m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[0m �[0m<br />
│ Encrypt everything! │ �[38;5;95m▄�[48;5;187;38;5;16m▄�[48;5;16;38;5;187m▄�[38;5;16m█�[48;5;137;38;5;137m███�[38;5;187m▄�[38;5;16m▄▄�[38;5;137m██�[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[0m �[0m<br />
│ ├──── �[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;16m▄▄▄�[48;5;137m███�[48;5;16;38;5;16m█�[48;5;187m▄�[48;5;16m█�[48;5;137;38;5;137m█�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
╰───────────────────────╯ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;16m▄�[38;5;16m█�[38;5;137m▄�[48;5;137m██████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;95m▀�[48;5;137m▄�[38;5;137m███████�[38;5;95m▄�[49m▀�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[48;5;95;38;5;187m▄▄▄�[38;5;137m▄�[48;5;137m██�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[38;5;95m▀�[48;5;130m▄�[38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;187m████�[48;5;137;38;5;137m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m██�[38;5;95m▄�[38;5;137m█�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;187;38;5;187m████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95m██�[48;5;137m▄▄�[48;5;187;38;5;187m████�[48;5;137;38;5;95m▄▄�[48;5;95;38;5;137m▄�[48;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;187;38;5;187m███�[48;5;95m▄�[38;5;137m▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[49m▄�[48;5;95;38;5;130m▄�[48;5;130m██████�[48;5;137;38;5;137m███�[38;5;95m▄�[49m▀�[0m�[0m<br />
�[48;5;187;38;5;95m▄�[38;5;187m████�[48;5;137;38;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m█████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;137m▄�[38;5;187m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██████�[48;5;95m▄▄�[48;5;130m▄▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▄▄▄�[48;5;95;38;5;137m▄�[48;5;187m▄�[38;5;187m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m█████�[38;5;95m▄�[38;5;137m███████████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀�[48;5;187m▄▄▄�[48;5;95;38;5;137m▄�[48;5;137m██�[38;5;95m▄�[49m▀�[0m �[38;5;95m▀▀�[48;5;137m▄▄▄▄▄▄�[49m▀▀▀�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀▀�[0m �[0m<br />
]]))<br />
</syntaxhighlight><br />
</div><br />
<br />
[[File:Squirrel-in-Mudlet.png|frameless]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.0+<br />
<br />
<br />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be removed.<br />
<br />
;Return values<br />
* ''string text:''<br />
: The plain text without ANSI colour sequences.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10+<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2string('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- 'replaced' should now contain You say in a baritone voice, "Test."<br />
print(replaced)<br />
</syntaxhighlight><br />
<br />
<br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name.<br />
: See also: [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[Manual:Lua_Functions#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</syntaxhighlight><br />
<br />
==bg==<br />
;bg([window, ]colorName)<br />
: Changes the background color of the text. Useful for highlighting text.<br />
: See Also: [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: 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).<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
<br />
-- or echo text with a green background to a miniconsole<br />
bg("my window", "green")<br />
echo("my window", "some green text\n")<br />
</syntaxhighlight><br />
<br />
==calcFontSize==<br />
;calcFontSize(window_or_fontsize, [fontname])<br />
: Returns the average height and width of characters in a particular window, or a font name and size combination. Helpful if you want to size a miniconsole to specific dimensions.<br />
: Returns two numbers, width/height<br />
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
;Parameters<br />
* ''window_or_fontsize:''<br />
: The miniconsole or font size you are wanting to calculate pixel sizes for.<br />
* ''fontname:''<br />
: Specific font name (along with the size as the first argument) to calculate for.<br />
<br />
{{note}}<br />
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide<br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</syntaxhighlight><br />
<br />
==cecho==<br />
;cecho([window], text)<br />
: Echoes text that can be easily formatted with colour tags. You can also include unicode art in it - try some examples from [http://1lineart.kulaone.com/#/ 1lineart].<br />
: See also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cecho("<blue:yellow>Blue on yellow text!")<br />
<br />
-- \n adds a new line<br />
cecho("<red>one line\n<green>another line\n<blue>last line")<br />
<br />
cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
<br />
cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")<br />
<br />
cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")<br />
<br />
cecho([[<br />
██╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗ ████████╗<br />
███║ ██║ ██║████╗ ██║██╔════╝ ██╔══██╗██╔══██╗╚══██╔══╝<br />
╚██║ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝ ██║<br />
██║ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗ ██║<br />
██║ ███████╗██║██║ ╚████║███████╗ ██║ ██║██║ ██║ ██║<br />
╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝<br />
]])<br />
</syntaxhighlight><br />
<br />
==cechoLink==<br />
;cechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#cecho|cecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cechoPopup==<br />
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#cecho|cecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertLink==<br />
;cinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#cinsertText|cinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertPopup==<br />
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#cinsertText|cinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertText==<br />
;cinsertText([window], text)<br />
: inserts text at the current cursor position, with the possibility for color tags.<br />
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cinsertText("<blue:yellow>Blue on yellow text!")<br />
<br />
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
</syntaxhighlight><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].<br />
<br />
==clearWindow==<br />
;clearWindow([windowName])<br />
: Clears the label, mini console, or user window 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 (starting with Mudlet 2.0-test3+)<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this can clear your whole main window - needs Mudlet version >= 2.0<br />
clearWindow()<br />
</syntaxhighlight><br />
<br />
==copy==<br />
; copy([windowName])<br />
: Copies the current selection to the lua virtual clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the lua virtual clipboard until it gets overwritten by another copy operation.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
; Parameters<br />
* ''windowName'' (optional):<br />
: the window from which to copy text - use the main console if not specified.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This script copies the current line on the main screen to a window (miniconsole or userwindow) called 'chat' and gags the output on the main screen.<br />
selectString(line, 1)<br />
copy()<br />
appendBuffer("chat")<br />
replace("This line has been moved to the chat window!")<br />
</syntaxhighlight><br />
<br />
==copy2decho==<br />
; copy2decho([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in decho format.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line.<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and dechos it to a miniconsole named "test"<br />
decho("test", copy2decho())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and decho it to a Geyser miniconsole stored as the variable enemylist<br />
enemylist:decho(copy2decho(matches[2]))<br />
</syntaxhighlight><br />
<br />
==copy2html==<br />
; copy2html([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in html format for echoing to a label.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main"<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and echos it to a label named "TestLabel"<br />
echo("TestLabel", copy2html())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and echo it to a Geyser label stored as the variable enemylist<br />
enemylist:echo(copy2html(matches[2]))<br />
</syntaxhighlight><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: 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.<br />
<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</syntaxhighlight><br />
<br />
==createCommandLine==<br />
;createCommandLine([name of userwindow], name, x, y, width, height)<br />
: Creates a new command line inside the main window of Mudlet. If only a command line inside a miniConsole/UserWindow is needed see [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]].<br />
: You can use [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]] / [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]] and other command line functions to customize the input.<br />
{{note}} [[Manual:UI_Functions#setCmdLineAction|setCmdLineAction]] allows you to attach an action to your command line input.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#disableCommandLine|disableCommandLine()]], [[Manual:Mudlet_Object_Functions#clearCmdLine|clearCmdLine()]], [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]], [[Manual:Mudlet_Object_Functions#printCmdLine|printCmdLine()]], [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the command line is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the command line. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the command line size and location - it is also possible to set them by using [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createCommandLine() will only set them once.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==createConsole==<br />
;createConsole([name of userwindow], consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow your new miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,<br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
''(For Mudlet Makers)'' This function is implemented outside the application's core via the '''GUIUtils.lua''' file of the Mudlet supporting Lua code using [[Manual:UI_Functions#createMiniConsole|createMiniConsole()]] and other functions to position and size the mini-console and configure the font.<br />
<br />
==createGauge==<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the gauge is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: 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<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
* ''orientation:''<br />
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.<br />
<syntaxhighlight lang="lua"><br />
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")<br />
</syntaxhighlight><br />
<br />
==createLabel==<br />
;createLabel([name of userwindow], name, Xpos, Ypos, width, height, fillBackground, [enableClickthrough])<br />
: 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.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]], [[Manual:Lua_Functions#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will display the background color, 0 or false will not.<br />
* ''enableClickthrough:''<br />
: Whether or not enable clickthrough on this label. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will enable clickthrough, 0 or false will not. Optional, defaults to clickthrough not enabled if not provided.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label situated at x=300 y=400 with dimensions 100x200<br />
createLabel("a very basic label",300,400,100,200,1)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle<br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent<br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
<br />
-- you can also make it react to clicks!<br />
mynamespace = {<br />
messageBoxClicked = function()<br />
echo("hey you've clicked the box!\n")<br />
end<br />
}<br />
<br />
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")<br />
<br />
<br />
-- uncomment code below to make it also hide after a short while<br />
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</syntaxhighlight><br />
<br />
==createMiniConsole==<br />
;createMiniConsole([name of userwindow], name, x, y, width, height)<br />
: 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.<br />
: You can use [[Manual:Lua_Functions#clearWindow|clearWindow()]] / [[Manual:Lua_Functions#moveCursor|moveCursor()]] and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. [[Manual:Lua_Functions#setWindowWrap|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 [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent()]], [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|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.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
==creplace==<br />
;creplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, with color names inside angle brackets as with [[Manual:Lua_Functions#cecho|cecho()]]. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
creplace("<magenta>[ALERT!]: <reset>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==creplaceLine==<br />
;creplaceLine (text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''text:''<br />
*: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)<br />
</syntaxhighlight><br />
<br />
==decho==<br />
;decho ([name of console,] text)<br />
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB,[BA]> 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,[BA]>. 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")''.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]]<br />
<br />
;Parameters<br />
* ''name of console''<br />
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.<br />
* ''text:''<br />
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.<br />
<br />
<br />
{{note}}<br />
Optional background transparancy parameter (BA) available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
decho("<50,50,0:0,255,0>test")<br />
<br />
decho("miniconsolename", "<50,50,0:0,255,0>test")<br />
</syntaxhighlight><br />
<br />
==dechoLink==<br />
;dechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#decho|decho()]]. This version allows you to use colours within your link text.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) allows selection between sending the link to a miniconsole or the "main" window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==dechoPopup==<br />
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#decho|decho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertLink==<br />
;dinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#dinsertText|dinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertPopup==<br />
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#dinsertText|dinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
== deleteLabel ==<br />
; deleteLabel(labelName)<br />
<br />
: Deletes and removes a label from the screen. Note that if you'd like to show the label again, it is much more performant to hide/show it instead.<br />
<br />
: Note that you shouldn't use the Geyser label associated with the label you delete afterwards - that doesn't make sense and Geyser right now wouldn't know that it's been deleted, either.<br />
<br />
: See also: [[#hideWindow|hideWindow()]], [[#showWindow|showWindow()]], [[#createLabel|createLabel()]]<br />
<br />
; Parameters<br />
<br />
* ''labelName'': name of the label to delete.<br />
<br />
<syntaxhighlight lang="lua"><br />
createLabel("a very basic label",300,400,100,200,1)<br />
setBackgroundColor("a very basic label", 255, 204, 0, 200)<br />
<br />
-- delete the label after 3 seconds<br />
tempTimer(3, function()<br />
deleteLabel("a very basic label")<br />
end)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 4.5+<br />
<br />
==deleteLine==<br />
;deleteLine([windowName])<br />
: 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. This is purely visual - triggers will still fire on the line as expected.<br />
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.<br />
<br />
{{note}} for replacing text, [[Manual:Lua_Functions#replace|replace()]] is the proper option; doing the following: <code>selectCurrentLine(); replace(""); cecho("new line!\n")</code> is better.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- deletes the line - just put this command into the big script box. Keep the case the same -<br />
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else<br />
deleteLine()<br />
<br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
<br />
-- example of deleting multiple lines:<br />
deleteLine() -- delete the current line<br />
moveCursor(0,getLineNumber()-1) -- move the cursor back one line<br />
deleteLine() -- delete the previous line now<br />
</syntaxhighlight><br />
<br />
==deselect==<br />
;deselect([window name])<br />
: 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.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''window name:''<br />
: (optional) The name of the window to stop having anything selected in. If name is not provided the main window will have its selection cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further<br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</syntaxhighlight><br />
<br />
==disableClickthrough==<br />
; disableClickthrough(label)<br />
: Disables clickthrough for a label - making it act 'normal' again and receive clicks, doubleclicks, onEnter, and onLeave events. This is the default behaviour for labels.<br />
: See also: [[#enableClickthrough|enableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name of the label to restore clickability on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==disableCommandLine==<br />
; disableCommandLine(windowName)<br />
: Disables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableCommandLine|enableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to disable the command line in.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10<br />
<br />
==disableScrollBar==<br />
; disableScrollBar(windowName)<br />
: Disables the scroll bar for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to disable the scroll bar in.<br />
<br />
==dreplace==<br />
;dreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#decho|decho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
dreplace("<255,0,255>[ALERT!]: <r>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''text:''<br />
: Text to display in the echo. Same as a normal echo().<br />
* ''command:''<br />
: Lua code to do when the link is clicked.<br />
* ''hint:''<br />
: Text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentFormatElseDefault:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
echoLink("press me!", [[send("hi")]], "This is a tooltip")<br />
<br />
-- do the same, but send this link to a miniConsole<br />
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")<br />
</syntaxhighlight><br />
<br />
==echoUserWindow==<br />
;echoUserWindow(windowName)<br />
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.<br />
<br />
==echoPopup==<br />
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==enableClickthrough==<br />
; enableClickthrough(label)<br />
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.<br />
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.<br />
: See also: [[#disableClickthrough|disableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: The name of the label to enable clickthrough on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==enableCommandLine==<br />
; enableCommandLine(windowName)<br />
: Enables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#disableCommandLine|disableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to enable the command line in.<br />
<br />
{{note}} The command line name is the same as the miniConsole name<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableScrollBar==<br />
; enableScrollBar(windowName)<br />
: Enables the scrollbar for the miniConsole named ''windowName''.<br />
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in.<br />
<br />
==fg==<br />
; fg([window], colorName)<br />
: 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)<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything or use ''main'' (since Mudlet 3.0).<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
<br />
-- example of working on a miniconsole<br />
fg("my console", "red")<br />
echo("my console", "red text")<br />
</syntaxhighlight><br />
<br />
==getAvailableFonts==<br />
; getAvailableFonts()<br />
: This returns a "font - true" key-value list of available fonts which you can use to verify that Mudlet has access to a given font.<br />
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.<br />
<br />
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]<br />
<br />
{{note}}<br />
Available since Mudlet 3.10<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if Ubuntu Mono is a font we can use<br />
if getAvailableFonts()["Ubuntu Mono"] then<br />
-- make the miniconsole use the font at size 16<br />
setFont("my miniconsole", "Ubuntu Mono")<br />
setFontSize("my miniconsole", 16)<br />
end<br />
</syntaxhighlight><br />
<br />
==getBgColor==<br />
; getBgColor(windowName)<br />
: 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.<br />
<br />
: See also: [[#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r,g,b;<br />
selectString("troll",1)<br />
r,g,b = getBgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getBorderBottom==<br />
;getBorderBottom()<br />
: Returns the size of the bottom border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
getBorderBottom()<br />
-- returns: 150<br />
</syntaxhighlight><br />
<br />
==getBorderLeft==<br />
;getBorderLeft()<br />
: Returns the size of the left border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
getBorderLeft()<br />
-- returns: 5<br />
</syntaxhighlight><br />
<br />
==getBorderRight==<br />
;getBorderRight()<br />
: Returns the size of the right border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
getBorderRight()<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderSizes==<br />
;getBorderSizes()<br />
: Returns the a named table with the sizes of all borders of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]],[[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0)<br />
getBorderSizes()<br />
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }<br />
getBorderSizes().right<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderTop==<br />
;getBorderTop()<br />
: Returns the size of the top border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
getBorderTop()<br />
-- returns: 100<br />
</syntaxhighlight><br />
<br />
==getClipboardText==<br />
;getClipboardText()<br />
: Returns any text that is currently present in the clipboard. <br />
: See also: [[#setClipboardText | setClipboardText()]]<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local clipboardContents = getClipboardText()<br />
echo("Clipboard: " .. clipboardContents)<br />
</syntaxhighlight><br />
<br />
==getColorWildcard==<br />
; getColorWildcard(ansi color number)<br />
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.<br />
<br />
: See also: [[#isAnsiFgColor|isAnsiFgColor()]], [[#isAnsiBgColor|isAnsiBgColor()]]<br />
<br />
;Parameters<br />
* ''ansi color number:''<br />
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- we can run this script on a line that has the players name coloured differently to easily capture it from<br />
-- anywhere on the line<br />
local match = getColorWildcard(14)<br />
<br />
if match then<br />
echo("\nFound "..match.."!")<br />
else<br />
echo("\nDidn't find anyone.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getColumnCount==<br />
;getColumnCount([windowName])<br />
: Gets the maximum number of columns (characters) that a given window can display on a single row, taking into consideration factors such as window width, font size, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum number of columns on the main window "..getColumnCount())<br />
</syntaxhighlight><br />
<br />
==getColumnNumber==<br />
;getColumnNumber([windowName])<br />
: Gets the absolute column number of the current user cursor.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
<br />
{{note}} the argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
<br />
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
</syntaxhighlight><br />
<br />
==getCurrentLine==<br />
;getCurrentLine([windowName])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Currently selected line: "..getCurrentLine())<br />
</syntaxhighlight><br />
<br />
==getFgColor==<br />
; getFgColor(windowName)<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString("troll",1)<br />
local r,g,b = getFgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is written in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getFont==<br />
;getFont(windowName)<br />
: Gets the current font of the given window or console name. Can be used to get font of the main console, dockable userwindows and miniconsoles.<br />
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
display("Font in the main window: "..getFont())<br />
<br />
display("Font in the main window: "..getFont("main"))<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
display("Font size: " .. getFont("user window awesome"))<br />
</syntaxhighlight><br />
<br />
==getFontSize==<br />
;getFontSize(windowName)<br />
: Gets the current font size of the given window or console name. Can be used to get font size of the Main console as well as dockable UserWindows.<br />
: See also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
local mainWindowFontSize = getFontSize()<br />
if mainWindowFontSize then<br />
display("Font size: " .. mainWindowFontSize)<br />
end<br />
<br />
local mainWindowFontSize = getFontSize("main")<br />
if mainWindowFontSize then<br />
display("Font size: " .. fs2)<br />
end<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
local awesomeWindowFontSize = getFontSize("user window awesome")<br />
if awesomeWindowFontSize then<br />
display("Font size: " .. awesomeWindowFontSize)<br />
end<br />
</syntaxhighlight><br />
<br />
==getImageSize==<br />
;getImageSize(imageLocation)<br />
: Returns the width and the height of the given image. If the image can't be found, loaded, or isn't a valid image file - nil+error message will be returned instead.<br />
: See also: [[#createLabel|createLabel()]]<br />
<br />
;Parameters<br />
* ''imageLocation:''<br />
: Path to the image.<br />
<br />
{{note}}<br />
Available in Mudlet 4.5+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local path = getMudletHomeDir().."/my-image.png"<br />
<br />
cecho("Showing dimensions of the picture in: "..path.."\n")<br />
<br />
local width, height = getImageSize(path)<br />
<br />
if not width then<br />
-- in case of an problem, we don't get a height back - but the error message<br />
cecho("error: "..height.."\n")<br />
else<br />
cecho(string.format("They are: %sx%s", width, height))<br />
end<br />
</syntaxhighlight><br />
<br />
==getLastLineNumber==<br />
;getLastLineNumber(windowName)<br />
:Returns the latest line's number in the main window or the miniconsole. This could be different from [[Manual:UI_Functions#getLineNumber|getLineNumber()]] if the cursor was moved around.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the latest line's # in the buffer<br />
local latestline = getLastLineNumber("main")<br />
</syntaxhighlight><br />
<br />
==getLineCount==<br />
;getLineCount()<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
''Need example''<br />
<br />
==getLines==<br />
;getLines([windowName,] from_line_number, to_line_number)<br />
: 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}''.<br />
<br />
:Absolute line numbers are used.<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)<br />
* ''from_line_number:''<br />
: First line number<br />
* ''to_line_number:''<br />
: End line number<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- retrieve & echo the last line:<br />
echo(getLines(getLineNumber()-1, getLineNumber())[1])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- find out which server and port you are connected to (as per Mudlet settings dialog):<br />
local t = getLines(0, getLineNumber())<br />
<br />
local server, port<br />
<br />
for i = 1, #t do<br />
local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")<br />
if s then server, port = s, p break end<br />
end<br />
<br />
display(server)<br />
display(port)<br />
</syntaxhighlight><br />
<br />
==getLineNumber==<br />
;getLineNumber([windowName])<br />
: 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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#moveCursorEnd|moveCursorEnd()]]. This function can come in handy in combination when using with [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#getLines|getLines()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.<br />
<br />
{{note}}<br />
The argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word<br />
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end<br />
<br />
-- check how many lines you've got in your miniconsole after echoing some text.<br />
-- Note the use of moveCursorEnd() to update getLineNumber()'s output<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
print(getLineNumber("HelloWorld"))<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
-- update the cursors position, as it seems to be necessary to do<br />
moveCursorEnd("HelloWorld")<br />
print(getLineNumber("HelloWorld"))<br />
</syntaxhighlight><br />
<br />
==getMainConsoleWidth==<br />
;getMainConsoleWidth()<br />
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.<br />
<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Save width of the main console to a variable for future use.<br />
consoleWidth = getMainConsoleWidth()<br />
</syntaxhighlight><br />
<br />
==getMousePosition==<br />
;getMousePosition()<br />
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{note}} Available since Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- 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<br />
local x, y = getMousePosition()<br />
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)<br />
-- if the label already exists, just move it<br />
moveWindow("clickGeneratedLabel", x, y)<br />
-- and make it easier to notice<br />
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)<br />
</syntaxhighlight><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getUserWindowSize|getUserWindowSize()]], [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your main mudlet window and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</syntaxhighlight><br />
<br />
==getRowCount==<br />
;getRowCount([windowName])<br />
: Gets the maximum number of rows that a given window can display at once, taking into consideration factors such as window height, font type, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum of rows on the main window "..getRowCount())<br />
</syntaxhighlight><br />
<br />
==getSelection==<br />
;getSelection([windowName])<br />
: Returns the text currently selected with [[#selectString|selectString()]], [[#selectSection|selectSection()]], or [[#selectCurrentLine|selectCurrentLine()]]. Note that this isn't the text currently selected with the mouse.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window to get the selection from. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.16.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
print("Current selection is: "..getSelection())<br />
</syntaxhighlight><br />
<br />
==getTextFormat==<br />
;getTextFormat([windowName])<br />
: Gets the current text format of the currently selected text. May be used with other console windows. The returned values come in a table containing text attribute names and their values. The values given will be booleans for: bold, italics, underline, overline, strikeout, and reverse - followed by color triplet tables for the foreground and background colors.<br />
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.<br />
<br />
{{note}} Available since Mudlet 3.20.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- A suitable test for getTextFormat()<br />
-- (copy it into an alias or a script)<br />
<br />
clearWindow()<br />
<br />
echo("\n")<br />
<br />
local SGR = string.char(27)..'['<br />
feedTriggers("Format attributes: '"..SGR.."1mBold"..SGR.."0m' '"..SGR.."3mItalic"..SGR.."0m' '"..SGR.."4mUnderline"..SGR.."0m' '"..SGR.."5mBlink"..SGR.."0m' '"..SGR.."6mF.Blink"..SGR.."0m' '"..SGR.."7mReverse"..SGR.."0m' '"..SGR.."9mStruckout"..SGR.."0m' '"..SGR.."53mOverline"..SGR.."0m'.\n")<br />
<br />
moveCursor(1,1)<br />
selectSection(1,1)<br />
<br />
local results = getTextFormat()<br />
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))<br />
echo("\nItalic detected: " .. tostring(results["italic"]))<br />
echo("\nUnderline detected: " .. tostring(results["underline"]))<br />
echo("\nReverse detected: " .. tostring(results["reverse"]))<br />
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))<br />
echo("\nOverline detected: " .. tostring(results["overline"]))<br />
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")<br />
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")<br />
<br />
selectSection(21,1)<br />
echo("\n\nFor individual parts of test text:")<br />
echo("\nBold detected (character 21): " .. tostring(results["bold"]))<br />
<br />
selectSection(28,1)<br />
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))<br />
<br />
selectSection(37,1)<br />
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))<br />
<br />
selectSection(67,1)<br />
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))<br />
<br />
selectSection(77,1)<br />
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))<br />
<br />
selectSection(89,1)<br />
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))<br />
echo("\n")<br />
</syntaxhighlight><br />
<br />
==getUserWindowSize==<br />
{{note}} available in Mudlet 4.6.1+<br />
;getUserWindowSize(windowName)<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the given userwindow dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''windowName''<br />
:the name of the userwindow we will get the dimensions from<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your userwindow named "ChatWindow" and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getUserWindowSize("ChatWindow")<br />
</syntaxhighlight><br />
<br />
==handleWindowResizeEvent==<br />
;handleWindowResizeEvent()<br />
: (''depreciated'') This function is depreciated and should not be used; it's only documented here for historical reference - use the [[Manual:Technical_Manual#sysWindowResizeEvent|sysWindowResizeEvent]] event instead.<br />
<br />
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.<br />
<br />
; Parameters<br />
:None<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
function handleWindowResizeEvent()<br />
-- determine the size of your screen<br />
WindowWidth=0;<br />
WindowHeight=0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
-- move mini console "sys" to the far right side of the screen whenever the screen gets resized<br />
moveWindow("sys",WindowWidth-300,0)<br />
end<br />
</syntaxhighlight><br />
<br />
==hasFocus==<br />
;hasFocus()<br />
: 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). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if attacked and not hasFocus() then<br />
runaway()<br />
else<br />
fight()<br />
end<br />
</syntaxhighlight><br />
<br />
==hecho==<br />
;hecho([windowName], text)<br />
: Echoes text that can be easily formatted with colour tags in the hexadecimal format.<br />
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.<br />
* ''text:''<br />
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #FRFGFB,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 or #r can be used within the string to reset the colors to default. Hexadecimal color codes can be found here: https://www.color-hex.com/<br />
<br />
{{note}}<br />
Transparency for background in hex-format available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hecho("\n#ffffff White text!")<br />
-- your text in white<br />
hecho("\n#ca0004 Red text! And now reset #rit to the default color")<br />
-- your text in red, then reset to default using #r<br />
hecho("\n#ffffff,ca0004 White text with a red background!")<br />
-- your text in white, against a red background<br />
hecho("\n|c0000ff Blue text, this time using |c instead of #")<br />
-- your text in blue, activated with |c vs #.<br />
</syntaxhighlight><br />
<br />
==hechoLink==<br />
;hechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#hecho|hecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
-- # format also works<br />
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==hechoPopup==<br />
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#hecho|hecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertLink==<br />
;hinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#hinsertText|hinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertPopup==<br />
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#hinsertText|hinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hreplace==<br />
;hreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#hecho|hecho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
hreplace("#EE00EE[ALERT!]: #r"..matches[2])<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.5+<br />
<br />
==hideToolBar==<br />
;hideToolBar(name)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to hide<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hideToolBar("my offensive buttons")<br />
</syntaxhighlight><br />
<br />
==hideWindow==<br />
;hideWindow(name)<br />
: This function hides a '''mini console''', a '''user window''' or a '''label''' with the given name. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].<br />
<br />
: See also: [[#createMiniConsole|createMiniConsole()]], [[#createLabel|createLabel()]], [[#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name''<br />
: specifies the label or console you want to hide.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function miniconsoleTest()<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
print("created red window top-right")<br />
<br />
tempTimer(1, function()<br />
hideWindow("sys")<br />
print("hid red window top-right")<br />
end)<br />
<br />
tempTimer(3, function()<br />
showWindow("sys")<br />
print("showed red window top-right")<br />
end)<br />
end<br />
<br />
miniconsoleTest()<br />
</syntaxhighlight><br />
<br />
==insertLink==<br />
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])<br />
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) the window to insert the link in - use either "main" or omit for the main window.<br />
* ''text:''<br />
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) true or false. 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- link with the default blue on white colors<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")<br />
<br />
-- use current cursor colors by adding true at the end<br />
fg("red")<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==insertPopup==<br />
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])<br />
: Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to [[Manual:Lua_Functions#insertText|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''name:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.<br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==insertText==<br />
;insertText([windowName], text)<br />
: Inserts text at cursor postion in window - unlike [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] to move the cursor into position first.<br />
<br />
: insertHTML() also does the same thing as insertText, if you ever come across it.<br />
<br />
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) The window to insert the text to.<br />
* ''text:''<br />
: The text you will insert into the current cursor position.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the cursor to the end of the previous line and insert some text<br />
<br />
-- move to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
-- move the end the of the previous line<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
<br />
fg("dark_slate_gray")<br />
insertText(' <- that looks nice.')<br />
<br />
deselect()<br />
resetFormat()<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
==ioprint==<br />
;ioprint(text, some more text, ...)<br />
:Prints text to the to the stdout. This is only available if you [http://www.wikihow.com/Run-a-Program-on-Command-Prompt launched Mudlet from cmd.exe] on Windows, [http://www.wikihow.com/Open-Applications-Using-Terminal-on-Mac from the terminal] on Mac, or from the terminal on a Linux OS (launch the terminal program, type ''mudlet'' and press enter).<br />
<br />
Similar to [[Manual:Lua_Functions#echo|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.<br />
<br />
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.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
ioprint("hi!")<br />
ioprint(1,2,3)<br />
ioprint(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==isAnsiBgColor==<br />
; isAnsiBgColor(bgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the background color specified by bgColorCode.<br />
<br />
;Parameters<br />
* ''bgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiBgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the background of the text is light green" )<br />
else<br />
echo( "no sorry, some other background color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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 getBgColor() and then handling the color comparison in Lua.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default background color in the zeroth position.''<br />
<br />
==isAnsiFgColor==<br />
; isAnsiFgColor(fgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the foreground color specified by fgColorCode.<br />
<br />
;Parameters<br />
* ''fgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiFgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the text is light green" )<br />
else<br />
echo( "no sorry, some other foreground color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default foreground color in the zeroth position.''<br />
<br />
==lowerWindow==<br />
;lowerWindow(labelName)<br />
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to move below the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top<br />
</syntaxhighlight><br />
<br />
==moveCursor==<br />
;moveCursor([windowName], x, y)<br />
: 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 [[Manual:Lua_Functions#getLineNumber|getLineNumber()]], [[Manual:Lua_Functions#getColumnNumber|getColumnNumber()]] and [[Manual:Lua_Functions#getLastLineNumber|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.<br />
<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The window you are going to move the cursor in.<br />
* ''x:''<br />
: The horizontal axis in the window - that is, the letter position within the line.<br />
* ''y:''<br />
: The vertical axis in the window - that is, the line number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move cursor to the start of the previous line and insert -<(<br />
-- the first 0 means we want the cursor right at the start of the line,<br />
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which<br />
-- equals to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
insertText("-<(")<br />
<br />
-- now we move the cursor at the end of the previous line. Because the<br />
-- cursor is on the previous line already, we can use #getCurrentLine()<br />
-- to see how long it is. We also just do getLineNumber() because getLineNumber()<br />
-- returns the current line # the cursor is on<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
insertText(")>-")<br />
<br />
-- finally, reset it to the end where it was after our shenaningans - other scripts<br />
-- could expect the cursor to be at the end<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a more complicated example showing how to work with Mudlet functions<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
local WindowWidth, WindowHeight = getMainWindowSize()<br />
<br />
-- define a mini console named "sys" and set its background color<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
<br />
-- you *must* set the font size, otherwise mini windows will not work properly<br />
setMiniConsoleFontSize("sys", 12)<br />
-- wrap lines in window "sys" at 65 characters per line<br />
setWindowWrap("sys", 60)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
-- clear the window<br />
clearUserWindow("sys")<br />
<br />
moveCursorEnd("sys")<br />
setFgColor("sys", 10,10,0)<br />
setBgColor("sys", 0,0,255)<br />
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")<br />
echo("sys", "test1---line2\n")<br />
echo("sys", "test1---line3\n")<br />
setTextFormat("sys",158,0,255,255,0,255,0,0,0);<br />
--setFgColor("sys",255,0,0);<br />
echo("sys", "test1---line4\n")<br />
echo("sys", "test1---line5\n")<br />
moveCursor("sys", 1,1)<br />
<br />
-- deleting lines 2+3<br />
deleteLine("sys")<br />
deleteLine("sys")<br />
<br />
-- inserting a line at pos 5,2<br />
moveCursor("sys", 5,2)<br />
setFgColor("sys", 100,100,0)<br />
setBgColor("sys", 255,100,0)<br />
insertText("sys","############## line inserted at pos 5/2 ##############")<br />
<br />
-- inserting a line at pos 0,0<br />
moveCursor("sys", 0,0)<br />
selectCurrentLine("sys")<br />
setFgColor("sys", 255,155,255)<br />
setBold( "sys", true );<br />
setUnderline( "sys", true )<br />
setItalics( "sys", true )<br />
insertText("sys", "------- line inserted at: 0/0 -----\n")<br />
<br />
setBold( "sys", true )<br />
setUnderline( "sys", false )<br />
setItalics( "sys", false )<br />
setFgColor("sys", 255,100,0)<br />
setBgColor("sys", 155,155,0)<br />
echo("sys", "*** This is the end. ***\n")<br />
</syntaxhighlight><br />
<br />
==moveCursorDown==<br />
;moveCursorDown([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window down a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor down by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorUp==<br />
;moveCursorUp([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window up a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor up by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorEnd==<br />
;moveCursorEnd([windowName])<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
: Returns true or false<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveGauge==<br />
;moveGauge(gaugeName, newX, newY)<br />
: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.<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: The name of your gauge<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would move the health bar gauge to the location 1200, 400<br />
moveGauge("healthBar", 1200, 400)<br />
</syntaxhighlight><br />
<br />
==moveWindow==<br />
;moveWindow(name, x, y)<br />
: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.<br />
<br />
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of your window<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles.<br />
<br />
==openUserWindow==<br />
;openUserWindow(windowName, [restoreLayout], [autoDock], [dockingArea])<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).<br />
* ''restoreLayout:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.<br />
* ''autoDock:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't dock automatically at the corners.<br />
* ''dockingArea:''<br />
: (optional) - the area your UserWindow will be docked at. possible docking areas your UserWindow will be created in (f" floating "t" top "b" bottom "r" right and "l" left). Docking area is "right" if not given any value.<br />
<br />
{{note}}<br />
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.<br />
<br />
{{note}}<br />
The parameters autoDock and dockingArea are available since Mudlet 4.7+ <br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
openUserWindow("My floating window")<br />
cecho("My floating window", "<red>hello <blue>bob!")<br />
<br />
-- if you don't want Mudlet to remember its last position:<br />
openUserWindow("My floating window", false)<br />
</syntaxhighlight><br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]]<br />
<br />
==paste==<br />
;paste(windowName)<br />
: Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The [[#copy | copy()]] and [[#paste | 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
<br />
==prefix==<br />
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
:Prefixes text at the beginning of the current line when used in a trigger.<br />
<br />
;Parameters<br />
* ''text:''<br />
: the information you want to prefix<br />
* "writingFunction:"<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* "foregroundColor:"<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* "backgroundColor:"<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* "windowName:"<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that<br />
prefix(os.date("%H:%M:%S "))<br />
-- Prefix the time in red into a miniconsole named "my_console"<br />
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#suffix | suffix()]]<br />
<br />
==print==<br />
;print(text, some more text, ...)<br />
:Prints text to the main window. Similar to [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#display|display()]] for those. This function works similarly to the print() you will see in guides for Lua.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
print("hi!")<br />
print(1,2,3)<br />
print(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==raiseWindow==<br />
;raiseWindow(labelName)<br />
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to bring to the top of the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel<br />
</syntaxhighlight><br />
<br />
==replace==<br />
;replace([windowName], with, [keepcolor])<br />
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.<br />
<br />
{{note}}<br />
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.<br />
<br />
{{note}}<br />
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 | insertText()]] does.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of window (a miniconsole)<br />
* ''with:''<br />
: the new text to display.<br />
* ''keepcolor:''<br />
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
-- replace word "troll" with "cute trolly"<br />
selectString("troll",1)<br />
replace("cute trolly")<br />
<br />
-- replace the whole line<br />
selectCurrentLine()<br />
replace("Out with the old, in with the new!")<br />
</syntaxhighlight><br />
<br />
==replaceAll==<br />
;replaceAll(what, with, [keepcolor])<br />
: Replaces all occurrences of ''what'' in the current line with ''with''.<br />
<br />
;Parameters<br />
* ''what:''<br />
: the text to replace<br />
{{note}}<br />
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]<br />
* ''with:''<br />
: the new text to have in place<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors.<br />
{{note}} keepcolor available in Mudlet 4.10+, is not in previous versions.<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the word "south" in the line with "north"<br />
replaceAll("south", "north")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the text that the variable "target" has<br />
replaceAll(target, "The Bad Guy")<br />
</syntaxhighlight><br />
<br />
==replaceWildcard==<br />
;replaceWildcard(which, replacement, [keepcolor])<br />
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString(matches[2], 1)<br />
replace("text")<br />
</syntaxhighlight><br />
<br />
;Parameters<br />
* ''which:''<br />
: Wildcard to replace.<br />
* ''replacement:''<br />
: Text to replace the wildcard with.<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors<br />
{{note}} keepcolor available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello<br />
</syntaxhighlight><br />
<br />
==resetCmdLineAction==<br />
;resetCmdLineAction(commandLineName)<br />
: Resets the action on the command line so the it behaves like the main command line again.<br />
;Parameters<br />
<br />
* ''commandLineName''<br />
: The name of the command line the action will be resetet.<br />
: See also: [[#setCmdLineAction | setCmdLineAction()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetConsoleBackgroundImage==<br />
;resetConsoleBackgroundImage([windowName])<br />
: Resets the console background-image<br />
;Parameters<br />
<br />
* ''windowName''<br />
: (optional) name of the console the image will be reset<br />
: See also: [[#setConsoleBackgroundImage | setConsoleBackgroundImage()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: 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.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==resetLabelCursor==<br />
;resetLabelCursor(labelName)<br />
: Resets your mouse cursor to the default one.<br />
<br />
: See also: [[#setLabelCursor|setLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName'': label for which to reset the cursor for.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetLabelCursor("myLabel")<br />
-- This will reset the mouse cursor over myLabel to the default one<br />
</syntaxhighlight><br />
<br />
==resetLabelToolTip==<br />
;resetLabelToolTip(labelName)<br />
: Resets the tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label the tooltip will be reseted.<br />
: See also: [[#setLabelToolTip | setLabelToolTip()]]<br />
<br />
==resetMapWindowTitle==<br />
;resetMapWindowTitle()<br />
: resets the title of the popped out map window to default.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setMapWindowTitle|setMapWindowTitle()]]<br />
<br />
==resetUserWindowTitle==<br />
;resetUserWindowTitle(windowName)<br />
: resets the title of the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow for which the title will be resetet<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setUserWindowTitle|setUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==resizeWindow==<br />
;resizeWindow(windowName, width, height)<br />
: Resizes a mini console, label, or floating User Windows.<br />
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
* ''width:''<br />
: The new width you want<br />
* ''height:''<br />
: The new height you want<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.<br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumber:''<br />
: number of the capture group you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".<br />
--If you want to color the amount of money you have green you do:<br />
<br />
selectCaptureGroup(1)<br />
setFgColor(0,255,0)<br />
</syntaxhighlight><br />
<br />
==selectCurrentLine==<br />
; selectCurrentLine([windowName])<br />
: 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.<br />
<br />
{{note}}<br />
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.<br />
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- color the whole line green!<br />
selectCurrentLine()<br />
fg("green")<br />
deselect()<br />
resetFormat()<br />
<br />
-- to select the previous line, you can do this:<br />
moveCursor(0, getLineNumber()-1)<br />
selectCurrentLine()<br />
<br />
-- to select two lines back, this:<br />
moveCursor(0, getLineNumber()-2)<br />
selectCurrentLine()<br />
<br />
</syntaxhighlight><br />
<br />
==selectSection==<br />
;selectSection( [windowName], fromPosition, length )<br />
: 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.<br />
: 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.<br />
<br />
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]<br />
<br />
;Parameters<br />
* "windowName:"<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.<br />
: Will not work if "main" is given as the windowName to try to select from the main window.<br />
* ''fromPosition:''<br />
: number to specify at which position in the line to begin selecting<br />
* ''length:''<br />
: number to specify the amount of characters you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and colour the first character in the line red<br />
if selectSection(0,1) then fg("red") end<br />
<br />
-- select and colour the second character green (start selecting from the first character, and select 1 character)<br />
if selectSection(1,1) then fg("green") end<br />
<br />
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)<br />
if selectSection(2,3) then fg("grey") end<br />
</syntaxhighlight><br />
<br />
==selectString==<br />
;selectString( [windowName], text, number_of_match )<br />
: 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).<br />
<br />
{{note}}<br />
You can move the user cursor with [[#moveCursor | 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 | deselect()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.<br />
* ''text:''<br />
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).<br />
* ''number_of_match:''<br />
: 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.<br />
<br />
: Returns position in line or -1 on error (text not found in line)<br />
<br />
{{note}}<br />
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if selectString( "big monster", 1 ) > -1 then fg("red") end<br />
</syntaxhighlight><br />
<br />
==setAppStyleSheet==<br />
;setAppStyleSheet(stylesheet [, tag])<br />
: Sets a stylesheet for the entire Mudlet application and every open profile. Because it affects other profiles that might not be related to yours, it's better to use [[#setProfileStyleSheet|setProfileStyleSheet()]] instead of this function.<br />
<br />
: Raises the sysAppStyleSheetChange event which comes with two arguments in addition to the event name. The first is the optional tag which was passed into the function, or "" if nothing was given. The second is the profile which made the stylesheet changes.<br />
<br />
: See also: [[#setProfileStyleSheet|setProfileStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use.<br />
<br />
* ''tag:'' (with Mudlet 3.19+)<br />
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.<br />
<br />
;References<br />
: See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setAppStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
]])<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 3.0.<br />
<br />
Enhanced in Mudlet version 3.19.0 to generate an event that profiles/packages can utilise to redraw any parts of the UI that they themselves had previously styled so their effects can be re-applied to the new application style.<br />
<br />
It is anticipated that the Mudlet application itself will make further use of application styling effects and two strings are provisionally planned for the second parameter in the ''sysAppStyleSheetChange'' event: "''mudlet-theme-dark''" and "''mudlet-theme-light''"; it will also set the third parameter to "''system''".<br />
<br />
==setBackgroundColor==<br />
;setBackgroundColor([windowName], r, g, b, transparency)<br />
: Sets the background for the given label, miniconsole, or userwindow. Colors are from 0 to 255 (0 being black), and transparency is from 0 to 255 (0 being completely transparent).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.<br />
* ''r:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''g:''<br />
: Amount of green to use, from 0 (none) to 255 (full).<br />
* ''b:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).<br />
<br />
{{note}}<br />
Transparency also available for main/miniconsoles in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red label that's somewhat transparent<br />
setBackgroundColor("some label",255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setBackgroundImage==<br />
;setBackgroundImage(labelName, imageLocation)<br />
: Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.<br />
<br />
{{note}}<br />
You can only do this for labels, not miniconsoles.<br />
<br />
{{note}}<br />
You can also load images via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to change it's background color.<br />
* ''imageLocation:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give the top border a nice look<br />
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])<br />
</syntaxhighlight><br />
<br />
==setBgColor==<br />
;setBgColor([windowName], r, g, b, transparency)<br />
: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.<br />
<br />
: ''See also:'' [[#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Optional, if not used color is fully opaque<br />
<br />
<br />
<br />
{{note}}<br />
Transparency parameter available in Mudlet 4.10+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red background color.<br />
selectString( "Tom", 1 )<br />
setBgColor( 255,0,0 )<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--prints "Hello" on red background and "You" on blue.<br />
setBgColor(255,0,0)<br />
echo("Hello")<br />
setBgColor(0,0,255)<br />
echo(" You!")<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBold==<br />
;setBold(windowName, boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
<br />
* ''boolean:''<br />
: A <code>true</code> or <code>false</code> that enables or disables bolding of text<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- enable bold formatting<br />
setBold(true)<br />
-- the following echo will be bolded<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBorderBottom==<br />
;setBorderBottom(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
</syntaxhighlight><br />
<br />
==setBorderColor==<br />
;setBorderColor(red, green, blue)<br />
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]<br />
<br />
;Parameters<br />
* ''red:''<br />
: Amount of red color to use, from 0 to 255.<br />
* ''green:''<br />
: Amount of green color to use, from 0 to 255.<br />
* ''blue:''<br />
: Amount of blue color to use, from 0 to 255.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set the border to be completely blue<br />
setBorderColor(0, 0, 255)<br />
<br />
-- or red, using a name<br />
setBorderColor( unpack(color_table.red) )<br />
</syntaxhighlight><br />
<br />
==setBorderLeft==<br />
;setBorderLeft(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
</syntaxhighlight><br />
<br />
==setBorderRight==<br />
;setBorderRight(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
</syntaxhighlight><br />
<br />
==setBorderSizes==<br />
;setBorderSizes(top, right, bottom, left)<br />
: Sets the size of all borders 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.<br />
: The exact result of this function depends on how many numbers you give to it as arguments.<br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Arguments<br />
* '''setBorderSizes(top, right, bottom, left)'''<br />
: ''4 arguments:'' All borders will be set to their new given size.<br />
* '''setBorderSizes(top, width, bottom)''' <br />
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width. <br />
* '''setBorderSizes(height, width)'''<br />
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width. <br />
* '''setBorderSizes(size)'''<br />
: ''1 argument:'' All borders will be set to the same size.<br />
* '''setBorderSizes()'''<br />
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0) <br />
-- big border at the top, bigger at the bottom, small at the right, none at the left<br />
<br />
setBorderSizes(100, 50, 150) <br />
-- big border at the top, bigger at the bottom, small at the right and the left<br />
<br />
setBorderSizes(100, 50) <br />
-- big border at the top and the bottom, small at the right and the left<br />
<br />
setBorderSizes(100) <br />
-- big borders at all four sides<br />
<br />
setBorderSizes() <br />
-- no borders at all four sides<br />
</syntaxhighlight><br />
<br />
==setBorderTop==<br />
;setBorderTop(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
</syntaxhighlight><br />
<br />
==setFgColor==<br />
;setFgColor([windowName], red, green, blue)<br />
:Sets the current text foreground color in the main window unless windowName parameter given.<br />
<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''red:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''green:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''blue:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]], [[#setHexBgColor | setHexBgColor()]], [[#resetFormat | resetFormat()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setFgColor( 255, 0, 0 )<br />
</syntaxhighlight><br />
<br />
==setButtonStyleSheet==<br />
;setButtonStyleSheet(button, markup)<br />
: Applies Qt style formatting to a button via a special markup language.<br />
<br />
; Parameters<br />
* ''button:''<br />
: The name of the button to be formatted.<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note: You can instead use QWidget { markup }. QWidget will reference 'button', allowing the use of pseudostates like QWidget:hover and QWidget:selected<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setButtonStyleSheet("my test button", [[<br />
QWidget {<br />
background-color: #999999;<br />
border: 3px #777777;<br />
}<br />
QWidget:hover {<br />
background-color: #bbbbbb;<br />
}<br />
QWidget:checked {<br />
background-color: #77bb77;<br />
border: 3px #559955;<br />
}<br />
QWidget:hover:checked {<br />
background-color: #99dd99;<br />
} ]])</syntaxhighlight><br />
<br />
==setClipboardText==<br />
;setClipboardText(textContent)<br />
: Sets the value of the computer's clipboard to the string data provided.<br />
: See also: [[#getClipboardText | getClipboardText()]]<br />
<br />
; Parameters<br />
* ''textContent:''<br />
: The text to be put into the clipboard.<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setClipboardText("New Clipboard Contents")<br />
echo("Clipboard: " .. getClipboardText()) -- should echo "Clipboard: New Clipboard Contents"<br />
</syntaxhighlight><br />
<br />
==setCmdLineAction==<br />
;setCmdLineAction(commandLineName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user sends text to the command line. 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 command line action. Additionally, this function passes the command line input text as the final argument.<br />
{{note}} If no action is set the command line behaves like the main command line and sends commands directly to the game or alias engine.<br />
<br />
The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, text)<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#resetCmdLineAction|resetCmdLineAction()]]<br />
<br />
;Parameters<br />
<br />
* ''commandLineName:''<br />
: The name of the command line to attach the action function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} You can also pass a function directly instead of using a string<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function sendTextToMiniConsole(miniConsoleName, cmdLineText)<br />
echo(miniConsoleName, cmdLineText.."\n")<br />
end<br />
<br />
setCmdLineAction("myCmdLine", "sendTextToMiniConsole", "myMiniConsole")<br />
<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setConsoleBackgroundImage==<br />
;setConsoleBackgroundImage([windowname], imageLocation, [mode])<br />
: Loads an image file (for example png) as a background image for a console (main/miniconsole and userwindows).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow to change the background image on, or "main" for the main window.<br />
* ''imageLocation:''<br />
: 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.<br />
* ''mode:''<br />
: (optional) allows different modes for drawing the background image<br />
possible modes areː "border" (the background image is stretched) , 2 "center" (the background image is in the center), <br />
3 "tile" (the background image is 'tiled'), 4 "style" (choose your own background image stylesheet. see example below) <br />
<br />
: See also: [[#resetConsoleBackgroundImage | resetConsoleBackgroundImage()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give my_miniconsole a nice background image and put it in the center<br />
setConsoleBackgroundImage("my_miniconsole", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image with own stylesheet option<br />
setConsoleBackgroundImage("my_miniconsole", [[background-image: url(:/Mudlet_splashscreen_development.png); background-repeat: no-repeat; background-position: right;]], "style")<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setFont==<br />
;setFont(name, font)<br />
: Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Prefer a monospaced font - those work best with text games. See here [https://doc.qt.io/qt-5/qfont.html#setFamily for more].<br />
: See also: [[#getFont|getFont()]], [[#setFontSize|setFontSize()]], [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''font:''<br />
: The font to use.<br />
<br />
{{note}}<br />
Available in Mudlet 3.9+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.<br />
setFont("Ubuntu Mono")<br />
setFont("main", "Ubuntu Mono")<br />
<br />
-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.<br />
setFont("combat", "Ubuntu Mono")<br />
</syntaxhighlight><br />
<br />
==setFontSize==<br />
;setFontSize(name, size)<br />
: Sets a font size on the given window or console name. Can be used to change font size of the Main console as well as dockable UserWindows.<br />
: See Also: [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
* ''size:''<br />
: The font size to apply to the window.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to 12-point font.<br />
setFontSize(12)<br />
setFontSize("main", 12)<br />
<br />
-- This will set the font size of a user window named "uw1" to 12-point font.<br />
setFontSize("uw1", 12)<br />
</syntaxhighlight><br />
<br />
==setGauge==<br />
;setGauge(gaugeName, currentValue, maxValue, gaugeText)<br />
: 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.<br />
<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#createGauge|createGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a gauge<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
--Change the looks of the gauge named healthBar and make it<br />
--fill to half of its capacity. The height is always remembered.<br />
setGauge("healthBar", 200, 400)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
--If you wish to change the text on your gauge, you’d do the following:<br />
setGauge("healthBar", 200, 400, "some text")<br />
</syntaxhighlight><br />
<br />
==setGaugeStyleSheet==<br />
;setGaugeStyleSheet(gaugeName, css, cssback, csstext)<br />
: 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. You can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create stylesheets.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]],<br />
[[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
</syntaxhighlight><br />
<br />
==setGaugeText==<br />
;setGaugeText(gaugename, css, ccstext )<br />
: Set the formatting of the text used inside the inserted gaugename.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
setGaugeText("healthBar", [[<p style="font-weight:bold;color:#C9C9C9;letter-spacing:1pt;word-spacing:2pt;font-size:12px;text-align:center;font-family:arial black, sans-serif;">]]..MY_NUMERIC_VARIABLE_HERE..[[</p>]])</syntaxhighlight><br />
<br />
;Useful resources:<br />
:http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.<br />
:https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!<br />
<br />
==setHexBgColor==<br />
;setHexBgColor([windowName], hexColorString)<br />
:Sets the current text nackground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.<br />
selectString( "Tom", 1 )<br />
setHexBgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setHexFgColor==<br />
;setHexFgColor([windowName], hexColorString)<br />
:Sets the current text foreground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text foreground color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setFgColor | setFgColor()]], [[#setHexBgColor | setHexBgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setHexFgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setItalics==<br />
;setItalics(windowName, bool)<br />
: Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setLabelToolTip==<br />
;setLabelToolTip(labelName, [duration])<br />
: Sets a tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to set the tooltip to.<br />
* ''duration:''<br />
: Duration of the tooltip timeout in seconds. Optional, if not set the default duration will be set.<br />
<br />
: See also: [[Manual:UI_Functions#resetLabelToolTip|resetLabelToolTip()]]<br />
<br />
==setLabelClickCallback==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument. This table contains information about the mouse button clicked, other buttons that were pressed at the time, and the mouse cursor's local (relative to the label) and global (relative to the Mudlet window) position. The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, event)<br />
</syntaxhighlight><br />
<br />
where '''event''' has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
button = "LeftButton",<br />
buttons = {"RightButton", "MidButton"},<br />
}<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]],[[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} Event argument is available in 3.6+, and in 4.8+ you can pass a function directly instead of a string.<br />
<br />
{{note}}<br />
While '''event.button''' may contain a single string of any listed below, '''event.buttons''' will only ever contain some combination of "LeftButton", "MidButton", and "RightButton"<br />
:The following mouse button strings are defined:<br />
<pre><br />
"LeftButton" "RightButton" "MidButton"<br />
"BackButton" "ForwardButton" "TaskButton"<br />
"ExtraButton4" "ExtraButton5" "ExtraButton6"<br />
"ExtraButton7" "ExtraButton8" "ExtraButton9"<br />
"ExtraButton10" "ExtraButton11" "ExtraButton12"<br />
"ExtraButton13" "ExtraButton14" "ExtraButton15"<br />
"ExtraButton16" "ExtraButton17" "ExtraButton18"<br />
"ExtraButton19" "ExtraButton20" "ExtraButton21"<br />
"ExtraButton22" "ExtraButton23" "ExtraButton24"<br />
</pre><br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
else if event.button == "RightButton" then<br />
send("swim north")<br />
else if event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )<br />
<br />
-- you can also use them within tables now:<br />
mynamespace = {<br />
onClickGoNorth = function()<br />
echo("the north button was clicked!")<br />
end<br />
}<br />
<br />
setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )<br />
<br />
</syntaxhighlight><br />
<br />
==setLabelDoubleClickCallback==<br />
;setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user double 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.6+<br />
<br />
: See also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
==setLabelMoveCallback==<br />
;setLabelMoveCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse moves while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
==setLabelOnEnter==<br />
;setLabelOnEnter(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the '''event''' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
}<br />
</syntaxhighlight><br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseOver()<br />
echo("The mouse is hovering over the label!\n")<br />
end<br />
<br />
setLabelOnEnter( "compassNorthImage", "onMouseOver" )<br />
</syntaxhighlight><br />
<br />
==setLabelOnLeave==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseLeft(argument)<br />
echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)<br />
end<br />
<br />
setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )<br />
</syntaxhighlight><br />
<br />
==setLabelReleaseCallback==<br />
;setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
This command was added in version 3.0.0<br />
<br />
{{note}}<br />
The ''event'' argument only available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onReleaseNorth()<br />
echo("the north button was released!")<br />
end<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onReleaseNorth = function()<br />
echo("the north button was released!")<br />
end<br />
}<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )<br />
</syntaxhighlight><br />
<br />
==setLabelStyleSheet==<br />
;setLabelStyleSheet(label, markup)<br />
: Applies Qt style formatting to a label via a special markup language.<br />
<br />
; Parameters<br />
* ''label:''<br />
: The name of the label to be formatted (passed when calling createLabel).<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a white background and a green border, with the text "test"<br />
-- inside.<br />
createLabel("test", 50, 50, 100, 100, 0)<br />
setLabelStyleSheet("test", [[<br />
background-color: white;<br />
border: 10px solid green;<br />
font-size: 12px;<br />
]])<br />
echo("test", "test")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that will tile or clip depending on the<br />
-- size of the label. To use this example, please supply your own image.<br />
createLabel("test5", 50, 353, 164, 55, 0)<br />
setLabelStyleSheet("test5", [[<br />
background-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that can be resized (such as during a<br />
-- sysWindowResizeEvent). To use this example, please supply your own image.<br />
createLabel("test9", 215, 353, 100, 100, 0)<br />
setLabelStyleSheet("test9", [[<br />
border-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--This creates a label whose background changes when the users mouse hovers over it.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
local ourLabelStyle = [[<br />
QLabel{<br />
background-color: ]]..labelBackgroundColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
QLabel::hover{<br />
background-color: ]]..labelHoverColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--Using QLabel::hover mentioned above. Lets "trick" the label into changing it's text.<br />
--Please keep in mind that the setLabelMoveCallback allows for much more control over not just your label but your entire project.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
--Notice we are adding a string returned from a function. In this case, the users profile directory.<br />
local ourLabelStyle = [[<br />
QLabel{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithtext.png");<br />
}<br />
QLabel::hover{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithhovertext.png");<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
--This is just to example that echos draw on top of the label. You would not want to echo onto a label you were drawing text on with images, because echos would draw on top of them.<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<br />
==setLabelCursor==<br />
;setLabelCursor(labelName, cursorShape)<br />
: Changes how the mouse cursor looks like when over the label. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''cursorShape''<br />
: Shape of the mouse cursor. List of possible cursor shapes is [[CursorShapes| available here]].<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCursor("myLabel", "Cross")<br />
-- This will change the mouse cursor to a cross if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelCustomCursor==<br />
;setLabelCustomCursor(labelName, custom cursor, [hotX, hotY])<br />
: Changes the mouse cursor shape over your label to a custom cursor. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCursor|setLabelCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''custom cursor''<br />
: Location of your custom cursor file. To be compatible with all systems it is recommended to use png files with size of 32x32.<br />
* ''hotX''<br />
: X-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
* ''hotY''<br />
: Y-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCustomCursor("myLabel", getMudletHomeDir().."/custom_cursor.png")<br />
-- This will change the mouse cursor to your custom cursor if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelWheelCallback==<br />
;setLabelWheelCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse wheel is scrolled while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the ''event'' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
buttons = {"RightButton", "MidButton"},<br />
angleDeltaX = 0,<br />
angleDeltaY = 120<br />
}<br />
</syntaxhighlight><br />
<br />
: Keys ''angleDeltaX'' and ''angleDeltaY'' correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onWheelNorth(event)<br />
if event.angleDeltaY > 0 then<br />
echo("the north button was wheeled forwards over!")<br />
else<br />
echo("the north button was wheeled backwards over!")<br />
end<br />
end<br />
<br />
setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onWheelNorth = function()<br />
echo("the north button was wheeled over!")<br />
end<br />
}<br />
<br />
setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )<br />
</syntaxhighlight><br />
<br />
==setLink==<br />
;setLink([windowName], command, tooltip)<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of a miniconsole or a userwindow in which to select the text in.<br />
* ''command:''<br />
: command to do when the text is clicked.<br />
* ''tooltip:''<br />
: tooltip to show when the mouse is over the text - explaining what would clicking do.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can clickify a lot of things to save yourself some time - for example, you can change<br />
-- the line where you receive a message to be clickable to read it!<br />
-- prel regex trigger:<br />
-- ^You just received message #(\w+) from \w+\.$<br />
-- script:<br />
selectString(matches[2], 1)<br />
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])<br />
resetFormat()<br />
<br />
-- an example of selecting text in a miniconsole and turning it into a link:<br />
<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
HelloWorld:echo("hi")<br />
selectString("HelloWorld", "hi", 1)<br />
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")<br />
</syntaxhighlight><br />
<br />
==setMainWindowSize==<br />
;setMainWindowSize(mainWidth, mainHeight)<br />
: Changes the size of your main Mudlet window to the values given.<br />
: See Also: [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''mainWidth:''<br />
: The new width in pixels.<br />
* ''mainHeight:''<br />
: The new height in pixels.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will resize your main Mudlet window<br />
setMainWindowSize(1024, 768)<br />
</syntaxhighlight><br />
<br />
==setMapWindowTitle==<br />
;setMapWindowTitle(text)<br />
: Changes the title shown in the mapper window when it's popped out.<br />
: See also: [[#resetMapWindowTitle|resetMapWindowTitle()]]<br />
<br />
; Parameters<br />
* ''text:''<br />
: New window title to set.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapWindowTitle("my cool game map")<br />
</syntaxhighlight><br />
<br />
==setMiniConsoleFontSize==<br />
;setMiniConsoleFontSize(name, fontSize)<br />
: Sets the font size of the mini console. see also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]]<br />
<br />
==setOverline==<br />
;setOverline([windowName], boolean)<br />
: Sets the current text font to be overlined (true) or not overlined (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 overlined. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be overlined until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be overlined or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables overlining of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable overlined text<br />
setOverline(true)<br />
-- the following echo will be have an overline<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and reverse have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==setPopup==<br />
;setPopup(windowName, {lua code}, {hints})<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,<br />
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking<br />
-- will show some commands you can do.<br />
<br />
selectString("Hello", 1)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})<br />
</syntaxhighlight><br />
<br />
==setProfileStyleSheet==<br />
;setProfileStyleSheet(stylesheet)<br />
: Sets a stylesheet for the current Mudlet profile - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). This function is better than setAppStyleSheet() because it affects only the current profile and not every other one as well.<br />
<br />
: See also: [[#setAppStyleSheet|setAppStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use. See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setProfileStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
<br />
QTreeView {<br />
background: ]]..background_color..[[;<br />
color: white;<br />
}<br />
<br />
QMenuBar{ background-color: ]]..background_color..[[;}<br />
<br />
QMenuBar::item{ background-color: ]]..background_color..[[;}<br />
<br />
QDockWidget::title {<br />
background: ]]..border_color..[[;<br />
}<br />
QStatusBar {<br />
background: ]]..border_color..[[;<br />
}<br />
QScrollBar:vertical {<br />
background: ]]..background_color..[[;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background-color: ]]..background_color..[[;<br />
min-height: 20px;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 7px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-bottom-left-radius: 7px;<br />
border-bottom-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-top-left-radius: 7px;<br />
border-top-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
background: white;<br />
width: 4px;<br />
height: 3px;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]])<br />
<br />
-- if you'd like to reset it, use:<br />
setProfileStyleSheet("")<br />
<br />
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':<br />
setProfileStyleSheet[[<br />
TConsole QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
TConsole QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
TConsole QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 4.6.<br />
<br />
==setReverse==<br />
;setReverse([windowName], boolean)<br />
: Sets the current text to swap foreground and background color settings (true) or not (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 have it's colors swapped. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will have their foreground and background colors swapped until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text colors to be reversed or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables reversing of the fore- and back-ground colors of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable fore/back-ground color reversal of text<br />
setReverse(true)<br />
-- the following echo will have the text colors reversed<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and overline have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
{{note}} Although the visual effect on-screen is the same as that of text being selected if both apply to a piece of text they neutralise each other - however the effect of the reversal ''will'' be carried over in copies made by the "Copy to HTML" and in logs made in HTML format log file mode.<br />
<br />
==setStrikeOut==<br />
;setStrikeOut([windowName], boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be striken out until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be stricken out or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables striking out of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable striken-out text<br />
setStrikeOut(true)<br />
-- the following echo will be have a strikethrough<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setTextFormat==<br />
;setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])<br />
: Sets current text format of selected window. This is a more convenient means to set all the individual features at once compared to using [[#setFgColor|setFgColor]]( windowName, r,g,b ), [[#setBold|setBold]]( windowName, true ), [[#setItalics|setItalics]]( windowName, true ), [[#setUnderline|setUnderline]]( windowName, true ), [[#setStrikeOut|setStrikeOut]]( windowName, true ).<br />
: See Also: [[Manual:Lua_Functions#getTextFormat|getTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: Specify name of selected window. If empty string "" or "main" format will be applied to the main console<br />
* ''r1,g1,b1''<br />
: To color text background, give number values in RBG style<br />
* ''r2,g2,b2''<br />
: To color text foreground, give number values in RBG style<br />
* ''bold''<br />
: To format text bold, set to 1 or true, otherwise 0 or false<br />
* ''underline''<br />
: To underline text, set to 1 or true, otherwise 0 or false<br />
* ''italics''<br />
: To format text italic, set to 1 or true, otherwise 0 or false<br />
* ''strikeout<br />
: (optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''overline<br />
: (optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''reverse<br />
: (optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This script would create a mini text console and write with bold, struck-out, yellow foreground color and blue background color "This is a test".<br />
createMiniConsole( "con1", 0,0,300,100);<br />
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);<br />
echo("con1","This is a test")<br />
</syntaxhighlight><br />
<br />
{{note}} In versions prior to 3.7.0 the error messages ''and this wiki'' were wrong in that they had the foreground color parameters as r1, g1 and b1 and the background ones as r2, g2 and b2.<br />
<br />
==setUnderline==<br />
;setUnderline(windowName, bool)<br />
: Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setUserWindowTitle==<br />
;setUserWindowTitle(windowName, text)<br />
: sets a new title text for the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''text''<br />
: new title text<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==setUserWindowStyleSheet==<br />
;setUserWindowStyleSheet(windowName, markup)<br />
: Applies Qt style formatting to the border/title area of a userwindow via a special markup language.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when you dock the userwindow the border style is not provided by this<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- changes the title area style of the UserWindow 'myUserWindow'<br />
setUserWindowStyleSheet("myUserWindow", [[QDockWidget::title{ <br />
background-color: rgb(0,255,150);<br />
border: 2px solid red;<br />
border-radius: 8px;<br />
text-align: center; <br />
}]])<br />
</syntaxhighlight><br />
<br />
: See also: [[#openUserWindow|openUserWindow()]]<br />
<br />
==setWindow==<br />
;setWindow(windowName, name, [Xpos, Ypos, show])<br />
: Changes the parent window of an element.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow which you want the element put in. If you want to put the element into the main window, use windowName "main".<br />
* ''name''<br />
: Name of the element which you want to switch the parent from. Elements can be labels, miniconsoles and the embedded mapper. If you want to move the mapper use the name "mapper"<br />
* ''Xpos:''<br />
: X position of the element. Measured in pixels, with 0 being the very left. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''Ypos:''<br />
: Y position of the element. Measured in pixels, with 0 being the very top. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''show:''<br />
: true or false to decide if the element will be shown or not in the new parent window. Optional, if not given it will be true.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindow("myuserwindow", "mapper")<br />
-- This will put your embedded mapper in your userwindow "myuserwindow".<br />
</syntaxhighlight><br />
<br />
==setWindowWrap==<br />
;setWindowWrap(windowName, wrapAt)<br />
: sets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapAt:''<br />
: Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==setWindowWrapIndent==<br />
;setWindowWrapIndent(windowName, wrapTo)<br />
: sets how many spaces wrapped text will be indented with (after the first line of course).<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapTo:''<br />
: Number of spaces which wrapped lines are prefixed with.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
setWindowWrapIndent("main", 3)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==showCaptureGroups==<br />
;showCaptureGroups()<br />
:Lua debug function that highlights in random colors 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.<br />
<br />
;Example:<br />
: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.<br />
<br />
==showMultimatches==<br />
;showMultimatches()<br />
: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.<br />
<br />
==showWindow==<br />
;showWindow(name)<br />
: Makes a hidden window (label or miniconsole) be shown again.<br />
<br />
: See also: [[#hideWindow | hideWindow()]]<br />
<br />
==showColors==<br />
;showColors([columns], [filterColor], [sort])<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in '''color_table''', in table form. The format is ''color_table.colorName = {r, g, b}''.<br />
<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: (optional) number of columns to print the color table in.<br />
* ''filterColor:''<br />
: (optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.<br />
* ''sort:''<br />
: (optional) sort colors alphabetically.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- display as four columns:<br />
showColors(4)<br />
<br />
-- show only red colours:<br />
showColors("red")<br />
</syntaxhighlight><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)|thumb|center]]<br />
<br />
==showToolBar==<br />
;showToolBar(name)<br />
: Makes a toolbar (a button group) appear on the screen.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
showToolBar("my attack buttons")<br />
</syntaxhighlight><br />
<br />
==suffix==<br />
;suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
: Suffixes text at the end of the current line. This is similar to [[Manual:Lua_Functions#echo | echo()]], which also suffixes text at the end of the line, but different - [[Manual:Lua_Functions#echo | 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.<br />
<br />
;Parameters<br />
* ''text''<br />
: the information you want to prefix<br />
* ''writingFunction''<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* ''foregroundColor''<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* ''backgroundColor''<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* ''windowName''<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
<br />
: See also: [[#prefix | prefix()]], [[Manual:Lua_Functions#echo | echo()]]<br />
<br />
==wrapLine==<br />
;wrapLine(windowName, lineNumber)<br />
: 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.:<br />
<br />
<syntaxhighlight lang="lua">selectString(line,1)<br />
replace("")</syntaxhighlight><br />
<br />
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.<br />
<br />
: See Also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#deleteLine|deleteLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The miniconsole or the main window (use ''main'' for the main window)<br />
* ''lineNumber:''<br />
: The line number which you'd like re-wrapped.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- re-wrap the last line in the main window<br />
wrapLine("main", getLineCount())<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=15590Manual:UI Functions2020-09-30T11:23:27Z<p>Smurf: /* setWindowWrapIndent */ added missing documentation</p>
<hr />
<div>{{TOC right}}<br />
= UI Functions =<br />
<br />
All functions that help you customize Mudlet's interface and the game's text.<br />
<br />
==ansi2decho==<br />
;ansi2decho(text, default_colour)<br />
: Converts ANSI colour sequences in <code>text</code> to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.<br />
: See also: [[Manual:Lua_Functions#decho|decho()]]<br />
{{note}}<br />
ANSI bold is available since Mudlet 3.7.1+.<br />
R<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be replaced.<br />
* ''default_colour:''<br />
: Optional - ANSI default colour code (used when handling orphan bold tags).<br />
<br />
;Return values<br />
* ''string text:''<br />
: The decho-valid converted text.<br />
* ''string colour:''<br />
: The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- '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><br />
decho(replaced)<br />
</syntaxhighlight><br />
<br />
Or show a complete colourful squirrel! It's a lotta code to do all the colours, so click the '''Expand''' button on the right to show it:<br />
<div class="toccolours mw-collapsible mw-collapsed"><br />
<syntaxhighlight lang="lua"><br />
decho(ansi2decho([[<br />
�[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m �[0m<br />
╭───────────────────────╮ �[38;5;95m▄▄�[0m �[38;5;95m▄�[48;5;95;38;5;130m▄▄�[48;5;130m█�[38;5;137m▄�[48;5;137;38;5;95m▄�[49m▀�[0m �[0m<br />
│ │ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄▄▄�[48;5;95;38;5;137m▄▄▄�[49;38;5;95m▄▄�[48;5;95;38;5;130m▄�[48;5;130m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[0m �[0m<br />
│ Encrypt everything! │ �[38;5;95m▄�[48;5;187;38;5;16m▄�[48;5;16;38;5;187m▄�[38;5;16m█�[48;5;137;38;5;137m███�[38;5;187m▄�[38;5;16m▄▄�[38;5;137m██�[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[0m �[0m<br />
│ ├──── �[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;16m▄▄▄�[48;5;137m███�[48;5;16;38;5;16m█�[48;5;187m▄�[48;5;16m█�[48;5;137;38;5;137m█�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
╰───────────────────────╯ �[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;16m▄�[38;5;16m█�[38;5;137m▄�[48;5;137m██████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;95m▀�[48;5;137m▄�[38;5;137m███████�[38;5;95m▄�[49m▀�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[48;5;95;38;5;187m▄▄▄�[38;5;137m▄�[48;5;137m██�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m█████████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;187m▄�[48;5;187m███�[38;5;137m▄�[48;5;137m█�[48;5;95;38;5;95m█�[48;5;137;38;5;137m███�[48;5;95m▄�[49;38;5;95m▄�[0m �[38;5;95m▀�[48;5;130m▄�[38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;187m████�[48;5;137;38;5;137m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m██�[38;5;95m▄�[38;5;137m█�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;187;38;5;187m████�[48;5;137;38;5;137m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██�[48;5;95m▄�[49;38;5;95m▄�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[38;5;95m▄�[48;5;95m██�[48;5;137m▄▄�[48;5;187;38;5;187m████�[48;5;137;38;5;95m▄▄�[48;5;95;38;5;137m▄�[48;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[48;5;95;38;5;95m█�[48;5;130;38;5;130m██████�[48;5;137;38;5;137m████�[48;5;95;38;5;95m█�[0m�[0m<br />
�[48;5;187;38;5;187m███�[48;5;95m▄�[38;5;137m▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[49m▄�[48;5;95;38;5;130m▄�[48;5;130m██████�[48;5;137;38;5;137m███�[38;5;95m▄�[49m▀�[0m�[0m<br />
�[48;5;187;38;5;95m▄�[38;5;187m████�[48;5;137;38;5;137m█�[38;5;95m▄�[48;5;95;38;5;137m▄�[48;5;137m█████�[48;5;95;38;5;95m█�[48;5;130;38;5;130m███████�[38;5;137m▄�[48;5;137m████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[48;5;95;38;5;95m█�[48;5;187;38;5;137m▄�[38;5;187m███�[48;5;95;38;5;95m█�[48;5;137;38;5;137m██████�[48;5;95m▄▄�[48;5;130m▄▄▄▄▄�[48;5;137m██████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▄▄▄�[48;5;95;38;5;137m▄�[48;5;187m▄�[38;5;187m██�[48;5;95m▄�[48;5;137;38;5;95m▄�[38;5;137m█████�[38;5;95m▄�[38;5;137m███████████�[48;5;95;38;5;95m█�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀�[48;5;187m▄▄▄�[48;5;95;38;5;137m▄�[48;5;137m██�[38;5;95m▄�[49m▀�[0m �[38;5;95m▀▀�[48;5;137m▄▄▄▄▄▄�[49m▀▀▀�[0m �[0m<br />
�[38;5;95m▀▀▀▀▀▀▀▀▀�[0m �[0m<br />
]]))<br />
</syntaxhighlight><br />
</div><br />
<br />
[[File:Squirrel-in-Mudlet.png|frameless]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.0+<br />
<br />
<br />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
;Parameters<br />
* ''text:''<br />
: String that contains ANSI colour sequences that should be removed.<br />
<br />
;Return values<br />
* ''string text:''<br />
: The plain text without ANSI colour sequences.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10+<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local replaced = ansi2string('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')<br />
-- 'replaced' should now contain You say in a baritone voice, "Test."<br />
print(replaced)<br />
</syntaxhighlight><br />
<br />
<br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name.<br />
: See also: [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[Manual:Lua_Functions#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</syntaxhighlight><br />
<br />
==bg==<br />
;bg([window, ]colorName)<br />
: Changes the background color of the text. Useful for highlighting text.<br />
: See Also: [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: 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).<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
<br />
-- or echo text with a green background to a miniconsole<br />
bg("my window", "green")<br />
echo("my window", "some green text\n")<br />
</syntaxhighlight><br />
<br />
==calcFontSize==<br />
;calcFontSize(window_or_fontsize, [fontname])<br />
: Returns the average height and width of characters in a particular window, or a font name and size combination. Helpful if you want to size a miniconsole to specific dimensions.<br />
: Returns two numbers, width/height<br />
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
;Parameters<br />
* ''window_or_fontsize:''<br />
: The miniconsole or font size you are wanting to calculate pixel sizes for.<br />
* ''fontname:''<br />
: Specific font name (along with the size as the first argument) to calculate for.<br />
<br />
{{note}}<br />
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide<br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</syntaxhighlight><br />
<br />
==cecho==<br />
;cecho([window], text)<br />
: Echoes text that can be easily formatted with colour tags. You can also include unicode art in it - try some examples from [http://1lineart.kulaone.com/#/ 1lineart].<br />
: See also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cecho("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cecho("<blue:yellow>Blue on yellow text!")<br />
<br />
-- \n adds a new line<br />
cecho("<red>one line\n<green>another line\n<blue>last line")<br />
<br />
cecho("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
<br />
cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")<br />
<br />
cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")<br />
<br />
cecho([[<br />
██╗ ██╗ ██╗███╗ ██╗███████╗ █████╗ ██████╗ ████████╗<br />
███║ ██║ ██║████╗ ██║██╔════╝ ██╔══██╗██╔══██╗╚══██╔══╝<br />
╚██║ ██║ ██║██╔██╗ ██║█████╗ ███████║██████╔╝ ██║<br />
██║ ██║ ██║██║╚██╗██║██╔══╝ ██╔══██║██╔══██╗ ██║<br />
██║ ███████╗██║██║ ╚████║███████╗ ██║ ██║██║ ██║ ██║<br />
╚═╝ ╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝<br />
]])<br />
</syntaxhighlight><br />
<br />
==cechoLink==<br />
;cechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#cecho|cecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cechoPopup==<br />
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#cecho|cecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertLink==<br />
;cinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#cinsertText|cinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertPopup==<br />
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#cinsertText|cinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==cinsertText==<br />
;cinsertText([window], text)<br />
: inserts text at the current cursor position, with the possibility for color tags.<br />
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.<br />
* ''text:''<br />
: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")<br />
<br />
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")<br />
<br />
cinsertText("<blue:yellow>Blue on yellow text!")<br />
<br />
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")<br />
</syntaxhighlight><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].<br />
<br />
==clearWindow==<br />
;clearWindow([windowName])<br />
: Clears the label, mini console, or user window 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 (starting with Mudlet 2.0-test3+)<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this can clear your whole main window - needs Mudlet version >= 2.0<br />
clearWindow()<br />
</syntaxhighlight><br />
<br />
==copy==<br />
; copy([windowName])<br />
: Copies the current selection to the lua virtual clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the lua virtual clipboard until it gets overwritten by another copy operation.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
; Parameters<br />
* ''windowName'' (optional):<br />
: the window from which to copy text - use the main console if not specified.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This script copies the current line on the main screen to a window (miniconsole or userwindow) called 'chat' and gags the output on the main screen.<br />
selectString(line, 1)<br />
copy()<br />
appendBuffer("chat")<br />
replace("This line has been moved to the chat window!")<br />
</syntaxhighlight><br />
<br />
==copy2decho==<br />
; copy2decho([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in decho format.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line.<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and dechos it to a miniconsole named "test"<br />
decho("test", copy2decho())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and decho it to a Geyser miniconsole stored as the variable enemylist<br />
enemylist:decho(copy2decho(matches[2]))<br />
</syntaxhighlight><br />
<br />
==copy2html==<br />
; copy2html([window], [stringToCopy], [instanceToCopy])<br />
: Copies a string from the current line of window, including color information in html format for echoing to a label.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
; Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main"<br />
* ''stringToCopy'' (optional): <br />
: the string to copy. Defaults to copying the entire line<br />
* ''instanceToCopy'' (optional):<br />
: the instance of the string to copy. Defaults to 1<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This copies the current line on the main console and echos it to a label named "TestLabel"<br />
echo("TestLabel", copy2html())<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This when put into a trigger would copy matches[2] with color information and echo it to a Geyser label stored as the variable enemylist<br />
enemylist:echo(copy2html(matches[2]))<br />
</syntaxhighlight><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: 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.<br />
<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</syntaxhighlight><br />
<br />
==createCommandLine==<br />
;createCommandLine([name of userwindow], name, x, y, width, height)<br />
: Creates a new command line inside the main window of Mudlet. If only a command line inside a miniConsole/UserWindow is needed see [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]].<br />
: You can use [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]] / [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]] and other command line functions to customize the input.<br />
{{note}} [[Manual:UI_Functions#setCmdLineAction|setCmdLineAction]] allows you to attach an action to your command line input.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:UI_Functions#enableCommandLine|enableCommandLine()]], [[Manual:UI_Functions#disableCommandLine|disableCommandLine()]], [[Manual:Mudlet_Object_Functions#clearCmdLine|clearCmdLine()]], [[Manual:Mudlet_Object_Functions#getCmdLine|getCmdLine()]], [[Manual:Mudlet_Object_Functions#printCmdLine|printCmdLine()]], [[Manual:Mudlet_Object_Functions#appendCmdLine|appendCmdLine()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the command line is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the command line. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the command line size and location - it is also possible to set them by using [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createCommandLine() will only set them once.<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==createConsole==<br />
;createConsole([name of userwindow], consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow your new miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,<br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
''(For Mudlet Makers)'' This function is implemented outside the application's core via the '''GUIUtils.lua''' file of the Mudlet supporting Lua code using [[Manual:UI_Functions#createMiniConsole|createMiniConsole()]] and other functions to position and size the mini-console and configure the font.<br />
<br />
==createGauge==<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)<br />
;createGauge([name of userwindow], name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the gauge is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: 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<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
* ''orientation:''<br />
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.<br />
<syntaxhighlight lang="lua"><br />
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")<br />
</syntaxhighlight><br />
<br />
==createLabel==<br />
;createLabel([name of userwindow], name, Xpos, Ypos, width, height, fillBackground, [enableClickthrough])<br />
: 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.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]], [[Manual:Lua_Functions#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will display the background color, 0 or false will not.<br />
* ''enableClickthrough:''<br />
: Whether or not enable clickthrough on this label. Passed as integer number (1 or 0) or as boolean (true, false). 1 or true will enable clickthrough, 0 or false will not. Optional, defaults to clickthrough not enabled if not provided.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label situated at x=300 y=400 with dimensions 100x200<br />
createLabel("a very basic label",300,400,100,200,1)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle<br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent<br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
<br />
-- you can also make it react to clicks!<br />
mynamespace = {<br />
messageBoxClicked = function()<br />
echo("hey you've clicked the box!\n")<br />
end<br />
}<br />
<br />
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")<br />
<br />
<br />
-- uncomment code below to make it also hide after a short while<br />
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</syntaxhighlight><br />
<br />
==createMiniConsole==<br />
;createMiniConsole([name of userwindow], name, x, y, width, height)<br />
: 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.<br />
: You can use [[Manual:Lua_Functions#clearWindow|clearWindow()]] / [[Manual:Lua_Functions#moveCursor|moveCursor()]] and other functions for this window for custom printing as well as copy & paste functions for colored text copies from the main window. [[Manual:Lua_Functions#setWindowWrap|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 [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.<br />
<br />
: Returns true or false.<br />
<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#hideWindow|hideWindow()]], [[Manual:Lua_Functions#showWindow|showWindow()]], [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], [[Manual:Lua_Functions#setTextFormat|setTextFormat()]], [[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent()]], [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]], [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]], [[Manual:Lua_Functions#calcFontSize|calcFontSize()]]<br />
<br />
;Parameters<br />
* ''name of userwindow:''<br />
: Name of userwindow the miniconsole is created in. Optional, defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|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.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<br />
==creplace==<br />
;creplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, with color names inside angle brackets as with [[Manual:Lua_Functions#cecho|cecho()]]. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
creplace("<magenta>[ALERT!]: <reset>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==creplaceLine==<br />
;creplaceLine (text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
;Parameters<br />
* ''text:''<br />
*: 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: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)<br />
</syntaxhighlight><br />
<br />
==decho==<br />
;decho ([name of console,] text)<br />
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB,[BA]> 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,[BA]>. 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")''.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]]<br />
<br />
;Parameters<br />
* ''name of console''<br />
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.<br />
* ''text:''<br />
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.<br />
<br />
<br />
{{note}}<br />
Optional background transparancy parameter (BA) available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
decho("<50,50,0:0,255,0>test")<br />
<br />
decho("miniconsolename", "<50,50,0:0,255,0>test")<br />
</syntaxhighlight><br />
<br />
==dechoLink==<br />
;dechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#decho|decho()]]. This version allows you to use colours within your link text.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) allows selection between sending the link to a miniconsole or the "main" window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==dechoPopup==<br />
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#decho|decho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertLink==<br />
;dinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#dinsertText|dinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==dinsertPopup==<br />
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#dinsertText|dinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
== deleteLabel ==<br />
; deleteLabel(labelName)<br />
<br />
: Deletes and removes a label from the screen. Note that if you'd like to show the label again, it is much more performant to hide/show it instead.<br />
<br />
: Note that you shouldn't use the Geyser label associated with the label you delete afterwards - that doesn't make sense and Geyser right now wouldn't know that it's been deleted, either.<br />
<br />
: See also: [[#hideWindow|hideWindow()]], [[#showWindow|showWindow()]], [[#createLabel|createLabel()]]<br />
<br />
; Parameters<br />
<br />
* ''labelName'': name of the label to delete.<br />
<br />
<syntaxhighlight lang="lua"><br />
createLabel("a very basic label",300,400,100,200,1)<br />
setBackgroundColor("a very basic label", 255, 204, 0, 200)<br />
<br />
-- delete the label after 3 seconds<br />
tempTimer(3, function()<br />
deleteLabel("a very basic label")<br />
end)<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 4.5+<br />
<br />
==deleteLine==<br />
;deleteLine([windowName])<br />
: 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. This is purely visual - triggers will still fire on the line as expected.<br />
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.<br />
<br />
{{note}} for replacing text, [[Manual:Lua_Functions#replace|replace()]] is the proper option; doing the following: <code>selectCurrentLine(); replace(""); cecho("new line!\n")</code> is better.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- deletes the line - just put this command into the big script box. Keep the case the same -<br />
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else<br />
deleteLine()<br />
<br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
<br />
-- example of deleting multiple lines:<br />
deleteLine() -- delete the current line<br />
moveCursor(0,getLineNumber()-1) -- move the cursor back one line<br />
deleteLine() -- delete the previous line now<br />
</syntaxhighlight><br />
<br />
==deselect==<br />
;deselect([window name])<br />
: 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.<br />
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''window name:''<br />
: (optional) The name of the window to stop having anything selected in. If name is not provided the main window will have its selection cleared.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further<br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</syntaxhighlight><br />
<br />
==disableClickthrough==<br />
; disableClickthrough(label)<br />
: Disables clickthrough for a label - making it act 'normal' again and receive clicks, doubleclicks, onEnter, and onLeave events. This is the default behaviour for labels.<br />
: See also: [[#enableClickthrough|enableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name of the label to restore clickability on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==disableCommandLine==<br />
; disableCommandLine(windowName)<br />
: Disables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableCommandLine|enableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to disable the command line in.<br />
<br />
{{note}}<br />
Available in Mudlet 4.10<br />
<br />
==disableScrollBar==<br />
; disableScrollBar(windowName)<br />
: Disables the scroll bar for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to disable the scroll bar in.<br />
<br />
==dreplace==<br />
;dreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#decho|decho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
dreplace("<255,0,255>[ALERT!]: <r>"..matches[2])<br />
</syntaxhighlight><br />
<br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''text:''<br />
: Text to display in the echo. Same as a normal echo().<br />
* ''command:''<br />
: Lua code to do when the link is clicked.<br />
* ''hint:''<br />
: Text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentFormatElseDefault:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
echoLink("press me!", [[send("hi")]], "This is a tooltip")<br />
<br />
-- do the same, but send this link to a miniConsole<br />
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")<br />
</syntaxhighlight><br />
<br />
==echoUserWindow==<br />
;echoUserWindow(windowName)<br />
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.<br />
<br />
==echoPopup==<br />
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==enableClickthrough==<br />
; enableClickthrough(label)<br />
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.<br />
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.<br />
: See also: [[#disableClickthrough|disableClickthrough()]]<br />
<br />
;Parameters<br />
* ''label:''<br />
: The name of the label to enable clickthrough on.<br />
<br />
{{note}}<br />
Available since Mudlet 3.17<br />
<br />
==enableCommandLine==<br />
; enableCommandLine(windowName)<br />
: Enables the command line for the miniConsole named ''windowName''<br />
: See Also: [[Manual:Lua_Functions#disableCommandLine|disableCommandLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the miniConsole to enable the command line in.<br />
<br />
{{note}} The command line name is the same as the miniConsole name<br />
<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==enableScrollBar==<br />
; enableScrollBar(windowName)<br />
: Enables the scrollbar for the miniConsole named ''windowName''.<br />
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of the window to enable the scroll bar in.<br />
<br />
==fg==<br />
; fg([window], colorName)<br />
: 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)<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything or use ''main'' (since Mudlet 3.0).<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
<br />
-- example of working on a miniconsole<br />
fg("my console", "red")<br />
echo("my console", "red text")<br />
</syntaxhighlight><br />
<br />
==getAvailableFonts==<br />
; getAvailableFonts()<br />
: This returns a "font - true" key-value list of available fonts which you can use to verify that Mudlet has access to a given font.<br />
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.<br />
<br />
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]<br />
<br />
{{note}}<br />
Available since Mudlet 3.10<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if Ubuntu Mono is a font we can use<br />
if getAvailableFonts()["Ubuntu Mono"] then<br />
-- make the miniconsole use the font at size 16<br />
setFont("my miniconsole", "Ubuntu Mono")<br />
setFontSize("my miniconsole", 16)<br />
end<br />
</syntaxhighlight><br />
<br />
==getBgColor==<br />
; getBgColor(windowName)<br />
: 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.<br />
<br />
: See also: [[#setBgColor|setBgColor()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r,g,b;<br />
selectString("troll",1)<br />
r,g,b = getBgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getBorderBottom==<br />
;getBorderBottom()<br />
: Returns the size of the bottom border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
getBorderBottom()<br />
-- returns: 150<br />
</syntaxhighlight><br />
<br />
==getBorderLeft==<br />
;getBorderLeft()<br />
: Returns the size of the left border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
getBorderLeft()<br />
-- returns: 5<br />
</syntaxhighlight><br />
<br />
==getBorderRight==<br />
;getBorderRight()<br />
: Returns the size of the right border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
getBorderRight()<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderSizes==<br />
;getBorderSizes()<br />
: Returns the a named table with the sizes of all borders of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]],[[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0)<br />
getBorderSizes()<br />
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }<br />
getBorderSizes().right<br />
-- returns: 50<br />
</syntaxhighlight><br />
<br />
==getBorderTop==<br />
;getBorderTop()<br />
: Returns the size of the top border of the main window in pixels. <br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
getBorderTop()<br />
-- returns: 100<br />
</syntaxhighlight><br />
<br />
==getClipboardText==<br />
;getClipboardText()<br />
: Returns any text that is currently present in the clipboard. <br />
: See also: [[#setClipboardText | setClipboardText()]]<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local clipboardContents = getClipboardText()<br />
echo("Clipboard: " .. clipboardContents)<br />
</syntaxhighlight><br />
<br />
==getColorWildcard==<br />
; getColorWildcard(ansi color number)<br />
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.<br />
<br />
: See also: [[#isAnsiFgColor|isAnsiFgColor()]], [[#isAnsiBgColor|isAnsiBgColor()]]<br />
<br />
;Parameters<br />
* ''ansi color number:''<br />
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- we can run this script on a line that has the players name coloured differently to easily capture it from<br />
-- anywhere on the line<br />
local match = getColorWildcard(14)<br />
<br />
if match then<br />
echo("\nFound "..match.."!")<br />
else<br />
echo("\nDidn't find anyone.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getColumnCount==<br />
;getColumnCount([windowName])<br />
: Gets the maximum number of columns (characters) that a given window can display on a single row, taking into consideration factors such as window width, font size, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum number of columns on the main window "..getColumnCount())<br />
</syntaxhighlight><br />
<br />
==getColumnNumber==<br />
;getColumnNumber([windowName])<br />
: Gets the absolute column number of the current user cursor.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
<br />
{{note}} the argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
<br />
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))<br />
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line<br />
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))<br />
</syntaxhighlight><br />
<br />
==getCurrentLine==<br />
;getCurrentLine([windowName])<br />
: 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Currently selected line: "..getCurrentLine())<br />
</syntaxhighlight><br />
<br />
==getFgColor==<br />
; getFgColor(windowName)<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: A window to operate on - either a miniconsole or the main window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString("troll",1)<br />
local r,g,b = getFgColor()<br />
if r == 255 and g == 0 and b == 0 then<br />
echo("HELP! troll is written in red letters, the monster is aggressive!\n");<br />
end<br />
</syntaxhighlight><br />
<br />
==getFont==<br />
;getFont(windowName)<br />
: Gets the current font of the given window or console name. Can be used to get font of the main console, dockable userwindows and miniconsoles.<br />
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
display("Font in the main window: "..getFont())<br />
<br />
display("Font in the main window: "..getFont("main"))<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
display("Font size: " .. getFont("user window awesome"))<br />
</syntaxhighlight><br />
<br />
==getFontSize==<br />
;getFontSize(windowName)<br />
: Gets the current font size of the given window or console name. Can be used to get font size of the Main console as well as dockable UserWindows.<br />
: See also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will get the "main" console font size.<br />
local mainWindowFontSize = getFontSize()<br />
if mainWindowFontSize then<br />
display("Font size: " .. mainWindowFontSize)<br />
end<br />
<br />
local mainWindowFontSize = getFontSize("main")<br />
if mainWindowFontSize then<br />
display("Font size: " .. fs2)<br />
end<br />
<br />
-- This will get the font size of a user window named "user window awesome".<br />
local awesomeWindowFontSize = getFontSize("user window awesome")<br />
if awesomeWindowFontSize then<br />
display("Font size: " .. awesomeWindowFontSize)<br />
end<br />
</syntaxhighlight><br />
<br />
==getImageSize==<br />
;getImageSize(imageLocation)<br />
: Returns the width and the height of the given image. If the image can't be found, loaded, or isn't a valid image file - nil+error message will be returned instead.<br />
: See also: [[#createLabel|createLabel()]]<br />
<br />
;Parameters<br />
* ''imageLocation:''<br />
: Path to the image.<br />
<br />
{{note}}<br />
Available in Mudlet 4.5+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local path = getMudletHomeDir().."/my-image.png"<br />
<br />
cecho("Showing dimensions of the picture in: "..path.."\n")<br />
<br />
local width, height = getImageSize(path)<br />
<br />
if not width then<br />
-- in case of an problem, we don't get a height back - but the error message<br />
cecho("error: "..height.."\n")<br />
else<br />
cecho(string.format("They are: %sx%s", width, height))<br />
end<br />
</syntaxhighlight><br />
<br />
==getLastLineNumber==<br />
;getLastLineNumber(windowName)<br />
:Returns the latest line's number in the main window or the miniconsole. This could be different from [[Manual:UI_Functions#getLineNumber|getLineNumber()]] if the cursor was moved around.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the latest line's # in the buffer<br />
local latestline = getLastLineNumber("main")<br />
</syntaxhighlight><br />
<br />
==getLineCount==<br />
;getLineCount()<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
''Need example''<br />
<br />
==getLines==<br />
;getLines([windowName,] from_line_number, to_line_number)<br />
: 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}''.<br />
<br />
:Absolute line numbers are used.<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)<br />
* ''from_line_number:''<br />
: First line number<br />
* ''to_line_number:''<br />
: End line number<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- retrieve & echo the last line:<br />
echo(getLines(getLineNumber()-1, getLineNumber())[1])<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- find out which server and port you are connected to (as per Mudlet settings dialog):<br />
local t = getLines(0, getLineNumber())<br />
<br />
local server, port<br />
<br />
for i = 1, #t do<br />
local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")<br />
if s then server, port = s, p break end<br />
end<br />
<br />
display(server)<br />
display(port)<br />
</syntaxhighlight><br />
<br />
==getLineNumber==<br />
;getLineNumber([windowName])<br />
: 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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#moveCursorEnd|moveCursorEnd()]]. This function can come in handy in combination when using with [[Manual:Lua_Functions#moveCursor|moveCursor()]] and [[Manual:Lua_Functions#getLines|getLines()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.<br />
<br />
{{note}}<br />
The argument is available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word<br />
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end<br />
<br />
-- check how many lines you've got in your miniconsole after echoing some text.<br />
-- Note the use of moveCursorEnd() to update getLineNumber()'s output<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
<br />
print(getLineNumber("HelloWorld"))<br />
<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
HelloWorld:echo("hello!\n")<br />
<br />
-- update the cursors position, as it seems to be necessary to do<br />
moveCursorEnd("HelloWorld")<br />
print(getLineNumber("HelloWorld"))<br />
</syntaxhighlight><br />
<br />
==getMainConsoleWidth==<br />
;getMainConsoleWidth()<br />
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.<br />
<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Save width of the main console to a variable for future use.<br />
consoleWidth = getMainConsoleWidth()<br />
</syntaxhighlight><br />
<br />
==getMousePosition==<br />
;getMousePosition()<br />
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{note}} Available since Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- 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<br />
local x, y = getMousePosition()<br />
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)<br />
-- if the label already exists, just move it<br />
moveWindow("clickGeneratedLabel", x, y)<br />
-- and make it easier to notice<br />
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)<br />
</syntaxhighlight><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the window dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getUserWindowSize|getUserWindowSize()]], [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your main mudlet window and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</syntaxhighlight><br />
<br />
==getRowCount==<br />
;getRowCount([windowName])<br />
: Gets the maximum number of rows that a given window can display at once, taking into consideration factors such as window height, font type, spacing, etc.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.7.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print("Maximum of rows on the main window "..getRowCount())<br />
</syntaxhighlight><br />
<br />
==getSelection==<br />
;getSelection([windowName])<br />
: Returns the text currently selected with [[#selectString|selectString()]], [[#selectSection|selectSection()]], or [[#selectCurrentLine|selectCurrentLine()]]. Note that this isn't the text currently selected with the mouse.<br />
<br />
;Parameters:<br />
* ''windowName'':<br />
: (optional) name of the window to get the selection from. By default it operates on the main window.<br />
<br />
{{note}}<br />
Available since Mudlet 3.16.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCurrentLine()<br />
print("Current selection is: "..getSelection())<br />
</syntaxhighlight><br />
<br />
==getTextFormat==<br />
;getTextFormat([windowName])<br />
: Gets the current text format of the currently selected text. May be used with other console windows. The returned values come in a table containing text attribute names and their values. The values given will be booleans for: bold, italics, underline, overline, strikeout, and reverse - followed by color triplet tables for the foreground and background colors.<br />
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.<br />
<br />
{{note}} Available since Mudlet 3.20.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- A suitable test for getTextFormat()<br />
-- (copy it into an alias or a script)<br />
<br />
clearWindow()<br />
<br />
echo("\n")<br />
<br />
local SGR = string.char(27)..'['<br />
feedTriggers("Format attributes: '"..SGR.."1mBold"..SGR.."0m' '"..SGR.."3mItalic"..SGR.."0m' '"..SGR.."4mUnderline"..SGR.."0m' '"..SGR.."5mBlink"..SGR.."0m' '"..SGR.."6mF.Blink"..SGR.."0m' '"..SGR.."7mReverse"..SGR.."0m' '"..SGR.."9mStruckout"..SGR.."0m' '"..SGR.."53mOverline"..SGR.."0m'.\n")<br />
<br />
moveCursor(1,1)<br />
selectSection(1,1)<br />
<br />
local results = getTextFormat()<br />
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))<br />
echo("\nItalic detected: " .. tostring(results["italic"]))<br />
echo("\nUnderline detected: " .. tostring(results["underline"]))<br />
echo("\nReverse detected: " .. tostring(results["reverse"]))<br />
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))<br />
echo("\nOverline detected: " .. tostring(results["overline"]))<br />
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")<br />
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")<br />
<br />
selectSection(21,1)<br />
echo("\n\nFor individual parts of test text:")<br />
echo("\nBold detected (character 21): " .. tostring(results["bold"]))<br />
<br />
selectSection(28,1)<br />
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))<br />
<br />
selectSection(37,1)<br />
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))<br />
<br />
selectSection(67,1)<br />
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))<br />
<br />
selectSection(77,1)<br />
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))<br />
<br />
selectSection(89,1)<br />
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))<br />
echo("\n")<br />
</syntaxhighlight><br />
<br />
==getUserWindowSize==<br />
{{note}} available in Mudlet 4.6.1+<br />
;getUserWindowSize(windowName)<br />
: Returns two numbers, the width and height in pixels. This is useful for calculating the given userwindow dimensions and placement of custom GUI toolkit items like labels, buttons, mini consoles etc.<br />
: See also: [[#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''windowName''<br />
:the name of the userwindow we will get the dimensions from<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will get the size of your userwindow named "ChatWindow" and save them<br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getUserWindowSize("ChatWindow")<br />
</syntaxhighlight><br />
<br />
==handleWindowResizeEvent==<br />
;handleWindowResizeEvent()<br />
: (''depreciated'') This function is depreciated and should not be used; it's only documented here for historical reference - use the [[Manual:Technical_Manual#sysWindowResizeEvent|sysWindowResizeEvent]] event instead.<br />
<br />
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.<br />
<br />
; Parameters<br />
:None<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
function handleWindowResizeEvent()<br />
-- determine the size of your screen<br />
WindowWidth=0;<br />
WindowHeight=0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
-- move mini console "sys" to the far right side of the screen whenever the screen gets resized<br />
moveWindow("sys",WindowWidth-300,0)<br />
end<br />
</syntaxhighlight><br />
<br />
==hasFocus==<br />
;hasFocus()<br />
: 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). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if attacked and not hasFocus() then<br />
runaway()<br />
else<br />
fight()<br />
end<br />
</syntaxhighlight><br />
<br />
==hecho==<br />
;hecho([windowName], text)<br />
: Echoes text that can be easily formatted with colour tags in the hexadecimal format.<br />
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.<br />
* ''text:''<br />
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #FRFGFB,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 or #r can be used within the string to reset the colors to default. Hexadecimal color codes can be found here: https://www.color-hex.com/<br />
<br />
{{note}}<br />
Transparency for background in hex-format available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hecho("\n#ffffff White text!")<br />
-- your text in white<br />
hecho("\n#ca0004 Red text! And now reset #rit to the default color")<br />
-- your text in red, then reset to default using #r<br />
hecho("\n#ffffff,ca0004 White text with a red background!")<br />
-- your text in white, against a red background<br />
hecho("\n|c0000ff Blue text, this time using |c instead of #")<br />
-- your text in blue, activated with |c vs #.<br />
</syntaxhighlight><br />
<br />
==hechoLink==<br />
;hechoLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#hecho|hecho()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
-- # format also works<br />
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==hechoPopup==<br />
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like [[#hecho|hecho()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertLink==<br />
;hinsertLink([windowName], text, command, hint, true)<br />
: Echos a piece of text as a clickable link, at the end of the current cursor position - similar to [[#hinsertText|hinsertText()]]. This version allows you to use colours within your link text.<br />
<br />
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: optional parameter, allows selection between sending the link to a miniconsole or the main window.<br />
* ''text:''<br />
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''true:''<br />
: requires argument for the colouring to work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- echo a link named 'press me!' that'll send the 'hi' command to the game<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hinsertPopup==<br />
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])<br />
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current cursor position, like [[#hinsertText|hinsertText()]]. 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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''text:''<br />
: the text to display<br />
* ''{commands}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight><br />
* ''useCurrentFormatElseDefault:''<br />
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
==hreplace==<br />
;hreplace([window, ]text)<br />
: Replaces the output line from the MUD with a colour-tagged string.<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window:''<br />
*: The window to replace the selection in. Optional, defaults to the main window if not provided.<br />
* ''text:''<br />
*: The text to display, as with [[Manual:Lua_Functions#hecho|hecho()]]<br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectCaptureGroup(1)<br />
hreplace("#EE00EE[ALERT!]: #r"..matches[2])<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 4.5+<br />
<br />
==hideToolBar==<br />
;hideToolBar(name)<br />
: 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.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to hide<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hideToolBar("my offensive buttons")<br />
</syntaxhighlight><br />
<br />
==hideWindow==<br />
;hideWindow(name)<br />
: This function hides a '''mini console''', a '''user window''' or a '''label''' with the given name. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].<br />
<br />
: See also: [[#createMiniConsole|createMiniConsole()]], [[#createLabel|createLabel()]], [[#deleteLabel|deleteLabel()]]<br />
<br />
;Parameters<br />
* ''name''<br />
: specifies the label or console you want to hide.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function miniconsoleTest()<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
print("created red window top-right")<br />
<br />
tempTimer(1, function()<br />
hideWindow("sys")<br />
print("hid red window top-right")<br />
end)<br />
<br />
tempTimer(3, function()<br />
showWindow("sys")<br />
print("showed red window top-right")<br />
end)<br />
end<br />
<br />
miniconsoleTest()<br />
</syntaxhighlight><br />
<br />
==insertLink==<br />
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])<br />
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) the window to insert the link in - use either "main" or omit for the main window.<br />
* ''text:''<br />
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].<br />
* ''command:''<br />
: lua code to do when the link is clicked.<br />
* ''hint:''<br />
: text for the tooltip to be displayed when the mouse is over the link.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) true or false. 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- link with the default blue on white colors<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")<br />
<br />
-- use current cursor colors by adding true at the end<br />
fg("red")<br />
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==insertPopup==<br />
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])<br />
: Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to [[Manual:Lua_Functions#insertText|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.<br />
* ''name:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.<br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
* ''useCurrentLinkFormat:''<br />
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create some text as a clickable with a popup menu:<br />
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})<br />
</syntaxhighlight><br />
<br />
==insertText==<br />
;insertText([windowName], text)<br />
: Inserts text at cursor postion in window - unlike [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#moveCursor|moveCursor()]] to move the cursor into position first.<br />
<br />
: insertHTML() also does the same thing as insertText, if you ever come across it.<br />
<br />
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) The window to insert the text to.<br />
* ''text:''<br />
: The text you will insert into the current cursor position.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the cursor to the end of the previous line and insert some text<br />
<br />
-- move to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
-- move the end the of the previous line<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
<br />
fg("dark_slate_gray")<br />
insertText(' <- that looks nice.')<br />
<br />
deselect()<br />
resetFormat()<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
==ioprint==<br />
;ioprint(text, some more text, ...)<br />
:Prints text to the to the stdout. This is only available if you [http://www.wikihow.com/Run-a-Program-on-Command-Prompt launched Mudlet from cmd.exe] on Windows, [http://www.wikihow.com/Open-Applications-Using-Terminal-on-Mac from the terminal] on Mac, or from the terminal on a Linux OS (launch the terminal program, type ''mudlet'' and press enter).<br />
<br />
Similar to [[Manual:Lua_Functions#echo|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.<br />
<br />
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.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
ioprint("hi!")<br />
ioprint(1,2,3)<br />
ioprint(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==isAnsiBgColor==<br />
; isAnsiBgColor(bgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the background color specified by bgColorCode.<br />
<br />
;Parameters<br />
* ''bgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiBgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the background of the text is light green" )<br />
else<br />
echo( "no sorry, some other background color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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 getBgColor() and then handling the color comparison in Lua.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default background color in the zeroth position.''<br />
<br />
==isAnsiFgColor==<br />
; isAnsiFgColor(fgColorCode)<br />
: This function tests if the first character of '''the current selection''' in the main console has the foreground color specified by fgColorCode.<br />
<br />
;Parameters<br />
* ''fgColorCode:''<br />
: A color code to test for, possible codes are:<br />
<br />
<syntaxhighlight lang="lua"><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</syntaxhighlight><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
selectString( matches[1], 1 )<br />
if isAnsiFgColor( 5 ) then<br />
bg( "red" );<br />
resetFormat();<br />
echo( "yes, the text is light green" )<br />
else<br />
echo( "no sorry, some other foreground color" )<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
The variable named 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.<br />
<br />
''Also note that the color code numbers are Mudlet specific, though they do represent the colors in the 16 ANSI color-set for the main console they are not in the same order and they additionally have the default foreground color in the zeroth position.''<br />
<br />
==lowerWindow==<br />
;lowerWindow(labelName)<br />
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to move below the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
lowerWindow("redLabel") --lowers redLabel, causing blueLabel to be back on top<br />
</syntaxhighlight><br />
<br />
==moveCursor==<br />
;moveCursor([windowName], x, y)<br />
: 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 [[Manual:Lua_Functions#getLineNumber|getLineNumber()]], [[Manual:Lua_Functions#getColumnNumber|getColumnNumber()]] and [[Manual:Lua_Functions#getLastLineNumber|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.<br />
<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) The window you are going to move the cursor in.<br />
* ''x:''<br />
: The horizontal axis in the window - that is, the letter position within the line.<br />
* ''y:''<br />
: The vertical axis in the window - that is, the line number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move cursor to the start of the previous line and insert -<(<br />
-- the first 0 means we want the cursor right at the start of the line,<br />
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which<br />
-- equals to the previous line<br />
moveCursor(0, getLineNumber()-1)<br />
insertText("-<(")<br />
<br />
-- now we move the cursor at the end of the previous line. Because the<br />
-- cursor is on the previous line already, we can use #getCurrentLine()<br />
-- to see how long it is. We also just do getLineNumber() because getLineNumber()<br />
-- returns the current line # the cursor is on<br />
moveCursor(#getCurrentLine(), getLineNumber())<br />
insertText(")>-")<br />
<br />
-- finally, reset it to the end where it was after our shenaningans - other scripts<br />
-- could expect the cursor to be at the end<br />
moveCursorEnd()<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a more complicated example showing how to work with Mudlet functions<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
local WindowWidth, WindowHeight = getMainWindowSize()<br />
<br />
-- define a mini console named "sys" and set its background color<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
<br />
-- you *must* set the font size, otherwise mini windows will not work properly<br />
setMiniConsoleFontSize("sys", 12)<br />
-- wrap lines in window "sys" at 65 characters per line<br />
setWindowWrap("sys", 60)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
-- clear the window<br />
clearUserWindow("sys")<br />
<br />
moveCursorEnd("sys")<br />
setFgColor("sys", 10,10,0)<br />
setBgColor("sys", 0,0,255)<br />
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")<br />
echo("sys", "test1---line2\n")<br />
echo("sys", "test1---line3\n")<br />
setTextFormat("sys",158,0,255,255,0,255,0,0,0);<br />
--setFgColor("sys",255,0,0);<br />
echo("sys", "test1---line4\n")<br />
echo("sys", "test1---line5\n")<br />
moveCursor("sys", 1,1)<br />
<br />
-- deleting lines 2+3<br />
deleteLine("sys")<br />
deleteLine("sys")<br />
<br />
-- inserting a line at pos 5,2<br />
moveCursor("sys", 5,2)<br />
setFgColor("sys", 100,100,0)<br />
setBgColor("sys", 255,100,0)<br />
insertText("sys","############## line inserted at pos 5/2 ##############")<br />
<br />
-- inserting a line at pos 0,0<br />
moveCursor("sys", 0,0)<br />
selectCurrentLine("sys")<br />
setFgColor("sys", 255,155,255)<br />
setBold( "sys", true );<br />
setUnderline( "sys", true )<br />
setItalics( "sys", true )<br />
insertText("sys", "------- line inserted at: 0/0 -----\n")<br />
<br />
setBold( "sys", true )<br />
setUnderline( "sys", false )<br />
setItalics( "sys", false )<br />
setFgColor("sys", 255,100,0)<br />
setBgColor("sys", 155,155,0)<br />
echo("sys", "*** This is the end. ***\n")<br />
</syntaxhighlight><br />
<br />
==moveCursorDown==<br />
;moveCursorDown([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window down a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor down by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorUp==<br />
;moveCursorUp([windowName,] [lines,] [keepHorizontal])<br />
: Moves the cursor in the given window up a specified number of lines.<br />
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
* ''lines:''<br />
: (optional) number of lines to move cursor up by, or 1 by default.<br />
<br />
* ''keepHorizontal:''<br />
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.<br />
<br />
{{Note}}<br />
Available since Mudlet 3.17+<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveCursorEnd==<br />
;moveCursorEnd([windowName])<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
: Returns true or false<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow, or "main" for the main window.<br />
<br />
;Example<br />
'' Need example''<br />
<br />
==moveGauge==<br />
;moveGauge(gaugeName, newX, newY)<br />
: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.<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: The name of your gauge<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This would move the health bar gauge to the location 1200, 400<br />
moveGauge("healthBar", 1200, 400)<br />
</syntaxhighlight><br />
<br />
==moveWindow==<br />
;moveWindow(name, x, y)<br />
: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.<br />
<br />
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of your window<br />
* ''newX:''<br />
: The horizontal pixel location<br />
* ''newY:''<br />
: The vertical pixel location<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles.<br />
<br />
==openUserWindow==<br />
;openUserWindow(windowName, [restoreLayout], [autoDock], [dockingArea])<br />
: 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).<br />
* ''restoreLayout:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.<br />
* ''autoDock:''<br />
: (optional) - only relevant, if ''false'' is provided. Then the window won't dock automatically at the corners.<br />
* ''dockingArea:''<br />
: (optional) - the area your UserWindow will be docked at. possible docking areas your UserWindow will be created in (f" floating "t" top "b" bottom "r" right and "l" left). Docking area is "right" if not given any value.<br />
<br />
{{note}}<br />
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.<br />
<br />
{{note}}<br />
The parameters autoDock and dockingArea are available since Mudlet 4.7+ <br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
openUserWindow("My floating window")<br />
cecho("My floating window", "<red>hello <blue>bob!")<br />
<br />
-- if you don't want Mudlet to remember its last position:<br />
openUserWindow("My floating window", false)<br />
</syntaxhighlight><br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]]<br />
<br />
==paste==<br />
;paste(windowName)<br />
: Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The [[#copy | copy()]] and [[#paste | 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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
<br />
==prefix==<br />
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
:Prefixes text at the beginning of the current line when used in a trigger.<br />
<br />
;Parameters<br />
* ''text:''<br />
: the information you want to prefix<br />
* "writingFunction:"<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* "foregroundColor:"<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* "backgroundColor:"<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* "windowName:"<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that<br />
prefix(os.date("%H:%M:%S "))<br />
-- Prefix the time in red into a miniconsole named "my_console"<br />
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#suffix | suffix()]]<br />
<br />
==print==<br />
;print(text, some more text, ...)<br />
:Prints text to the main window. Similar to [[Manual:Lua_Functions#echo|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 [[Manual:Lua_Functions#display|display()]] for those. This function works similarly to the print() you will see in guides for Lua.<br />
<br />
;Parameters<br />
* ''text:''<br />
: The information you want to display.<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
print("hi!")<br />
print(1,2,3)<br />
print(myvariable, someothervariable, yetanothervariable)<br />
</syntaxhighlight><br />
<br />
==raiseWindow==<br />
;raiseWindow(labelName)<br />
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: the name of the label/console you wish to bring to the top of the rest.<br />
<br />
{{note}}<br />
Available since Mudlet 3.1.0<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
createLabel("blueLabel", 300, 300, 100, 100, 1) --creates a blue label<br />
setBackgroundColor("blueLabel", 50, 50, 250, 255)<br />
<br />
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<br />
setBackgroundColor("redLabel", 250, 50, 50, 255)<br />
<br />
raiseWindow("blueLabel") --raises blueLabel back at the top, above redLabel<br />
</syntaxhighlight><br />
<br />
==replace==<br />
;replace([windowName], with, [keepcolor])<br />
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.<br />
<br />
{{note}}<br />
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.<br />
<br />
{{note}}<br />
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 | insertText()]] does.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of window (a miniconsole)<br />
* ''with:''<br />
: the new text to display.<br />
* ''keepcolor:''<br />
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
-- replace word "troll" with "cute trolly"<br />
selectString("troll",1)<br />
replace("cute trolly")<br />
<br />
-- replace the whole line<br />
selectCurrentLine()<br />
replace("Out with the old, in with the new!")<br />
</syntaxhighlight><br />
<br />
==replaceAll==<br />
;replaceAll(what, with, [keepcolor])<br />
: Replaces all occurrences of ''what'' in the current line with ''with''.<br />
<br />
;Parameters<br />
* ''what:''<br />
: the text to replace<br />
{{note}}<br />
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]<br />
* ''with:''<br />
: the new text to have in place<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors.<br />
{{note}} keepcolor available in Mudlet 4.10+, is not in previous versions.<br />
<br />
;Examples:<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the word "south" in the line with "north"<br />
replaceAll("south", "north")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- replace all occurrences of the text that the variable "target" has<br />
replaceAll(target, "The Bad Guy")<br />
</syntaxhighlight><br />
<br />
==replaceWildcard==<br />
;replaceWildcard(which, replacement, [keepcolor])<br />
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:<br />
<br />
<syntaxhighlight lang="lua"><br />
selectString(matches[2], 1)<br />
replace("text")<br />
</syntaxhighlight><br />
<br />
;Parameters<br />
* ''which:''<br />
: Wildcard to replace.<br />
* ''replacement:''<br />
: Text to replace the wildcard with.<br />
* ''keepcolor:''<br />
: setting this to true will keep the existing colors<br />
{{note}} keepcolor available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello<br />
</syntaxhighlight><br />
<br />
==resetCmdLineAction==<br />
;resetCmdLineAction(commandLineName)<br />
: Resets the action on the command line so the it behaves like the main command line again.<br />
;Parameters<br />
<br />
* ''commandLineName''<br />
: The name of the command line the action will be resetet.<br />
: See also: [[#setCmdLineAction | setCmdLineAction()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetConsoleBackgroundImage==<br />
;resetConsoleBackgroundImage([windowName])<br />
: Resets the console background-image<br />
;Parameters<br />
<br />
* ''windowName''<br />
: (optional) name of the console the image will be reset<br />
: See also: [[#setConsoleBackgroundImage | setConsoleBackgroundImage()]]<br />
{{note}} available in Mudlet 4.10+<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: 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.<br />
<br />
; Parameters<br />
:None<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==resetLabelCursor==<br />
;resetLabelCursor(labelName)<br />
: Resets your mouse cursor to the default one.<br />
<br />
: See also: [[#setLabelCursor|setLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName'': label for which to reset the cursor for.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetLabelCursor("myLabel")<br />
-- This will reset the mouse cursor over myLabel to the default one<br />
</syntaxhighlight><br />
<br />
==resetLabelToolTip==<br />
;resetLabelToolTip(labelName)<br />
: Resets the tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label the tooltip will be reseted.<br />
: See also: [[#setLabelToolTip | setLabelToolTip()]]<br />
<br />
==resetMapWindowTitle==<br />
;resetMapWindowTitle()<br />
: resets the title of the popped out map window to default.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setMapWindowTitle|setMapWindowTitle()]]<br />
<br />
==resetUserWindowTitle==<br />
;resetUserWindowTitle(windowName)<br />
: resets the title of the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow for which the title will be resetet<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#setUserWindowTitle|setUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==resizeWindow==<br />
;resizeWindow(windowName, width, height)<br />
: Resizes a mini console, label, or floating User Windows.<br />
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The name of your window<br />
* ''width:''<br />
: The new width you want<br />
* ''height:''<br />
: The new height you want<br />
<br />
{{note}}<br />
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.<br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumber:''<br />
: number of the capture group you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".<br />
--If you want to color the amount of money you have green you do:<br />
<br />
selectCaptureGroup(1)<br />
setFgColor(0,255,0)<br />
</syntaxhighlight><br />
<br />
==selectCurrentLine==<br />
; selectCurrentLine([windowName])<br />
: 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.<br />
<br />
{{note}}<br />
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.<br />
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- color the whole line green!<br />
selectCurrentLine()<br />
fg("green")<br />
deselect()<br />
resetFormat()<br />
<br />
-- to select the previous line, you can do this:<br />
moveCursor(0, getLineNumber()-1)<br />
selectCurrentLine()<br />
<br />
-- to select two lines back, this:<br />
moveCursor(0, getLineNumber()-2)<br />
selectCurrentLine()<br />
<br />
</syntaxhighlight><br />
<br />
==selectSection==<br />
;selectSection( [windowName], fromPosition, length )<br />
: 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.<br />
: 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.<br />
<br />
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]<br />
<br />
;Parameters<br />
* "windowName:"<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.<br />
: Will not work if "main" is given as the windowName to try to select from the main window.<br />
* ''fromPosition:''<br />
: number to specify at which position in the line to begin selecting<br />
* ''length:''<br />
: number to specify the amount of characters you want to select<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- select and colour the first character in the line red<br />
if selectSection(0,1) then fg("red") end<br />
<br />
-- select and colour the second character green (start selecting from the first character, and select 1 character)<br />
if selectSection(1,1) then fg("green") end<br />
<br />
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)<br />
if selectSection(2,3) then fg("grey") end<br />
</syntaxhighlight><br />
<br />
==selectString==<br />
;selectString( [windowName], text, number_of_match )<br />
: 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).<br />
<br />
{{note}}<br />
You can move the user cursor with [[#moveCursor | 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 | deselect()]].<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.<br />
* ''text:''<br />
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).<br />
* ''number_of_match:''<br />
: 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.<br />
<br />
: Returns position in line or -1 on error (text not found in line)<br />
<br />
{{note}}<br />
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
if selectString( "big monster", 1 ) > -1 then fg("red") end<br />
</syntaxhighlight><br />
<br />
==setAppStyleSheet==<br />
;setAppStyleSheet(stylesheet [, tag])<br />
: Sets a stylesheet for the entire Mudlet application and every open profile. Because it affects other profiles that might not be related to yours, it's better to use [[#setProfileStyleSheet|setProfileStyleSheet()]] instead of this function.<br />
<br />
: Raises the sysAppStyleSheetChange event which comes with two arguments in addition to the event name. The first is the optional tag which was passed into the function, or "" if nothing was given. The second is the profile which made the stylesheet changes.<br />
<br />
: See also: [[#setProfileStyleSheet|setProfileStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use.<br />
<br />
* ''tag:'' (with Mudlet 3.19+)<br />
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.<br />
<br />
;References<br />
: See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setAppStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
]])<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 3.0.<br />
<br />
Enhanced in Mudlet version 3.19.0 to generate an event that profiles/packages can utilise to redraw any parts of the UI that they themselves had previously styled so their effects can be re-applied to the new application style.<br />
<br />
It is anticipated that the Mudlet application itself will make further use of application styling effects and two strings are provisionally planned for the second parameter in the ''sysAppStyleSheetChange'' event: "''mudlet-theme-dark''" and "''mudlet-theme-light''"; it will also set the third parameter to "''system''".<br />
<br />
==setBackgroundColor==<br />
;setBackgroundColor([windowName], r, g, b, transparency)<br />
: Sets the background for the given label, miniconsole, or userwindow. Colors are from 0 to 255 (0 being black), and transparency is from 0 to 255 (0 being completely transparent).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.<br />
* ''r:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''g:''<br />
: Amount of green to use, from 0 (none) to 255 (full).<br />
* ''b:''<br />
: Amount of red to use, from 0 (none) to 255 (full).<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).<br />
<br />
{{note}}<br />
Transparency also available for main/miniconsoles in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red label that's somewhat transparent<br />
setBackgroundColor("some label",255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setBackgroundImage==<br />
;setBackgroundImage(labelName, imageLocation)<br />
: Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.<br />
<br />
{{note}}<br />
You can only do this for labels, not miniconsoles.<br />
<br />
{{note}}<br />
You can also load images via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to change it's background color.<br />
* ''imageLocation:''<br />
: 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.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give the top border a nice look<br />
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])<br />
</syntaxhighlight><br />
<br />
==setBgColor==<br />
;setBgColor([windowName], r, g, b, transparency)<br />
: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.<br />
<br />
: ''See also:'' [[#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''transparency:''<br />
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Optional, if not used color is fully opaque<br />
<br />
<br />
<br />
{{note}}<br />
Transparency parameter available in Mudlet 4.10+<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red background color.<br />
selectString( "Tom", 1 )<br />
setBgColor( 255,0,0 )<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--prints "Hello" on red background and "You" on blue.<br />
setBgColor(255,0,0)<br />
echo("Hello")<br />
setBgColor(0,0,255)<br />
echo(" You!")<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBold==<br />
;setBold(windowName, boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
<br />
* ''boolean:''<br />
: A <code>true</code> or <code>false</code> that enables or disables bolding of text<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- enable bold formatting<br />
setBold(true)<br />
-- the following echo will be bolded<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setBorderBottom==<br />
;setBorderBottom(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderBottom(150)<br />
</syntaxhighlight><br />
<br />
==setBorderColor==<br />
;setBorderColor(red, green, blue)<br />
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]<br />
<br />
;Parameters<br />
* ''red:''<br />
: Amount of red color to use, from 0 to 255.<br />
* ''green:''<br />
: Amount of green color to use, from 0 to 255.<br />
* ''blue:''<br />
: Amount of blue color to use, from 0 to 255.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- set the border to be completely blue<br />
setBorderColor(0, 0, 255)<br />
<br />
-- or red, using a name<br />
setBorderColor( unpack(color_table.red) )<br />
</syntaxhighlight><br />
<br />
==setBorderLeft==<br />
;setBorderLeft(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderLeft(5)<br />
</syntaxhighlight><br />
<br />
==setBorderRight==<br />
;setBorderRight(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Width of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderRight(50)<br />
</syntaxhighlight><br />
<br />
==setBorderSizes==<br />
;setBorderSizes(top, right, bottom, left)<br />
: Sets the size of all borders 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.<br />
: The exact result of this function depends on how many numbers you give to it as arguments.<br />
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]<br />
<br />
: {{note}} Available since Mudlet 4.0<br />
<br />
;Arguments<br />
* '''setBorderSizes(top, right, bottom, left)'''<br />
: ''4 arguments:'' All borders will be set to their new given size.<br />
* '''setBorderSizes(top, width, bottom)''' <br />
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width. <br />
* '''setBorderSizes(height, width)'''<br />
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width. <br />
* '''setBorderSizes(size)'''<br />
: ''1 argument:'' All borders will be set to the same size.<br />
* '''setBorderSizes()'''<br />
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderSizes(100, 50, 150, 0) <br />
-- big border at the top, bigger at the bottom, small at the right, none at the left<br />
<br />
setBorderSizes(100, 50, 150) <br />
-- big border at the top, bigger at the bottom, small at the right and the left<br />
<br />
setBorderSizes(100, 50) <br />
-- big border at the top and the bottom, small at the right and the left<br />
<br />
setBorderSizes(100) <br />
-- big borders at all four sides<br />
<br />
setBorderSizes() <br />
-- no borders at all four sides<br />
</syntaxhighlight><br />
<br />
==setBorderTop==<br />
;setBorderTop(size)<br />
: 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.<br />
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]<br />
<br />
;Parameters<br />
* ''size:''<br />
: Height of the border in pixels - with 0 indicating no border.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setBorderTop(100)<br />
</syntaxhighlight><br />
<br />
==setFgColor==<br />
;setFgColor([windowName], red, green, blue)<br />
:Sets the current text foreground color in the main window unless windowName parameter given.<br />
<br />
* ''windowName:''<br />
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''red:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''green:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''blue:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]], [[#setHexBgColor | setHexBgColor()]], [[#resetFormat | resetFormat()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setFgColor( 255, 0, 0 )<br />
</syntaxhighlight><br />
<br />
==setButtonStyleSheet==<br />
;setButtonStyleSheet(button, markup)<br />
: Applies Qt style formatting to a button via a special markup language.<br />
<br />
; Parameters<br />
* ''button:''<br />
: The name of the button to be formatted.<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note: You can instead use QWidget { markup }. QWidget will reference 'button', allowing the use of pseudostates like QWidget:hover and QWidget:selected<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setButtonStyleSheet("my test button", [[<br />
QWidget {<br />
background-color: #999999;<br />
border: 3px #777777;<br />
}<br />
QWidget:hover {<br />
background-color: #bbbbbb;<br />
}<br />
QWidget:checked {<br />
background-color: #77bb77;<br />
border: 3px #559955;<br />
}<br />
QWidget:hover:checked {<br />
background-color: #99dd99;<br />
} ]])</syntaxhighlight><br />
<br />
==setClipboardText==<br />
;setClipboardText(textContent)<br />
: Sets the value of the computer's clipboard to the string data provided.<br />
: See also: [[#getClipboardText | getClipboardText()]]<br />
<br />
; Parameters<br />
* ''textContent:''<br />
: The text to be put into the clipboard.<br />
<br />
: {{note}} Note: Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setClipboardText("New Clipboard Contents")<br />
echo("Clipboard: " .. getClipboardText()) -- should echo "Clipboard: New Clipboard Contents"<br />
</syntaxhighlight><br />
<br />
==setCmdLineAction==<br />
;setCmdLineAction(commandLineName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user sends text to the command line. 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 command line action. Additionally, this function passes the command line input text as the final argument.<br />
{{note}} If no action is set the command line behaves like the main command line and sends commands directly to the game or alias engine.<br />
<br />
The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, text)<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#resetCmdLineAction|resetCmdLineAction()]]<br />
<br />
;Parameters<br />
<br />
* ''commandLineName:''<br />
: The name of the command line to attach the action function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} You can also pass a function directly instead of using a string<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function sendTextToMiniConsole(miniConsoleName, cmdLineText)<br />
echo(miniConsoleName, cmdLineText.."\n")<br />
end<br />
<br />
setCmdLineAction("myCmdLine", "sendTextToMiniConsole", "myMiniConsole")<br />
<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setConsoleBackgroundImage==<br />
;setConsoleBackgroundImage([windowname], imageLocation, [mode])<br />
: Loads an image file (for example png) as a background image for a console (main/miniconsole and userwindows).<br />
<br />
;Parameters<br />
<br />
* ''windowName:''<br />
: (optional) name of the miniconsole/userwindow to change the background image on, or "main" for the main window.<br />
* ''imageLocation:''<br />
: 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.<br />
* ''mode:''<br />
: (optional) allows different modes for drawing the background image<br />
possible modes areː "border" (the background image is stretched) , 2 "center" (the background image is in the center), <br />
3 "tile" (the background image is 'tiled'), 4 "style" (choose your own background image stylesheet. see example below) <br />
<br />
: See also: [[#resetConsoleBackgroundImage | resetConsoleBackgroundImage()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- give my_miniconsole a nice background image and put it in the center<br />
setConsoleBackgroundImage("my_miniconsole", [[:/Mudlet_splashscreen_development.png]], "center")<br />
<br />
-- give my_miniconsole a nice background image with own stylesheet option<br />
setConsoleBackgroundImage("my_miniconsole", [[background-image: url(:/Mudlet_splashscreen_development.png); background-repeat: no-repeat; background-position: right;]], "style")<br />
</syntaxhighlight><br />
{{note}} available in Mudlet 4.10+<br />
<br />
==setFont==<br />
;setFont(name, font)<br />
: Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Prefer a monospaced font - those work best with text games. See here [https://doc.qt.io/qt-5/qfont.html#setFamily for more].<br />
: See also: [[#getFont|getFont()]], [[#setFontSize|setFontSize()]], [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.<br />
* ''font:''<br />
: The font to use.<br />
<br />
{{note}}<br />
Available in Mudlet 3.9+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.<br />
setFont("Ubuntu Mono")<br />
setFont("main", "Ubuntu Mono")<br />
<br />
-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.<br />
setFont("combat", "Ubuntu Mono")<br />
</syntaxhighlight><br />
<br />
==setFontSize==<br />
;setFontSize(name, size)<br />
: Sets a font size on the given window or console name. Can be used to change font size of the Main console as well as dockable UserWindows.<br />
: See Also: [[#getFontSize|getFontSize()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.<br />
* ''size:''<br />
: The font size to apply to the window.<br />
<br />
{{note}}<br />
Available in Mudlet 3.4+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The following will set the "main" console window font to 12-point font.<br />
setFontSize(12)<br />
setFontSize("main", 12)<br />
<br />
-- This will set the font size of a user window named "uw1" to 12-point font.<br />
setFontSize("uw1", 12)<br />
</syntaxhighlight><br />
<br />
==setGauge==<br />
;setGauge(gaugeName, currentValue, maxValue, gaugeText)<br />
: 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.<br />
<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#createGauge|createGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a gauge<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
--Change the looks of the gauge named healthBar and make it<br />
--fill to half of its capacity. The height is always remembered.<br />
setGauge("healthBar", 200, 400)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
--If you wish to change the text on your gauge, you’d do the following:<br />
setGauge("healthBar", 200, 400, "some text")<br />
</syntaxhighlight><br />
<br />
==setGaugeStyleSheet==<br />
;setGaugeStyleSheet(gaugeName, css, cssback, csstext)<br />
: 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. You can use [https://build-system.fman.io/qt-designer-download Qt Designer] to create stylesheets.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
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);<br />
border-top: 1px black solid;<br />
border-left: 1px black solid;<br />
border-bottom: 1px black solid;<br />
border-radius: 7;<br />
padding: 3px;]],<br />
[[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);<br />
border-width: 1px;<br />
border-color: black;<br />
border-style: solid;<br />
border-radius: 7;<br />
padding: 3px;]])<br />
</syntaxhighlight><br />
<br />
==setGaugeText==<br />
;setGaugeText(gaugename, css, ccstext )<br />
: Set the formatting of the text used inside the inserted gaugename.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
setGaugeText("healthBar", [[<p style="font-weight:bold;color:#C9C9C9;letter-spacing:1pt;word-spacing:2pt;font-size:12px;text-align:center;font-family:arial black, sans-serif;">]]..MY_NUMERIC_VARIABLE_HERE..[[</p>]])</syntaxhighlight><br />
<br />
;Useful resources:<br />
:http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.<br />
:https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!<br />
<br />
==setHexBgColor==<br />
;setHexBgColor([windowName], hexColorString)<br />
:Sets the current text nackground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text background color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setBgColor | setBgColor()]], [[#setHexFgColor | setHexFgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.<br />
selectString( "Tom", 1 )<br />
setHexBgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setHexFgColor==<br />
;setHexFgColor([windowName], hexColorString)<br />
:Sets the current text foreground color in the main window unless windowName parameter given. This function allows to specify the color as a 6 character hexadecimal string.<br />
<br />
* ''windowName:''<br />
: Optional parameter set the current text foreground color in windowname given.<br />
* ''hexColorString''<br />
: 6 character long hexadecimal string to set the color to. The first two characters 00-FF represent the red part of the color, the next two the green and the last two characters stand for the blue part of the color<br />
<br />
: See also: [[#setFgColor | setFgColor()]], [[#setHexBgColor | setHexBgColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.<br />
selectString( "Tom", 1 )<br />
setHexFgColor( "FF0000" )<br />
</syntaxhighlight><br />
<br />
==setItalics==<br />
;setItalics(windowName, bool)<br />
: Sets the current text font to italics/non-italics mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setLabelToolTip==<br />
;setLabelToolTip(labelName, [duration])<br />
: Sets a tooltip on the given label.<br />
{{note}} available in Mudlet 4.6.1+<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to set the tooltip to.<br />
* ''duration:''<br />
: Duration of the tooltip timeout in seconds. Optional, if not set the default duration will be set.<br />
<br />
: See also: [[Manual:UI_Functions#resetLabelToolTip|resetLabelToolTip()]]<br />
<br />
==setLabelClickCallback==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument. This table contains information about the mouse button clicked, other buttons that were pressed at the time, and the mouse cursor's local (relative to the label) and global (relative to the Mudlet window) position. The function specified in ''luaFunctionName'' is called like so:<br />
<br />
<syntaxhighlight lang="lua"><br />
luaFuncName(optional number of arguments, event)<br />
</syntaxhighlight><br />
<br />
where '''event''' has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
button = "LeftButton",<br />
buttons = {"RightButton", "MidButton"},<br />
}<br />
</syntaxhighlight><br />
<br />
: See also: [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]],[[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}} Event argument is available in 3.6+, and in 4.8+ you can pass a function directly instead of a string.<br />
<br />
{{note}}<br />
While '''event.button''' may contain a single string of any listed below, '''event.buttons''' will only ever contain some combination of "LeftButton", "MidButton", and "RightButton"<br />
:The following mouse button strings are defined:<br />
<pre><br />
"LeftButton" "RightButton" "MidButton"<br />
"BackButton" "ForwardButton" "TaskButton"<br />
"ExtraButton4" "ExtraButton5" "ExtraButton6"<br />
"ExtraButton7" "ExtraButton8" "ExtraButton9"<br />
"ExtraButton10" "ExtraButton11" "ExtraButton12"<br />
"ExtraButton13" "ExtraButton14" "ExtraButton15"<br />
"ExtraButton16" "ExtraButton17" "ExtraButton18"<br />
"ExtraButton19" "ExtraButton20" "ExtraButton21"<br />
"ExtraButton22" "ExtraButton23" "ExtraButton24"<br />
</pre><br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
else if event.button == "RightButton" then<br />
send("swim north")<br />
else if event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )<br />
<br />
-- you can also use them within tables now:<br />
mynamespace = {<br />
onClickGoNorth = function()<br />
echo("the north button was clicked!")<br />
end<br />
}<br />
<br />
setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )<br />
<br />
</syntaxhighlight><br />
<br />
==setLabelDoubleClickCallback==<br />
;setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called if the user double 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
{{note}}<br />
Available in Mudlet 3.6+<br />
<br />
: See also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
==setLabelMoveCallback==<br />
;setLabelMoveCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse moves while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
==setLabelOnEnter==<br />
;setLabelOnEnter(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the '''event''' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
}<br />
</syntaxhighlight><br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseOver()<br />
echo("The mouse is hovering over the label!\n")<br />
end<br />
<br />
setLabelOnEnter( "compassNorthImage", "onMouseOver" )<br />
</syntaxhighlight><br />
<br />
==setLabelOnLeave==<br />
;setLabelClickCallback(labelName, luaFunctionName, [any arguments])<br />
: 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.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onMouseLeft(argument)<br />
echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)<br />
end<br />
<br />
setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )<br />
</syntaxhighlight><br />
<br />
==setLabelReleaseCallback==<br />
;setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])<br />
: 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. Additionally, this function passes an event table as the final argument, as in [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]]<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelWheelCallback|setLabelWheelCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
This command was added in version 3.0.0<br />
<br />
{{note}}<br />
The ''event'' argument only available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onReleaseNorth()<br />
echo("the north button was released!")<br />
end<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onReleaseNorth = function()<br />
echo("the north button was released!")<br />
end<br />
}<br />
<br />
setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )<br />
</syntaxhighlight><br />
<br />
==setLabelStyleSheet==<br />
;setLabelStyleSheet(label, markup)<br />
: Applies Qt style formatting to a label via a special markup language.<br />
<br />
; Parameters<br />
* ''label:''<br />
: The name of the label to be formatted (passed when calling createLabel).<br />
* ''markup:''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.<br />
<br />
;References<br />
: http://qt-project.org/doc/qt-5/stylesheet-reference.html<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a white background and a green border, with the text "test"<br />
-- inside.<br />
createLabel("test", 50, 50, 100, 100, 0)<br />
setLabelStyleSheet("test", [[<br />
background-color: white;<br />
border: 10px solid green;<br />
font-size: 12px;<br />
]])<br />
echo("test", "test")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that will tile or clip depending on the<br />
-- size of the label. To use this example, please supply your own image.<br />
createLabel("test5", 50, 353, 164, 55, 0)<br />
setLabelStyleSheet("test5", [[<br />
background-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
-- This creates a label with a single image, that can be resized (such as during a<br />
-- sysWindowResizeEvent). To use this example, please supply your own image.<br />
createLabel("test9", 215, 353, 100, 100, 0)<br />
setLabelStyleSheet("test9", [[<br />
border-image: url("C:/Users/Administrator/.config/mudlet/profiles/Midkemia Online/Vyzor/MkO_logo.png");<br />
]])<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--This creates a label whose background changes when the users mouse hovers over it.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
local ourLabelStyle = [[<br />
QLabel{<br />
background-color: ]]..labelBackgroundColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
QLabel::hover{<br />
background-color: ]]..labelHoverColor..[[;<br />
font-size: ]]..labelFontSize..[[px;<br />
qproperty-alignment: 'AlignCenter | AlignCenter';<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
--Using QLabel::hover mentioned above. Lets "trick" the label into changing it's text.<br />
--Please keep in mind that the setLabelMoveCallback allows for much more control over not just your label but your entire project.<br />
<br />
--putting the styleSheet in a variable allows us to easily change the styleSheet. We also are placing colors in variables that have been preset. <br />
local labelBackgroundColor = "#123456"<br />
local labelHoverColor = "#654321"<br />
local labelFontSize = 12<br />
local labelName = "HoverLabel"<br />
--Notice we are adding a string returned from a function. In this case, the users profile directory.<br />
local ourLabelStyle = [[<br />
QLabel{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithtext.png");<br />
}<br />
QLabel::hover{<br />
border-image: url("]]..getMudletHomeDir()..[[/imagewithhovertext.png");<br />
}<br />
]]<br />
<br />
--Creating the label using the labelName and ourLabelStyle variables created above.<br />
createLabel(labelName,0,0,400,400,1)<br />
setLabelStyleSheet(labelName, ourLabelStyle)<br />
--This is just to example that echos draw on top of the label. You would not want to echo onto a label you were drawing text on with images, because echos would draw on top of them.<br />
echo("HoverLabel","This text shows while mouse is or is not over the label.")<br />
</syntaxhighlight><br />
<br />
==setLabelCursor==<br />
;setLabelCursor(labelName, cursorShape)<br />
: Changes how the mouse cursor looks like when over the label. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCustomCursor|setLabelCustomCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''cursorShape''<br />
: Shape of the mouse cursor. List of possible cursor shapes is [[CursorShapes| available here]].<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCursor("myLabel", "Cross")<br />
-- This will change the mouse cursor to a cross if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelCustomCursor==<br />
;setLabelCustomCursor(labelName, custom cursor, [hotX, hotY])<br />
: Changes the mouse cursor shape over your label to a custom cursor. To reset the cursor shape, use [[#resetLabelCursor|resetLabelCursor()]].<br />
<br />
: See also: [[#resetLabelCursor|resetLabelCursor()]], [[#setLabelCursor|setLabelCursor()]]<br />
<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''labelName:''<br />
: Name of the label which you want the mouse cursor change at.<br />
* ''custom cursor''<br />
: Location of your custom cursor file. To be compatible with all systems it is recommended to use png files with size of 32x32.<br />
* ''hotX''<br />
: X-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
* ''hotY''<br />
: Y-coordinate of the cursors hotspot position. Optional, if not set it is set to -1 which is in the middle of your custom cursor.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setLabelCustomCursor("myLabel", getMudletHomeDir().."/custom_cursor.png")<br />
-- This will change the mouse cursor to your custom cursor if it's over the label myLabel<br />
</syntaxhighlight><br />
<br />
==setLabelWheelCallback==<br />
;setLabelWheelCallback(labelName, luaFunctionName, [any arguments])<br />
: Specifies a Lua function to be called when the mouse wheel is scrolled while inside the specified label/console. 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. Additionally, this function passes an event table as the final argument, similar to [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], but with slightly different information.<br />
: For this callback, the ''event'' argument has the following structure:<br />
<br />
<syntaxhighlight lang="lua"><br />
event = {<br />
x = 100,<br />
y = 200,<br />
globalX = 300,<br />
globalY = 320,<br />
buttons = {"RightButton", "MidButton"},<br />
angleDeltaX = 0,<br />
angleDeltaY = 120<br />
}<br />
</syntaxhighlight><br />
<br />
: Keys ''angleDeltaX'' and ''angleDeltaY'' correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.<br />
<br />
: See Also: [[Manual:UI_Functions#setLabelClickCallback|setLabelClickCallback()]], [[Manual:UI_Functions#setLabelDoubleClickCallback|setLabelDoubleClickCallback()]], [[Manual:UI_Functions#setLabelReleaseCallback|setLabelReleaseCallback()]], [[Manual:UI_Functions#setLabelMoveCallback|setLabelMoveCallback()]], [[Manual:UI_Functions#setLabelOnEnter|setLabelOnEnter()]], [[Manual:UI_Functions#setLabelOnLeave|setLabelOnLeave()]]<br />
<br />
;Parameters<br />
<br />
* ''labelName:''<br />
: The name of the label to attach a callback function to.<br />
* ''luaFunctionName:''<br />
: The Lua function name to call, as a string.<br />
* ''any arguments:''<br />
: (optional) Any amount of arguments you'd like to pass to the calling function.<br />
<br />
{{note}}<br />
Available since Mudlet 3.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onWheelNorth(event)<br />
if event.angleDeltaY > 0 then<br />
echo("the north button was wheeled forwards over!")<br />
else<br />
echo("the north button was wheeled backwards over!")<br />
end<br />
end<br />
<br />
setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )<br />
<br />
-- you can also use them within tables:<br />
mynamespace = {<br />
onWheelNorth = function()<br />
echo("the north button was wheeled over!")<br />
end<br />
}<br />
<br />
setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )<br />
</syntaxhighlight><br />
<br />
==setLink==<br />
;setLink([windowName], command, tooltip)<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: (optional) name of a miniconsole or a userwindow in which to select the text in.<br />
* ''command:''<br />
: command to do when the text is clicked.<br />
* ''tooltip:''<br />
: tooltip to show when the mouse is over the text - explaining what would clicking do.<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- you can clickify a lot of things to save yourself some time - for example, you can change<br />
-- the line where you receive a message to be clickable to read it!<br />
-- prel regex trigger:<br />
-- ^You just received message #(\w+) from \w+\.$<br />
-- script:<br />
selectString(matches[2], 1)<br />
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])<br />
resetFormat()<br />
<br />
-- an example of selecting text in a miniconsole and turning it into a link:<br />
<br />
HelloWorld = Geyser.MiniConsole:new({<br />
name="HelloWorld",<br />
x="70%", y="50%",<br />
width="30%", height="50%",<br />
})<br />
HelloWorld:echo("hi")<br />
selectString("HelloWorld", "hi", 1)<br />
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")<br />
</syntaxhighlight><br />
<br />
==setMainWindowSize==<br />
;setMainWindowSize(mainWidth, mainHeight)<br />
: Changes the size of your main Mudlet window to the values given.<br />
: See Also: [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]<br />
<br />
; Parameters<br />
* ''mainWidth:''<br />
: The new width in pixels.<br />
* ''mainHeight:''<br />
: The new height in pixels.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--this will resize your main Mudlet window<br />
setMainWindowSize(1024, 768)<br />
</syntaxhighlight><br />
<br />
==setMapWindowTitle==<br />
;setMapWindowTitle(text)<br />
: Changes the title shown in the mapper window when it's popped out.<br />
: See also: [[#resetMapWindowTitle|resetMapWindowTitle()]]<br />
<br />
; Parameters<br />
* ''text:''<br />
: New window title to set.<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapWindowTitle("my cool game map")<br />
</syntaxhighlight><br />
<br />
==setMiniConsoleFontSize==<br />
;setMiniConsoleFontSize(name, fontSize)<br />
: Sets the font size of the mini console. see also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]]<br />
<br />
==setOverline==<br />
;setOverline([windowName], boolean)<br />
: Sets the current text font to be overlined (true) or not overlined (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 overlined. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be overlined until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be overlined or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables overlining of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable overlined text<br />
setOverline(true)<br />
-- the following echo will be have an overline<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and reverse have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
==setPopup==<br />
;setPopup(windowName, {lua code}, {hints})<br />
: Turns the [[Manual:Lua_Functions#selectString|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.<br />
<br />
; Parameters<br />
* ''windowName:''<br />
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.<br />
* ''{lua code}:''<br />
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,<br />
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking<br />
-- will show some commands you can do.<br />
<br />
selectString("Hello", 1)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})<br />
</syntaxhighlight><br />
<br />
==setProfileStyleSheet==<br />
;setProfileStyleSheet(stylesheet)<br />
: Sets a stylesheet for the current Mudlet profile - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). This function is better than setAppStyleSheet() because it affects only the current profile and not every other one as well.<br />
<br />
: See also: [[#setAppStyleSheet|setAppStyleSheet()]]<br />
<br />
;Parameters<br />
<br />
* ''stylesheet:''<br />
: The entire stylesheet you'd like to use. See [http://qt-project.org/doc/qt-5/stylesheet-reference.html Qt Style Sheets Reference] for the list of widgets you can style and CSS properties you can apply on them.<br />
<br />
: See also [https://github.com/vadi2/QDarkStyleSheet/blob/master/qdarkstyle/style.qss QDarkStyleSheet], a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an [http://forums.mudlet.org/viewtopic.php?f=6&t=17624 mpackage here].<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770<br />
local background_color = "#26192f"<br />
local border_color = "#b8731b"<br />
<br />
setProfileStyleSheet([[<br />
QMainWindow {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolBar {<br />
background: ]]..background_color..[[;<br />
}<br />
QToolButton {<br />
background: ]]..background_color..[[;<br />
border-style: solid;<br />
border-width: 2px;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 5px;<br />
font-family: BigNoodleTitling;<br />
color: white;<br />
margin: 2px;<br />
font-size: 12pt;<br />
}<br />
QToolButton:hover { background-color: grey;}<br />
QToolButton:focus { background-color: grey;}<br />
<br />
QTreeView {<br />
background: ]]..background_color..[[;<br />
color: white;<br />
}<br />
<br />
QMenuBar{ background-color: ]]..background_color..[[;}<br />
<br />
QMenuBar::item{ background-color: ]]..background_color..[[;}<br />
<br />
QDockWidget::title {<br />
background: ]]..border_color..[[;<br />
}<br />
QStatusBar {<br />
background: ]]..border_color..[[;<br />
}<br />
QScrollBar:vertical {<br />
background: ]]..background_color..[[;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background-color: ]]..background_color..[[;<br />
min-height: 20px;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-radius: 7px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-bottom-left-radius: 7px;<br />
border-bottom-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
background-color: ]]..background_color..[[;<br />
border-width: 2px;<br />
border-style: solid;<br />
border-color: ]]..border_color..[[;<br />
border-top-left-radius: 7px;<br />
border-top-right-radius: 7px;<br />
height: 15px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
background: white;<br />
width: 4px;<br />
height: 3px;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]])<br />
<br />
-- if you'd like to reset it, use:<br />
setProfileStyleSheet("")<br />
<br />
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':<br />
setProfileStyleSheet[[<br />
TConsole QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
TConsole QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
TConsole QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
Available since Mudlet 4.6.<br />
<br />
==setReverse==<br />
;setReverse([windowName], boolean)<br />
: Sets the current text to swap foreground and background color settings (true) or not (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 have it's colors swapped. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will have their foreground and background colors swapped until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text colors to be reversed or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables reversing of the fore- and back-ground colors of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable fore/back-ground color reversal of text<br />
setReverse(true)<br />
-- the following echo will have the text colors reversed<br />
echo("hi")<br />
-- turns off bolding, italics, underlines, colouring, and strikethrough (and, after this and overline have been added, them as well). It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.17+<br />
<br />
{{note}} Although the visual effect on-screen is the same as that of text being selected if both apply to a piece of text they neutralise each other - however the effect of the reversal ''will'' be carried over in copies made by the "Copy to HTML" and in logs made in HTML format log file mode.<br />
<br />
==setStrikeOut==<br />
;setStrikeOut([windowName], boolean)<br />
: 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 [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be striken out until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].<br />
<br />
* ''windowName:''<br />
: (optional) name of the window to set the text to be stricken out or not.<br />
<br />
* ''boolean:''<br />
: A ''true'' or ''false'' that enables or disables striking out of text<br />
<br />
;Example<br />
<br />
<syntaxhighlight lang="lua"><br />
-- enable striken-out text<br />
setStrikeOut(true)<br />
-- the following echo will be have a strikethrough<br />
echo("hi")<br />
-- 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.<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
==setTextFormat==<br />
;setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])<br />
: Sets current text format of selected window. This is a more convenient means to set all the individual features at once compared to using [[#setFgColor|setFgColor]]( windowName, r,g,b ), [[#setBold|setBold]]( windowName, true ), [[#setItalics|setItalics]]( windowName, true ), [[#setUnderline|setUnderline]]( windowName, true ), [[#setStrikeOut|setStrikeOut]]( windowName, true ).<br />
: See Also: [[Manual:Lua_Functions#getTextFormat|getTextFormat()]]<br />
<br />
;Parameters<br />
* ''windowName''<br />
: Specify name of selected window. If empty string "" or "main" format will be applied to the main console<br />
* ''r1,g1,b1''<br />
: To color text background, give number values in RBG style<br />
* ''r2,g2,b2''<br />
: To color text foreground, give number values in RBG style<br />
* ''bold''<br />
: To format text bold, set to 1 or true, otherwise 0 or false<br />
* ''underline''<br />
: To underline text, set to 1 or true, otherwise 0 or false<br />
* ''italics''<br />
: To format text italic, set to 1 or true, otherwise 0 or false<br />
* ''strikeout<br />
: (optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''overline<br />
: (optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument<br />
* ''reverse<br />
: (optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This script would create a mini text console and write with bold, struck-out, yellow foreground color and blue background color "This is a test".<br />
createMiniConsole( "con1", 0,0,300,100);<br />
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);<br />
echo("con1","This is a test")<br />
</syntaxhighlight><br />
<br />
{{note}} In versions prior to 3.7.0 the error messages ''and this wiki'' were wrong in that they had the foreground color parameters as r1, g1 and b1 and the background ones as r2, g2 and b2.<br />
<br />
==setUnderline==<br />
;setUnderline(windowName, bool)<br />
: Sets the current text font to underline/non-underline mode. If the windowName parameters omitted, the main screen will be used.<br />
<br />
==setUserWindowTitle==<br />
;setUserWindowTitle(windowName, text)<br />
: sets a new title text for the UserWindow windowName<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''text''<br />
: new title text<br />
<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
==setUserWindowStyleSheet==<br />
;setUserWindowStyleSheet(windowName, markup)<br />
: Applies Qt style formatting to the border/title area of a userwindow via a special markup language.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow<br />
* ''markup''<br />
: The string instructions, as specified by the Qt Style Sheet reference.<br />
: Note that when you dock the userwindow the border style is not provided by this<br />
<br />
{{note}} Available in Mudlet 4.10+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- changes the title area style of the UserWindow 'myUserWindow'<br />
setUserWindowStyleSheet("myUserWindow", [[QDockWidget::title{ <br />
background-color: rgb(0,255,150);<br />
border: 2px solid red;<br />
border-radius: 8px;<br />
text-align: center; <br />
}]])<br />
</syntaxhighlight><br />
<br />
: See also: [[#openUserWindow|openUserWindow()]]<br />
<br />
==setWindow==<br />
;setWindow(windowName, name, [Xpos, Ypos, show])<br />
: Changes the parent window of an element.<br />
{{Note}} Available in Mudlet 4.8+<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the userwindow which you want the element put in. If you want to put the element into the main window, use windowName "main".<br />
* ''name''<br />
: Name of the element which you want to switch the parent from. Elements can be labels, miniconsoles and the embedded mapper. If you want to move the mapper use the name "mapper"<br />
* ''Xpos:''<br />
: X position of the element. Measured in pixels, with 0 being the very left. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''Ypos:''<br />
: Y position of the element. Measured in pixels, with 0 being the very top. Passed as an integer number. Optional, if not given it will be 0.<br />
* ''show:''<br />
: true or false to decide if the element will be shown or not in the new parent window. Optional, if not given it will be true.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindow("myuserwindow", "mapper")<br />
-- This will put your embedded mapper in your userwindow "myuserwindow".<br />
</syntaxhighlight><br />
<br />
==setWindowWrap==<br />
;setWindowWrap(windowName, wrapAt)<br />
: sets at what position in the line the will start word wrap.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapAt:''<br />
: Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==setWindowWrapIndent==<br />
;setWindowWrapIndent(windowName, wrapTo)<br />
: sets at what position in the line wrapped txt will continue.<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: Name of the "main" console or user-created miniconsole which you want to be wrapped differently. If you want to wrap the main window, use windowName "main".<br />
* ''wrapTo:''<br />
: Number of spaces which wrapped lines are prefixed with.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setWindowWrap("main", 10)<br />
setWindowWrapIndent("main", 3)<br />
display("This is just a test")<br />
<br />
-- The following output will result in the main window console:<br />
"This is<br />
just a<br />
test"<br />
</syntaxhighlight><br />
<br />
==showCaptureGroups==<br />
;showCaptureGroups()<br />
:Lua debug function that highlights in random colors 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.<br />
<br />
;Example:<br />
: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.<br />
<br />
==showMultimatches==<br />
;showMultimatches()<br />
: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.<br />
<br />
==showWindow==<br />
;showWindow(name)<br />
: Makes a hidden window (label or miniconsole) be shown again.<br />
<br />
: See also: [[#hideWindow | hideWindow()]]<br />
<br />
==showColors==<br />
;showColors([columns], [filterColor], [sort])<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in '''color_table''', in table form. The format is ''color_table.colorName = {r, g, b}''.<br />
<br />
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#fg|fg()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: (optional) number of columns to print the color table in.<br />
* ''filterColor:''<br />
: (optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.<br />
* ''sort:''<br />
: (optional) sort colors alphabetically.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- display as four columns:<br />
showColors(4)<br />
<br />
-- show only red colours:<br />
showColors("red")<br />
</syntaxhighlight><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)|thumb|center]]<br />
<br />
==showToolBar==<br />
;showToolBar(name)<br />
: Makes a toolbar (a button group) appear on the screen.<br />
<br />
;Parameters<br />
* ''name:''<br />
: name of the button group to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
showToolBar("my attack buttons")<br />
</syntaxhighlight><br />
<br />
==suffix==<br />
;suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])<br />
: Suffixes text at the end of the current line. This is similar to [[Manual:Lua_Functions#echo | echo()]], which also suffixes text at the end of the line, but different - [[Manual:Lua_Functions#echo | 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.<br />
<br />
;Parameters<br />
* ''text''<br />
: the information you want to prefix<br />
* ''writingFunction''<br />
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.<br />
* ''foregroundColor''<br />
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function<br />
* ''backgroundColor''<br />
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function<br />
* ''windowName''<br />
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed<br />
<br />
: See also: [[#prefix | prefix()]], [[Manual:Lua_Functions#echo | echo()]]<br />
<br />
==wrapLine==<br />
;wrapLine(windowName, lineNumber)<br />
: 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.:<br />
<br />
<syntaxhighlight lang="lua">selectString(line,1)<br />
replace("")</syntaxhighlight><br />
<br />
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.<br />
<br />
: See Also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#deleteLine|deleteLine()]]<br />
<br />
;Parameters<br />
* ''windowName:''<br />
: The miniconsole or the main window (use ''main'' for the main window)<br />
* ''lineNumber:''<br />
: The line number which you'd like re-wrapped.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- re-wrap the last line in the main window<br />
wrapLine("main", getLineCount())<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Trigger_Engine&diff=15589Manual:Trigger Engine2020-09-30T06:06:56Z<p>Smurf: /* Multi-Line Triggers and Multi-Condition Triggers */ typo</p>
<hr />
<div>=Trigger Engine=<br />
<br />
Unlike alias that define patterns that match on user input, triggers define patterns that match on MUD output. In other words, triggers react to text that has been sent by the MUD, whereas alias react to user commands that have been typed into the command line.<br />
<br />
==Simple Trigger Matching==<br />
[[File:Simple-trigger.png|600px]]<br />
<br />
<br />
{{note}} QUICKSTART: Here is a simple '''[http://www.youtube.com/watch?v=URbwW41LBcQ&hd=1 video tutorial]''' on how to make basic triggers in Mudlet.<br />
<br />
<br />
To begin with, click on the "Add" button to create a new trigger. Then put the text pattern that you’d like to trigger on into the trigger conditions table on the right side of the screen above the script editor. Afterwards, chose the correct pattern type of your trigger pattern in the drop down list on the right side of the trigger pattern i.e. in the second column of the trigger pattern table. If you define multiple patterns in the same trigger, your trigger will run whenever any one of these patterns matches unless you chose the AND-trigger option, in which case the trigger will only fire if all patterns match within a specified amount of lines from the MUD. For more advanced information on AND and OR trigger see the corresponding AND/OR trigger section below. The next step is to define what should happen when the trigger matches. Usually, this will be done by a Lua script in the Lua editor below the table with the pattern list. In the beginning, you can simply chose the "highlight trigger" option to make your trigger highlight the text that it has triggered on or send a clear text command to the MUD whenever the trigger fires until you have learned enough Lua to more meaningful scripts. Clear text command can be defined in the "send plain text" input box next to the trigger name above the pattern table. Finally, you need to save the new trigger and then activate it with the padlock icon button. By default, new triggers are deactivated and thus will do nothing unless you explicitly activate them. Activated triggers show a green tick in the little blue box on the left side of the trigger name in the trigger tree on the left side of the script editor dialog. There is three ways to save your changes. 1. click on the save icon 2. adding a new trigger 3. clicking on another trigger item. Triggers that have not been saved yet cannot be activated. If you see a bug icon instead of an activation box, there is some error that prevents to activate your trigger. Check the error message above the pattern table.<br />
<br />
<blockquote>Example: You want to trigger on the word "pond" in a line such as: "The frog swims in the pond. Plop." All you need to do is add "pond" as a pattern and chose "substring" as a pattern type. Then enter the command you like to send to the MUD if the trigger matches. For example enter "drink water" into the "send plain text" input box and activate your new trigger. Your new trigger will send the command "drink water" to the MUD any time it sees the word "pond" somewhere in the MUD output.</blockquote><br />
<br />
==Simple Highlighter Triggers==<br />
<br />
{{note}} Beginners should use Mudlets automated highlight triggers in the beginning to get the hang of the different trigger and pattern types quicker. Click on the "highlight trigger" option and pick a foreground and a background color. When the trigger matches it automatically highlights its pattern. This is the most used form of triggers in mudding as it is a quick way of highlighting words that are important to you at the moment. This helps you spot things at a single glance instead of reading the entire text. You don’t have to know anything about scripting, regular expressions etc. to use highlight triggers. Just type in the word you like to be highlighted, select appropriate colors, save the new trigger and activate it.<br />
<br />
More advanced users will often want to do custom highlighting from within scripts. This is how it works: If you want to highlight the word "pond" in the above example you have to add the following little Lua script to the script editor on the lower right side of the Script Editor window:<br />
<syntaxhighlight lang="lua"><br />
selectString( "pond", 1 )<br />
fg( "red " )<br />
bg( "blue" )<br />
resetFormat()<br />
</syntaxhighlight><br />
<br />
=="multiline / AND" and "OR" Condition Triggers==<br />
<br />
[[File:OR trigger.png|thumb|left|Any of the patterns in this trigger can match for it to fire]]<br />
<br />
[[File:AND trigger.png|thumb|left|All of the patterns have to match for it to fire. This is a common example of a "shielded regex" - don't run the expensive regex all the time unless you really need to, and match on the faster begin of line the majority of the time]]<br />
<br />
Multiline, or AND triggers execute their respective command or script only if all conditions in their respective conditions expression list are fulfilled. <br />
<br />
OR-Triggers execute when '''any one of''' their conditions is true. To make OR-Triggers you simply have to add a few conditions to the conditions list e.g. in our example: "pond", "frog", "Plop". The trigger will now also execute on lines like this: "A frog is green" or "You hear a loud Plop!" because "frog" matched in the first line and "Plop" matched in the second line.<br />
<br />
<br />
Multiline / AND triggers execute when '''all of''' their conditions are true. Taking the previous patterns of "pond", "frog", "Plop" and clicking the 'AND' button will make the trigger not fire on "A frog is green" or "You hear a loud Plop!" anymore, because all 3 patterns don't match. It however would fire on "In a brown pond, the frog said Plop!" because all 3 patterns matched. As you might have noticed, all 3 patterns are on the same line: this means that in a multiline/AND trigger, the next pattern starts matching on the same line to make this work.<br />
<br />
To make the engine skip lines in a multiline / AND trigger, use the line spacer pattern: select 'line spacer' as the type and put in a number on the left to make it go to the next X lines, for example 1 will make it go to the next line.<br />
<br />
The simplest form of AND-Triggers in Mudlet are Trigger Chains or Filter Chains, whatever you’d like to call it.<br />
<br />
==Trigger Chains & Filter Chains==<br />
<br />
"Chains" and "filters" are different trigger group entities in Mudlet and serve completely different ends.<br />
<br />
===Chains===<br />
<br />
A chain is defined in Mudlet by making a trigger group and adding a trigger pattern to the group. A group without a pattern is a simple trigger group that serves no other purposes than adding structure to your trigger system in order to organize your triggers better. Such a normal trigger group will always grant access to its children unless it has been explicitly disabled (= all access to itself or any of its children is locked) either manually or by a script.<br />
<br />
A trigger group with a defined trigger pattern, however, will behave like a normal trigger and match if the pattern matches. Such a trigger group is called "chain head". A chain head will only grant access to its children if the trigger pattern has matched and the chain has been enabled. Thus, chains can be looked at as a mechanism to automatically enable and disable triggers or groups of triggers when a certain condition has been met i. e. the trigger pattern of the chain head has been matched. (However, technically this is not correct as disabled child triggers will not be invoked if the chain head matches. In other words, in chains you can still have enabled/disabled elements. The idea of a chain can better be described by necessary and sufficient condition - both of which need to be met before a child trigger is being run.)<br />
<br />
Adding child triggers to this group will add elements to the trigger chain. These chain elements will only be activated if the chain head has matched before and thus opened the trigger chain. The chain stays open until the "keep chain open for x lines" value has been reached. The default is 0 which means that the chain only stays open for the current line. When access to the chain has been granted all child triggers will be tested against the content of the current line. Consequently, trigger chains are a means to automatically enable/disable trigger groups without the hassle of enabling and disabling trigger groups manually. This has 2 important advantages: Chains are faster than conventional solutions and chains reduce the complexity of your scripts and greatly reduce the usual system bugs that inevitably go along with enable/disable trigger xy function calls as it’s very difficult and error prone to enable and disable your triggers correctly in large complex trigger systems. This is one of the most powerful features in Mudlet and should be used whenever possible.<br />
<br />
Let’s look at a practical example for a trigger chain:<br />
<br />
My newbie prompt on Achaea looks like this <code>500h, 500m ex-</code> when I have balance and <code>500h, 500m e-</code> when I have lost balance. We are going to develop a prompt detection trigger that raises the event gotPrompt and sets the variables <code>myBalance=true</code> or <code>myBalance=false</code> To begin with, we add a new trigger group and add the Perl regex pattern to detect the prompt:<br />
<br />
<code>^(\d+)h, (\d+)m</code><br />
<br />
The pattern reads in plain English: At the beginning of a prompt line there are is a number directly followed by the letter h, a comma, a space and another number followed by the letter h. Whenever this pattern matches the trigger will fire and we’ll know that we have a prompt line. We use the 2 numbers that we captured in our pattern to update our health and mana stats.<br />
<br />
Detecting balance is more difficult as balance is indicated by the letters ex- on the same line after the prompt and imbalance is indicated by the letters e-. As we have set a pattern in a trigger group (folder), the folder is turned into a trigger chain head. It will now only let data through to its children when its own pattern is matched. In other words, the child triggers of the trigger chain will only receive data on prompt lines. We are going to take advantage of this by adding two simple substring triggers to detect balance and imbalance. The balance trigger pattern is ex- and the imbalance detector pattern is e-.<br />
<br />
In the two balance detection triggers we now write <code>myBalance=false</code> and <code>myBalance=true</code> respectively plus a little echo on the screen that shows our current balance status.<br />
<br />
We could now add a call <code>deleteLine()</code> to the prompt detection trigger to erase the prompt from the screen if we don’t want to see it as we have computed all relevant information.<br />
<br />
===Filters===<br />
<br />
You can turn a trigger chain head into a filter by checking the "filter" option. This changes the content of what is forwarded as trigger text to the children triggers in the chain. Chains forward the content of the current line as trigger text whereas filters forward the matched pattern instead of the current line. In other words, the text of the current line is filtered according to the pattern of the filter. For example: You want to know the exits in the current room. The simplest solution is a simple filter on <code>You see exits to: (.*)</code> Then you simply add triggers to the filter chain such as <code>north</code>, <code>south</code>, <code>west</code>, <code>east</code> etc. The direction triggers will only be called if the filter head has matched.<br />
<br />
Imagine the following scenario: You want to collect some berries. You know that the room contains some berries if the room description contains the words "You are inside a forest. There are some strawberries." or "You are inside a forest. There are some blackberries." and there are always only one kind of berry in the room. You make a new substring trigger for this line, but instead of choosing a regular trigger, you chose to add a new trigger group. Now you add <code>You are inside a forest\. There are some (\w+)\.</code> as an Regular Expression to the expression list of the trigger group. '''<span style="color:blue">When adding conditions to a trigger group, the trigger group turns from an organizational unit into a filter unit, if the "filter" option is checked.</span>''' From now on this folder is a filter and will only let its matches pass through. In our case this is exactly what we want, because we don’t want to collect all sorts of berries, but we only want 2 particular kinds, namely, strawberries and blackberries, and we know that these berries can only be trusted if they are picked inside a forest as other areas may contain contaminated berries. Now you add two regular triggers to our berry-in-the-forest filter - one containing the condition: <code>strawberries</code> and the other one <code>blackberries</code>. Then we add the commands to pick the particular kind of berry to both triggers (send field). Now what happens is that as soon as a room description reads "You are inside a forest. There are some strawberries/blackberries." the filter will let the kind of berry pass through to our two berry triggers and they will issue commands to pick berries, if there are such berries. However, in any other situation the words "strawberries" and "blackberries" will NOT trigger a pick - only in the above scenario when the filter parent’s condition is met. This is a very nice way to solve complicated problems with a few easy filter chains. This example is trivial, but using filter chains will rapidly show you how formerly complicated things that could only be solved with very complicated regular expressions can be solved easily now with a couple of filter chains.<br />
<br />
==Multi-Line Triggers and Multi-Condition Triggers==<br />
<br />
Multi Condition Triggers are the most advanced feature of Mudlets trigger engine. Like trigger chains or filter chains they are a form of AND-Triggers. All conditions in the list must have matched within the specified margin of lines (delta), in order to trigger the script. Normal triggers fire and run the script as soon as one of the conditions in the regex list is met i.e. if one of the regex/string matches match - or the Lua function condition returns true, the trigger script is run. In multiline triggers, however, each single regex/string/Lua function condition in the list has to have matched within the specified margin of lines at least once to trigger the script. The sequence of the conditions is binding. This means that if the 10th regex on the regex list would be matched on the eleventh line after the match of the first line happened, the trigger will NOT run unless the margin of lines is set to 11. If condition #3 is true but currently #2 is waiting to be true, condition #3 is ignored and must be true again after condition #2 has been true. Conditions can also be Lua Functions or plain Lua code that returns a boolean truth value. You can mix all types of conditions to build complex multi-condition triggers that only fire if all conditions are met. This is a very powerful feature as it reduces the amount of scripting to a minimum or even takes away with the need to script formerly complex processes completely. Multicondition triggers are multi-line triggers, i. e. the conditions can all be met in a single line or many lines after the first condition has been fulfilled. This effectively reduces the amount of complexity as you have all the important conditions placed into a single trigger and all the tedious bookkeeping, variable and condition state accounting is being done by Mudlets trigger engine. The result of this is that the amount of manual condition checking via many different trigger scripts and legions of if condition1 == true then check condition2 can be forgotten about. All you have to do is to define the conditions and the final action that is taken if the trigger fires.<br />
<br />
{{note}} to retrieve wildcards in multi-line or multi-condition triggers, use the '''multimatches[line][match]''' table instead of matches[].<br />
<br />
[[File:Trigger-engine-diagram.png|center|border]] <br />
<br />
{{Note}} This diagram shows what steps are involved in the process of problem solving with Mudlets trigger engine. The main question is: How do we arrive at a solution to our problem, and how can we simplify the problem as much as possible?<br />
<br />
<br />
Example: Let’s go back to our pond & frog example. We have explained the difference between AND-triggers and OR-triggers. If you have a room description consisting of 3 lines:<br />
<div style="width:100%; background:#F0F0F0; margin-top:1.2em; border:1px solid #ccc; color:#0000FF;"><br />
# You see a pond<br />
# You see a frog.<br />
# The frog sits on a stone.<br />
</div><br />
<br />
Every single one of these 3 lines will be fed into the trigger engine one after another. If we define an OR-trigger with a condition list consisting of 3 condition patterns:<br />
<br />
:condition #1 pattern = pond <br />
:condition #2 pattern = frog <br />
:condition #3 pattern = stone<br />
<br />
Whether or not a condition is found to be true also depends on another property, namely the type of the condition. The condition type can be among others:<br />
<br />
<div style="width:100%; background:#F0F0F0; border:1px solid #ccc; color:#000;"><br />
# substring matching → the condition is true if the condition pattern is a substring of the output line from the MUD. In other words: If the pattern "pond" is contained in any line of output, the condition is true.<br />
# begin of line matching → the condition is only true if the condition pattern can be found at the beginning of a line from the MUD.<br />
# Perl regular expression → the condition is true if the Perl regex pattern is matched. You’ll find more information on Perl regex below.<br />
# Lua code that returns a truth value e.g. a call to a function check() that return either true or false depending on the condition<br />
</div><br />
In our example we chose condition type "substring" for all three conditions. Consequently, the trigger will fire the command or script 3 times i. e. the trigger will do on each line it is matched against because in every line at least one condition evaluates to true because the pattern is a substring of the line.<br />
<br />
<div style="width:100%; background:#F0F0F0; border:1px solid #ccc; color:#000;"><br />
:in line #1 we get: pond = true.<br />
:in line #2 we get frog = true and<br />
:in line #3 two conditions are true i.e. frog=true and stone = true<br />
</div><br />
<br />
Because an OR-trigger fires on the first condition that is true and ignores the rest the trigger will only execute 3 times on these 3 lines although 4 conditions are true.<br />
<br />
{{note}} <span style="color:#0000FF;">'''CAUTION:''' The multi line condition switch must be turned off to get an OR-trigger! If the multi-line condition switch is turned on the trigger becomes an AND trigger which means that the trigger only fires if all conditions are true and fulfilled in the correct sequence. With OR-triggers the sequence is irrelevant.</span><br />
<br />
To complicate matters, however, you don’t want your trigger to fire 3 commands, because you want to use this room description as a whole to fire your trigger e. g. this pond is the only kind of ponds in the entire world that doesn’t have poisoned water. So you want to make sure that you only drink water from a pond of this kind and from no other pond. Your solution is to use Multi Condition Triggers (MCT). If you check the MCT checkbox this trigger will fire only once from now on - and only if all conditions are met i e. when you can guarantee that you only drink water from a good pond because your drinking trigger is matching on the entire room description despite that this room description my be spread over a number of lines. (NOTE: If you have word wrap turned off in your MUD chances are that the entire room description will be contained in a single line, but we are trying to keep the examples as easy as possible.)<br />
<br />
Sadly, there are many unfriendly people in this world and somebody goes around and poisons your good ponds. Consequently, you would want to examine the frog and find out if it is poisoned before drinking water from the pond. This is difficult because the villain is a mean magician who used illusion spells to make everything look like the good pond. To solve the problem you can now resort to Lua function conditions in the trigger condition list that perform certain check ups to put the current room description into a wider context e. g. check if you have been here before etc. This adds yet another level of complexity to your problem but this is a very powerful means to use the full potential of Mudlets MCTs.<br />
<br />
You can combine all forms of conditions with trigger chains, filters and Lua functions. Mudlet gives you relatively easy to use tools that require no programming background. However, these tools can evolve into complex powerful problem solving mechanisms if they are combined with each other thus enabling non-programmer users to solve problems that would need a profound programming background in other MUD clients. However, unlocking the full potential of Mudlet requires you do learn some Lua basics. In this manual we’ll try to be as easy on you as we can in this respect, but it’s highly recommended that you dig deeper into Lua after a while. It’s one of the easiest fully fledged scripting languages available, easy to learn and the fastest of them all, and this is why it has been chosen by us. You don’t need to become a programmer to be able to use Mudlet effectively. All you have to know is how to work with variables and how to do if conditions and maybe a few loops. But knowing more won’t harm you and it will make your systems more effective.<br />
<br />
==Lua Code Conditions & Variable Triggers - Expression Triggers==<br />
<br />
In a Lua Code/Function Condition (LFC) you can run Lua code inside the trigger engine directly, as a trigger pattern. If the trigger pattern returns anything Lua considers true (false in Lua is only ''nil'' and the boolean ''false'' value, everything else is true), then the pattern will be considered to have matched. The easiest example would be a simple variable trigger: add a new trigger and chose pattern type '''Lua function'''. Then define this pattern: <code>if health <= 100 then escape() end</code>. If your health is lower than 100, and your escape function with more logic inside it returns true, the pattern will match. Another formulation of the same would be: <code>checkHealth()</code>. For the last formulation to work you have defined a Lua function <code>checkHealth()</code>. Open the script editor, add a new script "health care" and add this code to the new script-script.<br />
<syntaxhighlight lang="lua"><br />
function checkHealth()<br />
if health <= 100 then<br />
echo( "WARNING: Low health! I have to run away!\n" )<br />
startEscape()<br />
return true<br />
else<br />
return false<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
{note} Mudlet used to only allow the boolean ''true'' value as the return value to consider the pattern to have been a match. It has since been improved to allow any value Lua would consider true - but if you see any LFCs making use of ''and true or false'' at the end, that'd be why.<br />
<br />
'''Lua Syntax Primer: Expressions'''<br />
<syntaxhighlight lang="lua"><br />
if A == B then (...) ----> if A equals B<br />
if A ~= B then (...) ----> if A *NOT* equals B<br />
if A <= B then (...) ----> if A is smaller or equal to B<br />
if A >= B then (...) ----> if A is greater or equal to B<br />
if A < B then (...) ----> if A is smaller than B<br />
if A > B then (...) ----> if A is greater than B<br />
</syntaxhighlight><br />
The operators ''and'' and ''or'' behave differently in Lua than in most other programming languages as they are not guaranteed to return a boolean value.[http://hisham.hm/2011/05/04/luas-and-or-as-a-ternary-operator/]<br />
<br />
Lua function conditions effectively means that you run the Lua code they represent on every single line that is received from the MUD, unless the LFCs are part of a multi-condition trigger, in which case the LFCs would only be run when they would be the current test-condition of their respective trigger state. LFCs are implemented in such a way that the trigger engine only calls the compiled byte code, but running as few scripts as possible is always the best idea. LFCs are nice and handy, and for most people the performance aspect will not be relevant at all.<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Miscellaneous_Functions&diff=15588Manual:Miscellaneous Functions2020-09-29T10:59:43Z<p>Smurf: /* registerAnonymousEventHandler */ Capture all events with "*" in Mudlet 4.10</p>
<hr />
<div>{{TOC right}}<br />
= Miscellaneous Functions =<br />
<br />
==addSupportedTelnetOption==<br />
;addSupportedTelnetOption(option)<br />
:Adds a telnet option, which when queried by a MUD server, Mudlet will return DO (253) on. Use this to register the telnet option that you will be adding support for with Mudlet - see [[Manual:Supported_Protocols#Adding_support_for_a_telnet_protocol|additional protocols]] section for more.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
<event handlers that add support for MSDP... see http://www.mudbytes.net/forum/comment/63920/#c63920 for an example><br />
<br />
-- register with Mudlet that it should not decline the request of MSDP support<br />
local TN_MSDP = 69<br />
addSupportedTelnetOption(TN_MSDP)<br />
</syntaxhighlight><br />
<br />
==alert==<br />
;alert([seconds])<br />
:alerts the user to something happening - makes Mudlet flash in the Windows window bar, bounce in the macOS dock, or flash on Linux.<br />
<br />
{{note}} Available in Mudlet 3.2+<br />
<br />
;Parameters<br />
* ''seconds:''<br />
:(optional) number of seconds to have the alert for. If not provided, Mudlet will flash until the user opens Mudlet again.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- flash indefinitely until Mudlet is open<br />
alert()<br />
<br />
-- flash for just 3 seconds<br />
alert(3)<br />
</syntaxhighlight><br />
<br />
==cfeedTriggers==<br />
;cfeedTriggers(str)<br />
:Like feedTriggers, but you can add color information using color names, similar to cecho.<br />
<br />
;Parameters<br />
* ''str'': The string to feed to the trigger engine. Include colors by name as black,red,green,yellow,blue,magenta,cyan,white and light_* versions of same. You can also use a number to get the ansi color corresponding to that number.<br />
:See also: [[Manual:Lua_Functions#feedTriggers|feedTriggers]]<br />
<br />
{{note}} Available in Mudlet 4.11+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
cfeedTriggers("<green:red>green on red<r> reset <124:100> foreground of ANSI124 and background of ANSI100<r>\n")<br />
</syntaxhighlight><br />
<br />
==closeMudlet==<br />
;closeMudlet()<br />
<br />
:Closes Mudlet and all profiles immediately.<br />
:See also: [[Manual:Lua_Functions#saveProfile|saveProfile()]]<br />
<br />
{{note}} Use with care. This potentially lead to data loss, if "save on close" is not activated and the user didn't save the profile manually as this will NOT ask for confirmation nor will the profile be saved. Also it does not consider if there are ''other'' profiles open if multi-playing: they '''all''' will be closed!<br />
<br />
{{note}} Available in Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
closeMudlet()<br />
</syntaxhighlight><br />
<br />
==denyCurrentSend==<br />
;denyCurrentSend()<br />
<br />
:Cancels a [[Manual:Lua_Functions#send|send()]] or user-entered command, but only if used within a [[Manual:Event_Engine#sysDataSendRequest|sysDataSendRequest]] event.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- cancels all "eat hambuger" commands<br />
function cancelEatHamburger(event, command)<br />
if command == "eat hamburger" then<br />
denyCurrentSend()<br />
cecho("<red>Denied! Didn't let the command through.\n")<br />
end<br />
end<br />
<br />
registerAnonymousEventHandler("sysDataSendRequest", "cancelEatHamburger")<br />
</syntaxhighlight><br />
<br />
==dfeedTriggers==<br />
;dfeedTriggers(str)<br />
:Like feedTriggers, but you can add color information using <r,g,b>, similar to decho.<br />
<br />
;Parameters<br />
* ''str'': The string to feed to the trigger engine. Include color information inside tags like decho.<br />
:See also: [[Manual:Lua_Functions#cfeedTriggers|cfeedTriggers]]<br />
:See also: [[Manual:Lua_Functions#decho|decho]]<br />
<br />
{{note}} Available in Mudlet 4.11+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
dfeedTriggers("<0,128,0:128,0,0>green on red<r> reset\n")<br />
</syntaxhighlight><br />
<br />
==disableModuleSync==<br />
;disableModuleSync(name)<br />
: Stops syncing the given module.<br />
<br />
;Parameter<br />
* ''name'': name of the module.<br />
<br />
:See also: [[Manual:Lua_Functions#enableModuleSync|enableModuleSync()]], [[Manual:Lua_Functions#getModuleSync|getModuleSync()]]<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
==enableModuleSync==<br />
;enableModuleSync(name)<br />
: Enables the sync for the given module name - any changes done to it will be saved to disk and if the module is installed in any other profile(s), it'll be updated in them as well on profile save.<br />
<br />
;Parameter<br />
* ''name'': name of the module to enable sync on.<br />
<br />
:See also: [[Manual:Lua_Functions#disableModuleSync|disableModuleSync()]], [[Manual:Lua_Functions#getModuleSync|getModuleSync()]]<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
==expandAlias==<br />
;expandAlias(command, [echoBackToBuffer])<br />
:Runs the command as if it was from the command line - so aliases are checked and if none match, it's sent to the game unchanged. <br />
<br />
;Parameters<br />
* ''command''<br />
: Text of the command you want to send to the game. Will be checked for aliases.<br />
* ''echoBackToBuffer''<br />
: (optional) If ''false'', the command will not be echoed back in your buffer. Defaults to ''true'' if omitted.<br />
<br />
{{note}} Using expandAlias is not recommended anymore as it is not very robust and may lead to problems down the road. The recommendation is to use lua functions instead. See [[Manual:Functions_vs_expandAlias]] for details and examples.<br />
<br />
{{note}} If you want to be using the ''matches'' table after calling ''expandAlias'', you should save it first, as, e.g. ''local oldmatches = matches'' before calling ''expandAlias'', since ''expandAlias'' will overwrite it after using it again.<br />
<br />
{{note}} Since '''Mudlet 3.17.1''' the optional second argument to echo the command on screen will be ineffective whilst the game server has negotiated the telnet ECHO option to provide the echoing of text we ''send'' to him.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
expandAlias("t rat")<br />
<br />
-- don't echo the command<br />
expandAlias("t rat", false)<br />
</syntaxhighlight><br />
<br />
==feedTriggers==<br />
;feedTriggers(text[, dataIsUtf8Encoded = true])<br />
:This function will have Mudlet parse the given text as if it came from the MUD - one great application is trigger testing. The built-in '''`echo''' alias provides this functionality as well.<br />
<br />
;Parameters<br />
* ''text:''<br />
:string which is sent to the trigger processing system almost as if it came from the MUD Game Server. This string must be byte encoded in a manner to match the currently selected ''Server Encoding''. <br />
* ''dataIsUtf8Encoded:''<br />
:Set this to false, if you need pre-Mudlet 4.0 behavior. Most players won't need this.<br />
:(Before Mudlet 4.0 the text had to be encoded directly in whatever encoding the setting in the preferences was set to. <br />
:(Encoding could involve using the Lua string character escaping mechanism of \ and a base 10 number for character codes from \1 up to \255 at maximum)<br />
:Since Mudlet 4.0 it is assumed that the text is UTF-8 encoded. It will then be automatically converted to the currently selected MUD Game Server encoding.<br />
:Preventing the automatic conversion can be useful to Mudlet developers testing things, or possibly to those who are creating handlers for Telnet protocols within the Lua subsystem, who need to avoid the transcoding of individual protocol bytes, when they might otherwise be seen as extended ASCII characters.)<br />
<br />
;Returns<br />
* ''true'' on success, ''nil'' and an error message if the text contains characters that cannot be conveyed by the current Game Server encoding.<br />
<br />
{{note}} Both the optional parameter dataIsUtf8Encoded and the returned value are only available since Mudlet 4.2.0<br />
<br />
{{note}} The trigger processing system also requires that some data is (or appears to be) received from the game to process the feedTriggers(), so use a send("\n") to get a new prompt (thus new data) right after or ensure that the ''text'' includes a new-line "\n" character so as to simulate a line of data from the Game Server.<br />
<br />
{{note}} It is important to ensure that in Mudlet 4.0.0 and beyond the text data only contains characters that can be encoded in the current Game Server encoding, from 4.2.0 the content is checked that it can successfully be converted from the UTF-8 that the Mudlet Lua subsystem uses internally into that particular encoding and if it cannot the function call will fail and not pass any of the data, this will be significant if the text component contains any characters that are not plain ASCII.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try using this on the command line<br />
`echo This is a sample line from the game<br />
<br />
-- You can use \n to represent a new line - you also want to use it before and after the text you’re testing, like so:<br />
feedTriggers("\nYou sit yourself down.\n")<br />
send("\n")<br />
<br />
-- The function also accept ANSI color codes that are used in MUDs. A sample table can be found http://codeworld.wikidot.com/ansicolorcodes<br />
feedTriggers("\nThis is \27[1;32mgreen\27[0;37m, \27[1;31mred\27[0;37m, \27[46mcyan background\27[0;37m," ..<br />
"\27[32;47mwhite background and green foreground\27[0;37m.\n")<br />
send("\n")<br />
</syntaxhighlight><br />
<br />
==getCharacterName==<br />
;getCharacterName()<br />
<br />
:Returns the name entered into the "Character name" field on the Connection Preferences form. Can be used to find out the name that might need to be handled specially in scripts or anything that needs to be personalized to the player. If there is nothing set in that entry will return an empty string.<br />
Introduced along with two other functions to enable MUD Game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined ''doLogin()'' function that may be replaced for more sophisticated requirements.<br />
<br />
:See also: [[#sendCharacterName|sendCharacterName()]], [[#sendCharacterPassword|sendCharacterPassword()]].<br />
<br />
{{note}} Expected to be available from Mudlet 4.10<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua send("cast 'glamor' " .. getCharacterName())<br />
<br />
You get a warm feeling passing from your core to the tips of your hands, feet and other body parts.<br />
A small twittering bird settles on your shoulder and starts to look adoringly at you.<br />
A light brown faun gambles around you and then nuzzles your hand.<br />
A tawny long-haired cat saunters over and start to rub itself against your ankles.<br />
A small twittering bird settles on your shoulder and starts to look adoringly at you.<br />
A light brown faun gambles around you and then nuzzles your hand.<br />
A small twittering bird settles on your shoulder and starts to look adoringly at you.<br />
A mangy dog trots up to you and proceeds to mark the bottom of your leggings.<br />
</syntaxhighlight><br />
<br />
==getModulePath==<br />
;path = getModulePath(module name)<br />
<br />
:Returns the location of a module on the disk. If the given name does not correspond to an installed module, it'll return <code>nil</code><br />
:See also: [[Manual:Lua_Functions#installModule|installModule()]]<br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getModulePath("mudlet-mapper")<br />
</syntaxhighlight><br />
<br />
==getModulePriority==<br />
;priority = getModulePriority(module name)<br />
<br />
:Returns the priority of a module as an integer. This determines the order modules will be loaded in - default is 0. Useful if you have a module that depends on another module being loaded first, for example.<br />
:See also: [[Manual:Lua_Functions#setModulePriority|setModulePriority()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getModulePriority("mudlet-mapper")<br />
</syntaxhighlight><br />
<br />
==getModuleSync==<br />
;getModuleSync(name)<br />
: returns false if module sync is not active, true if it is active and nil if module is not found.<br />
<br />
;Parameter<br />
* ''name'': name of the module<br />
<br />
:See also: [[Manual:Lua_Functions#enableModuleSync|enableModuleSync()]], [[Manual:Lua_Functions#disableModuleSync|disableModuleSync()]]<br />
{{note}} Available in Mudlet 4.8+<br />
<br />
==getMudletHomeDir==<br />
;getMudletHomeDir()<br />
:Returns the current home directory of the current profile. This can be used to store data, save statistical information, or load resource files from packages.<br />
<br />
{{note}} intentionally uses forward slashes <code>/</code> as separators on Windows since [[Manual:UI_Functions#setLabelStyleSheet|stylesheets]] require them.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save a table<br />
table.save(getMudletHomeDir().."/myinfo.dat", myinfo)<br />
<br />
-- or access package data. The forward slash works even on Windows fine<br />
local path = getMudletHomeDir().."/mypackagename"<br />
</syntaxhighlight><br />
<br />
==getMudletInfo==<br />
;getMudletInfo()<br />
:Prints debugging information about the Mudlet that you're running - this can come in handy for diagnostics.<br />
<br />
Don't use this command in your scripts to find out if certain features are supported in Mudlet - there are better functions available for this.<br />
<br />
{{note}} Available since Mudlet 4.8+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getMudletInfo()<br />
</syntaxhighlight><br />
<br />
==getMudletVersion==<br />
;getMudletVersion(style)<br />
:Returns the current Mudlet version. Note that you shouldn't hardcode against a specific Mudlet version if you'd like to see if a function is present - instead, check for the existence of the function itself. Otherwise, checking for the version can come in handy if you'd like to test for a broken function or so on.<br />
<br />
See also: [[#mudletOlderThan|mudletOlderThan()]]<br />
<br />
{{note}} Available since Mudlet 3.0.0-alpha.<br />
<br />
;Parameters<br />
* ''style:''<br />
:(optional) allows you to choose what you'd like returned. By default, if you don't specify it, a key-value table with all the values will be returned: major version, minor version, revision number and the optional build name.<br />
<br />
;Values you can choose<br />
* ''"string"'':<br />
:Returns the full Mudlet version as text.<br />
* ''"table"'':<br />
:Returns the full Mudlet version as four values (multi-return)<br />
* ''"major"'':<br />
:Returns the major version number (the first one).<br />
* ''"minor"'':<br />
:Returns the minor version number (the second one).<br />
* ''"revision"'':<br />
:Returns the revision version number (the third one).<br />
* ''"build"'':<br />
:Returns the build of Mudlet (the ending suffix, if any).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- see the full Mudlet version as text:<br />
getMudletVersion("string")<br />
-- returns for example "3.0.0-alpha"<br />
<br />
-- check that the major Mudlet version is at least 3:<br />
if getMudletVersion("major") >= 3 then echo("You're running on Mudlet 3+!") end<br />
-- but mudletOlderThan() is much better for this:<br />
if mudletOlderThan(3) then echo("You're running on Mudlet 3+!") end <br />
<br />
-- if you'd like to see if a function is available however, test for it explicitly instead:<br />
if setAppStyleSheet then<br />
-- example credit to http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qscrollbar<br />
setAppStyleSheet[[<br />
QScrollBar:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
width: 15px;<br />
margin: 22px 0 22px 0;<br />
}<br />
QScrollBar::handle:vertical {<br />
background: white;<br />
min-height: 20px;<br />
}<br />
QScrollBar::add-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: bottom;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::sub-line:vertical {<br />
border: 2px solid grey;<br />
background: #32CC99;<br />
height: 20px;<br />
subcontrol-position: top;<br />
subcontrol-origin: margin;<br />
}<br />
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {<br />
border: 2px solid grey;<br />
width: 3px;<br />
height: 3px;<br />
background: white;<br />
}<br />
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {<br />
background: none;<br />
}<br />
]]<br />
end<br />
</syntaxhighlight><br />
<br />
==getOS==<br />
;getOS()<br />
<br />
:Returns the name of the Operating system. Useful for applying particular scripts only under particular operating systems, such as applying a stylesheet only when the OS is Windows. <br />
:Returned string will be one of these: "cygwin", "windows", "mac", "linux", "hurd", "freebsd", "kfreebsd", "openbsd", "netbsd", "bsd4", "unix" or "unknown" otherwise.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getOS())<br />
<br />
if getOS() == "windows" then<br />
echo("\nWindows OS detected.\n")<br />
else<br />
echo("\nDetected Operating system is NOT windows.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
;Using getOS() to detect a specific Windows version<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local os = getOS()<br />
if os ~= "windows" then<br />
echo("\nToday we'd like to detect only windows version\n")<br />
end<br />
<br />
-- open command window and send "ver"<br />
local f = io.popen("ver") <br />
-- read command output<br />
local ver = f:read("*a")<br />
-- close the windows (user may see a small flicker on screen)<br />
f:close()<br />
-- Example output: Microsoft Windows [Version 6.1.7601]<br />
-- Output may change due to language settings so use a language indipendent regexp<br />
local major = rex.match(ver,"\w+ ([0-9]+)\.[\d\.]+") --<br />
if major == nil then <br />
echo("\nNo version detect. Very bad!\n") <br />
else<br />
echo("\nVersion is: " .. major .. "!\n") <br />
end<br />
</syntaxhighlight><br />
<br />
==getProfileName==<br />
;getProfileName()<br />
<br />
:Returns the name of the profile. Useful when combined with [[Manual:Mudlet_Object_Functions#raiseGlobalEvent|raiseGlobalEvent()]] to know which profile a global event came from.<br />
<br />
{{note}} Available in Mudlet 3.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- if connected to the Achaea profile, will print Achaea to the main console<br />
echo(getProfileName())<br />
</syntaxhighlight><br />
<br />
==getCommandSeparator==<br />
;getCommandSeparator()<br />
<br />
:Returns the command separator in use by the profile.<br />
<br />
{{note}} Available in Mudlet 3.18+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- if your command separator is ;;, the following would send("do thing 1;;do thing 2"). <br />
-- This way you can determine what it is set to and use that and share this script with <br />
-- someone who has changed their command separator.<br />
-- Note: This is not really the preferred way to send this, using sendAll("do thing 1", "do thing 2") is,<br />
-- but this illustates the use case.<br />
local s = getCommandSeparator()<br />
expandAlias("do thing 1" .. s .. "do thing 2")<br />
</syntaxhighlight><br />
<br />
==getServerEncoding==<br />
;getServerEncoding()<br />
:Returns the current server [https://www.w3.org/International/questions/qa-what-is-encoding data encoding] in use.<br />
<br />
:See also: [[#setServerEncoding|setServerEncoding()]], [[#getServerEncodingsList|getServerEncodingsList()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getServerEncoding()<br />
</syntaxhighlight><br />
<br />
==getServerEncodingsList==<br />
;getServerEncodingsList()<br />
:Returns an indexed list of the server [https://www.w3.org/International/questions/qa-what-is-encoding data encodings] that Mudlet knows. This is not the list of encodings the servers knows - there's unfortunately no agreed standard for checking that. See [[Manual:Unicode#Changing_encoding|encodings in Mudlet]] for the list of which encodings are available in which Mudlet version.<br />
<br />
:See also: [[#setServerEncoding|setServerEncoding()]], [[#getServerEncoding|getServerEncoding()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if UTF-8 is available:<br />
if table.contains(getServerEncodingsList(), "UTF-8") then<br />
print("UTF-8 is available!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getWindowsCodepage==<br />
;getWindowsCodepage()<br />
:Returns the current [https://docs.microsoft.com/en-us/windows/desktop/Intl/code-page-identifiers codepage] of your Windows system.<br />
<br />
{{Note}} Available since Mudlet 3.22<br />
{{Note}} This function only works on Windows - It is only needed internally in Mudlet to enable Lua to work with non-ASCII usernames (e.g. Iksiński, Jäger) for the purposes of IO. Linux and macOS work fine with with these out of the box.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(getWindowsCodepage())<br />
</syntaxhighlight><br />
<br />
==hfeedTriggers==<br />
;hfeedTriggers(str)<br />
:Like feedTriggers, but you can add color information using #RRGGBB in hex, similar to hecho.<br />
<br />
;Parameters<br />
* ''str'': The string to feed to the trigger engine. Include color information in the same manner as hecho.<br />
:See also: [[Manual:Lua_Functions#dfeedTriggers|dfeedTriggers]]<br />
:See also: [[Manual:Lua_Functions#hecho|hecho]]<br />
<br />
{{note}} Available in Mudlet 4.11+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
hfeedTriggers("#008000,800000green on red#r reset\n")<br />
</syntaxhighlight><br />
<br />
==installModule==<br />
;installModule(location)<br />
:Installs a Mudlet XML, zip, or mpackage as a module.<br />
<br />
;Parameters<br />
* ''location:''<br />
:Exact location of the file install.<br />
<br />
:See also: [[#uninstallModule | uninstallModule()]], [[Manual:Event_Engine#sysLuaInstallModule | Event: sysLuaInstallModule]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
installModule([[C:\Documents and Settings\bub\Desktop\myalias.xml]])<br />
</syntaxhighlight><br />
<br />
==installPackage==<br />
;installPackage(location)<br />
:Installs a Mudlet XML or package.<br />
<br />
;Parameters<br />
* ''location:''<br />
:Exact location of the xml or package to install.<br />
<br />
:See also: [[#uninstallPackage | uninstallPackage()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
installPackage([[C:\Documents and Settings\bub\Desktop\myalias.xml]])<br />
</syntaxhighlight><br />
<br />
==killAnonymousEventHandler==<br />
;killAnonymousEventHandler(handler id)<br />
:Disables and removes the given event handler.<br />
<br />
;Parameters<br />
* ''handler id''<br />
:ID of the event handler to remove as returned by the [[ #registerAnonymousEventHandler | registerAnonymousEventHandler ]] function.<br />
<br />
:See also: [[ #registerAnonymousEventHandler | registerAnonymousEventHandler ]]<br />
<br />
{{note}} Available in Mudlet 3.5+.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- registers an event handler that prints the first 5 GMCP events and then terminates itself<br />
<br />
local counter = 0<br />
local handlerId = registerAnonymousEventHandler("gmcp", function(_, origEvent)<br />
print(origEvent)<br />
counter = counter + 1<br />
if counter == 5 then<br />
killAnonymousEventHandler(handlerId)<br />
end<br />
end)<br />
</syntaxhighlight><br />
<br />
==loadWindowLayout==<br />
;loadWindowLayout<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]]<br />
<br />
{{note}} Available in Mudlet 3.2+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><br />
<br />
==mudletOlderThan==<br />
;mudletOlderThan(major, [minor], [patch])<br />
:Returns true if Mudlet is older than the given version to check. This is useful if you'd like to use a feature that you can't check for easily, such as coroutines support. However, if you'd like to check if a certain function exists, do not use this and use <code>if mudletfunction then</code> - it'll be much more readable and reliable.<br />
<br />
See also: [[#getMudletVersion|getMudletVersion()]]<br />
<br />
;Parameters<br />
* ''major:''<br />
:Mudlet major version to check. Given a Mudlet version 3.0.1, 3 is the major version, second 0 is the minor version, and third 1 is the patch version.<br />
* ''minor:''<br />
:(optional) minor version to check.<br />
* ''patch:''<br />
:(optional) patch version to check.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- stop doing the script of Mudlet is older than 3.2<br />
if mudletOlderThan(3,2) then return end<br />
<br />
-- or older than 2.1.3<br />
if mudletOlderThan(2, 1, 3) then return end<br />
<br />
-- however, if you'd like to check that a certain function is available, like getMousePosition(), do this instead:<br />
if not getMousePosition then return end<br />
<br />
-- if you'd like to check that coroutines are supported, do this instead:<br />
if not mudlet.supportscoroutines then return end<br />
</syntaxhighlight><br />
<br />
==openWebPage==<br />
;openWebPage(URL)<br />
:Opens the browser to the given webpage.<br />
<br />
;Parameters<br />
* ''URL:''<br />
:Exact URL to open.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
openWebPage("http://google.com")<br />
</syntaxhighlight><br />
<br />
Note: This function can be used to open a local file or file folder as well by using "file:///" and the file path instead of "http://".<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
openWebPage("file:///"..getMudletHomeDir().."file.txt")<br />
</syntaxhighlight><br />
<br />
==playSoundFile==<br />
;playSoundFile(fileName, volume)<br />
:This function plays a sound file (no limit on how many you can start).<br />
<br />
;Parameters:<br />
* ''fileName:''<br />
:Exact path of the sound file.<br />
* ''volume:''<br />
:Set the volume (in percent) of the sound. If no volume is given, 100 (maximum) is used.<br />
:Optional, available since 3.0<br />
<br />
See also: [[#stopSounds|stopSounds()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- play a sound in Windows<br />
playSoundFile([[C:\My folder\boing.wav]])<br />
<br />
-- play a sound in Linux<br />
playSoundFile([[/home/myname/Desktop/boingboing.wav]])<br />
<br />
-- play a sound from a package<br />
playSoundFile(getMudletHomeDir().. [[/mypackage/boingboing.wav]])<br />
<br />
-- play a sound in Linux at half volume<br />
playSoundFile([[/home/myname/Desktop/boingboing.wav]], 50)<br />
</syntaxhighlight><br />
<br />
==registerAnonymousEventHandler==<br />
;registerAnonymousEventHandler(event name, functionReference, [one shot])<br />
:Registers a function to an event handler, not requiring you to set one up via script. [[Manual:Event_Engine#Mudlet-raised_events|See here]] for a list of Mudlet-raised events. The function may be refered to either by name as a string containing a global function name, or with the lua function object itself.<br />
<br />
:The optional <code>one shot</code> parameter allows you to automatically kill an event handler after it is done by giving a true value. If the event you waited for did not occur yet, return <code>true</code> from the function to keep it registered.<br />
<br />
:The function returns an ID that can be used in [[Manual:Lua_Functions#killAnonymousEventHandler|killAnonymousEventHandler()]] to unregister the handler again.<br />
<br />
:If you use an asterisk ''("*")'' as the event name, your code will capture all events. Useful for debugging, or integration with external programs.<br />
<br />
{{note}} The ability to refer lua functions directly, the <code>one shot</code> parameter and the returned ID are features of Mudlet 3.5 and above.<br />
<br />
{{note}} The ''"*"'' all-events capture was added in Mudlet 4.10.<br />
<br />
;See also<br />
:[[Manual:Lua_Functions#killAnonymousEventHandler|killAnonymousEventHandler()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from the God Wars 2 (http://godwars2.org) Mudlet UI - forces the window to keep to a certain size<br />
function keepStaticSize()<br />
setMainWindowSize(1280,720)<br />
end -- keepStaticSize<br />
<br />
if keepStaticSizeEventHandlerID then killAnonymousEventHandler(keepStaticSizeEventHandlerID) end -- clean up any already registered handlers for this function<br />
keepStatisSizeEventHandlerID = registerAnonymousEventHandler("sysWindowResizeEvent", "keepStaticSize") -- register the event handler and save the ID for later killing<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- simple inventory tracker for GMCP enabled games. This version does not leak any of the methods<br />
-- or tables into the global namespace. If you want to access it, you should export the inventory<br />
-- table via an own namespace.<br />
local inventory = {}<br />
<br />
local function inventoryAdd()<br />
if gmcp.Char.Items.Add.location == "inv" then<br />
inventory[#inventory + 1] = table.deepcopy(gmcp.Char.Items.Add.item)<br />
end<br />
end<br />
if inventoryAddHandlerID then killAnonymousEventHandler(inventoryAddHandlerID) end -- clean up any already registered handlers for this function<br />
inventoryAddHandlerID = registerAnonymousEventHandler("gmcp.Char.Items.Add", inventoryAdd) -- register the event handler and save the ID for later killing<br />
<br />
local function inventoryList()<br />
if gmcp.Char.Items.List.location == "inv" then<br />
inventory = table.deepcopy(gmcp.Char.Items.List.items)<br />
end<br />
end<br />
if inventoryListHandlerID then killAnonymousEventHandler(inventoryListHandlerID) end -- clean up any already registered handlers for this function<br />
inventoryListHandlerID = registerAnonymousEventHandler("gmcp.Char.Items.List", inventoryList) -- register the event handler and save the ID for later killing<br />
<br />
local function inventoryUpdate()<br />
if gmcp.Char.Items.Remove.location == "inv" then<br />
local found<br />
local updatedItem = gmcp.Char.Items.Update.item<br />
for index, item in ipairs(inventory) do<br />
if item.id == updatedItem.id then<br />
found = index<br />
break<br />
end<br />
end<br />
if found then<br />
inventory[found] = table.deepcopy(updatedItem)<br />
end<br />
end<br />
end<br />
if inventoryUpdateHandlerID then killAnonymousEventHandler(inventoryUpdateHandlerID) end -- clean up any already registered handlers for this function<br />
inventoryUpdateHandlerID = registerAnonymousEventHandler("gmcp.Char.Items.Update", inventoryUpdate)<br />
<br />
local function inventoryRemove()<br />
if gmcp.Char.Items.Remove.location == "inv" then<br />
local found<br />
local removedItem = gmcp.Char.Items.Remove.item<br />
for index, item in ipairs(inventory) do<br />
if item.id == removedItem.id then<br />
found = index<br />
break<br />
end<br />
end<br />
if found then<br />
table.remove(inventory, found)<br />
end<br />
end<br />
end<br />
if inventoryRemoveHandlerID then killAnonymousEventHandler(inventoryRemoveHandlerID) end -- clean up any already registered handlers for this function<br />
inventoryRemoveHandlerID = registerAnonymousEventHandler("gmcp.Char.Items.Remove", inventoryRemove)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- downloads a package from the internet and kills itself after it is installed.<br />
local saveto = getMudletHomeDir().."/dark-theme-mudlet.zip"<br />
local url = "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip"<br />
<br />
if myPackageInstallHandler then killAnonymousEventHandler(myPackageInstallHandler) end<br />
myPackageInstallHandler = registerAnonymousEventHandler(<br />
"sysDownloadDone",<br />
function(_, filename)<br />
if filename ~= saveto then<br />
return true -- keep the event handler since this was not our file<br />
end<br />
installPackage(saveto)<br />
os.remove(b)<br />
end,<br />
true<br />
)<br />
<br />
downloadFile(saveto, url)<br />
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")<br />
</syntaxhighlight><br />
<br />
==reloadModule==<br />
;reloadModule(module name)<br />
:Reload a module (by uninstalling and reinstalling).<br />
<br />
:See also: [[#installModule|installModule()]], [[#uninstallModule|uninstallModule()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
reloadModule("3k-mapper")<br />
</syntaxhighlight><br />
<br />
==resetProfile==<br />
;resetProfile()<br />
<br />
:Reloads your entire Mudlet profile - as if you've just opened it. All UI elements will be cleared, so this useful when you're coding your UI.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetProfile()<br />
</syntaxhighlight><br />
<br />
The function used to require input from the game to work, but as of Mudlet 3.20 that is no longer the case.<br />
<br />
<br />
{{note}} Don't put resetProfile() in the a script-item in the script editor as the script will be reloaded by resetProfile() as well better use <br />
<syntaxhighlight lang="lua"><br />
lua resetProfile()<br />
</syntaxhighlight><br />
in your commandline or make an Alias containing resetProfile().<br />
<br />
==saveProfile==<br />
;saveProfile()<br />
<br />
:Saves the current Mudlet profile to disk, which is equivalent to pressing the "Save Profile" button.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveProfile()<br />
</syntaxhighlight><br />
<br />
==saveWindowLayout==<br />
;saveWindowLayout<br />
:Saves the layout of userwindows (floating miniconsoles), in case you'd like to load them again later.<br />
<br />
:See also: [[#loadWindowLayout|loadWindowLayout()]]<br />
<br />
{{note}} Available in Mudlet 3.2+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><br />
<br />
==sendCharacterName==<br />
;sendCharacterName()<br />
<br />
Sends the name entered into the "Character name" field on the Connection Preferences form directly to the MUD Game Server. Returns ''true'' unless there is nothing set in that entry in which case a ''nil'' and an error message will be returned instead.<br />
<br />
Introduced along with two other functions to enable MUD Game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined ''doLogin()'' function that may be replaced for more sophisticated requirements.<br />
:See also: [[#getCharacterName|getCharacterName()]], [[#sendCharacterPassword|sendCharacterPassword()]].<br />
<br />
{{note}} Expected to be available from Mudlet 4.9<br />
<br />
==sendCharacterPassword==<br />
;sendCharacterPassword()<br />
<br />
Sends the password entered into the "Password" field on the Connection Preferences form directly to the MUD Game Server. Returns ''true'' unless there is nothing set in that entry or it is too long after (or before) a connection was successfully made in which case a ''nil'' and an error message will be returned instead.<br />
<br />
Introduced along with two other functions to enable MUD Game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined ''doLogin()'' function, reproduced below, that may be replaced for more sophisticated requirements.<br />
:See also: [[#getCharacterName|getCharacterName()]], [[#sendCharacterName|sendCharacterName()]].<br />
<br />
{{note}} Expected to be available from Mudlet 4.9 <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- The default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:<br />
function doLogin()<br />
if getCharacterName() ~= "" then<br />
tempTime(2.0, [[sendCharacterName()]], 1)<br />
tempTime(3.0, [[sendCharacterPassword()]], 1)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==sendSocket==<br />
;sendSocket(data)<br />
<br />
:Sends given binary data as-is to the MUD. You can use this to implement support for a [[Manual:Supported_Protocols#Adding_support_for_a_telnet_protocol|new telnet protocol]], [http://forums.mudlet.org/viewtopic.php?f=5&t=2272 simultronics] [http://forums.mudlet.org/viewtopic.php?f=5&t=2213#p9810 login] or etcetera.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
TN_IAC = 255<br />
TN_WILL = 251<br />
TN_DO = 253<br />
TN_SB = 250<br />
TN_SE = 240<br />
TN_MSDP = 69<br />
<br />
MSDP_VAL = 1<br />
MSDP_VAR = 2<br />
<br />
sendSocket( string.char( TN_IAC, TN_DO, TN_MSDP ) ) -- sends IAC DO MSDP<br />
<br />
--sends: IAC SB MSDP MSDP_VAR "LIST" MSDP_VAL "COMMANDS" IAC SE<br />
local msg = string.char( TN_IAC, TN_SB, TN_MSDP, MSDP_VAR ) .. " LIST " ..string.char( MSDP_VAL ) .. " COMMANDS " .. string.char( TN_IAC, TN_SE )<br />
sendSocket( msg )<br />
</syntaxhighlight><br />
<br />
{{Note}} Remember that should it be necessary to send the byte value of 255 as a ''data'' byte and not as the Telnet '''IAC''' value it is required to repeat it for Telnet to ignore it and not treat it as the latter.<br />
<br />
==setMergeTables==<br />
;setMergeTables(module)<br />
:Makes Mudlet merge the table of the given GMCP or MSDP module instead of overwriting the data. This is useful if the game sends only partial updates which need combining for the full data. By default "Char.Status" is the only merged module.<br />
<br />
;Parameters<br />
* ''module:''<br />
:Name of the GMCP or MSDP module that should be merged as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMergeTables("Char.Skills", "Char.Vitals")<br />
</syntaxhighlight><br />
<br />
==setModulePriority==<br />
;setModulePriority(moduleName, priority)<br />
<br />
:Sets the module priority on a given module as a number - the module priority determines the order modules are loaded in, which can be helpful if you have ones dependent on each other. This can also be set from the module manager window.<br />
: See also: [[#getModulePriority|getModulePriority()]]<br />
<br />
<syntaxhighlight lang="lua"><br />
setModulePriority("mudlet-mapper", 1)<br />
</syntaxhighlight><br />
<br />
==setServerEncoding==<br />
;setServerEncoding(encoding)<br />
:Makes Mudlet use the specified [https://www.w3.org/International/questions/qa-what-is-encoding encoding] for communicating with the game.<br />
<br />
;Parameters<br />
* ''encoding:''<br />
:Encoding to use.<br />
<br />
:See also: [[#getServerEncodingsList|getServerEncodingsList()]], [[#getServerEncoding|getServerEncoding()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- use UTF-8 if Mudlet knows it. Unfortunately there's no way to check if the game's server knows it too.<br />
if table.contains(getServerEncodingsList(), "UTF-8") then<br />
setServerEncoding("UTF-8")<br />
end<br />
</syntaxhighlight><br />
<br />
==spawn==<br />
;spawn(readFunction, processToSpawn[, ...arguments])<br />
<br />
:Spawns a process and opens a communicatable link with it - ''read function'' is the function you'd like to use for reading output from the process, and ''t'' is a table containing functions specific to this connection - ''send(data)'', ''true/false = isRunning()'', and ''close()''.<br />
<br />
:This allows you to setup RPC communication with another process.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function<br />
local f = spawn(display, "ls")<br />
display(f.isRunning())<br />
f.close()<br />
</syntaxhighlight><br />
<syntaxhighlight lang="lua"><br />
local f = spawn(display, "ls", "-la")<br />
display(f.isRunning())<br />
f.close()<br />
</syntaxhighlight><br />
<br />
==startLogging==<br />
;startLogging(state)<br />
<br />
:Control logging of the main console text as text or HTML (as specified by the "Save log files in HTML format instead of plain text" setting on the "General" tab of the "Profile preferences" or "Settings" dialog). Despite being called startLogging it can also stop the process and correctly close the file being created. The file will have an extension of type ".txt" or ".html" as appropriate and the name will be in the form of a date/time "yyyy-MM-dd#hh-mm-ss" using the time/date of when logging started. Note that this control parallels the corresponding icon in the "bottom buttons" for the profile and that button can also start and stop the same logging process and will reflect the state as well.<br />
<br />
;Parameters<br />
* ''state:''<br />
:Required: logging state. Passed as a boolean<br />
<br />
;Returns (4 values)<br />
* ''successful (bool)''<br />
:''true'' if the logging state actually changed; if, for instance, logging was already active and ''true'' was supplied then no change in logging state actually occurred and ''nil'' will be returned (and logging will continue).<br />
* ''fileName (string)''<br />
:The log will be/is being written to the path/file name returned.<br />
* ''message (string)''<br />
:A displayable message given one of four messages depending on the current and previous logging states, this will include the file name except for the case when logging was not taking place and the supplied argument was also ''false''.<br />
* ''code (number)''<br />
:A value indicating the response to the system to this instruction:<br />
* 0 = logging has just stopped<br />
* 1 = logging has just started<br />
* -1 = logging was already in progress so no change in logging state<br />
* -2 = logging was already not in progress so no change in logging state<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- start logging<br />
startLogging(true)<br />
<br />
-- stop logging<br />
startLogging(false)<br />
</syntaxhighlight><br />
<br />
==stopSounds==<br />
;stopSounds()<br />
<br />
:Stops all currently playing sounds.<br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
:See also: [[#playSoundFile|playSoundFile()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
stopSounds()<br />
</syntaxhighlight><br />
<br />
==timeframe==<br />
;timeframe(vname, true_time, nil_time, ...)<br />
<br />
:A utility function that helps you change and track variable states without using a lot of tempTimers.<br />
<br />
{{note}} Available in Mudlet 3.6+<br />
<br />
;Parameters<br />
* ''vname:''<br />
:A string or function to use as the variable placeholder.<br />
* ''true_time:''<br />
:Time before setting the variable to true. Can be a number or a table in the format: <code>{time, value}</code><br />
* ''nil_time:''<br />
:(optional) Number of seconds until <code>vname</code> is set back to nil. Leaving it undefined will leave it at whatever it was set to last. Can be a number of a table in the format: <code>{time, value}</code><br />
* ''...:''<br />
:(optional) Further list of times and values to set the variable to, in the following format: <code>{time, value}</code><br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sets the global 'limiter' variable to true immediately (see the 0) and back to nil in one second (that's the 1).<br />
timeframe("limiter", 0, 1)<br />
<br />
-- An angry variable 'giant' immediately set to "fee", followed every second after by "fi", "fo", and "fum" before being reset to nil at four seconds.<br />
timeframe("giant", {0, "fee"}, 4, {1, "fi"}, {2, "fo"}, {3, "fum"})<br />
<br />
-- sets the local 'width' variable to true immediately and back to nil in one second.<br />
local width<br />
timeframe(function(value) width = value end, 0, 1)<br />
</syntaxhighlight><br />
<br />
==translateTable==<br />
;translateTable(directions, [languagecode])<br />
<br />
:Given a table of directions (such as <code>speedWalkDir</code>), translates directions to another language for you. Right now, it can only translate it into the language of Mudlet's user interface - but [https://github.com/Mudlet/Mudlet/issues/new let us know if you need more].<br />
<br />
{{note}} Available in Mudlet 3.22+<br />
<br />
;Parameters<br />
* ''directions:''<br />
:An indexed table of directions (eg. <code>{"sw", "w", "nw", "s"}</code>).<br />
* ''languagecode:''<br />
:(optional) Language code (eg <code>ru_RU</code> or <code>it_IT</code>) - by default, <code>mudlet.translations.interfacelanguage</code> is used.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- get the path from room 2 to room 5 and translate directions<br />
if getPath(2, 5) then<br />
speedWalkDir = translateTable(speedWalkDir)<br />
print("Translated directions:")<br />
display(speedWalkDir)<br />
</syntaxhighlight><br />
<br />
==uninstallModule==<br />
;uninstallModule(name)<br />
<br />
:Uninstalls a Mudlet module with the given name.<br />
<br />
:See also: [[#installModule | installModule()]], [[Manual:Event_Engine#sysLuaUninstallModule | Event: sysLuaUninstallModule]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
uninstallModule("myalias")<br />
</syntaxhighlight><br />
<br />
==uninstallPackage==<br />
;uninstallPackage(name)<br />
<br />
:Uninstalls a Mudlet package with the given name.<br />
<br />
:See also: [[#installPackage | installPackage()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
uninstallPackage("myalias")<br />
</syntaxhighlight><br />
<br />
==unzipAsync==<br />
;unzipAsync(path, location)<br />
<br />
:Unzips the zip file at path, extracting the contents to the location provided. Returns true if it is able to start unzipping, or nil+message if it cannot<br />
Raises the <code>sysUnzipDone</code> event with the zip file location and location unzipped to as arguments if unzipping is successful, and <code>sysUnzipError</code> with the same arguments if it is not.<br />
<br />
{{note}}Available since Mudlet 4.6<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function handleUnzipEvents(event, ...)<br />
local args = {...}<br />
local zipName = args[1]<br />
local unzipLocation = args[2]<br />
if event == "sysUnzipDone" then<br />
cecho(string.format("<green>Unzip successful! Unzipped %s to %s\n", zipName, unzipLocation))<br />
elseif event == "sysUnzipError" then<br />
cecho(string.format("<firebrick>Unzip failed! Tried to unzip %s to %s\n", zipName, unzipLocation))<br />
end<br />
end<br />
if unzipSuccessHandler then killAnonymousEventHandler(unzipSuccessHandler) end<br />
if unzipFailureHandler then killAnonymousEventHandler(unzipFailureHandler) end<br />
unzipSuccessHandler = registerAnonymousEventHandler("sysUnzipDone", "handleUnzipEvents")<br />
unzipFailureHandler = registerAnonymousEventHandler("sysUnzipError", "handleUnzipEvents")<br />
--use the path to your zip file for this, not mine<br />
local zipFileLocation = "/home/demonnic/Downloads/Junkyard_Orc.zip" <br />
--directory to unzip to, it does not need to exist but you do need to be able to create it<br />
local unzipLocation = "/home/demonnic/Downloads/Junkyard_Orcs" <br />
unzipAsync(zipFileLocation, unzipLocation) -- this will work<br />
unzipAsync(zipFileLocation .. "s", unzipLocation) --demonstrate error, will happen first because unzipping takes time</syntaxhighlight><br />
<br />
==yajl.to_string==<br />
;yajl.to_string(data)<br />
<br />
:Encodes a Lua table into JSON data and returns it as a string. This function is very efficient - if you need to encode into JSON, use this.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- on IRE MUDs, you can send a GMCP request to request the skills in a particular skillset. Here's an example:<br />
sendGMCP("Char.Skills.Get "..yajl.to_string{group = "combat"})<br />
<br />
-- you can also use it to convert a Lua table into a string, so you can, for example, store it as room's userdata<br />
local toserialize = yajl.to_string(continents)<br />
setRoomUserData(1, "areaContinents", toserialize)<br />
</syntaxhighlight><br />
<br />
<br />
==yajl.to_value==<br />
;yajl.to_value(data)<br />
<br />
:Decodes JSON data (as a string) into a Lua table. This function is very efficient - if you need to dencode into JSON, use this.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- given the serialization example above with yajl.to_string, you can deserialize room userdata back into a table<br />
local tmp = getRoomUserData(1, "areaContinents")<br />
if tmp == "" then return end<br />
<br />
local continents = yajl.to_value(tmp)<br />
display(continents)<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Basic_Essentials&diff=15544Manual:Basic Essentials2020-09-13T11:21:06Z<p>Smurf: /* send */ servers aren't male</p>
<hr />
<div>{{TOC right}}<br />
= Basic Essentials =<br />
These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
<br />
==send==<br />
;send(command, showOnScreen)<br />
:This sends "command" directly to the network layer, skipping the alias matching. The optional second argument of type boolean (print) determines if the outgoing command is to be echoed on the screen.<br />
<br />
See also: [[Manual:Networking_Functions#sendAll|sendAll()]], [[Manual:Lua_Functions#speedwalk|speedwalk()]]<br />
<br />
{{note}} If you want your command to be checked as if it's an alias, use [[Manual:Miscellaneous Functions#expandAlias|expandAlias()]] instead - send() will ignore them.<br />
<br />
<syntaxhighlight lang="lua"><br />
send("Hello Jane") --echos the command on the screen<br />
send("Hello Jane", true) --echos the command on the screen<br />
send("Hello Jane", false) --does not echo the command on the screen<br />
<br />
-- use a variable in the send:<br />
send("kick "..target)<br />
<br />
-- to send directions:<br />
speedwalk("s;s;w;w;w;w;w;w;w;")<br />
<br />
-- to send many things:<br />
sendAll("hi", "open door e", "e", "get item", "sit")<br />
</syntaxhighlight><br />
<br />
{{note}} Since '''Mudlet 3.17.1''' the optional second argument to echo the command on screen will be ineffective whilst the game server has negotiated the telnet ECHO option to provide the echoing of text we ''send'' to it.<br />
<br />
==echo==<br />
;echo([miniconsoleName or labelName], text)<br />
:This function appends text at the end of the current line.<br />
<br />
;Parameters <br />
* ''miniconsoleName:'' (optional) the miniconsole to echo to, or:<br />
* ''labelName:'' (optional) the label to echo to.<br />
* ''text:'' text you'd like to see printed. You can use \n in an echo to insert a new line. If you're echoing this to a label, you can also use styling to colour, center, increase/decrease size of text and various other formatting options [http://doc.qt.io/qt-5/richtext-html-subset.html as listed here].<br />
<br />
See also: [[Manual:Lua_Functions#moveCursor|moveCursor()]], [[Manual:Lua_Functions#insertText|insertText()]], [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#hecho|hecho()]]<br />
<br />
As of Mudlet 4.8+, a single line is capped to 10,000 characters (this is when ~200 at most will fit on one line on your screen).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- a miniconsole example<br />
<br />
-- first, determine the size of your screen<br />
local windowWidth, windowHeight = getMainWindowSize()<br />
<br />
-- create the miniconsole<br />
createMiniConsole("sys", windowWidth-650,0,650,300)<br />
setBackgroundColor("sys",255,69,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example<br />
setWindowWrap("sys", 40)<br />
<br />
echo("sys","Hello world!\n")<br />
cecho("sys", "<:OrangeRed>This is random spam with the same background\n")<br />
cecho("sys", "<blue:OrangeRed>and this is with a blue foreground. ")<br />
cecho("sys", "<bisque:BlueViolet>Lastly, this is with both a foreground and a background.\n")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- a label example<br />
<br />
-- This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle <br />
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent <br />
-- and 255 opaque) the background text can still be read through.<br />
local width, height = getMainWindowSize()<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)<br />
resizeWindow("messageBox",500,70)<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 )<br />
setBackgroundColor("messageBox", 255, 204, 0, 200)<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])<br />
</syntaxhighlight><br />
<br />
==display==<br />
;display(content)<br />
:This is much like echo, in that is will show text at your screen, not send anything to anywhere. However, it also works with other objects than just text, like a number, table, function, or even many arguments at once. This function is useful to easily take a look at the values of a lua table, for example. If a value is a string, it'll be in quotes, and if it's a number, it won't be quoted.<br />
<br />
{{note}} Do not use this to display information to end-users. It may be hard to read. It is mainly useful for developing/debugging.<br />
<br />
<syntaxhighlight lang="lua"><br />
myTable = {} -- create an empty lua table<br />
myTable.foo = "Hello there" -- add a text<br />
myTable.bar = 23 -- add a number<br />
myTable.ubar = function () echo("OK") end -- add more stuff<br />
display( myTable ) -- take a look inside the table<br />
</syntaxhighlight><br />
<br />
==debugc==<br />
;debugc(content)<br />
:Again this will not send anything to anywhere. It will however print not to the main window, but only to the errors view. You need to open that window to see the message.<br />
<br />
:See also: [[Manual:Introduction#Runtime_errors_aka_Errors_View|Errors View]]<br />
<br />
{{note}} Do not use this to display information to end-users. It will be hard to find. It is mainly useful for developing/debugging.<br />
<br />
<syntaxhighlight lang="lua"><br />
debugc(" Trigger successful!")<br />
-- Text will be shown in errors view, not to main window.<br />
</syntaxhighlight><br />
<br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15529Manual:Mapper Functions2020-08-24T13:50:40Z<p>Smurf: removed duplicate entry</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that on clicking will send all the arguments.<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Favorites") -- will create a menu, favorites<br />
<br />
addMapMenu("Favorites1234343", "Favorites", "Favorites") <br />
</syntaxhighlight><br />
The last line will create a submenu with the unique id ''Favorites123''.. under Favorites with the display name of ''Favorites''.<br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original width of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==openMapWidget==<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==mapSymbolFontInfo==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;returns<br />
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:<br />
:* ''fontName'' - a string of the family name of the font specified<br />
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.<br />
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).<br />
* or ''nil'' and an error message on failure.<br />
<br />
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeMapEvent==<br />
;removeMapEvent (event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#addMapMenu | addMapMenu()]], [[#getMapEvents | getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out. Call [[#centerview|centerview()]] after you set the zoom to refresh the map.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it colour, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
:* - a string that is the family name of the font to use;<br />
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15528Manual:Mapper Functions2020-08-24T13:49:32Z<p>Smurf: Sorry about the confusion. This properly fixes a paste error.</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that on clicking will send all the arguments.<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Favorites") -- will create a menu, favorites<br />
<br />
addMapMenu("Favorites1234343", "Favorites", "Favorites") <br />
</syntaxhighlight><br />
The last line will create a submenu with the unique id ''Favorites123''.. under Favorites with the display name of ''Favorites''.<br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original width of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==openMapWidget==<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==mapSymbolFontInfo==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;returns<br />
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:<br />
:* ''fontName'' - a string of the family name of the font specified<br />
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.<br />
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).<br />
* or ''nil'' and an error message on failure.<br />
<br />
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeMapEvent==<br />
;removeMapEvent (event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#addMapMenu | addMapMenu()]], [[#getMapEvents | getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out. Call [[#centerview|centerview()]] after you set the zoom to refresh the map.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
* - a string that is the family name of the font to use;<br />
* - the empty string ''""'' to reset to the default {which is "Bitstream Vera Sans Mono"};<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned.<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns ''true'' on success or ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it colour, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
:* - a string that is the family name of the font to use;<br />
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15527Manual:Mapper Functions2020-08-24T13:47:20Z<p>Smurf: Undo revision 15524 by Smurf (talk)</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that on clicking will send all the arguments.<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Favorites") -- will create a menu, favorites<br />
<br />
addMapMenu("Favorites1234343", "Favorites", "Favorites") <br />
</syntaxhighlight><br />
The last line will create a submenu with the unique id ''Favorites123''.. under Favorites with the display name of ''Favorites''.<br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original width of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==openMapWidget==<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==mapSymbolFontInfo==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;returns<br />
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:<br />
:* ''fontName'' - a string of the family name of the font specified<br />
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.<br />
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).<br />
* or ''nil'' and an error message on failure.<br />
<br />
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeMapEvent==<br />
;removeMapEvent (event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#addMapMenu | addMapMenu()]], [[#getMapEvents | getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out. Call [[#centerview|centerview()]] after you set the zoom to refresh the map.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
* - a string that is the family name of the font to use;<br />
* - the empty string ''""'' to reset to the default {which is "Bitstream Vera Sans Mono"};<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned.<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns ''true'' on success or ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it colour, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
:* - a string that is the family name of the font to use;<br />
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15526Manual:Mapper Functions2020-08-24T13:47:01Z<p>Smurf: Undo revision 15525 by Smurf (talk)</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that on clicking will send all the arguments.<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Favorites") -- will create a menu, favorites<br />
<br />
addMapMenu("Favorites1234343", "Favorites", "Favorites") <br />
</syntaxhighlight><br />
The last line will create a submenu with the unique id ''Favorites123''.. under Favorites with the display name of ''Favorites''.<br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original width of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==openMapWidget==<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==mapSymbolFontInfo==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;returns<br />
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:<br />
:* ''fontName'' - a string of the family name of the font specified<br />
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.<br />
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).<br />
* or ''nil'' and an error message on failure.<br />
<br />
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeMapEvent==<br />
;removeMapEvent (event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#addMapMenu | addMapMenu()]], [[#getMapEvents | getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out. Call [[#centerview|centerview()]] after you set the zoom to refresh the map.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new==setupMapSymbolFont==<br />
<br />
==setupMapSymbolFont==<br />
setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
* - a string that is the family name of the font to use;<br />
* - the empty string ''""'' to reset to the default {which is "Bitstream Vera Sans Mono"};<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned.<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns ''true'' on success or ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it colour, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
:* - a string that is the family name of the font to use;<br />
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15525Manual:Mapper Functions2020-08-24T13:45:59Z<p>Smurf: /* setupMapSymbolFont */ so was the semicolon</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that on clicking will send all the arguments.<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Favorites") -- will create a menu, favorites<br />
<br />
addMapMenu("Favorites1234343", "Favorites", "Favorites") <br />
</syntaxhighlight><br />
The last line will create a submenu with the unique id ''Favorites123''.. under Favorites with the display name of ''Favorites''.<br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original width of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==openMapWidget==<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==mapSymbolFontInfo==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;returns<br />
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:<br />
:* ''fontName'' - a string of the family name of the font specified<br />
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.<br />
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).<br />
* or ''nil'' and an error message on failure.<br />
<br />
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeMapEvent==<br />
;removeMapEvent (event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#addMapMenu | addMapMenu()]], [[#getMapEvents | getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out. Call [[#centerview|centerview()]] after you set the zoom to refresh the map.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new==setupMapSymbolFont==<br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
* - a string that is the family name of the font to use;<br />
* - the empty string ''""'' to reset to the default {which is "Bitstream Vera Sans Mono"};<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned.<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns ''true'' on success or ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it colour, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
:* - a string that is the family name of the font to use;<br />
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15524Manual:Mapper Functions2020-08-24T13:45:32Z<p>Smurf: /* setupMapSymbolFont */ headline was missing</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that on clicking will send all the arguments.<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Favorites") -- will create a menu, favorites<br />
<br />
addMapMenu("Favorites1234343", "Favorites", "Favorites") <br />
</syntaxhighlight><br />
The last line will create a submenu with the unique id ''Favorites123''.. under Favorites with the display name of ''Favorites''.<br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original width of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==openMapWidget==<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==mapSymbolFontInfo==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;returns<br />
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:<br />
:* ''fontName'' - a string of the family name of the font specified<br />
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.<br />
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).<br />
* or ''nil'' and an error message on failure.<br />
<br />
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeMapEvent==<br />
;removeMapEvent (event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#addMapMenu | addMapMenu()]], [[#getMapEvents | getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out. Call [[#centerview|centerview()]] after you set the zoom to refresh the map.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new==setupMapSymbolFont==<br />
<br />
==setupMapSymbolFont==<br />
setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont(...)]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
* - a string that is the family name of the font to use;<br />
* - the empty string ''""'' to reset to the default {which is "Bitstream Vera Sans Mono"};<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned.<br />
* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns ''true'' on success or ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it colour, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
==setupMapSymbolFont==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
;Parameters<br />
* ''fontName'' one of:<br />
:* - a string that is the family name of the font to use;<br />
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.<br />
* ''onlyUseThisFont'' (optional) one of:<br />
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;<br />
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;<br />
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.<br />
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.<br />
<br />
;Returns<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).<br />
<br />
{{note}} pending, not yet available.<br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Networking_Functions&diff=15499Manual:Networking Functions2020-08-02T13:13:25Z<p>Smurf: /* putHTTP */ fix edit mistake</p>
<hr />
<div>{{TOC right}}<br />
= Networking Functions =<br />
A collection of functions for managing networking.<br />
<br />
==connectToServer==<br />
;connectToServer(host, port, [save])<br />
: Connects to a given game.<br />
<br />
;Parameters:<br />
* ''host:''<br />
: Server domain or IP address.<br />
* ''port:''<br />
: Servers port.<br />
* ''save:''<br />
: (optional, boolean) if provided, saves the new connection parameters in the profile so they'll be used next time you open it.<br />
<br />
{{note}} ''save'' is available in Mudlet 3.2+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
connectToServer("midnightsun2.org", 3000)<br />
<br />
-- save to disk so these parameters are used next time when opening the profile<br />
connectToServer("midnightsun2.org", 3000, true)<br />
</syntaxhighlight><br />
<br />
==disconnect==<br />
;disconnect()<br />
: Disconnects you from the game right away. Note that this will ''not'' properly log you out of the game - use an ingame command for that. Such commands vary, but typically QUIT will work.<br />
<br />
: See also: [[Manual:Networking_Functions#reconnect|reconnect()]]<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
disconnect()<br />
</syntaxhighlight><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Event_Engine#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Event_Engine#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
:See also: [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]]<br />
<br />
[[File:Downloadfile privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
{{note}} Since Mudlet 3.0, https downloads are supported and the actual url that was used for the download is returned - useful in case of redirects.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- just download a file and save it in our profile folder<br />
local saveto = getMudletHomeDir().."/dark-theme-mudlet.zip"<br />
local url = "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip"<br />
downloadFile(saveto, url)<br />
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")<br />
</syntaxhighlight><br />
<br />
<br />
<br />
<br />
A more advanced example that downloads a webpage, reads it, and prints a result from it:<br />
<syntaxhighlight lang="lua"><br />
-- create a function to parse the downloaded webpage and display a result<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:find("achaea-who-count.html", 1, true) then return end<br />
<br />
-- read the contents of the webpage in<br />
local f, s, webpage = io.open(filename)<br />
if f then webpage = f:read("*a"); io.close(f) end<br />
-- delete the file on disk, don't clutter<br />
os.remove(filename)<br />
<br />
-- parse our downloaded file for the player count<br />
local pc = webpage:match([[Total: (%d+) players online]])<br />
display("Achaea has "..tostring(pc).." players on right now.")<br />
end<br />
<br />
-- register our function to run on the event that something was downloaded<br />
registerAnonymousEventHandler("sysDownloadDone", "downloaded_file")<br />
<br />
-- download a list of fake users for a demo<br />
downloadFile(getMudletHomeDir().."/achaea-who-count.html", "https://www.achaea.com/game/who")<br />
</syntaxhighlight><br />
<br />
Result should look like this:<br />
<br />
[[File:DownloadFile_demo.png]].<br />
<br />
==getConnectionInfo==<br />
;getConnectionInfo()<br />
:Returns the server address and port that you're currently connected to.<br />
:See also: [[Manual:Networking_Functions#connectToServer|connectToServer()]]<br />
<br />
{{note}} Available in Mudlet 4.2+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Connected to <forest_green>%s:%s\n", host, port))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- echo the new connection parameters whenever we connect to a different host with connectToServer()<br />
function echoInfo()<br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Now connected to <forest_green>%s:%s\n", host, port))<br />
end<br />
<br />
registerAnonymousEventHandler("sysConnectionEvent", "echoInfo")<br />
</syntaxhighlight><br />
<br />
==getIrcChannels==<br />
;getIrcChannels()<br />
:Returns a list of channels the IRC client is joined to as a lua table. If the client is not yet started the value returned is loaded from disk and represents channels the client will auto-join when started.<br />
:See also: [[Manual:Networking_Functions#setIrcChannels|setIrcChannels()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getIrcChannels())<br />
-- Prints: {"#mudlet", "#lua"}<br />
</syntaxhighlight><br />
<br />
==getIrcConnectedHost==<br />
;getIrcConnectedHost()<br />
:Returns true+host where host is a string containing the host name of the IRC server, as given to the client by the server while starting the IRC connection. If the client has not yet started or finished connecting this will return false and an empty string. <br />
<br />
:This function can be particularly useful for testing if the IRC client has connected to a server prior to sending data, and it will not auto-start the IRC client.<br /> <br />
:The ''hostname'' value this function returns can be used to test if [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage]] events are sent from the server or a user on the network.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local status, hostname = getIrcConnectedHost()<br />
<br />
if status == true then<br />
-- do something with connected IRC, send IRC commands, store 'hostname' elsewhere.<br />
-- if sysIrcMessage sender = hostname from above, message is likely a status, command response, or an error from the Server.<br />
else <br />
-- print a status, change connection settings, or just continue waiting to send IRC data.<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==getIrcNick==<br />
;getIrcNick()<br />
:Returns a string containing the IRC client nickname. If the client is not yet started, your default nickname is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcNick|setIrcNick()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local nick = getIrcNick()<br />
echo(nick)<br />
-- Prints: "Sheldor"<br />
</syntaxhighlight><br />
<br />
==getIrcServer==<br />
;getIrcServer()<br />
:Returns the IRC client server name and port as a string and a number respectively. If the client is not yet started your default server is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcServer|setIrcServer()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local server, port = getIrcServer()<br />
echo("server: "..server..", port: "..port.."\n")<br />
</syntaxhighlight><br />
<br />
==getNetworkLatency==<br />
; getNetworkLatency()<br />
: Returns the last measured response time between the sent command and the server reply in seconds - e.g. 0.058 (=58 milliseconds lag) or 0.309 (=309 milliseconds). This is the ''N:'' number you see bottom-right of Mudlet.<br />
<br />
Also known as server lag.<br />
<br />
;Example<br />
''Need example''<br />
<br />
==openUrl==<br />
;openUrl (url)<br />
:Opens the default OS browser for the given URL.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
openUrl("http://google.com")<br />
openUrl("www.mudlet.org")<br />
</syntaxhighlight><br />
<br />
==receiveMSP==<br />
;receiveMSP(command)<br />
: Receives a well-formed Mud Sound Protocol (MSP) message to be processed by the Mudlet client. Reference the [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]] manual for more information on about what can be sent and example triggers.<br />
<br />
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Play a cow.wav media file stored in the media folder of the current profile. The sound would play twice at a normal volume.<br />
receiveMSP("!!SOUND(cow.wav L=2 V=50)")<br />
<br />
--Stop any SOUND media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!SOUND(Off)")<br />
<br />
--Play a city.mp3 media file stored in the media folder of the current profile. The music would play once at a low volume.<br />
--The music would continue playing if it was triggered earlier by another room, perhaps in the same area.<br />
receiveMSP([[!!MUSIC(city.mp3 L=1 V=25 C=1)]])<br />
<br />
--Stop any MUSIC media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!MUSIC(Off)")<br />
</syntaxhighlight><br />
<br />
==reconnect==<br />
;reconnect()<br />
: Force-reconnects (so if you're connected, it'll disconnect) you to the game.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- you could trigger this on a log out message to reconnect, if you'd like<br />
reconnect()<br />
</syntaxhighlight><br />
<br />
==restartIrc==<br />
;restartIrc()<br />
:Restarts the IRC client connection, reloading configurations from disk before reconnecting the IRC client.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==sendAll==<br />
; sendAll(list of things to send, [echo back or not])<br />
: sends multiple things to the game. If you'd like the commands not to be shown, include ''false'' at the end.<br />
<br />
:See also: [[Manual:Basic_Essentials#send|send()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- instead of using many send() calls, you can use one sendAll<br />
sendAll("outr paint", "outr canvas", "paint canvas")<br />
-- can also have the commands not be echoed<br />
sendAll("hi", "bye", false)<br />
</syntaxhighlight><br />
<br />
==sendATCP==<br />
;sendATCP(message, what)<br />
: ''Need description''<br />
<br />
: See also: [[Manual:Supported_Protocols#ATCP|ATCP Protocol]], [[Manual:ATCP_Extensions|ATCP Extensions]], [http://www.ironrealms.com/rapture/manual/files/FeatATCP-txt.html Achaea Telnet Client Protocol specification], [https://forums.mudlet.org/viewtopic.php?p=19502#p19502 Description by forum user KaVir (2013)], [https://forums.mudlet.org/viewtopic.php?p=2015#p2015 Description by forum user Iocun (2009)]<br />
<br />
;Parameters:<br />
* ''message:''<br />
: The message that you want to send.<br />
* ''what:''<br />
: ''Need description''<br />
<br />
;Example<br />
''Need example''<br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
: Note that this function is rarely used in practice. For most GMCP modules, the messages are automatically sent by the server when a relevant event happens in the game. For example, LOOKing in your room prompts the server to send the room description and contents, as well as the GMCP message gmcp.Room. A call to sendGMCP would not be required in this case.<br />
<br />
: See also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group = "vision"})<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group="MWP", name="block"})<br />
</syntaxhighlight><br />
<br />
==sendMSDP==<br />
;sendMSDP(variable[, value][, value...])<br />
: Sends a MSDP message to the server.<br />
<br />
;Parameters:<br />
* ''variable:''<br />
: The variable, in MSDP terms, that you want to request from the server.<br />
* ''value:''<br />
: The variables value that you want to request. You can request more than one value at a time.<br />
<br />
: See Also: [[Manual:Supported_Protocols#MSDP|MSDP support in Mudlet]], [http://tintin.sourceforge.net/msdp/ Mud Server Data Protocol specification]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- ask for a list of commands, lists, and reportable variables that the server supports<br />
sendMSDP("LIST", "COMMANDS", "LISTS", "REPORTABLE_VARIABLES")<br />
<br />
-- ask the server to start keeping you up to date on your health<br />
sendMSDP("REPORT", "HEALTH")<br />
<br />
-- or on your health and location<br />
sendMSDP("REPORT", "HEALTH", "ROOM_VNUM", "ROOM_NAME")<br />
</syntaxhighlight><br />
<br />
==sendIrc==<br />
;sendIrc(target, message)<br />
: Sends a message to an IRC channel or person. Returns ''true''+''status'' if message could be sent or was successfully processed by the client, or ''nil''+''error'' if the client is not ready for sending, and ''false''+''status'' if the client filtered the message or failed to send it for some reason. If the IRC client hasn't started yet, this function will initiate the IRC client and begin a connection.<br />
<br />
To receive an IRC message, check out the [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage event]].<br />
<br />
{{note}} Since Mudlet 3.3, auto-opens the IRC window and returns the success status.<br />
<br />
;Parameters:<br />
* ''target:''<br />
: nick or channel name and if omitted will default to the first available channel in the list of joined channels.<br />
* ''message:''<br />
: The message to send, may contain IRC client commands which start with <code>/</code> and can use all commands which are available through the client window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
-- this would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
<br />
-- use an in-built IRC command<br />
sendIrc("#mudlet", "/topic")<br />
</syntaxhighlight><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.3:<br />
* /ACTION <target> <message...><br />
* /ADMIN (<server>)<br />
* /AWAY (<reason...>)<br />
* /CLEAR (<buffer>) -- Clears the text log for the given buffer name. Uses the current active buffer if none are given.<br />
* /CLOSE (<buffer>) -- Closes the buffer and removes it from the Buffer list. Uses the current active buffer if none are given.<br />
* /HELP (<command>) -- Displays some help information about a given command or lists all available commands.<br />
* /INFO (<server>)<br />
* /INVITE <user> (<#channel>)<br />
* /JOIN <#channel> (<key>)<br />
* /KICK (<#channel>) <user> (<reason...>)<br />
* /KNOCK <#channel> (<message...>)<br />
* /LIST (<channels>) (<server>)<br />
* /ME [target] <message...><br />
* /MODE (<channel/user>) (<mode>) (<arg>)<br />
* /MOTD (<server>)<br />
* /MSG <target> <message...> -- Sends a message to target, can be used to send Private messages.<br />
* /NAMES (<#channel>)<br />
* /NICK <nick><br />
* /NOTICE <#channel/user> <message...><br />
* /PART (<#channel>) (<message...>)<br />
* /PING (<user>)<br />
* /RECONNECT -- Issues a Quit command to the IRC Server and closes the IRC connection then reconnects to the IRC server. The same as calling ircRestart() in Lua.<br />
* /QUIT (<message...>)<br />
* /QUOTE <command> (<parameters...>)<br />
* /STATS <query> (<server>)<br />
* /TIME (<user>)<br />
* /TOPIC (<#channel>) (<topic...>)<br />
* /TRACE (<target>)<br />
* /USERS (<server>)<br />
* /VERSION (<user>)<br />
* /WHO <mask><br />
* /WHOIS <user><br />
* /WHOWAS <user><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.15:<br />
* /MSGLIMIT <limit> (<buffer>) -- Sets the limit for messages to keep in the IRC client message buffers and saves this setting. If a specific buffer/channel name is given the limit is not saved and applies to the given buffer until the application is closed or the limit is changed again. For this reason, global settings should be applied first, before settings for specific channels/PM buffers.<br />
<br />
==sendTelnetChannel102==<br />
; sendTelnetChannel102(msg)<br />
: Sends a message via the 102 subchannel back to the MUD (that's used in Aardwolf). The msg is in a two byte format; see the link below to the Aardwolf Wiki for how that works.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- turn prompt flags on:<br />
sendTelnetChannel102("\52\1")<br />
<br />
-- turn prompt flags off:<br />
sendTelnetChannel102("\52\2")<br />
</syntaxhighlight><br />
<br />
To see the list of options that Aardwolf supports go to: [http://www.aardwolf.com/blog/2008/07/10/telnet-negotiation-control-mud-client-interaction/ Using Telnet negotiation to control MUD client interaction].<br />
<br />
==setIrcChannels==<br />
;setIrcChannels(channels)<br />
:Saves the given channels to disk as the new IRC client channel auto-join configuration. This value is not applied to the current active IRC client until it is restarted with [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
:See also: [[Manual:Networking_Functions#getIrcChannels|getIrcChannels()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''channels:''<br />
: A table containing strings which are valid channel names. Any channels in the list which aren't valid are removed from the list. <br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcChannels( {"#mudlet", "#lua", "irc"} )<br />
-- Only the first two will be accepted, as "irc" is not a valid channel name.<br />
</syntaxhighlight><br />
<br />
==setIrcNick==<br />
;setIrcNick(nickname)<br />
:Saves the given nickname to disk as the new IRC client configuration. This value is not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcNick|getIrcNick()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''nickname:''<br />
: A string with your new desired name in IRC.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcNick( "Sheldor" )<br />
</syntaxhighlight><br />
<br />
==setIrcServer==<br />
;setIrcServer(hostname, port)<br />
:Saves the given server's address to disk as the new IRC client connection configuration. These values are not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcServer|getIrcServer()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''hostname:''<br />
: A string containing the hostname of the IRC server.<br />
* ''port:''<br />
: (optional) A number indicating the port of the IRC server. Defaults to 6667, if not provided.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcServer("chat.freenode.net", 6667)<br />
</syntaxhighlight><br />
<br />
==getHTTP==<br />
;getHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/GET_(HTTP) HTTP GET] request to the given URL. Raises [[Manual:Event_Engine#sysGetHttpDone|sysGetHttpDone]] on success or [[Manual:Event_Engine#sysGetHttpError|sysGetHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available since Mudlet 4.10<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpGetDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysGetHttpDone", onHttpGetDone)<br />
<br />
getHTTP("https://httpbin.org/info")<br />
getHTTP("https://httpbin.org/are_you_awesome", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- Status requests typically use GET requests<br />
local url = "http://postman-echo.com/status"<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysGetHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysGetHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
getHTTP(url, header)<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
<br />
==postHTTP==<br />
;postHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/POST_(HTTP) HTTP POST] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPostHttpDone|sysPostHttpDone]] on success or [[Manual:Event_Engine#sysPostHttpError|sysPostHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|getHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the POST request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpPostDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPostHttpDone", onHttpPostDone)<br />
<br />
postHTTP("why hello there!", "https://httpbin.org/post")<br />
postHTTP("this us a request with custom headers", "https://httpbin.org/post", {["X-am-I-awesome"] = "yep I am"})<br />
postHTTP("https://httpbin.org/post", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This will create a JSON message body. Many modern REST APIs expect a JSON body. <br />
local url = "http://postman-echo.com/post"<br />
local data = {message = "I am the banana", user = "admin"}<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysPostHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysPostHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
postHTTP(yajl.to_string(data), url, header) -- yajl.to_string converts our Lua table into a JSON-like string so the server can understand it<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
==putHTTP==<br />
;putHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/PUT_(HTTP) HTTP PUT] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPutHttpDone|sysPutHttpDone]] on success or [[Manual:Event_Engine#sysPutHttpError|sysPutHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the PUT request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onHttpPutDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPutHttpDone", onHttpPutDone)<br />
putHTTP("this us a request with custom headers", "https://httpbin.org/put", {["X-am-I-awesome"] = "yep I am"})<br />
putHTTP("https://httpbin.org/put", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
==deleteHTTP==<br />
;deleteHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/DELETE_(HTTP) HTTP DELETE] request to the given URL. Raises [[Manual:Event_Engine#sysDeleteHttpDone|sysDeleteHttpDone]] on success or [[Manual:Event_Engine#sysDeleteHttpError|sysDeleteHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
function onHttpDeleteDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysDeleteHttpDone", onHttpDeleteDone)<br />
<br />
deleteHTTP("https://httpbin.org/delete")<br />
deleteHTTP("https://httpbin.org/delete", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Networking_Functions&diff=15498Manual:Networking Functions2020-08-02T13:13:04Z<p>Smurf: /* postHTTP */ add ref to getHTTP</p>
<hr />
<div>{{TOC right}}<br />
= Networking Functions =<br />
A collection of functions for managing networking.<br />
<br />
==connectToServer==<br />
;connectToServer(host, port, [save])<br />
: Connects to a given game.<br />
<br />
;Parameters:<br />
* ''host:''<br />
: Server domain or IP address.<br />
* ''port:''<br />
: Servers port.<br />
* ''save:''<br />
: (optional, boolean) if provided, saves the new connection parameters in the profile so they'll be used next time you open it.<br />
<br />
{{note}} ''save'' is available in Mudlet 3.2+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
connectToServer("midnightsun2.org", 3000)<br />
<br />
-- save to disk so these parameters are used next time when opening the profile<br />
connectToServer("midnightsun2.org", 3000, true)<br />
</syntaxhighlight><br />
<br />
==disconnect==<br />
;disconnect()<br />
: Disconnects you from the game right away. Note that this will ''not'' properly log you out of the game - use an ingame command for that. Such commands vary, but typically QUIT will work.<br />
<br />
: See also: [[Manual:Networking_Functions#reconnect|reconnect()]]<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
disconnect()<br />
</syntaxhighlight><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Event_Engine#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Event_Engine#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
:See also: [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]]<br />
<br />
[[File:Downloadfile privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
{{note}} Since Mudlet 3.0, https downloads are supported and the actual url that was used for the download is returned - useful in case of redirects.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- just download a file and save it in our profile folder<br />
local saveto = getMudletHomeDir().."/dark-theme-mudlet.zip"<br />
local url = "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip"<br />
downloadFile(saveto, url)<br />
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")<br />
</syntaxhighlight><br />
<br />
<br />
<br />
<br />
A more advanced example that downloads a webpage, reads it, and prints a result from it:<br />
<syntaxhighlight lang="lua"><br />
-- create a function to parse the downloaded webpage and display a result<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:find("achaea-who-count.html", 1, true) then return end<br />
<br />
-- read the contents of the webpage in<br />
local f, s, webpage = io.open(filename)<br />
if f then webpage = f:read("*a"); io.close(f) end<br />
-- delete the file on disk, don't clutter<br />
os.remove(filename)<br />
<br />
-- parse our downloaded file for the player count<br />
local pc = webpage:match([[Total: (%d+) players online]])<br />
display("Achaea has "..tostring(pc).." players on right now.")<br />
end<br />
<br />
-- register our function to run on the event that something was downloaded<br />
registerAnonymousEventHandler("sysDownloadDone", "downloaded_file")<br />
<br />
-- download a list of fake users for a demo<br />
downloadFile(getMudletHomeDir().."/achaea-who-count.html", "https://www.achaea.com/game/who")<br />
</syntaxhighlight><br />
<br />
Result should look like this:<br />
<br />
[[File:DownloadFile_demo.png]].<br />
<br />
==getConnectionInfo==<br />
;getConnectionInfo()<br />
:Returns the server address and port that you're currently connected to.<br />
:See also: [[Manual:Networking_Functions#connectToServer|connectToServer()]]<br />
<br />
{{note}} Available in Mudlet 4.2+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Connected to <forest_green>%s:%s\n", host, port))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- echo the new connection parameters whenever we connect to a different host with connectToServer()<br />
function echoInfo()<br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Now connected to <forest_green>%s:%s\n", host, port))<br />
end<br />
<br />
registerAnonymousEventHandler("sysConnectionEvent", "echoInfo")<br />
</syntaxhighlight><br />
<br />
==getIrcChannels==<br />
;getIrcChannels()<br />
:Returns a list of channels the IRC client is joined to as a lua table. If the client is not yet started the value returned is loaded from disk and represents channels the client will auto-join when started.<br />
:See also: [[Manual:Networking_Functions#setIrcChannels|setIrcChannels()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getIrcChannels())<br />
-- Prints: {"#mudlet", "#lua"}<br />
</syntaxhighlight><br />
<br />
==getIrcConnectedHost==<br />
;getIrcConnectedHost()<br />
:Returns true+host where host is a string containing the host name of the IRC server, as given to the client by the server while starting the IRC connection. If the client has not yet started or finished connecting this will return false and an empty string. <br />
<br />
:This function can be particularly useful for testing if the IRC client has connected to a server prior to sending data, and it will not auto-start the IRC client.<br /> <br />
:The ''hostname'' value this function returns can be used to test if [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage]] events are sent from the server or a user on the network.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local status, hostname = getIrcConnectedHost()<br />
<br />
if status == true then<br />
-- do something with connected IRC, send IRC commands, store 'hostname' elsewhere.<br />
-- if sysIrcMessage sender = hostname from above, message is likely a status, command response, or an error from the Server.<br />
else <br />
-- print a status, change connection settings, or just continue waiting to send IRC data.<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==getIrcNick==<br />
;getIrcNick()<br />
:Returns a string containing the IRC client nickname. If the client is not yet started, your default nickname is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcNick|setIrcNick()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local nick = getIrcNick()<br />
echo(nick)<br />
-- Prints: "Sheldor"<br />
</syntaxhighlight><br />
<br />
==getIrcServer==<br />
;getIrcServer()<br />
:Returns the IRC client server name and port as a string and a number respectively. If the client is not yet started your default server is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcServer|setIrcServer()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local server, port = getIrcServer()<br />
echo("server: "..server..", port: "..port.."\n")<br />
</syntaxhighlight><br />
<br />
==getNetworkLatency==<br />
; getNetworkLatency()<br />
: Returns the last measured response time between the sent command and the server reply in seconds - e.g. 0.058 (=58 milliseconds lag) or 0.309 (=309 milliseconds). This is the ''N:'' number you see bottom-right of Mudlet.<br />
<br />
Also known as server lag.<br />
<br />
;Example<br />
''Need example''<br />
<br />
==openUrl==<br />
;openUrl (url)<br />
:Opens the default OS browser for the given URL.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
openUrl("http://google.com")<br />
openUrl("www.mudlet.org")<br />
</syntaxhighlight><br />
<br />
==receiveMSP==<br />
;receiveMSP(command)<br />
: Receives a well-formed Mud Sound Protocol (MSP) message to be processed by the Mudlet client. Reference the [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]] manual for more information on about what can be sent and example triggers.<br />
<br />
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Play a cow.wav media file stored in the media folder of the current profile. The sound would play twice at a normal volume.<br />
receiveMSP("!!SOUND(cow.wav L=2 V=50)")<br />
<br />
--Stop any SOUND media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!SOUND(Off)")<br />
<br />
--Play a city.mp3 media file stored in the media folder of the current profile. The music would play once at a low volume.<br />
--The music would continue playing if it was triggered earlier by another room, perhaps in the same area.<br />
receiveMSP([[!!MUSIC(city.mp3 L=1 V=25 C=1)]])<br />
<br />
--Stop any MUSIC media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!MUSIC(Off)")<br />
</syntaxhighlight><br />
<br />
==reconnect==<br />
;reconnect()<br />
: Force-reconnects (so if you're connected, it'll disconnect) you to the game.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- you could trigger this on a log out message to reconnect, if you'd like<br />
reconnect()<br />
</syntaxhighlight><br />
<br />
==restartIrc==<br />
;restartIrc()<br />
:Restarts the IRC client connection, reloading configurations from disk before reconnecting the IRC client.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==sendAll==<br />
; sendAll(list of things to send, [echo back or not])<br />
: sends multiple things to the game. If you'd like the commands not to be shown, include ''false'' at the end.<br />
<br />
:See also: [[Manual:Basic_Essentials#send|send()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- instead of using many send() calls, you can use one sendAll<br />
sendAll("outr paint", "outr canvas", "paint canvas")<br />
-- can also have the commands not be echoed<br />
sendAll("hi", "bye", false)<br />
</syntaxhighlight><br />
<br />
==sendATCP==<br />
;sendATCP(message, what)<br />
: ''Need description''<br />
<br />
: See also: [[Manual:Supported_Protocols#ATCP|ATCP Protocol]], [[Manual:ATCP_Extensions|ATCP Extensions]], [http://www.ironrealms.com/rapture/manual/files/FeatATCP-txt.html Achaea Telnet Client Protocol specification], [https://forums.mudlet.org/viewtopic.php?p=19502#p19502 Description by forum user KaVir (2013)], [https://forums.mudlet.org/viewtopic.php?p=2015#p2015 Description by forum user Iocun (2009)]<br />
<br />
;Parameters:<br />
* ''message:''<br />
: The message that you want to send.<br />
* ''what:''<br />
: ''Need description''<br />
<br />
;Example<br />
''Need example''<br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
: Note that this function is rarely used in practice. For most GMCP modules, the messages are automatically sent by the server when a relevant event happens in the game. For example, LOOKing in your room prompts the server to send the room description and contents, as well as the GMCP message gmcp.Room. A call to sendGMCP would not be required in this case.<br />
<br />
: See also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group = "vision"})<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group="MWP", name="block"})<br />
</syntaxhighlight><br />
<br />
==sendMSDP==<br />
;sendMSDP(variable[, value][, value...])<br />
: Sends a MSDP message to the server.<br />
<br />
;Parameters:<br />
* ''variable:''<br />
: The variable, in MSDP terms, that you want to request from the server.<br />
* ''value:''<br />
: The variables value that you want to request. You can request more than one value at a time.<br />
<br />
: See Also: [[Manual:Supported_Protocols#MSDP|MSDP support in Mudlet]], [http://tintin.sourceforge.net/msdp/ Mud Server Data Protocol specification]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- ask for a list of commands, lists, and reportable variables that the server supports<br />
sendMSDP("LIST", "COMMANDS", "LISTS", "REPORTABLE_VARIABLES")<br />
<br />
-- ask the server to start keeping you up to date on your health<br />
sendMSDP("REPORT", "HEALTH")<br />
<br />
-- or on your health and location<br />
sendMSDP("REPORT", "HEALTH", "ROOM_VNUM", "ROOM_NAME")<br />
</syntaxhighlight><br />
<br />
==sendIrc==<br />
;sendIrc(target, message)<br />
: Sends a message to an IRC channel or person. Returns ''true''+''status'' if message could be sent or was successfully processed by the client, or ''nil''+''error'' if the client is not ready for sending, and ''false''+''status'' if the client filtered the message or failed to send it for some reason. If the IRC client hasn't started yet, this function will initiate the IRC client and begin a connection.<br />
<br />
To receive an IRC message, check out the [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage event]].<br />
<br />
{{note}} Since Mudlet 3.3, auto-opens the IRC window and returns the success status.<br />
<br />
;Parameters:<br />
* ''target:''<br />
: nick or channel name and if omitted will default to the first available channel in the list of joined channels.<br />
* ''message:''<br />
: The message to send, may contain IRC client commands which start with <code>/</code> and can use all commands which are available through the client window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
-- this would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
<br />
-- use an in-built IRC command<br />
sendIrc("#mudlet", "/topic")<br />
</syntaxhighlight><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.3:<br />
* /ACTION <target> <message...><br />
* /ADMIN (<server>)<br />
* /AWAY (<reason...>)<br />
* /CLEAR (<buffer>) -- Clears the text log for the given buffer name. Uses the current active buffer if none are given.<br />
* /CLOSE (<buffer>) -- Closes the buffer and removes it from the Buffer list. Uses the current active buffer if none are given.<br />
* /HELP (<command>) -- Displays some help information about a given command or lists all available commands.<br />
* /INFO (<server>)<br />
* /INVITE <user> (<#channel>)<br />
* /JOIN <#channel> (<key>)<br />
* /KICK (<#channel>) <user> (<reason...>)<br />
* /KNOCK <#channel> (<message...>)<br />
* /LIST (<channels>) (<server>)<br />
* /ME [target] <message...><br />
* /MODE (<channel/user>) (<mode>) (<arg>)<br />
* /MOTD (<server>)<br />
* /MSG <target> <message...> -- Sends a message to target, can be used to send Private messages.<br />
* /NAMES (<#channel>)<br />
* /NICK <nick><br />
* /NOTICE <#channel/user> <message...><br />
* /PART (<#channel>) (<message...>)<br />
* /PING (<user>)<br />
* /RECONNECT -- Issues a Quit command to the IRC Server and closes the IRC connection then reconnects to the IRC server. The same as calling ircRestart() in Lua.<br />
* /QUIT (<message...>)<br />
* /QUOTE <command> (<parameters...>)<br />
* /STATS <query> (<server>)<br />
* /TIME (<user>)<br />
* /TOPIC (<#channel>) (<topic...>)<br />
* /TRACE (<target>)<br />
* /USERS (<server>)<br />
* /VERSION (<user>)<br />
* /WHO <mask><br />
* /WHOIS <user><br />
* /WHOWAS <user><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.15:<br />
* /MSGLIMIT <limit> (<buffer>) -- Sets the limit for messages to keep in the IRC client message buffers and saves this setting. If a specific buffer/channel name is given the limit is not saved and applies to the given buffer until the application is closed or the limit is changed again. For this reason, global settings should be applied first, before settings for specific channels/PM buffers.<br />
<br />
==sendTelnetChannel102==<br />
; sendTelnetChannel102(msg)<br />
: Sends a message via the 102 subchannel back to the MUD (that's used in Aardwolf). The msg is in a two byte format; see the link below to the Aardwolf Wiki for how that works.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- turn prompt flags on:<br />
sendTelnetChannel102("\52\1")<br />
<br />
-- turn prompt flags off:<br />
sendTelnetChannel102("\52\2")<br />
</syntaxhighlight><br />
<br />
To see the list of options that Aardwolf supports go to: [http://www.aardwolf.com/blog/2008/07/10/telnet-negotiation-control-mud-client-interaction/ Using Telnet negotiation to control MUD client interaction].<br />
<br />
==setIrcChannels==<br />
;setIrcChannels(channels)<br />
:Saves the given channels to disk as the new IRC client channel auto-join configuration. This value is not applied to the current active IRC client until it is restarted with [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
:See also: [[Manual:Networking_Functions#getIrcChannels|getIrcChannels()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''channels:''<br />
: A table containing strings which are valid channel names. Any channels in the list which aren't valid are removed from the list. <br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcChannels( {"#mudlet", "#lua", "irc"} )<br />
-- Only the first two will be accepted, as "irc" is not a valid channel name.<br />
</syntaxhighlight><br />
<br />
==setIrcNick==<br />
;setIrcNick(nickname)<br />
:Saves the given nickname to disk as the new IRC client configuration. This value is not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcNick|getIrcNick()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''nickname:''<br />
: A string with your new desired name in IRC.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcNick( "Sheldor" )<br />
</syntaxhighlight><br />
<br />
==setIrcServer==<br />
;setIrcServer(hostname, port)<br />
:Saves the given server's address to disk as the new IRC client connection configuration. These values are not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcServer|getIrcServer()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''hostname:''<br />
: A string containing the hostname of the IRC server.<br />
* ''port:''<br />
: (optional) A number indicating the port of the IRC server. Defaults to 6667, if not provided.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcServer("chat.freenode.net", 6667)<br />
</syntaxhighlight><br />
<br />
==getHTTP==<br />
;getHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/GET_(HTTP) HTTP GET] request to the given URL. Raises [[Manual:Event_Engine#sysGetHttpDone|sysGetHttpDone]] on success or [[Manual:Event_Engine#sysGetHttpError|sysGetHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available since Mudlet 4.10<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpGetDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysGetHttpDone", onHttpGetDone)<br />
<br />
getHTTP("https://httpbin.org/info")<br />
getHTTP("https://httpbin.org/are_you_awesome", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- Status requests typically use GET requests<br />
local url = "http://postman-echo.com/status"<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysGetHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysGetHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
getHTTP(url, header)<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
<br />
==postHTTP==<br />
;postHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/POST_(HTTP) HTTP POST] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPostHttpDone|sysPostHttpDone]] on success or [[Manual:Event_Engine#sysPostHttpError|sysPostHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|getHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the POST request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpPostDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPostHttpDone", onHttpPostDone)<br />
<br />
postHTTP("why hello there!", "https://httpbin.org/post")<br />
postHTTP("this us a request with custom headers", "https://httpbin.org/post", {["X-am-I-awesome"] = "yep I am"})<br />
postHTTP("https://httpbin.org/post", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This will create a JSON message body. Many modern REST APIs expect a JSON body. <br />
local url = "http://postman-echo.com/post"<br />
local data = {message = "I am the banana", user = "admin"}<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysPostHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysPostHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
postHTTP(yajl.to_string(data), url, header) -- yajl.to_string converts our Lua table into a JSON-like string so the server can understand it<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
==putHTTP==<br />
;putHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/PUT_(HTTP) HTTP PUT] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPutHttpDone|sysPutHttpDone]] on success or [[Manual:Event_Engine#sysPutHttpError|sysPutHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|postHTTP()]], [[#getHTTP|postHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the PUT request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onHttpPutDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPutHttpDone", onHttpPutDone)<br />
putHTTP("this us a request with custom headers", "https://httpbin.org/put", {["X-am-I-awesome"] = "yep I am"})<br />
putHTTP("https://httpbin.org/put", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
==deleteHTTP==<br />
;deleteHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/DELETE_(HTTP) HTTP DELETE] request to the given URL. Raises [[Manual:Event_Engine#sysDeleteHttpDone|sysDeleteHttpDone]] on success or [[Manual:Event_Engine#sysDeleteHttpError|sysDeleteHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
function onHttpDeleteDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysDeleteHttpDone", onHttpDeleteDone)<br />
<br />
deleteHTTP("https://httpbin.org/delete")<br />
deleteHTTP("https://httpbin.org/delete", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Networking_Functions&diff=15497Manual:Networking Functions2020-08-02T13:12:09Z<p>Smurf: /* putHTTP */ add getHTTP ref</p>
<hr />
<div>{{TOC right}}<br />
= Networking Functions =<br />
A collection of functions for managing networking.<br />
<br />
==connectToServer==<br />
;connectToServer(host, port, [save])<br />
: Connects to a given game.<br />
<br />
;Parameters:<br />
* ''host:''<br />
: Server domain or IP address.<br />
* ''port:''<br />
: Servers port.<br />
* ''save:''<br />
: (optional, boolean) if provided, saves the new connection parameters in the profile so they'll be used next time you open it.<br />
<br />
{{note}} ''save'' is available in Mudlet 3.2+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
connectToServer("midnightsun2.org", 3000)<br />
<br />
-- save to disk so these parameters are used next time when opening the profile<br />
connectToServer("midnightsun2.org", 3000, true)<br />
</syntaxhighlight><br />
<br />
==disconnect==<br />
;disconnect()<br />
: Disconnects you from the game right away. Note that this will ''not'' properly log you out of the game - use an ingame command for that. Such commands vary, but typically QUIT will work.<br />
<br />
: See also: [[Manual:Networking_Functions#reconnect|reconnect()]]<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
disconnect()<br />
</syntaxhighlight><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Event_Engine#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Event_Engine#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
:See also: [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]]<br />
<br />
[[File:Downloadfile privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
{{note}} Since Mudlet 3.0, https downloads are supported and the actual url that was used for the download is returned - useful in case of redirects.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- just download a file and save it in our profile folder<br />
local saveto = getMudletHomeDir().."/dark-theme-mudlet.zip"<br />
local url = "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip"<br />
downloadFile(saveto, url)<br />
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")<br />
</syntaxhighlight><br />
<br />
<br />
<br />
<br />
A more advanced example that downloads a webpage, reads it, and prints a result from it:<br />
<syntaxhighlight lang="lua"><br />
-- create a function to parse the downloaded webpage and display a result<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:find("achaea-who-count.html", 1, true) then return end<br />
<br />
-- read the contents of the webpage in<br />
local f, s, webpage = io.open(filename)<br />
if f then webpage = f:read("*a"); io.close(f) end<br />
-- delete the file on disk, don't clutter<br />
os.remove(filename)<br />
<br />
-- parse our downloaded file for the player count<br />
local pc = webpage:match([[Total: (%d+) players online]])<br />
display("Achaea has "..tostring(pc).." players on right now.")<br />
end<br />
<br />
-- register our function to run on the event that something was downloaded<br />
registerAnonymousEventHandler("sysDownloadDone", "downloaded_file")<br />
<br />
-- download a list of fake users for a demo<br />
downloadFile(getMudletHomeDir().."/achaea-who-count.html", "https://www.achaea.com/game/who")<br />
</syntaxhighlight><br />
<br />
Result should look like this:<br />
<br />
[[File:DownloadFile_demo.png]].<br />
<br />
==getConnectionInfo==<br />
;getConnectionInfo()<br />
:Returns the server address and port that you're currently connected to.<br />
:See also: [[Manual:Networking_Functions#connectToServer|connectToServer()]]<br />
<br />
{{note}} Available in Mudlet 4.2+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Connected to <forest_green>%s:%s\n", host, port))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- echo the new connection parameters whenever we connect to a different host with connectToServer()<br />
function echoInfo()<br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Now connected to <forest_green>%s:%s\n", host, port))<br />
end<br />
<br />
registerAnonymousEventHandler("sysConnectionEvent", "echoInfo")<br />
</syntaxhighlight><br />
<br />
==getIrcChannels==<br />
;getIrcChannels()<br />
:Returns a list of channels the IRC client is joined to as a lua table. If the client is not yet started the value returned is loaded from disk and represents channels the client will auto-join when started.<br />
:See also: [[Manual:Networking_Functions#setIrcChannels|setIrcChannels()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getIrcChannels())<br />
-- Prints: {"#mudlet", "#lua"}<br />
</syntaxhighlight><br />
<br />
==getIrcConnectedHost==<br />
;getIrcConnectedHost()<br />
:Returns true+host where host is a string containing the host name of the IRC server, as given to the client by the server while starting the IRC connection. If the client has not yet started or finished connecting this will return false and an empty string. <br />
<br />
:This function can be particularly useful for testing if the IRC client has connected to a server prior to sending data, and it will not auto-start the IRC client.<br /> <br />
:The ''hostname'' value this function returns can be used to test if [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage]] events are sent from the server or a user on the network.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local status, hostname = getIrcConnectedHost()<br />
<br />
if status == true then<br />
-- do something with connected IRC, send IRC commands, store 'hostname' elsewhere.<br />
-- if sysIrcMessage sender = hostname from above, message is likely a status, command response, or an error from the Server.<br />
else <br />
-- print a status, change connection settings, or just continue waiting to send IRC data.<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==getIrcNick==<br />
;getIrcNick()<br />
:Returns a string containing the IRC client nickname. If the client is not yet started, your default nickname is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcNick|setIrcNick()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local nick = getIrcNick()<br />
echo(nick)<br />
-- Prints: "Sheldor"<br />
</syntaxhighlight><br />
<br />
==getIrcServer==<br />
;getIrcServer()<br />
:Returns the IRC client server name and port as a string and a number respectively. If the client is not yet started your default server is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcServer|setIrcServer()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local server, port = getIrcServer()<br />
echo("server: "..server..", port: "..port.."\n")<br />
</syntaxhighlight><br />
<br />
==getNetworkLatency==<br />
; getNetworkLatency()<br />
: Returns the last measured response time between the sent command and the server reply in seconds - e.g. 0.058 (=58 milliseconds lag) or 0.309 (=309 milliseconds). This is the ''N:'' number you see bottom-right of Mudlet.<br />
<br />
Also known as server lag.<br />
<br />
;Example<br />
''Need example''<br />
<br />
==openUrl==<br />
;openUrl (url)<br />
:Opens the default OS browser for the given URL.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
openUrl("http://google.com")<br />
openUrl("www.mudlet.org")<br />
</syntaxhighlight><br />
<br />
==receiveMSP==<br />
;receiveMSP(command)<br />
: Receives a well-formed Mud Sound Protocol (MSP) message to be processed by the Mudlet client. Reference the [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]] manual for more information on about what can be sent and example triggers.<br />
<br />
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Play a cow.wav media file stored in the media folder of the current profile. The sound would play twice at a normal volume.<br />
receiveMSP("!!SOUND(cow.wav L=2 V=50)")<br />
<br />
--Stop any SOUND media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!SOUND(Off)")<br />
<br />
--Play a city.mp3 media file stored in the media folder of the current profile. The music would play once at a low volume.<br />
--The music would continue playing if it was triggered earlier by another room, perhaps in the same area.<br />
receiveMSP([[!!MUSIC(city.mp3 L=1 V=25 C=1)]])<br />
<br />
--Stop any MUSIC media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!MUSIC(Off)")<br />
</syntaxhighlight><br />
<br />
==reconnect==<br />
;reconnect()<br />
: Force-reconnects (so if you're connected, it'll disconnect) you to the game.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- you could trigger this on a log out message to reconnect, if you'd like<br />
reconnect()<br />
</syntaxhighlight><br />
<br />
==restartIrc==<br />
;restartIrc()<br />
:Restarts the IRC client connection, reloading configurations from disk before reconnecting the IRC client.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==sendAll==<br />
; sendAll(list of things to send, [echo back or not])<br />
: sends multiple things to the game. If you'd like the commands not to be shown, include ''false'' at the end.<br />
<br />
:See also: [[Manual:Basic_Essentials#send|send()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- instead of using many send() calls, you can use one sendAll<br />
sendAll("outr paint", "outr canvas", "paint canvas")<br />
-- can also have the commands not be echoed<br />
sendAll("hi", "bye", false)<br />
</syntaxhighlight><br />
<br />
==sendATCP==<br />
;sendATCP(message, what)<br />
: ''Need description''<br />
<br />
: See also: [[Manual:Supported_Protocols#ATCP|ATCP Protocol]], [[Manual:ATCP_Extensions|ATCP Extensions]], [http://www.ironrealms.com/rapture/manual/files/FeatATCP-txt.html Achaea Telnet Client Protocol specification], [https://forums.mudlet.org/viewtopic.php?p=19502#p19502 Description by forum user KaVir (2013)], [https://forums.mudlet.org/viewtopic.php?p=2015#p2015 Description by forum user Iocun (2009)]<br />
<br />
;Parameters:<br />
* ''message:''<br />
: The message that you want to send.<br />
* ''what:''<br />
: ''Need description''<br />
<br />
;Example<br />
''Need example''<br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
: Note that this function is rarely used in practice. For most GMCP modules, the messages are automatically sent by the server when a relevant event happens in the game. For example, LOOKing in your room prompts the server to send the room description and contents, as well as the GMCP message gmcp.Room. A call to sendGMCP would not be required in this case.<br />
<br />
: See also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group = "vision"})<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group="MWP", name="block"})<br />
</syntaxhighlight><br />
<br />
==sendMSDP==<br />
;sendMSDP(variable[, value][, value...])<br />
: Sends a MSDP message to the server.<br />
<br />
;Parameters:<br />
* ''variable:''<br />
: The variable, in MSDP terms, that you want to request from the server.<br />
* ''value:''<br />
: The variables value that you want to request. You can request more than one value at a time.<br />
<br />
: See Also: [[Manual:Supported_Protocols#MSDP|MSDP support in Mudlet]], [http://tintin.sourceforge.net/msdp/ Mud Server Data Protocol specification]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- ask for a list of commands, lists, and reportable variables that the server supports<br />
sendMSDP("LIST", "COMMANDS", "LISTS", "REPORTABLE_VARIABLES")<br />
<br />
-- ask the server to start keeping you up to date on your health<br />
sendMSDP("REPORT", "HEALTH")<br />
<br />
-- or on your health and location<br />
sendMSDP("REPORT", "HEALTH", "ROOM_VNUM", "ROOM_NAME")<br />
</syntaxhighlight><br />
<br />
==sendIrc==<br />
;sendIrc(target, message)<br />
: Sends a message to an IRC channel or person. Returns ''true''+''status'' if message could be sent or was successfully processed by the client, or ''nil''+''error'' if the client is not ready for sending, and ''false''+''status'' if the client filtered the message or failed to send it for some reason. If the IRC client hasn't started yet, this function will initiate the IRC client and begin a connection.<br />
<br />
To receive an IRC message, check out the [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage event]].<br />
<br />
{{note}} Since Mudlet 3.3, auto-opens the IRC window and returns the success status.<br />
<br />
;Parameters:<br />
* ''target:''<br />
: nick or channel name and if omitted will default to the first available channel in the list of joined channels.<br />
* ''message:''<br />
: The message to send, may contain IRC client commands which start with <code>/</code> and can use all commands which are available through the client window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
-- this would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
<br />
-- use an in-built IRC command<br />
sendIrc("#mudlet", "/topic")<br />
</syntaxhighlight><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.3:<br />
* /ACTION <target> <message...><br />
* /ADMIN (<server>)<br />
* /AWAY (<reason...>)<br />
* /CLEAR (<buffer>) -- Clears the text log for the given buffer name. Uses the current active buffer if none are given.<br />
* /CLOSE (<buffer>) -- Closes the buffer and removes it from the Buffer list. Uses the current active buffer if none are given.<br />
* /HELP (<command>) -- Displays some help information about a given command or lists all available commands.<br />
* /INFO (<server>)<br />
* /INVITE <user> (<#channel>)<br />
* /JOIN <#channel> (<key>)<br />
* /KICK (<#channel>) <user> (<reason...>)<br />
* /KNOCK <#channel> (<message...>)<br />
* /LIST (<channels>) (<server>)<br />
* /ME [target] <message...><br />
* /MODE (<channel/user>) (<mode>) (<arg>)<br />
* /MOTD (<server>)<br />
* /MSG <target> <message...> -- Sends a message to target, can be used to send Private messages.<br />
* /NAMES (<#channel>)<br />
* /NICK <nick><br />
* /NOTICE <#channel/user> <message...><br />
* /PART (<#channel>) (<message...>)<br />
* /PING (<user>)<br />
* /RECONNECT -- Issues a Quit command to the IRC Server and closes the IRC connection then reconnects to the IRC server. The same as calling ircRestart() in Lua.<br />
* /QUIT (<message...>)<br />
* /QUOTE <command> (<parameters...>)<br />
* /STATS <query> (<server>)<br />
* /TIME (<user>)<br />
* /TOPIC (<#channel>) (<topic...>)<br />
* /TRACE (<target>)<br />
* /USERS (<server>)<br />
* /VERSION (<user>)<br />
* /WHO <mask><br />
* /WHOIS <user><br />
* /WHOWAS <user><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.15:<br />
* /MSGLIMIT <limit> (<buffer>) -- Sets the limit for messages to keep in the IRC client message buffers and saves this setting. If a specific buffer/channel name is given the limit is not saved and applies to the given buffer until the application is closed or the limit is changed again. For this reason, global settings should be applied first, before settings for specific channels/PM buffers.<br />
<br />
==sendTelnetChannel102==<br />
; sendTelnetChannel102(msg)<br />
: Sends a message via the 102 subchannel back to the MUD (that's used in Aardwolf). The msg is in a two byte format; see the link below to the Aardwolf Wiki for how that works.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- turn prompt flags on:<br />
sendTelnetChannel102("\52\1")<br />
<br />
-- turn prompt flags off:<br />
sendTelnetChannel102("\52\2")<br />
</syntaxhighlight><br />
<br />
To see the list of options that Aardwolf supports go to: [http://www.aardwolf.com/blog/2008/07/10/telnet-negotiation-control-mud-client-interaction/ Using Telnet negotiation to control MUD client interaction].<br />
<br />
==setIrcChannels==<br />
;setIrcChannels(channels)<br />
:Saves the given channels to disk as the new IRC client channel auto-join configuration. This value is not applied to the current active IRC client until it is restarted with [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
:See also: [[Manual:Networking_Functions#getIrcChannels|getIrcChannels()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''channels:''<br />
: A table containing strings which are valid channel names. Any channels in the list which aren't valid are removed from the list. <br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcChannels( {"#mudlet", "#lua", "irc"} )<br />
-- Only the first two will be accepted, as "irc" is not a valid channel name.<br />
</syntaxhighlight><br />
<br />
==setIrcNick==<br />
;setIrcNick(nickname)<br />
:Saves the given nickname to disk as the new IRC client configuration. This value is not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcNick|getIrcNick()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''nickname:''<br />
: A string with your new desired name in IRC.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcNick( "Sheldor" )<br />
</syntaxhighlight><br />
<br />
==setIrcServer==<br />
;setIrcServer(hostname, port)<br />
:Saves the given server's address to disk as the new IRC client connection configuration. These values are not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcServer|getIrcServer()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''hostname:''<br />
: A string containing the hostname of the IRC server.<br />
* ''port:''<br />
: (optional) A number indicating the port of the IRC server. Defaults to 6667, if not provided.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcServer("chat.freenode.net", 6667)<br />
</syntaxhighlight><br />
<br />
==getHTTP==<br />
;getHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/GET_(HTTP) HTTP GET] request to the given URL. Raises [[Manual:Event_Engine#sysGetHttpDone|sysGetHttpDone]] on success or [[Manual:Event_Engine#sysGetHttpError|sysGetHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available since Mudlet 4.10<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpGetDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysGetHttpDone", onHttpGetDone)<br />
<br />
getHTTP("https://httpbin.org/info")<br />
getHTTP("https://httpbin.org/are_you_awesome", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- Status requests typically use GET requests<br />
local url = "http://postman-echo.com/status"<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysGetHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysGetHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
getHTTP(url, header)<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
<br />
==postHTTP==<br />
;postHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/POST_(HTTP) HTTP POST] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPostHttpDone|sysPostHttpDone]] on success or [[Manual:Event_Engine#sysPostHttpError|sysPostHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the POST request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpPostDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPostHttpDone", onHttpPostDone)<br />
<br />
postHTTP("why hello there!", "https://httpbin.org/post")<br />
postHTTP("this us a request with custom headers", "https://httpbin.org/post", {["X-am-I-awesome"] = "yep I am"})<br />
postHTTP("https://httpbin.org/post", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This will create a JSON message body. Many modern REST APIs expect a JSON body. <br />
local url = "http://postman-echo.com/post"<br />
local data = {message = "I am the banana", user = "admin"}<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysPostHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysPostHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
postHTTP(yajl.to_string(data), url, header) -- yajl.to_string converts our Lua table into a JSON-like string so the server can understand it<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
==putHTTP==<br />
;putHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/PUT_(HTTP) HTTP PUT] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPutHttpDone|sysPutHttpDone]] on success or [[Manual:Event_Engine#sysPutHttpError|sysPutHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|postHTTP()]], [[#getHTTP|postHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the PUT request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onHttpPutDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPutHttpDone", onHttpPutDone)<br />
putHTTP("this us a request with custom headers", "https://httpbin.org/put", {["X-am-I-awesome"] = "yep I am"})<br />
putHTTP("https://httpbin.org/put", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
==deleteHTTP==<br />
;deleteHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/DELETE_(HTTP) HTTP DELETE] request to the given URL. Raises [[Manual:Event_Engine#sysDeleteHttpDone|sysDeleteHttpDone]] on success or [[Manual:Event_Engine#sysDeleteHttpError|sysDeleteHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
function onHttpDeleteDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysDeleteHttpDone", onHttpDeleteDone)<br />
<br />
deleteHTTP("https://httpbin.org/delete")<br />
deleteHTTP("https://httpbin.org/delete", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Networking_Functions&diff=15496Manual:Networking Functions2020-08-02T13:11:29Z<p>Smurf: /* deleteHTTP */ refer to getHTTP</p>
<hr />
<div>{{TOC right}}<br />
= Networking Functions =<br />
A collection of functions for managing networking.<br />
<br />
==connectToServer==<br />
;connectToServer(host, port, [save])<br />
: Connects to a given game.<br />
<br />
;Parameters:<br />
* ''host:''<br />
: Server domain or IP address.<br />
* ''port:''<br />
: Servers port.<br />
* ''save:''<br />
: (optional, boolean) if provided, saves the new connection parameters in the profile so they'll be used next time you open it.<br />
<br />
{{note}} ''save'' is available in Mudlet 3.2+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
connectToServer("midnightsun2.org", 3000)<br />
<br />
-- save to disk so these parameters are used next time when opening the profile<br />
connectToServer("midnightsun2.org", 3000, true)<br />
</syntaxhighlight><br />
<br />
==disconnect==<br />
;disconnect()<br />
: Disconnects you from the game right away. Note that this will ''not'' properly log you out of the game - use an ingame command for that. Such commands vary, but typically QUIT will work.<br />
<br />
: See also: [[Manual:Networking_Functions#reconnect|reconnect()]]<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
disconnect()<br />
</syntaxhighlight><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Event_Engine#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Event_Engine#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
:See also: [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]]<br />
<br />
[[File:Downloadfile privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
{{note}} Since Mudlet 3.0, https downloads are supported and the actual url that was used for the download is returned - useful in case of redirects.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- just download a file and save it in our profile folder<br />
local saveto = getMudletHomeDir().."/dark-theme-mudlet.zip"<br />
local url = "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip"<br />
downloadFile(saveto, url)<br />
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")<br />
</syntaxhighlight><br />
<br />
<br />
<br />
<br />
A more advanced example that downloads a webpage, reads it, and prints a result from it:<br />
<syntaxhighlight lang="lua"><br />
-- create a function to parse the downloaded webpage and display a result<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:find("achaea-who-count.html", 1, true) then return end<br />
<br />
-- read the contents of the webpage in<br />
local f, s, webpage = io.open(filename)<br />
if f then webpage = f:read("*a"); io.close(f) end<br />
-- delete the file on disk, don't clutter<br />
os.remove(filename)<br />
<br />
-- parse our downloaded file for the player count<br />
local pc = webpage:match([[Total: (%d+) players online]])<br />
display("Achaea has "..tostring(pc).." players on right now.")<br />
end<br />
<br />
-- register our function to run on the event that something was downloaded<br />
registerAnonymousEventHandler("sysDownloadDone", "downloaded_file")<br />
<br />
-- download a list of fake users for a demo<br />
downloadFile(getMudletHomeDir().."/achaea-who-count.html", "https://www.achaea.com/game/who")<br />
</syntaxhighlight><br />
<br />
Result should look like this:<br />
<br />
[[File:DownloadFile_demo.png]].<br />
<br />
==getConnectionInfo==<br />
;getConnectionInfo()<br />
:Returns the server address and port that you're currently connected to.<br />
:See also: [[Manual:Networking_Functions#connectToServer|connectToServer()]]<br />
<br />
{{note}} Available in Mudlet 4.2+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Connected to <forest_green>%s:%s\n", host, port))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- echo the new connection parameters whenever we connect to a different host with connectToServer()<br />
function echoInfo()<br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Now connected to <forest_green>%s:%s\n", host, port))<br />
end<br />
<br />
registerAnonymousEventHandler("sysConnectionEvent", "echoInfo")<br />
</syntaxhighlight><br />
<br />
==getIrcChannels==<br />
;getIrcChannels()<br />
:Returns a list of channels the IRC client is joined to as a lua table. If the client is not yet started the value returned is loaded from disk and represents channels the client will auto-join when started.<br />
:See also: [[Manual:Networking_Functions#setIrcChannels|setIrcChannels()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getIrcChannels())<br />
-- Prints: {"#mudlet", "#lua"}<br />
</syntaxhighlight><br />
<br />
==getIrcConnectedHost==<br />
;getIrcConnectedHost()<br />
:Returns true+host where host is a string containing the host name of the IRC server, as given to the client by the server while starting the IRC connection. If the client has not yet started or finished connecting this will return false and an empty string. <br />
<br />
:This function can be particularly useful for testing if the IRC client has connected to a server prior to sending data, and it will not auto-start the IRC client.<br /> <br />
:The ''hostname'' value this function returns can be used to test if [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage]] events are sent from the server or a user on the network.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local status, hostname = getIrcConnectedHost()<br />
<br />
if status == true then<br />
-- do something with connected IRC, send IRC commands, store 'hostname' elsewhere.<br />
-- if sysIrcMessage sender = hostname from above, message is likely a status, command response, or an error from the Server.<br />
else <br />
-- print a status, change connection settings, or just continue waiting to send IRC data.<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==getIrcNick==<br />
;getIrcNick()<br />
:Returns a string containing the IRC client nickname. If the client is not yet started, your default nickname is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcNick|setIrcNick()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local nick = getIrcNick()<br />
echo(nick)<br />
-- Prints: "Sheldor"<br />
</syntaxhighlight><br />
<br />
==getIrcServer==<br />
;getIrcServer()<br />
:Returns the IRC client server name and port as a string and a number respectively. If the client is not yet started your default server is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcServer|setIrcServer()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local server, port = getIrcServer()<br />
echo("server: "..server..", port: "..port.."\n")<br />
</syntaxhighlight><br />
<br />
==getNetworkLatency==<br />
; getNetworkLatency()<br />
: Returns the last measured response time between the sent command and the server reply in seconds - e.g. 0.058 (=58 milliseconds lag) or 0.309 (=309 milliseconds). This is the ''N:'' number you see bottom-right of Mudlet.<br />
<br />
Also known as server lag.<br />
<br />
;Example<br />
''Need example''<br />
<br />
==openUrl==<br />
;openUrl (url)<br />
:Opens the default OS browser for the given URL.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
openUrl("http://google.com")<br />
openUrl("www.mudlet.org")<br />
</syntaxhighlight><br />
<br />
==receiveMSP==<br />
;receiveMSP(command)<br />
: Receives a well-formed Mud Sound Protocol (MSP) message to be processed by the Mudlet client. Reference the [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]] manual for more information on about what can be sent and example triggers.<br />
<br />
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Play a cow.wav media file stored in the media folder of the current profile. The sound would play twice at a normal volume.<br />
receiveMSP("!!SOUND(cow.wav L=2 V=50)")<br />
<br />
--Stop any SOUND media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!SOUND(Off)")<br />
<br />
--Play a city.mp3 media file stored in the media folder of the current profile. The music would play once at a low volume.<br />
--The music would continue playing if it was triggered earlier by another room, perhaps in the same area.<br />
receiveMSP([[!!MUSIC(city.mp3 L=1 V=25 C=1)]])<br />
<br />
--Stop any MUSIC media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!MUSIC(Off)")<br />
</syntaxhighlight><br />
<br />
==reconnect==<br />
;reconnect()<br />
: Force-reconnects (so if you're connected, it'll disconnect) you to the game.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- you could trigger this on a log out message to reconnect, if you'd like<br />
reconnect()<br />
</syntaxhighlight><br />
<br />
==restartIrc==<br />
;restartIrc()<br />
:Restarts the IRC client connection, reloading configurations from disk before reconnecting the IRC client.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==sendAll==<br />
; sendAll(list of things to send, [echo back or not])<br />
: sends multiple things to the game. If you'd like the commands not to be shown, include ''false'' at the end.<br />
<br />
:See also: [[Manual:Basic_Essentials#send|send()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- instead of using many send() calls, you can use one sendAll<br />
sendAll("outr paint", "outr canvas", "paint canvas")<br />
-- can also have the commands not be echoed<br />
sendAll("hi", "bye", false)<br />
</syntaxhighlight><br />
<br />
==sendATCP==<br />
;sendATCP(message, what)<br />
: ''Need description''<br />
<br />
: See also: [[Manual:Supported_Protocols#ATCP|ATCP Protocol]], [[Manual:ATCP_Extensions|ATCP Extensions]], [http://www.ironrealms.com/rapture/manual/files/FeatATCP-txt.html Achaea Telnet Client Protocol specification], [https://forums.mudlet.org/viewtopic.php?p=19502#p19502 Description by forum user KaVir (2013)], [https://forums.mudlet.org/viewtopic.php?p=2015#p2015 Description by forum user Iocun (2009)]<br />
<br />
;Parameters:<br />
* ''message:''<br />
: The message that you want to send.<br />
* ''what:''<br />
: ''Need description''<br />
<br />
;Example<br />
''Need example''<br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
: Note that this function is rarely used in practice. For most GMCP modules, the messages are automatically sent by the server when a relevant event happens in the game. For example, LOOKing in your room prompts the server to send the room description and contents, as well as the GMCP message gmcp.Room. A call to sendGMCP would not be required in this case.<br />
<br />
: See also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group = "vision"})<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group="MWP", name="block"})<br />
</syntaxhighlight><br />
<br />
==sendMSDP==<br />
;sendMSDP(variable[, value][, value...])<br />
: Sends a MSDP message to the server.<br />
<br />
;Parameters:<br />
* ''variable:''<br />
: The variable, in MSDP terms, that you want to request from the server.<br />
* ''value:''<br />
: The variables value that you want to request. You can request more than one value at a time.<br />
<br />
: See Also: [[Manual:Supported_Protocols#MSDP|MSDP support in Mudlet]], [http://tintin.sourceforge.net/msdp/ Mud Server Data Protocol specification]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- ask for a list of commands, lists, and reportable variables that the server supports<br />
sendMSDP("LIST", "COMMANDS", "LISTS", "REPORTABLE_VARIABLES")<br />
<br />
-- ask the server to start keeping you up to date on your health<br />
sendMSDP("REPORT", "HEALTH")<br />
<br />
-- or on your health and location<br />
sendMSDP("REPORT", "HEALTH", "ROOM_VNUM", "ROOM_NAME")<br />
</syntaxhighlight><br />
<br />
==sendIrc==<br />
;sendIrc(target, message)<br />
: Sends a message to an IRC channel or person. Returns ''true''+''status'' if message could be sent or was successfully processed by the client, or ''nil''+''error'' if the client is not ready for sending, and ''false''+''status'' if the client filtered the message or failed to send it for some reason. If the IRC client hasn't started yet, this function will initiate the IRC client and begin a connection.<br />
<br />
To receive an IRC message, check out the [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage event]].<br />
<br />
{{note}} Since Mudlet 3.3, auto-opens the IRC window and returns the success status.<br />
<br />
;Parameters:<br />
* ''target:''<br />
: nick or channel name and if omitted will default to the first available channel in the list of joined channels.<br />
* ''message:''<br />
: The message to send, may contain IRC client commands which start with <code>/</code> and can use all commands which are available through the client window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
-- this would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
<br />
-- use an in-built IRC command<br />
sendIrc("#mudlet", "/topic")<br />
</syntaxhighlight><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.3:<br />
* /ACTION <target> <message...><br />
* /ADMIN (<server>)<br />
* /AWAY (<reason...>)<br />
* /CLEAR (<buffer>) -- Clears the text log for the given buffer name. Uses the current active buffer if none are given.<br />
* /CLOSE (<buffer>) -- Closes the buffer and removes it from the Buffer list. Uses the current active buffer if none are given.<br />
* /HELP (<command>) -- Displays some help information about a given command or lists all available commands.<br />
* /INFO (<server>)<br />
* /INVITE <user> (<#channel>)<br />
* /JOIN <#channel> (<key>)<br />
* /KICK (<#channel>) <user> (<reason...>)<br />
* /KNOCK <#channel> (<message...>)<br />
* /LIST (<channels>) (<server>)<br />
* /ME [target] <message...><br />
* /MODE (<channel/user>) (<mode>) (<arg>)<br />
* /MOTD (<server>)<br />
* /MSG <target> <message...> -- Sends a message to target, can be used to send Private messages.<br />
* /NAMES (<#channel>)<br />
* /NICK <nick><br />
* /NOTICE <#channel/user> <message...><br />
* /PART (<#channel>) (<message...>)<br />
* /PING (<user>)<br />
* /RECONNECT -- Issues a Quit command to the IRC Server and closes the IRC connection then reconnects to the IRC server. The same as calling ircRestart() in Lua.<br />
* /QUIT (<message...>)<br />
* /QUOTE <command> (<parameters...>)<br />
* /STATS <query> (<server>)<br />
* /TIME (<user>)<br />
* /TOPIC (<#channel>) (<topic...>)<br />
* /TRACE (<target>)<br />
* /USERS (<server>)<br />
* /VERSION (<user>)<br />
* /WHO <mask><br />
* /WHOIS <user><br />
* /WHOWAS <user><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.15:<br />
* /MSGLIMIT <limit> (<buffer>) -- Sets the limit for messages to keep in the IRC client message buffers and saves this setting. If a specific buffer/channel name is given the limit is not saved and applies to the given buffer until the application is closed or the limit is changed again. For this reason, global settings should be applied first, before settings for specific channels/PM buffers.<br />
<br />
==sendTelnetChannel102==<br />
; sendTelnetChannel102(msg)<br />
: Sends a message via the 102 subchannel back to the MUD (that's used in Aardwolf). The msg is in a two byte format; see the link below to the Aardwolf Wiki for how that works.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- turn prompt flags on:<br />
sendTelnetChannel102("\52\1")<br />
<br />
-- turn prompt flags off:<br />
sendTelnetChannel102("\52\2")<br />
</syntaxhighlight><br />
<br />
To see the list of options that Aardwolf supports go to: [http://www.aardwolf.com/blog/2008/07/10/telnet-negotiation-control-mud-client-interaction/ Using Telnet negotiation to control MUD client interaction].<br />
<br />
==setIrcChannels==<br />
;setIrcChannels(channels)<br />
:Saves the given channels to disk as the new IRC client channel auto-join configuration. This value is not applied to the current active IRC client until it is restarted with [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
:See also: [[Manual:Networking_Functions#getIrcChannels|getIrcChannels()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''channels:''<br />
: A table containing strings which are valid channel names. Any channels in the list which aren't valid are removed from the list. <br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcChannels( {"#mudlet", "#lua", "irc"} )<br />
-- Only the first two will be accepted, as "irc" is not a valid channel name.<br />
</syntaxhighlight><br />
<br />
==setIrcNick==<br />
;setIrcNick(nickname)<br />
:Saves the given nickname to disk as the new IRC client configuration. This value is not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcNick|getIrcNick()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''nickname:''<br />
: A string with your new desired name in IRC.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcNick( "Sheldor" )<br />
</syntaxhighlight><br />
<br />
==setIrcServer==<br />
;setIrcServer(hostname, port)<br />
:Saves the given server's address to disk as the new IRC client connection configuration. These values are not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcServer|getIrcServer()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''hostname:''<br />
: A string containing the hostname of the IRC server.<br />
* ''port:''<br />
: (optional) A number indicating the port of the IRC server. Defaults to 6667, if not provided.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcServer("chat.freenode.net", 6667)<br />
</syntaxhighlight><br />
<br />
==getHTTP==<br />
;getHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/GET_(HTTP) HTTP GET] request to the given URL. Raises [[Manual:Event_Engine#sysGetHttpDone|sysGetHttpDone]] on success or [[Manual:Event_Engine#sysGetHttpError|sysGetHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available since Mudlet 4.10<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpGetDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysGetHttpDone", onHttpGetDone)<br />
<br />
getHTTP("https://httpbin.org/info")<br />
getHTTP("https://httpbin.org/are_you_awesome", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- Status requests typically use GET requests<br />
local url = "http://postman-echo.com/status"<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysGetHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysGetHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
getHTTP(url, header)<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
<br />
==postHTTP==<br />
;postHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/POST_(HTTP) HTTP POST] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPostHttpDone|sysPostHttpDone]] on success or [[Manual:Event_Engine#sysPostHttpError|sysPostHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the POST request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpPostDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPostHttpDone", onHttpPostDone)<br />
<br />
postHTTP("why hello there!", "https://httpbin.org/post")<br />
postHTTP("this us a request with custom headers", "https://httpbin.org/post", {["X-am-I-awesome"] = "yep I am"})<br />
postHTTP("https://httpbin.org/post", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This will create a JSON message body. Many modern REST APIs expect a JSON body. <br />
local url = "http://postman-echo.com/post"<br />
local data = {message = "I am the banana", user = "admin"}<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysPostHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysPostHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
postHTTP(yajl.to_string(data), url, header) -- yajl.to_string converts our Lua table into a JSON-like string so the server can understand it<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
==putHTTP==<br />
;putHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/PUT_(HTTP) HTTP PUT] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPutHttpDone|sysPutHttpDone]] on success or [[Manual:Event_Engine#sysPutHttpError|sysPutHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#postHTTP|postHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the PUT request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onHttpPutDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPutHttpDone", onHttpPutDone)<br />
putHTTP("this us a request with custom headers", "https://httpbin.org/put", {["X-am-I-awesome"] = "yep I am"})<br />
putHTTP("https://httpbin.org/put", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
==deleteHTTP==<br />
;deleteHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/DELETE_(HTTP) HTTP DELETE] request to the given URL. Raises [[Manual:Event_Engine#sysDeleteHttpDone|sysDeleteHttpDone]] on success or [[Manual:Event_Engine#sysDeleteHttpError|sysDeleteHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
function onHttpDeleteDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysDeleteHttpDone", onHttpDeleteDone)<br />
<br />
deleteHTTP("https://httpbin.org/delete")<br />
deleteHTTP("https://httpbin.org/delete", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Networking_Functions&diff=15495Manual:Networking Functions2020-08-02T13:09:58Z<p>Smurf: /* downloadFile */ add ref to getHTTP</p>
<hr />
<div>{{TOC right}}<br />
= Networking Functions =<br />
A collection of functions for managing networking.<br />
<br />
==connectToServer==<br />
;connectToServer(host, port, [save])<br />
: Connects to a given game.<br />
<br />
;Parameters:<br />
* ''host:''<br />
: Server domain or IP address.<br />
* ''port:''<br />
: Servers port.<br />
* ''save:''<br />
: (optional, boolean) if provided, saves the new connection parameters in the profile so they'll be used next time you open it.<br />
<br />
{{note}} ''save'' is available in Mudlet 3.2+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
connectToServer("midnightsun2.org", 3000)<br />
<br />
-- save to disk so these parameters are used next time when opening the profile<br />
connectToServer("midnightsun2.org", 3000, true)<br />
</syntaxhighlight><br />
<br />
==disconnect==<br />
;disconnect()<br />
: Disconnects you from the game right away. Note that this will ''not'' properly log you out of the game - use an ingame command for that. Such commands vary, but typically QUIT will work.<br />
<br />
: See also: [[Manual:Networking_Functions#reconnect|reconnect()]]<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
disconnect()<br />
</syntaxhighlight><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Event_Engine#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Event_Engine#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
:See also: [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]]<br />
<br />
[[File:Downloadfile privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
{{note}} Since Mudlet 3.0, https downloads are supported and the actual url that was used for the download is returned - useful in case of redirects.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- just download a file and save it in our profile folder<br />
local saveto = getMudletHomeDir().."/dark-theme-mudlet.zip"<br />
local url = "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip"<br />
downloadFile(saveto, url)<br />
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")<br />
</syntaxhighlight><br />
<br />
<br />
<br />
<br />
A more advanced example that downloads a webpage, reads it, and prints a result from it:<br />
<syntaxhighlight lang="lua"><br />
-- create a function to parse the downloaded webpage and display a result<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:find("achaea-who-count.html", 1, true) then return end<br />
<br />
-- read the contents of the webpage in<br />
local f, s, webpage = io.open(filename)<br />
if f then webpage = f:read("*a"); io.close(f) end<br />
-- delete the file on disk, don't clutter<br />
os.remove(filename)<br />
<br />
-- parse our downloaded file for the player count<br />
local pc = webpage:match([[Total: (%d+) players online]])<br />
display("Achaea has "..tostring(pc).." players on right now.")<br />
end<br />
<br />
-- register our function to run on the event that something was downloaded<br />
registerAnonymousEventHandler("sysDownloadDone", "downloaded_file")<br />
<br />
-- download a list of fake users for a demo<br />
downloadFile(getMudletHomeDir().."/achaea-who-count.html", "https://www.achaea.com/game/who")<br />
</syntaxhighlight><br />
<br />
Result should look like this:<br />
<br />
[[File:DownloadFile_demo.png]].<br />
<br />
==getConnectionInfo==<br />
;getConnectionInfo()<br />
:Returns the server address and port that you're currently connected to.<br />
:See also: [[Manual:Networking_Functions#connectToServer|connectToServer()]]<br />
<br />
{{note}} Available in Mudlet 4.2+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Connected to <forest_green>%s:%s\n", host, port))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- echo the new connection parameters whenever we connect to a different host with connectToServer()<br />
function echoInfo()<br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Now connected to <forest_green>%s:%s\n", host, port))<br />
end<br />
<br />
registerAnonymousEventHandler("sysConnectionEvent", "echoInfo")<br />
</syntaxhighlight><br />
<br />
==getIrcChannels==<br />
;getIrcChannels()<br />
:Returns a list of channels the IRC client is joined to as a lua table. If the client is not yet started the value returned is loaded from disk and represents channels the client will auto-join when started.<br />
:See also: [[Manual:Networking_Functions#setIrcChannels|setIrcChannels()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getIrcChannels())<br />
-- Prints: {"#mudlet", "#lua"}<br />
</syntaxhighlight><br />
<br />
==getIrcConnectedHost==<br />
;getIrcConnectedHost()<br />
:Returns true+host where host is a string containing the host name of the IRC server, as given to the client by the server while starting the IRC connection. If the client has not yet started or finished connecting this will return false and an empty string. <br />
<br />
:This function can be particularly useful for testing if the IRC client has connected to a server prior to sending data, and it will not auto-start the IRC client.<br /> <br />
:The ''hostname'' value this function returns can be used to test if [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage]] events are sent from the server or a user on the network.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local status, hostname = getIrcConnectedHost()<br />
<br />
if status == true then<br />
-- do something with connected IRC, send IRC commands, store 'hostname' elsewhere.<br />
-- if sysIrcMessage sender = hostname from above, message is likely a status, command response, or an error from the Server.<br />
else <br />
-- print a status, change connection settings, or just continue waiting to send IRC data.<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==getIrcNick==<br />
;getIrcNick()<br />
:Returns a string containing the IRC client nickname. If the client is not yet started, your default nickname is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcNick|setIrcNick()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local nick = getIrcNick()<br />
echo(nick)<br />
-- Prints: "Sheldor"<br />
</syntaxhighlight><br />
<br />
==getIrcServer==<br />
;getIrcServer()<br />
:Returns the IRC client server name and port as a string and a number respectively. If the client is not yet started your default server is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcServer|setIrcServer()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local server, port = getIrcServer()<br />
echo("server: "..server..", port: "..port.."\n")<br />
</syntaxhighlight><br />
<br />
==getNetworkLatency==<br />
; getNetworkLatency()<br />
: Returns the last measured response time between the sent command and the server reply in seconds - e.g. 0.058 (=58 milliseconds lag) or 0.309 (=309 milliseconds). This is the ''N:'' number you see bottom-right of Mudlet.<br />
<br />
Also known as server lag.<br />
<br />
;Example<br />
''Need example''<br />
<br />
==openUrl==<br />
;openUrl (url)<br />
:Opens the default OS browser for the given URL.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
openUrl("http://google.com")<br />
openUrl("www.mudlet.org")<br />
</syntaxhighlight><br />
<br />
==receiveMSP==<br />
;receiveMSP(command)<br />
: Receives a well-formed Mud Sound Protocol (MSP) message to be processed by the Mudlet client. Reference the [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]] manual for more information on about what can be sent and example triggers.<br />
<br />
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Play a cow.wav media file stored in the media folder of the current profile. The sound would play twice at a normal volume.<br />
receiveMSP("!!SOUND(cow.wav L=2 V=50)")<br />
<br />
--Stop any SOUND media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!SOUND(Off)")<br />
<br />
--Play a city.mp3 media file stored in the media folder of the current profile. The music would play once at a low volume.<br />
--The music would continue playing if it was triggered earlier by another room, perhaps in the same area.<br />
receiveMSP([[!!MUSIC(city.mp3 L=1 V=25 C=1)]])<br />
<br />
--Stop any MUSIC media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!MUSIC(Off)")<br />
</syntaxhighlight><br />
<br />
==reconnect==<br />
;reconnect()<br />
: Force-reconnects (so if you're connected, it'll disconnect) you to the game.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- you could trigger this on a log out message to reconnect, if you'd like<br />
reconnect()<br />
</syntaxhighlight><br />
<br />
==restartIrc==<br />
;restartIrc()<br />
:Restarts the IRC client connection, reloading configurations from disk before reconnecting the IRC client.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==sendAll==<br />
; sendAll(list of things to send, [echo back or not])<br />
: sends multiple things to the game. If you'd like the commands not to be shown, include ''false'' at the end.<br />
<br />
:See also: [[Manual:Basic_Essentials#send|send()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- instead of using many send() calls, you can use one sendAll<br />
sendAll("outr paint", "outr canvas", "paint canvas")<br />
-- can also have the commands not be echoed<br />
sendAll("hi", "bye", false)<br />
</syntaxhighlight><br />
<br />
==sendATCP==<br />
;sendATCP(message, what)<br />
: ''Need description''<br />
<br />
: See also: [[Manual:Supported_Protocols#ATCP|ATCP Protocol]], [[Manual:ATCP_Extensions|ATCP Extensions]], [http://www.ironrealms.com/rapture/manual/files/FeatATCP-txt.html Achaea Telnet Client Protocol specification], [https://forums.mudlet.org/viewtopic.php?p=19502#p19502 Description by forum user KaVir (2013)], [https://forums.mudlet.org/viewtopic.php?p=2015#p2015 Description by forum user Iocun (2009)]<br />
<br />
;Parameters:<br />
* ''message:''<br />
: The message that you want to send.<br />
* ''what:''<br />
: ''Need description''<br />
<br />
;Example<br />
''Need example''<br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
: Note that this function is rarely used in practice. For most GMCP modules, the messages are automatically sent by the server when a relevant event happens in the game. For example, LOOKing in your room prompts the server to send the room description and contents, as well as the GMCP message gmcp.Room. A call to sendGMCP would not be required in this case.<br />
<br />
: See also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group = "vision"})<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group="MWP", name="block"})<br />
</syntaxhighlight><br />
<br />
==sendMSDP==<br />
;sendMSDP(variable[, value][, value...])<br />
: Sends a MSDP message to the server.<br />
<br />
;Parameters:<br />
* ''variable:''<br />
: The variable, in MSDP terms, that you want to request from the server.<br />
* ''value:''<br />
: The variables value that you want to request. You can request more than one value at a time.<br />
<br />
: See Also: [[Manual:Supported_Protocols#MSDP|MSDP support in Mudlet]], [http://tintin.sourceforge.net/msdp/ Mud Server Data Protocol specification]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- ask for a list of commands, lists, and reportable variables that the server supports<br />
sendMSDP("LIST", "COMMANDS", "LISTS", "REPORTABLE_VARIABLES")<br />
<br />
-- ask the server to start keeping you up to date on your health<br />
sendMSDP("REPORT", "HEALTH")<br />
<br />
-- or on your health and location<br />
sendMSDP("REPORT", "HEALTH", "ROOM_VNUM", "ROOM_NAME")<br />
</syntaxhighlight><br />
<br />
==sendIrc==<br />
;sendIrc(target, message)<br />
: Sends a message to an IRC channel or person. Returns ''true''+''status'' if message could be sent or was successfully processed by the client, or ''nil''+''error'' if the client is not ready for sending, and ''false''+''status'' if the client filtered the message or failed to send it for some reason. If the IRC client hasn't started yet, this function will initiate the IRC client and begin a connection.<br />
<br />
To receive an IRC message, check out the [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage event]].<br />
<br />
{{note}} Since Mudlet 3.3, auto-opens the IRC window and returns the success status.<br />
<br />
;Parameters:<br />
* ''target:''<br />
: nick or channel name and if omitted will default to the first available channel in the list of joined channels.<br />
* ''message:''<br />
: The message to send, may contain IRC client commands which start with <code>/</code> and can use all commands which are available through the client window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
-- this would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
<br />
-- use an in-built IRC command<br />
sendIrc("#mudlet", "/topic")<br />
</syntaxhighlight><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.3:<br />
* /ACTION <target> <message...><br />
* /ADMIN (<server>)<br />
* /AWAY (<reason...>)<br />
* /CLEAR (<buffer>) -- Clears the text log for the given buffer name. Uses the current active buffer if none are given.<br />
* /CLOSE (<buffer>) -- Closes the buffer and removes it from the Buffer list. Uses the current active buffer if none are given.<br />
* /HELP (<command>) -- Displays some help information about a given command or lists all available commands.<br />
* /INFO (<server>)<br />
* /INVITE <user> (<#channel>)<br />
* /JOIN <#channel> (<key>)<br />
* /KICK (<#channel>) <user> (<reason...>)<br />
* /KNOCK <#channel> (<message...>)<br />
* /LIST (<channels>) (<server>)<br />
* /ME [target] <message...><br />
* /MODE (<channel/user>) (<mode>) (<arg>)<br />
* /MOTD (<server>)<br />
* /MSG <target> <message...> -- Sends a message to target, can be used to send Private messages.<br />
* /NAMES (<#channel>)<br />
* /NICK <nick><br />
* /NOTICE <#channel/user> <message...><br />
* /PART (<#channel>) (<message...>)<br />
* /PING (<user>)<br />
* /RECONNECT -- Issues a Quit command to the IRC Server and closes the IRC connection then reconnects to the IRC server. The same as calling ircRestart() in Lua.<br />
* /QUIT (<message...>)<br />
* /QUOTE <command> (<parameters...>)<br />
* /STATS <query> (<server>)<br />
* /TIME (<user>)<br />
* /TOPIC (<#channel>) (<topic...>)<br />
* /TRACE (<target>)<br />
* /USERS (<server>)<br />
* /VERSION (<user>)<br />
* /WHO <mask><br />
* /WHOIS <user><br />
* /WHOWAS <user><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.15:<br />
* /MSGLIMIT <limit> (<buffer>) -- Sets the limit for messages to keep in the IRC client message buffers and saves this setting. If a specific buffer/channel name is given the limit is not saved and applies to the given buffer until the application is closed or the limit is changed again. For this reason, global settings should be applied first, before settings for specific channels/PM buffers.<br />
<br />
==sendTelnetChannel102==<br />
; sendTelnetChannel102(msg)<br />
: Sends a message via the 102 subchannel back to the MUD (that's used in Aardwolf). The msg is in a two byte format; see the link below to the Aardwolf Wiki for how that works.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- turn prompt flags on:<br />
sendTelnetChannel102("\52\1")<br />
<br />
-- turn prompt flags off:<br />
sendTelnetChannel102("\52\2")<br />
</syntaxhighlight><br />
<br />
To see the list of options that Aardwolf supports go to: [http://www.aardwolf.com/blog/2008/07/10/telnet-negotiation-control-mud-client-interaction/ Using Telnet negotiation to control MUD client interaction].<br />
<br />
==setIrcChannels==<br />
;setIrcChannels(channels)<br />
:Saves the given channels to disk as the new IRC client channel auto-join configuration. This value is not applied to the current active IRC client until it is restarted with [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
:See also: [[Manual:Networking_Functions#getIrcChannels|getIrcChannels()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''channels:''<br />
: A table containing strings which are valid channel names. Any channels in the list which aren't valid are removed from the list. <br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcChannels( {"#mudlet", "#lua", "irc"} )<br />
-- Only the first two will be accepted, as "irc" is not a valid channel name.<br />
</syntaxhighlight><br />
<br />
==setIrcNick==<br />
;setIrcNick(nickname)<br />
:Saves the given nickname to disk as the new IRC client configuration. This value is not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcNick|getIrcNick()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''nickname:''<br />
: A string with your new desired name in IRC.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcNick( "Sheldor" )<br />
</syntaxhighlight><br />
<br />
==setIrcServer==<br />
;setIrcServer(hostname, port)<br />
:Saves the given server's address to disk as the new IRC client connection configuration. These values are not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcServer|getIrcServer()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''hostname:''<br />
: A string containing the hostname of the IRC server.<br />
* ''port:''<br />
: (optional) A number indicating the port of the IRC server. Defaults to 6667, if not provided.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcServer("chat.freenode.net", 6667)<br />
</syntaxhighlight><br />
<br />
==getHTTP==<br />
;getHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/GET_(HTTP) HTTP GET] request to the given URL. Raises [[Manual:Event_Engine#sysGetHttpDone|sysGetHttpDone]] on success or [[Manual:Event_Engine#sysGetHttpError|sysGetHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available since Mudlet 4.10<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpGetDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysGetHttpDone", onHttpGetDone)<br />
<br />
getHTTP("https://httpbin.org/info")<br />
getHTTP("https://httpbin.org/are_you_awesome", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- Status requests typically use GET requests<br />
local url = "http://postman-echo.com/status"<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysGetHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysGetHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
getHTTP(url, header)<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
<br />
==postHTTP==<br />
;postHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/POST_(HTTP) HTTP POST] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPostHttpDone|sysPostHttpDone]] on success or [[Manual:Event_Engine#sysPostHttpError|sysPostHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the POST request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpPostDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPostHttpDone", onHttpPostDone)<br />
<br />
postHTTP("why hello there!", "https://httpbin.org/post")<br />
postHTTP("this us a request with custom headers", "https://httpbin.org/post", {["X-am-I-awesome"] = "yep I am"})<br />
postHTTP("https://httpbin.org/post", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This will create a JSON message body. Many modern REST APIs expect a JSON body. <br />
local url = "http://postman-echo.com/post"<br />
local data = {message = "I am the banana", user = "admin"}<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysPostHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysPostHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
postHTTP(yajl.to_string(data), url, header) -- yajl.to_string converts our Lua table into a JSON-like string so the server can understand it<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
==putHTTP==<br />
;putHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/PUT_(HTTP) HTTP PUT] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPutHttpDone|sysPutHttpDone]] on success or [[Manual:Event_Engine#sysPutHttpError|sysPutHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#postHTTP|postHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the PUT request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onHttpPutDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPutHttpDone", onHttpPutDone)<br />
putHTTP("this us a request with custom headers", "https://httpbin.org/put", {["X-am-I-awesome"] = "yep I am"})<br />
putHTTP("https://httpbin.org/put", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
==deleteHTTP==<br />
;deleteHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/DELETE_(HTTP) HTTP DELETE] request to the given URL. Raises [[Manual:Event_Engine#sysDeleteHttpDone|sysDeleteHttpDone]] on success or [[Manual:Event_Engine#sysDeleteHttpError|sysDeleteHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
function onHttpDeleteDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysDeleteHttpDone", onHttpDeleteDone)<br />
<br />
deleteHTTP("https://httpbin.org/delete")<br />
deleteHTTP("https://httpbin.org/delete", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Networking_Functions&diff=15494Manual:Networking Functions2020-08-02T13:09:23Z<p>Smurf: /* getHTTP */ added</p>
<hr />
<div>{{TOC right}}<br />
= Networking Functions =<br />
A collection of functions for managing networking.<br />
<br />
==connectToServer==<br />
;connectToServer(host, port, [save])<br />
: Connects to a given game.<br />
<br />
;Parameters:<br />
* ''host:''<br />
: Server domain or IP address.<br />
* ''port:''<br />
: Servers port.<br />
* ''save:''<br />
: (optional, boolean) if provided, saves the new connection parameters in the profile so they'll be used next time you open it.<br />
<br />
{{note}} ''save'' is available in Mudlet 3.2+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
connectToServer("midnightsun2.org", 3000)<br />
<br />
-- save to disk so these parameters are used next time when opening the profile<br />
connectToServer("midnightsun2.org", 3000, true)<br />
</syntaxhighlight><br />
<br />
==disconnect==<br />
;disconnect()<br />
: Disconnects you from the game right away. Note that this will ''not'' properly log you out of the game - use an ingame command for that. Such commands vary, but typically QUIT will work.<br />
<br />
: See also: [[Manual:Networking_Functions#reconnect|reconnect()]]<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
disconnect()<br />
</syntaxhighlight><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Event_Engine#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Event_Engine#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
:See also: [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]]<br />
<br />
[[File:Downloadfile privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
{{note}} Since Mudlet 3.0, https downloads are supported and the actual url that was used for the download is returned - useful in case of redirects.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- just download a file and save it in our profile folder<br />
local saveto = getMudletHomeDir().."/dark-theme-mudlet.zip"<br />
local url = "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip"<br />
downloadFile(saveto, url)<br />
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")<br />
</syntaxhighlight><br />
<br />
<br />
<br />
<br />
A more advanced example that downloads a webpage, reads it, and prints a result from it:<br />
<syntaxhighlight lang="lua"><br />
-- create a function to parse the downloaded webpage and display a result<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:find("achaea-who-count.html", 1, true) then return end<br />
<br />
-- read the contents of the webpage in<br />
local f, s, webpage = io.open(filename)<br />
if f then webpage = f:read("*a"); io.close(f) end<br />
-- delete the file on disk, don't clutter<br />
os.remove(filename)<br />
<br />
-- parse our downloaded file for the player count<br />
local pc = webpage:match([[Total: (%d+) players online]])<br />
display("Achaea has "..tostring(pc).." players on right now.")<br />
end<br />
<br />
-- register our function to run on the event that something was downloaded<br />
registerAnonymousEventHandler("sysDownloadDone", "downloaded_file")<br />
<br />
-- download a list of fake users for a demo<br />
downloadFile(getMudletHomeDir().."/achaea-who-count.html", "https://www.achaea.com/game/who")<br />
</syntaxhighlight><br />
<br />
Result should look like this:<br />
<br />
[[File:DownloadFile_demo.png]].<br />
<br />
==getConnectionInfo==<br />
;getConnectionInfo()<br />
:Returns the server address and port that you're currently connected to.<br />
:See also: [[Manual:Networking_Functions#connectToServer|connectToServer()]]<br />
<br />
{{note}} Available in Mudlet 4.2+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Connected to <forest_green>%s:%s\n", host, port))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- echo the new connection parameters whenever we connect to a different host with connectToServer()<br />
function echoInfo()<br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Now connected to <forest_green>%s:%s\n", host, port))<br />
end<br />
<br />
registerAnonymousEventHandler("sysConnectionEvent", "echoInfo")<br />
</syntaxhighlight><br />
<br />
==getIrcChannels==<br />
;getIrcChannels()<br />
:Returns a list of channels the IRC client is joined to as a lua table. If the client is not yet started the value returned is loaded from disk and represents channels the client will auto-join when started.<br />
:See also: [[Manual:Networking_Functions#setIrcChannels|setIrcChannels()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getIrcChannels())<br />
-- Prints: {"#mudlet", "#lua"}<br />
</syntaxhighlight><br />
<br />
==getIrcConnectedHost==<br />
;getIrcConnectedHost()<br />
:Returns true+host where host is a string containing the host name of the IRC server, as given to the client by the server while starting the IRC connection. If the client has not yet started or finished connecting this will return false and an empty string. <br />
<br />
:This function can be particularly useful for testing if the IRC client has connected to a server prior to sending data, and it will not auto-start the IRC client.<br /> <br />
:The ''hostname'' value this function returns can be used to test if [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage]] events are sent from the server or a user on the network.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local status, hostname = getIrcConnectedHost()<br />
<br />
if status == true then<br />
-- do something with connected IRC, send IRC commands, store 'hostname' elsewhere.<br />
-- if sysIrcMessage sender = hostname from above, message is likely a status, command response, or an error from the Server.<br />
else <br />
-- print a status, change connection settings, or just continue waiting to send IRC data.<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==getIrcNick==<br />
;getIrcNick()<br />
:Returns a string containing the IRC client nickname. If the client is not yet started, your default nickname is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcNick|setIrcNick()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local nick = getIrcNick()<br />
echo(nick)<br />
-- Prints: "Sheldor"<br />
</syntaxhighlight><br />
<br />
==getIrcServer==<br />
;getIrcServer()<br />
:Returns the IRC client server name and port as a string and a number respectively. If the client is not yet started your default server is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcServer|setIrcServer()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local server, port = getIrcServer()<br />
echo("server: "..server..", port: "..port.."\n")<br />
</syntaxhighlight><br />
<br />
==getNetworkLatency==<br />
; getNetworkLatency()<br />
: Returns the last measured response time between the sent command and the server reply in seconds - e.g. 0.058 (=58 milliseconds lag) or 0.309 (=309 milliseconds). This is the ''N:'' number you see bottom-right of Mudlet.<br />
<br />
Also known as server lag.<br />
<br />
;Example<br />
''Need example''<br />
<br />
==openUrl==<br />
;openUrl (url)<br />
:Opens the default OS browser for the given URL.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
openUrl("http://google.com")<br />
openUrl("www.mudlet.org")<br />
</syntaxhighlight><br />
<br />
==receiveMSP==<br />
;receiveMSP(command)<br />
: Receives a well-formed Mud Sound Protocol (MSP) message to be processed by the Mudlet client. Reference the [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]] manual for more information on about what can be sent and example triggers.<br />
<br />
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Play a cow.wav media file stored in the media folder of the current profile. The sound would play twice at a normal volume.<br />
receiveMSP("!!SOUND(cow.wav L=2 V=50)")<br />
<br />
--Stop any SOUND media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!SOUND(Off)")<br />
<br />
--Play a city.mp3 media file stored in the media folder of the current profile. The music would play once at a low volume.<br />
--The music would continue playing if it was triggered earlier by another room, perhaps in the same area.<br />
receiveMSP([[!!MUSIC(city.mp3 L=1 V=25 C=1)]])<br />
<br />
--Stop any MUSIC media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!MUSIC(Off)")<br />
</syntaxhighlight><br />
<br />
==reconnect==<br />
;reconnect()<br />
: Force-reconnects (so if you're connected, it'll disconnect) you to the game.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- you could trigger this on a log out message to reconnect, if you'd like<br />
reconnect()<br />
</syntaxhighlight><br />
<br />
==restartIrc==<br />
;restartIrc()<br />
:Restarts the IRC client connection, reloading configurations from disk before reconnecting the IRC client.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==sendAll==<br />
; sendAll(list of things to send, [echo back or not])<br />
: sends multiple things to the game. If you'd like the commands not to be shown, include ''false'' at the end.<br />
<br />
:See also: [[Manual:Basic_Essentials#send|send()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- instead of using many send() calls, you can use one sendAll<br />
sendAll("outr paint", "outr canvas", "paint canvas")<br />
-- can also have the commands not be echoed<br />
sendAll("hi", "bye", false)<br />
</syntaxhighlight><br />
<br />
==sendATCP==<br />
;sendATCP(message, what)<br />
: ''Need description''<br />
<br />
: See also: [[Manual:Supported_Protocols#ATCP|ATCP Protocol]], [[Manual:ATCP_Extensions|ATCP Extensions]], [http://www.ironrealms.com/rapture/manual/files/FeatATCP-txt.html Achaea Telnet Client Protocol specification], [https://forums.mudlet.org/viewtopic.php?p=19502#p19502 Description by forum user KaVir (2013)], [https://forums.mudlet.org/viewtopic.php?p=2015#p2015 Description by forum user Iocun (2009)]<br />
<br />
;Parameters:<br />
* ''message:''<br />
: The message that you want to send.<br />
* ''what:''<br />
: ''Need description''<br />
<br />
;Example<br />
''Need example''<br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
: Note that this function is rarely used in practice. For most GMCP modules, the messages are automatically sent by the server when a relevant event happens in the game. For example, LOOKing in your room prompts the server to send the room description and contents, as well as the GMCP message gmcp.Room. A call to sendGMCP would not be required in this case.<br />
<br />
: See also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group = "vision"})<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group="MWP", name="block"})<br />
</syntaxhighlight><br />
<br />
==sendMSDP==<br />
;sendMSDP(variable[, value][, value...])<br />
: Sends a MSDP message to the server.<br />
<br />
;Parameters:<br />
* ''variable:''<br />
: The variable, in MSDP terms, that you want to request from the server.<br />
* ''value:''<br />
: The variables value that you want to request. You can request more than one value at a time.<br />
<br />
: See Also: [[Manual:Supported_Protocols#MSDP|MSDP support in Mudlet]], [http://tintin.sourceforge.net/msdp/ Mud Server Data Protocol specification]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- ask for a list of commands, lists, and reportable variables that the server supports<br />
sendMSDP("LIST", "COMMANDS", "LISTS", "REPORTABLE_VARIABLES")<br />
<br />
-- ask the server to start keeping you up to date on your health<br />
sendMSDP("REPORT", "HEALTH")<br />
<br />
-- or on your health and location<br />
sendMSDP("REPORT", "HEALTH", "ROOM_VNUM", "ROOM_NAME")<br />
</syntaxhighlight><br />
<br />
==sendIrc==<br />
;sendIrc(target, message)<br />
: Sends a message to an IRC channel or person. Returns ''true''+''status'' if message could be sent or was successfully processed by the client, or ''nil''+''error'' if the client is not ready for sending, and ''false''+''status'' if the client filtered the message or failed to send it for some reason. If the IRC client hasn't started yet, this function will initiate the IRC client and begin a connection.<br />
<br />
To receive an IRC message, check out the [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage event]].<br />
<br />
{{note}} Since Mudlet 3.3, auto-opens the IRC window and returns the success status.<br />
<br />
;Parameters:<br />
* ''target:''<br />
: nick or channel name and if omitted will default to the first available channel in the list of joined channels.<br />
* ''message:''<br />
: The message to send, may contain IRC client commands which start with <code>/</code> and can use all commands which are available through the client window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
-- this would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
<br />
-- use an in-built IRC command<br />
sendIrc("#mudlet", "/topic")<br />
</syntaxhighlight><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.3:<br />
* /ACTION <target> <message...><br />
* /ADMIN (<server>)<br />
* /AWAY (<reason...>)<br />
* /CLEAR (<buffer>) -- Clears the text log for the given buffer name. Uses the current active buffer if none are given.<br />
* /CLOSE (<buffer>) -- Closes the buffer and removes it from the Buffer list. Uses the current active buffer if none are given.<br />
* /HELP (<command>) -- Displays some help information about a given command or lists all available commands.<br />
* /INFO (<server>)<br />
* /INVITE <user> (<#channel>)<br />
* /JOIN <#channel> (<key>)<br />
* /KICK (<#channel>) <user> (<reason...>)<br />
* /KNOCK <#channel> (<message...>)<br />
* /LIST (<channels>) (<server>)<br />
* /ME [target] <message...><br />
* /MODE (<channel/user>) (<mode>) (<arg>)<br />
* /MOTD (<server>)<br />
* /MSG <target> <message...> -- Sends a message to target, can be used to send Private messages.<br />
* /NAMES (<#channel>)<br />
* /NICK <nick><br />
* /NOTICE <#channel/user> <message...><br />
* /PART (<#channel>) (<message...>)<br />
* /PING (<user>)<br />
* /RECONNECT -- Issues a Quit command to the IRC Server and closes the IRC connection then reconnects to the IRC server. The same as calling ircRestart() in Lua.<br />
* /QUIT (<message...>)<br />
* /QUOTE <command> (<parameters...>)<br />
* /STATS <query> (<server>)<br />
* /TIME (<user>)<br />
* /TOPIC (<#channel>) (<topic...>)<br />
* /TRACE (<target>)<br />
* /USERS (<server>)<br />
* /VERSION (<user>)<br />
* /WHO <mask><br />
* /WHOIS <user><br />
* /WHOWAS <user><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.15:<br />
* /MSGLIMIT <limit> (<buffer>) -- Sets the limit for messages to keep in the IRC client message buffers and saves this setting. If a specific buffer/channel name is given the limit is not saved and applies to the given buffer until the application is closed or the limit is changed again. For this reason, global settings should be applied first, before settings for specific channels/PM buffers.<br />
<br />
==sendTelnetChannel102==<br />
; sendTelnetChannel102(msg)<br />
: Sends a message via the 102 subchannel back to the MUD (that's used in Aardwolf). The msg is in a two byte format; see the link below to the Aardwolf Wiki for how that works.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- turn prompt flags on:<br />
sendTelnetChannel102("\52\1")<br />
<br />
-- turn prompt flags off:<br />
sendTelnetChannel102("\52\2")<br />
</syntaxhighlight><br />
<br />
To see the list of options that Aardwolf supports go to: [http://www.aardwolf.com/blog/2008/07/10/telnet-negotiation-control-mud-client-interaction/ Using Telnet negotiation to control MUD client interaction].<br />
<br />
==setIrcChannels==<br />
;setIrcChannels(channels)<br />
:Saves the given channels to disk as the new IRC client channel auto-join configuration. This value is not applied to the current active IRC client until it is restarted with [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
:See also: [[Manual:Networking_Functions#getIrcChannels|getIrcChannels()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''channels:''<br />
: A table containing strings which are valid channel names. Any channels in the list which aren't valid are removed from the list. <br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcChannels( {"#mudlet", "#lua", "irc"} )<br />
-- Only the first two will be accepted, as "irc" is not a valid channel name.<br />
</syntaxhighlight><br />
<br />
==setIrcNick==<br />
;setIrcNick(nickname)<br />
:Saves the given nickname to disk as the new IRC client configuration. This value is not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcNick|getIrcNick()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''nickname:''<br />
: A string with your new desired name in IRC.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcNick( "Sheldor" )<br />
</syntaxhighlight><br />
<br />
==setIrcServer==<br />
;setIrcServer(hostname, port)<br />
:Saves the given server's address to disk as the new IRC client connection configuration. These values are not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcServer|getIrcServer()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''hostname:''<br />
: A string containing the hostname of the IRC server.<br />
* ''port:''<br />
: (optional) A number indicating the port of the IRC server. Defaults to 6667, if not provided.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcServer("chat.freenode.net", 6667)<br />
</syntaxhighlight><br />
<br />
==getHTTP==<br />
;getHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/GET_(HTTP) HTTP GET] request to the given URL. Raises [[Manual:Event_Engine#sysGetHttpDone|sysGetHttpDone]] on success or [[Manual:Event_Engine#sysGetHttpError|sysGetHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available since Mudlet 4.10<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpGetDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysGetHttpDone", onHttpGetDone)<br />
<br />
getHTTP("https://httpbin.org/info")<br />
getHTTP("https://httpbin.org/are_you_awesome", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- Status requests typically use GET requests<br />
local url = "http://postman-echo.com/status"<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysGetHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysGetHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
getHTTP(url, header)<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
<br />
==postHTTP==<br />
;postHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/POST_(HTTP) HTTP POST] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPostHttpDone|sysPostHttpDone]] on success or [[Manual:Event_Engine#sysPostHttpError|sysPostHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the POST request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpPostDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPostHttpDone", onHttpPostDone)<br />
<br />
postHTTP("why hello there!", "https://httpbin.org/post")<br />
postHTTP("this us a request with custom headers", "https://httpbin.org/post", {["X-am-I-awesome"] = "yep I am"})<br />
postHTTP("https://httpbin.org/post", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This will create a JSON message body. Many modern REST APIs expect a JSON body. <br />
local url = "http://postman-echo.com/post"<br />
local data = {message = "I am the banana", user = "admin"}<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysPostHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysPostHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
postHTTP(yajl.to_string(data), url, header) -- yajl.to_string converts our Lua table into a JSON-like string so the server can understand it<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
==putHTTP==<br />
;putHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/PUT_(HTTP) HTTP PUT] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPutHttpDone|sysPutHttpDone]] on success or [[Manual:Event_Engine#sysPutHttpError|sysPutHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#postHTTP|postHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the PUT request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onHttpPutDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPutHttpDone", onHttpPutDone)<br />
putHTTP("this us a request with custom headers", "https://httpbin.org/put", {["X-am-I-awesome"] = "yep I am"})<br />
putHTTP("https://httpbin.org/put", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
==deleteHTTP==<br />
;deleteHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/DELETE_(HTTP) HTTP DELETE] request to the given URL. Raises [[Manual:Event_Engine#sysDeleteHttpDone|sysDeleteHttpDone]] on success or [[Manual:Event_Engine#sysDeleteHttpError|sysDeleteHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
function onHttpDeleteDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysDeleteHttpDone", onHttpDeleteDone)<br />
<br />
deleteHTTP("https://httpbin.org/delete")<br />
deleteHTTP("https://httpbin.org/delete", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Event_Engine&diff=15493Manual:Event Engine2020-08-02T12:25:22Z<p>Smurf: document sysGetHttpDone / sysGetHttpError</p>
<hr />
<div>{{TOC right}}<br />
=Event System=<br />
<br />
Events in Mudlet allow a paradigm of system-building that is easy to maintain (because if you’d like to restructure something, you’d have to do less work), enables interoperability (making a collection of scripts that work with each other is easier) and enables an event-based way of programming.<br />
<br />
The essentials of it are as such: you use Scripts to define which events should a function to listen to, and when the event is raised, the said function(s) will be called. Events can also have function parameters with them, which’ll be passed onto the receiving functions.<br />
<br />
== Registering an event handler via UI ==<br />
Registering an event handler means that you’ll be telling Mudlet what function should it call for you when an event is raised, so it’s a two step process - you need to tell it both what function you’d like to be called, and on what event should it be called.<br />
<br />
To tell it what function should be called, create a new script, and give the script the name of the function you’d like to be called. This is the only time where an items name matters in Mudlet. You can define the function right inside the script as well, if you’d like.<br />
<br />
Next, we tell it what event or events should this function be called on - you can add multiple ones. To do that, enter the events name in the Add User Defined Event Handler: field, press enter, and it’ll go into the list - and that is all.<br />
<br />
== Registering an event from a script ==<br />
You can also register your event with the ''[[Manual:Miscellaneous_Functions#registerAnonymousEventHandler|registerAnonymousEventHandler(event name, function name)]]'' function inside your scripts:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- example taken from the God Wars 2 (http://godwars2.org) Mudlet UI - forces the window to keep to a certain size<br />
function keepStaticSize()<br />
setMainWindowSize(1280,720)<br />
end -- keepStaticSize<br />
<br />
registerAnonymousEventHandler("sysWindowResizeEvent", "keepStaticSize")<br />
</syntaxhighlight><br />
<br />
{{note}} Mudlet also uses the event system in-game protocols (like ATCP, GMCP and others).<br />
<br />
== Raising a custom event== <br />
To raise an event, you'd use the [[Manual:Lua_Functions#raiseEvent|raiseEvent()]] function:<br />
<br />
<syntaxhighlight lang="lua">raiseEvent(name, [arguments...])</syntaxhighlight><br />
<br />
It takes an event name as the first argument, and then any amount of arguments after it which will be passed onto the receiving functions.<br />
<br />
== Example of registering and raising an event == <br />
Add a script to each profile you need the event.<br />
<br />
<syntaxhighlight lang="lua"><br />
<br />
-- This is the function that will be called when the event is raised.<br />
-- "event" is set to the event name.<br />
-- "arg" is the argument(s) provided with raiseEvent/rasieGlobalEvent.<br />
-- "profile" - Is the profile name from where the raiseGlobalEvent where triggered from<br />
-- It is 'nil' if raiseEvent() was used.<br />
function onMyEvent(event, arg, profile)<br />
echo("Event: " .. event .. "\n")<br />
echo("Arg : " .. arg .. "\n")<br />
-- If the event is not raised with raiseGlobalEvent() profile will be 'nil'<br />
echo("Profile: " .. (profile or "Local") .. "\n")<br />
end<br />
<br />
-- Register the event handler.<br />
registerAnonymousEventHandler("my_event", "onMyEvent")<br />
</syntaxhighlight><br />
<br />
To raise the event you can call:<br />
<syntaxhighlight lang="lua"><br />
-- Trigger only in the current profile:<br />
raiseEvent("my_event", "Hello world!")<br />
<br />
-- Trigger the event in all OTHER profiles:<br />
raiseGlobalEvent("my_event", "Hello World!")<br />
</syntaxhighlight><br />
<br />
To review, count and extract from an unknown number of arguments received by an event:<br />
<br />
<syntaxhighlight lang="lua"><br />
function eventArgs(...)<br />
local args = {...}<br />
local amount = select("#", ...)<br />
local first = select(1, ...)<br />
echo("Number of arguments: " .. amount)<br />
echo("\nTable of all arguments: ")<br />
display(args)<br />
echo("First argument: " .. first)<br />
echo("\n\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==Mudlet-raised events==<br />
Mudlet itself also creates events for your scripts to hook on. The following events are generated currently:<br />
<br />
===channel102Message===<br />
<br />
Raised when a telnet sub-option 102 message is received (which comprises of two numbers passed in the event). This is of particular use with the [http://www.aardwolf.com Aardwolf MUD] who originated this protocol. See [http://forums.mudlet.org/viewtopic.php?f=6&t=1471 this] forum topic for more about the Mudlet Aardwolf GUI that makes use of this.<br />
<br />
===mapOpenEvent===<br />
<br />
Raised when the mapper is opened - either the floating dock or the in-Mudlet widget.<br />
<br />
===sysAppStyleSheetChange===<br />
<br />
Raised when [[Manual:UI_Functions#setAppStyleSheet|setAppStyleSheet]] is called and a new stylesheet applied to Mudlet.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- This will respond to a future (as yet unpublished) addition to the Mudlet code that will allow some<br />
-- of a default application style sheet to be supplied with Mudlet to compensate for some text colors<br />
-- that do not show up equally well in both light and dark desktop themes. That, perhaps, might finally<br />
-- allow different colored texts to be uses again for the trigger item types!<br />
function appStyleSheetChangeEvent( event, tag, source )<br />
if source == "system" then<br />
colorTable = colorTable or {}<br />
if tag == "mudlet-dark-theme" then<br />
colorTable.blue = {64, 64, 255}<br />
colorTable.green = {0, 255, 0}<br />
elseif tag == "mudlet-light-theme" then<br />
colorTable.blue = {0, 0, 255}<br />
colorTable.green = {64, 255, 64}<br />
end<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.19<br />
<br />
===sysConnectionEvent===<br />
<br />
Raised when the profile becomes connected to a MUD - available in 2.0-test5+.<br />
<br />
===sysDataSendRequest===<br />
<br />
Raised right before a command from the send(), sendAll() functions or the command line is sent to the game - useful for keeping track of what your last command was, manipulating input or even denying the command to be sent if necessary with [[Manual:Miscellaneous_Functions#denyCurrentSend|denyCurrentSend()]].<br />
<br />
sysDataSendRequest will send the event name and the command sent (in string form) to the functions registered to it. IE: commandSent in the example below will be "eat hambuger" if the user entered only that into command line and pressed enter, send("eat hamburger"), sendAll("eat humburger", "eat fish") or sendAll("eat fish", "eat humburger")<br />
<br />
Note: if you'll be making use of denyCurrentSend(), you ''really should'' notify the user that you denied their command - unexperienced ones might conclude that your script or Mudlet is buggy if they don't see visual feedback. Do not mis-use this and use it as [http://en.wikipedia.org/wiki/Keylogger keylogger] either.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- cancels all "eat hambuger" commands<br />
function cancelEatHamburger(eventName, commandSent)<br />
if commandSent == "eat hamburger" then<br />
denyCurrentSend() --cancels the command sent.<br />
cecho("<red>Denied! You can't do "..commandSent.." right now.\n")<br />
end --if commandSent == eat hamburger<br />
end<br />
<br />
registerAnonymousEventHandler("sysDataSendRequest", "cancelEatHamburger")<br />
</syntaxhighlight><br />
<br />
If you wanted to control input you could set a bool after a trigger.<br />
This is useful if you want alias like control, do not know what text will be entered, but do know a trigger that WILL occur just before the user enters the command.<br />
<br />
<syntaxhighlight lang="lua"><br />
function controlInput(_, command) <br />
if changeCMDInput then<br />
changeCMDInput = false --set this if check to false to it doesn't occur every input<br />
--Also set the bool check BEFORE any send() functions within a sysDataSendRequest function<br />
sendAll(command .. "some target", command .. "some other target", true) --Duplicate and unknown command<br />
denyCurrentSend() --Deny the original command, not the commands sent with sendAll.<br />
end<br />
end<br />
registerAnonymousEventHandler("sysDataSendRequest", "controlInput")<br />
</syntaxhighlight><br />
<br />
Take note that functions registered under sysDataSendRequest WILL trigger with ALL commands that are sent.<br />
<br />
===sysDeleteHttpDone===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#deleteHTTP|deleteHTTP()]] request completes successfully. Arguments with the event are the URL that the request was sent to and the response body (if it's less than 10k characters).<br />
<br />
See also [[#sysDeleteHttpError|sysDeleteHttpError]].<br />
<br />
===sysDeleteHttpError===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#deleteHTTP|deleteHTTP()]] request fails. Arguments are the error message and the URL that the request was sent to.<br />
<br />
See also [[#sysDeleteHttpDone|sysDeleteHttpDone]].<br />
<br />
===sysDisconnectionEvent===<br />
<br />
Raised when the profile becomes disconnected, either manually or by the game - available in 2.0-test5+.<br />
<br />
===sysDownloadDone===<br />
<br />
Raised when Mudlet is finished downloading a file successfully - the location of the downloaded file is passed as a second argument.<br />
<br />
Example - put it into a new script and save it to run:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- create a function to parse the downloaded webpage and display a result<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:find("achaea-who-count.html", 1, true) then return end<br />
<br />
-- read the contents of the webpage in<br />
local f, s, webpage = io.open(filename)<br />
if f then webpage = f:read("*a"); io.close(f) end<br />
-- delete the file on disk, don't clutter<br />
os.remove(filename)<br />
<br />
-- parse our downloaded file for the player count<br />
local pc = webpage:match([[Total: (%d+) players online]])<br />
display("Achaea has "..tostring(pc).." players on right now.")<br />
end<br />
<br />
-- register our function to run on the event that something was downloaded<br />
registerAnonymousEventHandler("sysDownloadDone", "downloaded_file")<br />
<br />
-- download a list of fake users for a demo<br />
downloadFile(getMudletHomeDir().."/achaea-who-count.html", "https://www.achaea.com/game/who")<br />
</syntaxhighlight><br />
<br />
You should see a result like this:<br />
<br />
[[File:DownloadFile_demo.png|frameless|800px]]<br />
<br />
===sysDownloadError===<br />
<br />
Raised when downloading a file failed - the second argument contains the error message. Starting with Mudlet 2.0-test5+, it specifies the original URL that was going to be downloaded.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--if a download fails notify the player.<br />
function downloadErrorEventHandler(event, errorFound)<br />
cecho("fuction downloadErrorEventHandler, "..errorFound)<br />
debugc("fuction downloadErrorEventHandler, "..errorFound) --display to error screen in editor<br />
end --function downloadErrorEventHandler<br />
registerAnonymousEventHandler("sysDownloadError", "downloadErrorEventHandler")<br />
</syntaxhighlight><br />
<br />
===sysDropEvent===<br />
<br />
Raised when a file is dropped on the Mudlet main window or a userwindow.<br />
The arguments passed areː filepath, suffix, xpos, ypos, and consolename - "main" for the main window and otherwise of the userwindow/miniconsole name.<br />
<br />
{{note}} Available since Mudlet 4.8+<br />
<br />
<syntaxhighlight lang="lua"><br />
function onDragAndDrop(_, filepath, suffix, xpos, ypos, consolename)<br />
print(string.format("Dropped new file into %s: %s (suffix: %s)", consolename, filepath, suffix))<br />
end<br />
registerAnonymousEventHandler("sysDropEvent", "onDragAndDrop")<br />
</syntaxhighlight><br />
<br />
===sysExitEvent===<br />
<br />
Raised when Mudlet is shutting down the profile - a good event to hook onto for saving all of your data.<br />
<br />
<!-- Gamepad events do not actually seem to work --<br />
<br />
===sysGamepadAxisMove===<br />
<br />
Raised an axis on a gamepad is moved.<br />
<br />
Event handlers receive the device ID, axis number, and the new value as a number.<br />
<br />
{{note}}Available since Mudlet 3.3<br />
<br />
===sysGamepadButtonPress===<br />
<br />
Raised a button on a gamepad is pressed down.<br />
<br />
Event handlers receive the device ID, button number, and the new value as a number.<br />
<br />
===sysGamepadButtonRelease===<br />
<br />
Raised a button on a gamepad is released.<br />
<br />
Event handlers receive the device ID, button number, and the new value as a number.<br />
<br />
{{note}}Available since Mudlet 3.3<br />
<br />
===sysGamepadConnected===<br />
<br />
Raised a [https://en.wikipedia.org/wiki/Gamepad gamepad] is connected. On Windows, this uses the XInput backend.<br />
<br />
Event handlers receive device ID as an argument.<br />
<br />
{{note}}Available since Mudlet 3.3<br />
<br />
Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
function noticeConnection(deviceID)<br />
local output = string.format("New gamepad connected: %s\n", deviceID)<br />
echo(output)<br />
end<br />
<br />
function noticeDisconnection(deviceID)<br />
local output = string.format("Gamepad disconnected: %s\n", deviceID)<br />
echo(output)<br />
end<br />
<br />
function noticeButtonPress(deviceID, buttonNumber, valueNumber)<br />
local output = string.format("Button pressed: gamepad %s, button %s, value %s\n", deviceID, buttonNumber, valueNumber)<br />
echo(output)<br />
end<br />
<br />
function noticeButtonRelease(deviceID, buttonNumber, valueNumber)<br />
local output = string.format("Button released: gamepad %s, button %s, value %s\n", deviceID, buttonNumber, valueNumber)<br />
echo(output)<br />
end<br />
<br />
function noticeAxis(deviceID, axisNumber, valueNumber)<br />
local output = string.format("Axis moved: gamepad %s, axis %s, value %s\n", deviceID, axisNumber, valueNumber)<br />
echo(output)<br />
end<br />
<br />
registerAnonymousEventHandler("sysGamepadConnected", "noticeConnection")<br />
registerAnonymousEventHandler("sysGamepadDisconnected", "noticeDisconnection")<br />
registerAnonymousEventHandler("sysGamepadButtonPress", "noticeButtonPress")<br />
registerAnonymousEventHandler("sysGamepadButtonRelease", "noticeButtonRelease")<br />
registerAnonymousEventHandler("sysGamepadAxisMove", "noticeAxis")<br />
</syntaxhighlight><br />
<br />
===sysGamepadDisconnected===<br />
<br />
Raised a [https://en.wikipedia.org/wiki/Gamepad gamepad] is disconnected<br />
<br />
Event handlers receive device ID as an argument.<br />
<br />
{{note}}Available since Mudlet 3.3<br />
<br />
-- Gamepad events do not actually seem to work --><br />
<br />
===sysGetHttpDone===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#putHTTP|putHTTP()]] request completes successfully. Arguments with the event are the URL that the request was sent to and the response body (if it's less than 10k characters).<br />
<br />
This event is also raised when a post/put/delete request redirects to a ''GET''.<br />
<br />
See also [[#sysGetHttpError|sysGetHttpError]].<br />
<br />
{{note}}Available since Mudlet 4.10<br />
<br />
===sysGetHttpError===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#getHTTP|getHTTP()]] request fails. Arguments are the error message and the URL that the request was sent to.<br />
<br />
See also [[#sysGetHttpDone|sysGetHttpDone]].<br />
<br />
{{note}}Available since Mudlet 4.10<br />
<br />
===sysInstall===<br />
<br />
Raised right after a module or package is installed by any means. This can be used to display post-installation information or setup things.<br />
<br />
Event handlers receive the name of the installed package or module as additional argument.<br />
<br />
{{note}}Installed modules will raise this event handler each time the synced profile is opened. [[sysInstallModule]] and [[sysInstallPackage]] are not raised by opening profiles.<br />
Available since Mudlet 3.1<br />
<br />
<syntaxhighlight lang="lua"><br />
function myScriptInstalled(_, name)<br />
-- stop if what got installed isn't my thing<br />
if name ~= "my script name here" then return end<br />
<br />
print("Hey, thanks for installing my thing!")<br />
end<br />
registerAnonymousEventHandler("sysInstallPackage", "myScriptInstalled")<br />
</syntaxhighlight><br />
<br />
===sysInstallModule===<br />
<br />
Raised right after a module is installed through the module dialog. This can be used to display post-installation information or setup things.<br />
<br />
See also [[sysLuaInstallModule]] for when a module is installed via Lua.<br />
<br />
Event handlers receive the name of the installed module as well as the file name as additional arguments.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysInstallPackage===<br />
<br />
Raised right after a package is installed by any means. This can be used to display post-installation information or setup things.<br />
<br />
Event handlers receive the name of the installed package as well as the file name as additional arguments.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysIrcMessage===<br />
<br />
Raised when the IRC client receives an IRC message. The sender's name, channel name, and their message are passed as arguments to this event. <br />
<br />
Starting with Mudlet 3.3, this event changes slightly to provide more information from IRC network messages. Data such as status codes, command responses, or error messages sent by the IRC Server may be formatted as plain text by the client and posted to lua via this event. <br />
<br />
* sender: may be the nick name of an IRC user or the name of the IRC server host, as retrievable by [[Manual:Networking_Functions#getIrcConnectedHost|getIrcConnectedHost()]] <br />
* channel: may not always contain a channel name, but will be the name of the target/recipient of a message or action. In some networks the name may be that of a service (like ''"Auth"'' for example) <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onIrcMessage(_, sender, target, message)<br />
echo(string.format('(%s) %s says, "%s"\n', target, sender, message))<br />
end<br />
<br />
registerAnonymousEventHandler("sysIrcMessage", onIrcMessage)<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 2.1+<br />
<br />
To send a message, see [[Manual:Networking_Functions#sendIrc|sendIrc()]].<br />
<br />
===sysLabelDeleted===<br />
<br />
Raised after a label is deleted, with the former label's name as an argument.<br />
<br />
<br />
===sysLoadEvent===<br />
<br />
Raised after Mudlet is done loading the profile, after all of the scripts, packages, and modules are installed. Note that when it does so, it also compiles and runs all scripts - which could be a good idea to initialize everything at once, but beware - scripts are also run when saved. Hence, hooking only on the sysLoadEvent would prevent multiple re-loads as you’re editing the script.<br />
<br />
===sysLuaInstallModule===<br />
<br />
Raised right after a module is installed through the Lua installModule() command. This can be used to display post-installation information or setup things.<br />
<br />
Event handlers receive the name of the installed module as well as the file name as additional arguments.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysLuaUninstallModule===<br />
<br />
Raised right before a module is removed through the lua uninstallModule command. This can be used to display post-removal information or for cleanup.<br />
<br />
Event handlers receive the name of the removed module as additional argument.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysManualLocationSetEvent===<br />
<br />
Raised whenever the "set location" command (on the 2D mapper context menu) is used to reposition the current "player room". It provides the room ID of the new room ID that the player has been moved to.<br />
<br />
{{note}}Available since Mudlet 3.0<br />
<br />
===sysMapDownloadEvent===<br />
<br />
Raised whenever an [[Standards:MMP|MMP map]] is downloaded and loaded in.<br />
<br />
===sysPostHttpDone===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#postHTTP|postHTTP()]] request completes successfully. Arguments with the event are the URL that the request was sent to and the response body (if it's less than 10k characters).<br />
<br />
See also [[#sysPostHttpError|sysPostHttpError]].<br />
<br />
===sysPostHttpError===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#postHTTP|postHTTP()]] request fails. Arguments are the error message and the URL that the request was sent to.<br />
<br />
See also [[#sysPostHttpDone|sysPostHttpDone]].<br />
<br />
===sysProtocolDisabled===<br />
<br />
Raised whenever a communications protocol is disabled, with the protocol name passed as an argument. Current values Mudlet will use for this are: GMCP, MDSP, ATCP, MXP, and channel102.<br />
<br />
===sysProtocolEnabled===<br />
<br />
Raised whenever a communications protocol is enabled, with the protocol name passed as an argument. Current values Mudlet will use for this are: GMCP, MDSP, ATCP, MXP, and channel102.<br />
<br />
<syntaxhighlight lang="lua"><br />
function onProtocolEnabled(_, protocol)<br />
if protocol == "GMCP" then<br />
print("GMCP enabled! Now we can use GMCP data.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
===sysPutHttpDone===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#putHTTP|putHTTP()]] request completes successfully. Arguments with the event are the URL that the request was sent to and the response body (if it's less than 10k characters).<br />
<br />
See also [[#sysPutHttpError|sysPutHttpError]].<br />
<br />
===sysPutHttpError===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#putHTTP|putHTTP()]] request fails. Arguments are the error message and the URL that the request was sent to.<br />
<br />
See also [[#sysPutHttpDone|sysPutHttpDone]].<br />
<br />
===sysSoundFinished===<br />
<br />
Raised when a sound finished playing. This can be used in a music player for example to start the next song.<br />
<br />
Event handlers receive the sound file name and the file path as additional arguments.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysSyncInstallModule===<br />
<br />
Raised right after a module is installed through the "sync" mechanism. This can be used to display post-installation information or setup things.<br />
<br />
Event handlers receive the name of the installed module as well as the file name as additional arguments.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysSyncUninstallModule===<br />
<br />
Raised right before a module is removed through the "sync" mechanism. This can be used to display post-removal information or for cleanup.<br />
<br />
Event handlers receive the name of the removed module as additional argument.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysTelnetEvent===<br />
<br />
Raised whenever an unsupported telnet option is encountered, allowing you to handle it yourself. The arguments that get passed with the event are type, telnet option, and the message. Available in 2.1+<br />
<br />
===sysUninstall===<br />
<br />
Raised right before a module or package is uninstalled by any means. This can be used to display post-removal information or for cleanup.<br />
<br />
Event handlers receive the name of the removed package or module as additional argument.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysUninstallModule===<br />
<br />
Raised right before a module is removed through the module dialog. This can be used to display post-removal information or for cleanup.<br />
<br />
Event handlers receive the name of the removed module as additional argument.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysUninstallPackage===<br />
<br />
Raised right before a package is removed by any means. This can be used to display post-removal information or for cleanup.<br />
<br />
Event handlers receive the name of the removed package as additional argument.<br />
<br />
{{note}}Available since Mudlet 3.1<br />
<br />
===sysUnzipDone===<br />
<br />
Raised when a zip file is successfully unzipped using unzipAsync()<br />
<br />
Event handlers receive the zip file name and the unzip path as additional arguments.<br />
<br />
{{note}}Available since Mudlet 4.6<br />
<br />
===sysUnzipError===<br />
<br />
Raised when a zip file fails to unzip using unzipAsync()<br />
<br />
Event handlers receive the zip file name and the unzip path as additional arguments.<br />
<br />
{{note}}Available since Mudlet 4.6<br />
<br />
===sysUserWindowResizeEvent===<br />
<br />
Raised when a userwindow is resized, with the new height and width coordinates and the windowname passed to the event. A common usecase for this event is to move/resize your UI elements according to the new dimensions.<br />
<br />
See alsoː [[#sysWindowResizeEvent|sysWindowResizeEvent]]<br />
<br />
Example<br />
<br />
This sample code will echo whenever a resize happened with the new dimensions:<br />
<br />
<syntaxhighlight lang="lua"><br />
function resizeEvent( event, x, y, windowname )<br />
echo("RESIZE EVENT: event="..event.." x="..x.." y="..y.." windowname="..windowname.."\n")<br />
end<br />
</syntaxhighlight><br />
<br />
===sysWindowMousePressEvent===<br />
<br />
Raised when a mouse button is pressed down anywhere on the main window (note that a click is composed of a mouse press and mouse release). The button number, the x,y coordinates of the click and the windowname are reported.<br />
<br />
{{note}}Windowname reported in Mudlet 4.9+<br />
<br />
See alsoː [[#sysWindowMouseReleaseEvent|sysWindowMouseReleaseEvent]]<br />
<br />
Example<br />
<br />
<syntaxhighlight lang="lua"><br />
function onClickHandler( event, button, x, y, windowname )<br />
echo("CLICK event:"..event.." button="..button.." x="..x.." y="..y.." windowname="..windowname.."\n")<br />
end<br />
</syntaxhighlight><br />
<br />
===sysWindowMouseReleaseEvent===<br />
<br />
Raised when a mouse button is released after being pressed down anywhere on the main window (note that a click is composed of a mouse press and mouse release).<br />
<br />
See [[#sysWindowMousePressEvent|sysWindowMousePressEvent]] for example use.<br />
<br />
===sysWindowResizeEvent===<br />
<br />
Raised when the main window is resized, with the new height and width coordinates passed to the event. A common usecase for this event is to move/resize your UI elements according to the new dimensions.<br />
<br />
See alsoː [[#sysUserWindowResizeEvent|sysUserWindowResizeEvent]]<br />
<br />
Example<br />
<br />
This sample code will echo whenever a resize happened with the new dimensions:<br />
<br />
<syntaxhighlight lang="lua"><br />
function resizeEvent( event, x, y )<br />
echo("RESIZE EVENT: event="..event.." x="..x.." y="..y.."\n")<br />
end<br />
</syntaxhighlight><br />
<br />
<br />
[[Category:Mudlet Manual]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15492Manual:Mapper Functions2020-08-02T06:10:04Z<p>Smurf: /* resetRoomArea */ this affects a single room, not the whole area</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that on clicking will send all the arguments.<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Favorites") -- will create a menu, favorites<br />
<br />
addMapMenu("Favorites1234343", "Favorites", "Favorites") <br />
</syntaxhighlight><br />
The last line will create a submenu with the unique id ''Favorites123''.. under Favorites with the display name of ''Favorites''.<br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original width of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;areaTable = getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==openMapWidget==<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (roomID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeMapEvent==<br />
;removeMapEvent (event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#addMapMenu | addMapMenu()]], [[#getMapEvents | getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out. Call [[#centerview|centerview()]] after you set the zoom to refresh the map.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it colour, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. (See the link at the beginning of my post for something like that.)<br />
<br />
:Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=User:Smurf&diff=15488User:Smurf2020-07-31T06:58:13Z<p>Smurf: new</p>
<hr />
<div>I'm just playing around, except when I'm not.<br />
<br />
I'm working on Mapping, and on writing a mapper in Python. Because (a) I want to know whether that'd work at all (spoiler: yes it does) and (b) because I don't like Lua.</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=15487Manual:Mapper Functions2020-07-31T02:37:40Z<p>Smurf: /* getRoomHashByID */ no longer true, both are QMap data structures</p>
<hr />
<div>{{TOC right}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<syntaxhighlight lang="lua"><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</syntaxhighlight><br />
<br />
==addAreaName==<br />
;areaID = addAreaName(areaName)<br />
<br />
:Adds a new area name and returns the new (positive) area ID for the new name. If the name already exists, older versions of Mudlet returned -1 though since 3.0 the code will return ''nil'' and an error message.<br />
: See also: [[#deleteArea|deleteArea()]], [[#addRoom|addRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newId, err = addAreaName(string.random(10))<br />
<br />
if newId == nil or newId < 1 or err then<br />
echo("That area name could not be added - error is: ".. err.."\n")<br />
else<br />
cecho("<green>Created new area with the ID of "..newId..".\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==addCustomLine==<br />
;addCustomLine(roomID, id_to, direction, style, color, arrow)<br />
: See also: [[#getCustomLines|getCustomLines()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Adds a new/replaces an existing custom exit line to the 2D mapper for the room with the Id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to attach the custom line to.<br />
* ''id_to:''<br />
: EITHER: a room Id number, of a room on same area who's x and y coordinates are used as the other end of a SINGLE segment custom line (it does NOT imply that is what the exit it represent goes to, just the location of the end of the line);<br />
: OR: a table of sets of THREE (x,y and z) coordinates in that order, x and y can be decimals, z is an integer ('''and must be present and be the same for all points on the line''', though it is irrelevant to what is produced as the line is drawn on the same z-coordinate as the room that the line is attached to!)<br />
* ''direction:'' a string to associate the line with a valid exit direction, "n", "ne", "e", "se", "s", "sw", "w", "nw", "up", "down", "in" or "out" or a special exit (before Mudlet 3.17 this was case-sensitive and cardinal directions had to be uppercase).<br />
* ''style:'' a string, one of: "solid line", "dot line", "dash line", "dash dot line" or "dash dot dot line" exactly.<br />
* ''color:'' a table of three integers between 0 and 255 as the custom line color as the red, green and blue components in that order.<br />
* ''arrow:'' a boolean which if true will set the custom line to have an arrow on the end of the last segment.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- create a line from roomid 1 to roomid 2<br />
addCustomLine(1, 2, "N", "dot line", {0, 255, 255}, true)<br />
<br />
addCustomLine(1, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
</syntaxhighlight><br />
<br />
A bigger example that'll create a new area and the room in it:<br />
<br />
<syntaxhighlight lang="lua"><br />
local areaid = addAreaName("my first area")<br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
setRoomArea(newroomid, "my first area")<br />
setRoomCoordinates(newroomid, 0, 0, 0)<br />
<br />
addCustomLine(newroomid, {{4.5, 5.5, 3}, {4.5, 9.5, 3}, {6.0, 9.5, 3}}, "climb Rope", "dash dot dot line", {128, 128, 0}, false)<br />
<br />
centerview(newroomid)<br />
</syntaxhighlight><br />
<br />
Note: At the time of writing there is no Lua command to remove a custom exit line and, for Normal exits in the X-Y plane, revert to the standard straight line between the start room and the end room (or colored arrow for out of area exits) however this can be done from the GUI interface to the 2D mapper.<br />
<br />
==addMapEvent==<br />
;addMapEvent(uniquename, event name, parent, display name, arguments)<br />
<br />
:Adds a new entry to an existing mapper right-click entry. You can add one with addMapMenu. If there is no display name, it will default to the unique name (which otherwise isn't shown and is just used to differentiate this entry from others). ''event name'' is the Mudlet event that will be called when this is clicked on, and ''arguments'' will be passed to the handler function.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn") <br />
</syntaxhighlight><br />
The last line will make a label "Special Room!" under the "Favorites" menu that on clicking will send all the arguments.<br />
<br />
==addMapMenu==<br />
;addMapMenu(uniquename, parent, display name)<br />
<br />
:Adds a new submenu to the right-click menu that opens when you right-click on the mapper. You can then add more submenus to it, or add entries with [[#addMapEvent|addMapEvent()]].<br />
: See also: [[#addMapEvent|addMapEvent()]], [[#removeMapEvent|removeMapEvent()]], [[#getMapEvents|getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapMenu("Favorites") -- will create a menu, favorites<br />
<br />
addMapMenu("Favorites1234343", "Favorites", "Favorites") <br />
</syntaxhighlight><br />
The last line will create a submenu with the unique id ''Favorites123''.. under Favorites with the display name of ''Favorites''.<br />
<br />
==addRoom==<br />
;addRoom(roomID)<br />
<br />
:Creates a new room with the given ID, returns true if the room was successfully created. <br />
<br />
{{note}} If you're not using incremental room IDs but room IDs stitched together from other factors or in-game hashes for room IDs - and your room IDs are starting off at 250+million numbers, you need to look into incrementally creating Mudlets room IDs with [[#createRoomID|createRoomID()]] and associating your room IDs with Mudlets via [[#setRoomIDbyHash|setRoomIDbyHash()]] and [[#getRoomIDbyHash|getRoomIDbyHash()]]. The reason being is that Mudlet's A* pathfinding implementation from boost cannot deal with extremely large room IDs because the resulting matrices it creates for pathfinding are enormously huge.<br />
: See also: [[#createRoomID|createRoomID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</syntaxhighlight><br />
<br />
==addSpecialExit==<br />
;addSpecialExit(roomIDFrom, roomIDTo, moveCommand)<br />
<br />
:Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[#clearSpecialExits|clearSpecialExits()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- add a one-way special exit going from room 1 to room 2 using the 'pull rope' command<br />
addSpecialExit(1, 2, "pull rope")<br />
</syntaxhighlight><br />
<br />
Example in an alias:<br />
<syntaxhighlight lang="lua"><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- currentroom is your current room ID in this example<br />
addSpecialExit(currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(currentroom)<br />
</syntaxhighlight><br />
<br />
==centerview==<br />
;centerview (roomID)<br />
<br />
:Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
: See also: [[#getPlayerRoom|getPlayerRoom()]], [[#updateMap|updateMap()]]<br />
<br />
==clearAreaUserData==<br />
;clearAreaUserData(areaID)<br />
<br />
; Parameter<br />
* areaID - ID number for area to clear.<br />
<br />
:Clears all user data from a given area. Note that this will not touch the room user data.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#clearRoomUserData|clearRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearAreaUserData(34))<br />
-- I did have data in that area, so it returns:<br />
true<br />
<br />
display(clearAreaUserData(34))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearAreaUserDataItem==<br />
;clearAreaUserDataItem(areaID, key)<br />
<br />
:Removes the specific key and value from the user data from a given area.<br />
: See also: [[#setAreaUserData|setAreaUserData()]], [[#clearAreaUserData|clearAreaUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
true<br />
<br />
display(getAllAreaUserData(34))<br />
{<br />
description = [[<area description here>]],<br />
}<br />
<br />
display(clearAreaUserDataItem(34,"ruler"))<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserData==<br />
;clearMapUserData()<br />
<br />
:Clears all user data stored for the map itself. Note that this will not touch the area or room user data.<br />
<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserData|clearAreaUserData()]]<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearMapUserData())<br />
-- I did have user data stored for the map, so it returns:<br />
true<br />
<br />
display(clearMapUserData())<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearMapUserDataItem==<br />
;clearUserDataItem(mapID, key)<br />
<br />
:Removes the specific key and value from the user data from the map user data.<br />
: See also: [[#setMapUserData|setMapUserData()]], [[#clearMapUserData|clearMapUserData()]], [[#clearAreaRoomUserData|clearAreaRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
last_modified = "1483228799"<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
true<br />
<br />
display(getAllMapUserData())<br />
{<br />
description = [[<map description here>]],<br />
}<br />
<br />
display(clearMapUserDataItem("last_modified"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==clearRoomUserData==<br />
;clearRoomUserData(roomID)<br />
<br />
:Clears all user data from a given room.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]]:<br />
<br />
{{note}} Returns a boolean true if any data was removed from the specified room and false if there was nothing to erase since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(clearRoomUserData(3441))<br />
-- I did have data in that room, so it returns:<br />
true<br />
<br />
display(clearRoomUserData(3441))<br />
-- There is no data NOW, so it returns:<br />
false<br />
</syntaxhighlight><br />
<br />
==clearRoomUserDataItem==<br />
;clearRoomUserDataItem(roomID, key)<br />
<br />
:Removes the specific key and value from the user data from a given room.<br />
:Returns a boolean true if data was found against the give key in the user data for the given room and it is removed, will return false if exact key not present in the data. Returns nil if the room for the roomID not found.<br />
: See also: [[#setRoomUserData|setRoomUserData()]], [[#clearRoomUserData|clearRoomUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
true<br />
<br />
display(getAllRoomUserData(3441))<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
}<br />
<br />
display(clearRoomUserDataItem(3441,"doorname_up"))<br />
false<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0+<br />
<br />
==clearSpecialExits==<br />
;clearSpecialExits(roomID) <br />
<br />
:Removes all special exits from a room.<br />
: See also: [[#addSpecialExit|addSpecialExit()]], [[#removeSpecialExit|removeSpecialExit()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will never fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==closeMapWidget==<br />
;closeMapWidget()<br />
:closes (hides) the map window (similar to clicking on the map icon)<br />
<br />
{{note}} available in Mudlet 4.7+<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
==connectExitStub==<br />
;connectExitStub(fromID, direction) or connectExitStub(fromID, toID, [direction])<br />
<br />
:Connects existing rooms with matching exit stubs. If you only give it a roomID and a direction, it'll work out which room should be linked to it that has an appropriate opposite exit stub and is located in the right direction. You can also just specify from and to room IDs, and it'll smartly use the right direction to link in. Lastly, you can specify all three arguments - fromID, toID and the direction (in that order) if you'd like to be explicit, or use [[#setExit|setExit()]] for the same effect.<br />
<br />
;Parameters<br />
* ''fromID:''<br />
: Room ID to set the exit stub in.<br />
* ''direction:''<br />
: You can either specify the direction to link the room in, and/or a specific room ID (see below). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
* ''toID:''<br />
: The room ID to link this room to. If you don't specify it, the mapper will work out which room should be logically linked.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- try and connect all stubs that are in a room<br />
local stubs = getExitStubs(roomID)<br />
if stubs then<br />
for i,v in pairs(stubs) do<br />
connectExitStub(roomID, v)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==createMapLabel==<br />
;labelID = createMapLabel(areaID, text, posx, posy, posz, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling)<br />
<br />
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
<br />
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID where to put the label.<br />
* ''text:''<br />
: The text to put into the label. To get a multiline text label add a '\n' between the lines.<br />
* ''posx, posy, posz:''<br />
: Position of the label in room coordinates.<br />
* ''fgRed, fgGreen fgBlue:''<br />
: Foreground color or text color of the label.<br />
* ''bgRed, bgGreen bgBlue:''<br />
: Background color of the label.<br />
* ''zoom:''<br />
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.<br />
* ''fontSize:''<br />
: Size of the font of the text. Default is 50.<br />
* ''showOnTop:''<br />
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.<br />
* ''noScaling:''<br />
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper. <br />
<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area<br />
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB<br />
-- zoom is only relevant when when you're using a label of a static size, so we use 0<br />
-- and we use a font size of 20 for our label, which is a small medium compared to the map<br />
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)<br />
<br />
-- to create a multi line text label we add '\n' between lines<br />
-- the position is placed somewhat to the northeast of the center of the map<br />
-- this label will be scaled as you zoom the map.<br />
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)<br />
<br />
</syntaxhighlight><br />
<br />
==createMapImageLabel==<br />
;labelID = createMapImageLabel(areaID, filePath, posx, posy, posz, width, height, zoom, showOnTop)<br />
<br />
:Creates an image label on the map at the given coordinates, with the given dimensions and zoom. You might find the default room and image size correlation to be too big - try reducing the width and height of the image then, while also zooming in the same amount.<br />
<br />
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.<br />
: See also: [[#deleteMapLabel|deleteMapLabel]]<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
-- 138 is our pretend area ID<br />
-- next, inside [[]]'s, is the exact location of our image<br />
-- 0,0,0 are the x,y,z coordinates - so this will place it in the middle of the map<br />
-- 482 is the width of the image - we divide it by 100 to scale it down, and then we'll zoom it by 100 - making the image take up about 4 rooms in width then<br />
-- 555 is the original width of the image<br />
-- 100 is how much we zoom it by, 1 would be no zoom<br />
-- and lastly, false to make it go below our rooms<br />
createMapImageLabel(138, [[/home/vadi/Pictures/You only see what shown.png]], 0,0,0, 482/100, 555/100, 100, false)<br />
</syntaxhighlight><br />
<br />
==createMapper==<br />
;createMapper([name of userwindow], x, y, width, height)<br />
<br />
:Creates a miniconsole window for the mapper to render in, the with the given dimensions. You can only create one mapper at a time, and it is not currently possible to have a label on or under the mapper - otherwise, clicks won't register.<br />
<br />
{{note}}<br />
userwindow argument only available in 4.6.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper in the top-left corner of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- another example:<br />
local main = Geyser.Container:new({x=0,y=0,width="100%",height="100%",name="mapper container"})<br />
<br />
local mapper = Geyser.Mapper:new({<br />
name = "mapper",<br />
x = "70%", y = 0, -- edit here if you want to move it<br />
width = "30%", height = "50%"<br />
}, main)<br />
</syntaxhighlight><br />
<br />
{{Note}} If this command is ''not'' used then clicking on the Main Toolbar's '''Map''' button will create a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Map''' button will toggle between showing and hiding the map whether it was created using the ''createMapper'' function or as a dock-able widget.<br />
<br />
==createRoomID==<br />
;usableId = createRoomID([minimumStartingRoomId])<br />
<br />
:Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs. <br />
<br />
;Parameters<br />
* ''minimumStartingRoomId'' (optional):<br />
: If provided, specifies a roomID to start searching for an empty one at, instead of 1. Useful if you'd like to ensure certain areas have specific room number ranges, for example. If you you're working with a huge map, provide the last used room ID to this function for an available roomID to be found a lot quicker.<br />
<br />
{{note}} ''minimumStartingRoomId'' is available since Mudlet 3.0.<br />
<br />
: See also: [[#addRoom|addRoom()]]<br />
<br />
==deleteArea==<br />
;deleteArea(areaID or areaName)<br />
<br />
:Deletes the given area and all rooms in it. Returns ''true'' on success or ''nil'' + ''error message'' otherwise.<br />
: See also: [[#addAreaName|addAreaName()]]<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to delete.<br />
* ''areaName:''<br />
: Area name to delete (available since Mudlet 3.0).<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete by areaID<br />
deleteArea(23)<br />
-- or since Mudlet 3.0, by area name<br />
deleteArea("Big city")<br />
</syntaxhighlight><br />
<br />
==deleteMapLabel==<br />
;deleteMapLabel(areaID, labelID)<br />
<br />
:Deletes a map label from a specfic area.<br />
: See also: [[#createMapLabel|createMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteMapLabel(50, 1)<br />
</syntaxhighlight><br />
<br />
==deleteRoom==<br />
;deleteRoom(roomID)<br />
<br />
:Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
deleteRoom(335)<br />
</syntaxhighlight><br />
<br />
==exportAreaImage==<br />
;exportAreaImage(areaID)<br />
<br />
:Exports the area as an image into your profile's directory.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- save the area with ID 1 as a map<br />
exportAreaImage(1)<br />
</syntaxhighlight><br />
<br />
{{note}} This command is currently inoperable in current 3.0+ versions of Mudlet.<br />
<br />
==getAllAreaUserData==<br />
;dataTable = getAllAreaUserData(areaID)<br />
<br />
:Returns all the user data items stored in the given area ID; will return an empty table if there is no data stored or nil if there is no such area with that ID.<br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllAreaUserData(34))<br />
--might result in:--<br />
{<br />
country = "Andor",<br />
ruler = "Queen Morgase Trakand"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAllMapUserData==<br />
;dataTable = getAllMapUserData()<br />
<br />
:Returns all the user data items stored at the map level; will return an empty table if there is no data stored.<br />
<br />
: See also: [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllMapUserData())<br />
--might result in:--<br />
{<br />
description = [[This map is about so and so game]],<br />
author = "Bob",<br />
["last updated"] = "December 5, 2020"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0+<br />
<br />
==getAllRoomEntrances==<br />
;exitsTable = getAllRoomEntrances(roomID)<br />
<br />
:Returns an indexed list of normal and special exits leading into this room. In case of two-way exits, this'll report exactly the same rooms as [[#getRoomExits|getRoomExits()]], but this function has the ability to pick up one-way exits coming into the room as well.<br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- print the list of rooms that have exits leading into room 512<br />
for _, roomid in ipairs(getAllRoomEntrances(512)) do <br />
print(roomid)<br />
end<br />
</syntaxhighlight><br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
==getAllRoomUserData==<br />
;dataTable = getAllRoomUserData(roomID)<br />
<br />
:Returns all the user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#getRoomUserDataKeys|getRoomUserDataKeys()]] - for a related command that only returns the data keys.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAllRoomUserData(3441))<br />
--might result in:--<br />
{<br />
description = [[<br />
From this ledge you can see out across a large cavern to the southwest. The<br />
east side of the cavern is full of stalactites and stalagmites and other<br />
weird rock formations. The west side has a path through it and an exit to the<br />
south. The sound of falling water pervades the cavern seeming to come from<br />
every side. There is a small tunnel to your east and a stalactite within arms<br />
reach to the south. It appears to have grown till it connects with the<br />
stalagmite below it. Something smells... Yuck you are standing in bat guano!]],<br />
doorname_up = "trapdoor"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0.<br />
<br />
==getAreaExits==<br />
;roomTable = getAreaExits(areaID, showExits)<br />
<br />
: Returns a table (indexed or key-value) of the rooms in the given area that have exits leading out to other areas - that is, border rooms.<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID to list the exits for.<br />
* ''showExits:''<br />
: Boolean argument, if true then the exits that lead out to another area will be listed for each room.<br />
<br />
: See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- list all border rooms for area 44:<br />
getAreaExits(44)<br />
<br />
-- returns:<br />
--[[<br />
{<br />
7091,<br />
10659,<br />
11112,<br />
11122,<br />
11133,<br />
11400,<br />
12483,<br />
24012<br />
}<br />
]]<br />
<br />
-- list all border rooms for area 44, and the exits within them that go out to other areas:<br />
getAreaExits(44, true)<br />
--[[<br />
{<br />
[12483] = {<br />
north = 27278<br />
},<br />
[11122] = {<br />
["enter grate"] = 14551<br />
},<br />
[11112] = {<br />
["enter grate"] = 14829<br />
},<br />
[24012] = {<br />
north = 22413<br />
},<br />
[11400] = {<br />
south = 10577<br />
},<br />
[11133] = {<br />
["enter grate"] = 15610<br />
},<br />
[7091] = {<br />
down = 4411<br />
},<br />
[10659] = {<br />
["enter grate"] = 15510<br />
}<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getAreaRooms==<br />
;areaTable = getAreaRooms(area id)<br />
<br />
:Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in pairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTable==<br />
;areaTable = getAreaTable()<br />
<br />
:Returns a key(area name)-value(area id) table with all known areas and their IDs. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
: See also: [[#getAreaTableSwap|getAreaTableSwap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id)<br />
elseif not id and msg then<br />
echo("ID not found: " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</syntaxhighlight><br />
<br />
==getAreaTableSwap==<br />
;areaTable = getAreaTableSwap()<br />
<br />
:Returns a key(area id)-value(area name) table with all known areas and their IDs. Unlike getAreaTable which won't show you all areas with the same name by different IDs, this function will. Some older versions of Mudlet return an area with an empty name and an ID of 0 included in it, you should ignore that.<br />
<br />
==getAreaUserData==<br />
;dataValue = getAreaUserData(areaID, key)<br />
<br />
:Returns a specific data item stored against the given key for the given area ID number. This is very like the corresponding Room User Data command but intended for per area rather than for per room data (for storage of data relating to the whole map see the corresponding Map User Data commands.) <br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or a Lua ''nil'' and an error message if the key is not present in the Area User Data for the given Area ID. Use [[#setAreaUserData|setAreaUserData()]] function for storing the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><br />
<br />
{{note}} <br />
<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
==getCustomEnvColorTable==<br />
;envcolors = getCustomEnvColorTable()<br />
<br />
:Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</syntaxhighlight><br />
<br />
==getCustomLines==<br />
;lineTable = getCustomLines(roomID)<br />
: See also: [[#addCustomLine|addCustomLine()]], [[#removeCustomLine|removeCustomLine()]]<br />
<br />
:Returns a table including all the details of the custom exit lines, if any, for the room with the id given.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the custom line details of.<br />
<br />
{{note}} <br />
Available since Mudlet 3.0.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display getCustomLines(1)<br />
{<br />
["climb Rope"] = {<br />
attributes = {<br />
color = {<br />
b = 0,<br />
g = 128,<br />
r = 128<br />
},<br />
style = "dash dot dot line",<br />
arrow = false<br />
},<br />
points = {<br />
{<br />
y = 9.5,<br />
x = 4.5<br />
},<br />
{<br />
y = 9.5,<br />
x = 6<br />
},<br />
[0] = {<br />
y = 5.5,<br />
x = 4.5<br />
}<br />
}<br />
},<br />
N = {<br />
attributes = {<br />
color = {<br />
b = 255,<br />
g = 255,<br />
r = 0<br />
},<br />
style = "dot line",<br />
arrow = true<br />
},<br />
points = {<br />
[0] = {<br />
y = 27,<br />
x = -3<br />
}<br />
}<br />
}<br />
}<br />
</syntaxhighlight><br />
<br />
==getDoors==<br />
;doors = getDoors(roomID)<br />
<br />
:Returns a key-value table with the cardinal direction as the key and the door value as a number. If there are no doors in a room, it returns an empty table.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to check for doors in.<br />
<br />
: See also: [[#setDoor|setDoor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- an example that displays possible doors in room 2334<br />
local doors = getDoors(2334)<br />
<br />
if not next(doors) then cecho("\nThere aren't any doors in room 2334.") return end<br />
<br />
local door_status = {"open", "closed", "locked"}<br />
<br />
for direction, door in pairs(doors) do<br />
cecho("\nThere's a door leading in "..direction.." that is "..door_status[door]..".")<br />
end<br />
</syntaxhighlight><br />
<br />
==getExitStubs==<br />
;stubs = getExitStubs(roomid)<br />
<br />
:Returns an indexed table (starting at 0) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping.<br />
<br />
: See also: [[#setExitStub|setExitStub()]], [[#connectExitStub|connectExitStub()]], [[#getExitStubs1|getExitStubs1()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
local stubs = getExitStubs(6)<br />
for i = 0, #stubs do print(stubs[i]) end<br />
</syntaxhighlight><br />
<br />
{{note}} Previously would throw a lua error on non-existent room - now returns nil plus error message (as does other run-time errors) - previously would return just a nil on NO exit stubs but now returns a notification error message as well, to aide disambiguation of the nil value.<br />
<br />
==getExitStubs1==<br />
;stubs = getExitStubs1(roomid)<br />
<br />
:Returns an indexed table (starting at 1) of the direction #'s that have an exit stub marked in them. You can use this information to connect earlier-made exit stubs between rooms when mapping. As this function starts indexing from 1 as it is default in Lua, you can use ipairs() to iterate over the results.<br />
<br />
; See also: [[#getExitStubs|getExitStubs()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- show the exit stubs in room 6 as numbers<br />
for k,v in ipairs(getExitStubs1(6)) do print(k,v) end<br />
</syntaxhighlight><br />
<br />
==getExitWeights==<br />
;weights = getExitWeights(roomid)<br />
<br />
:Returns a key-value table of the exit weights that a room has, with the direction or special exit as a key and the value as the exit weight. If a weight for a direction wasn't yet set, it won't be listed.<br />
<br />
;Parameters<br />
* ''roomid:''<br />
: Room ID to view the exit weights in.<br />
<br />
: See also: [[#setExitWeight|setExitWeight()]]<br />
<br />
==getGridMode==<br />
;TrueOrFalse = getGridMode(areaID)<br />
<br />
:Use this to see, if a specific area has grid/wilderness view mode set. This way, you can also calculate from a script, how many grid areas a map has got in total.<br />
<br />
{{note}} <br />
Available since Mudlet 3.11<br />
<br />
;Parameters<br />
* ''areaID:''<br />
: Area ID (number) to view the grid mode of.<br />
<br />
: See also: [[#setGridMode|setGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getGridMode(55)<br />
-- will return: false<br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
getGridMode(55)<br />
-- will return: true<br />
</syntaxhighlight><br />
<br />
==getMapEvents==<br />
; mapevents = getMapEvents()<br />
<br />
: Returns a list of map events currently registered. Each event is a dictionary with the keys ''uniquename'', ''parent'', ''event name'', ''display name'', and ''arguments'', which correspond to the arguments of ''addMapEvent()''.<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#removeMapEvent|removeMapEvent()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- will make a label "room a" on the map menu's right click that calls onFavorite<br />
<br />
addMapEvent("room b", "onFavorite", "Favorites", "Special Room!", 12345, "arg1", "arg2", "argn")<br />
<br />
local mapEvents = getMapEvents()<br />
for _, event in ipairs(mapEvents) do<br />
echo(string.format("MapEvent '%s' is bound to event '%s' with these args: '%s'", event["uniquename"], event["event name"], table.concat(event["arguments"], ",")))<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabels(areaID, labelID)<br />
<br />
:Returns a key-value table describing that particular label in an area. Keys it contains are the ''X'', ''Y'', ''Z'' coordinates, ''Height'' and ''Width'', and the ''Text'' it contains. If the label is an image label, then ''Text'' will be set to the ''no text'' string.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabels|getMapLabels()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lua getMapLabels(1658987)<br />
table {<br />
1: 'no text'<br />
0: 'test'<br />
}<br />
<br />
lua getMapLabel(1658987, 0)<br />
table {<br />
'Y': -2<br />
'X': -8<br />
'Z': 11<br />
'Height': 3.9669418334961<br />
'Text': 'test'<br />
'Width': 8.6776866912842<br />
}<br />
<br />
lua getMapLabel(1658987, 1)<br />
table {<br />
'Y': 8<br />
'X': -15<br />
'Z': 11<br />
'Height': 7.2520666122437<br />
'Text': 'no text'<br />
'Width': 11.21900844574<br />
}<br />
<br />
<br />
</syntaxhighlight><br />
<br />
==getMapLabels==<br />
;arealabels = getMapLabels(areaID)<br />
<br />
:Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[#deleteMapLabel|deleteMapLabel()]] it.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Waterways'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Waterways'<br />
}<br />
</syntaxhighlight><br />
<br />
==getMapSelection==<br />
; getMapSelection()<br />
<br />
:Returns a table containing details of the current mouse selection in the 2D mapper.<br />
<br />
:Reports on one or more rooms being selected (i.e. they are highlighted in orange).<br />
<br />
:The contents of the table will vary depending on what is currently selected. If the selection is of map rooms then there will be keys of ''center'' and ''rooms'': the former will indicates the center room (the one with the yellow cross-hairs) if there is more than one room selected or the only room if there is only one selected (there will not be cross-hairs in that case); the latter will contain a list of the one or more rooms.<br />
<br />
; Example - several rooms selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5011,<br />
5012,<br />
5013,<br />
5014,<br />
5018,<br />
5019,<br />
5020<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - one room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
center = 5013,<br />
rooms = {<br />
5013<br />
}<br />
}<br />
</syntaxhighlight><br />
; Example - no or something other than a room selected<br />
<syntaxhighlight lang="lua"><br />
display(getMapSelection())<br />
{<br />
}<br />
</syntaxhighlight><br />
<br />
{{Note}} Available in Mudlet 3.17+<br />
<br />
==getMapUserData==<br />
;getMapUserData( key )<br />
<br />
;Parameters<br />
* ''key:''<br />
: string used as a key to select the data stored in the map as a whole.<br />
<br />
:Returns the user data item (string); will return a nil+error message if there is no data with such a key in the map data.<br />
<br />
: See also: [[#getAllMapUserData|getAllMapUserData()]], [[#setMapUserData|setMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getMapUserData("last updated"))<br />
--might result in:--<br />
"December 5, 2020"<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.0<br />
<br />
==getPath==<br />
;getPath(roomID from, roomID to)<br />
<br />
:Returns a boolean true/false if a path between two room IDs is possible. If it is, the global ''speedWalkDir'' table is set to all of the directions that have to be taken to get there, and the global ''speedWalkPath'' table is set to all of the roomIDs you'll encounter on the way, and as of 3.0, ''speedWalkWeight'' will return all of the room weights. Additionally returns the total cost (all weights added up) of the path after the boolean argument in 3.0.<br />
<br />
<br />
: See also: [[Manual:Lua_Functions#translateTable()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- check if we can go to room 155 from room 34 - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</syntaxhighlight><br />
<br />
==getPlayerRoom==<br />
;getPlayerRoom()<br />
<br />
:Returns the current player location as set by [[#centerview|centerview()]].<br />
<br />
: See also: [[#centerview|centerview]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("We're currently in " .. getRoomName(getPlayerRoom()))<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.14<br />
<br />
==getRoomArea==<br />
;getRoomArea(roomID)<br />
<br />
:Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by [[#getAreaTable | getAreaTable()]] function, or use the [[#getRoomAreaName |getRoomAreaName()]] function.<br />
<br />
{{note}} If the room ID does not exist, this function will raise an error.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</syntaxhighlight><br />
<br />
==getRoomAreaName==<br />
;getRoomAreaName(areaID or areaName)<br />
<br />
:Returns the area name for a given area id; or the area id for a given area name.<br />
<br />
{{note}} Despite the name, this function will not return the area name for a given ''room'' id (or room name) directly. However, renaming or revising it would break existing scripts.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</syntaxhighlight><br />
<br />
<br />
==getRoomChar==<br />
;getRoomChar(roomID)<br />
<br />
:Returns the single ASCII character that forms the ''symbol'' for the given room id.<br />
<br />
: '''Since Mudlet version 3.8 :''' this facility has been extended:<br />
: Returns the string (UTF-8) that forms the ''symbol'' for the given room id; this may have been set with either [[#setRoomChar|setRoomChar()]] or with the ''symbol'' (was ''letter'' in prior versions) context menu item for rooms in the 2D Map.<br />
<br />
==getRoomCoordinates==<br />
;getRoomCoordinates(roomID)<br />
<br />
:Returns the room coordinates of the given room ID.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- A quick function that will find all rooms on the same z-position in an area; this is useful if, say, you want to know what all the same rooms on the same "level" of an area is.<br />
function sortByZ(areaID, zval)<br />
local area = getAreaRooms(areaID)<br />
local t = {}<br />
for _, id in ipairs(area) do<br />
local _, _, z = getRoomCoordinates(id)<br />
if z == zval then<br />
table.insert(t, id)<br />
end<br />
end<br />
return t<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomEnv==<br />
;envID = getRoomEnv(roomID)<br />
<br />
:Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</syntaxhighlight><br />
<br />
== getRoomExits ==<br />
;getRoomExits (roomID)<br />
:Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid''.<br />
<br />
: See also: [[#getSpecialExits|getSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</syntaxhighlight><br />
<br />
Here's a practical example that queries the rooms around you and searched for one of the water environments (the number would depend on how it was mapped):<br />
<br />
<syntaxhighlight lang="lua"><br />
local exits = getRoomExits(mycurrentroomid)<br />
for direction,num in pairs(exits) do<br />
local env_num = getRoomEnv(num)<br />
if env_num == 22 or env_num == 20 or env_num == 30 then<br />
print("There's water to the "..direction.."!")<br />
end<br />
end</syntaxhighlight><br />
<br />
==getRoomHashByID==<br />
;getRoomHashByID(roomID)<br />
<br />
:Returns a room hash that is associated with a given room ID in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs. It may be used to share map data while not sharing map itself. ''nil'' is returned if no room is not found.<br />
<br />
: See also: [[#getRoomIDbyHash|getRoomIDbyHash()]]<br />
{{note}} Available since Mudlet 3.13.0<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
for id,name in pairs(getRooms()) do<br />
local h = getRoomUserData(id, "herbs")<br />
if h ~= "" then<br />
echo(string.format([[["%s"] = "%s",]], getRoomHashByID(id), h))<br />
echo("\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomIDbyHash==<br />
;roomID = getRoomIDbyHash(hash)<br />
<br />
:Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
: See also: [[#getRoomHashByID|getRoomHashByID()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
local id = getRoomIDbyHash("5dfe55b0c8d769e865fd85ba63127fbc")<br />
if id == -1 then <br />
id = createRoomID()<br />
setRoomIDbyHash(id, "5dfe55b0c8d769e865fd85ba63127fbc")<br />
addRoom(id)<br />
setRoomCoordinates(id, 0, 0, -1)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomName==<br />
;getRoomName(roomID)<br />
<br />
:Returns the room name for a given room id.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("The name of the room id #455 is %s.", getRoomName(455))<br />
</syntaxhighlight><br />
<br />
==getRooms==<br />
;rooms = getRooms()<br />
<br />
:Returns the list of '''all''' rooms in the map in the whole map in roomid - room name format.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- simple, raw viewer for rooms in the world<br />
display(getRooms())<br />
<br />
-- iterate over all rooms in code<br />
for id,name in pairs(getRooms()) do<br />
print(id, name)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomsByPosition==<br />
;roomTable = getRoomsByPosition(areaID, x,y,z)<br />
<br />
:Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
{{note}} The returned table starts indexing from '''0''' and not the usual lua index of '''1''', which means that using '''#''' to count the size of the returned table will produce erroneous results - use [[Manual:Table_Functions#table.size|table.size()]] instead.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- sample alias to determine a room nearby, given a relative direction from the current room<br />
<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</syntaxhighlight><br />
<br />
==getRoomUserData==<br />
;getRoomUserData(roomID, key)<br />
<br />
:Returns the user data value (string) stored at a given room with a given key (string), or "" if none is stored. Use [[#setRoomUserData|setRoomUserData()]] function for setting the user data.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserData(341, "visitcount"))<br />
</syntaxhighlight><br />
<br />
:;getRoomUserData(roomID, key, enableFullErrorReporting)<br />
<br />
::Returns the user data value (string) stored at a given room with a given key (string), or, if the boolean value ''enableFullErrorReporting'' is true, ''nil'' and an error message if the key is not present or the room does not exist; if ''enableFullErrorReporting'' is false an empty string is returned but then it is not possible to tell if that particular value is actually stored or not against the given key.<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<!-- I would like this block to be indented to match the Example header but the mark-up system seems to be broken and only includes the first line<br />
if the start of the code line begins: ":<lua>..."--><br />
<syntaxhighlight lang="lua">local vNum = 341<br />
result, errMsg = getRoomUserData(vNum, "visitcount", true)<br />
if result ~= nil then<br />
display(result)<br />
else<br />
echo("\nNo visitcount data for room: "..vNum.."; reason: "..errMsg.."\n")<br />
end</syntaxhighlight><br />
<br />
==getRoomUserDataKeys==<br />
;getRoomUserDataKeys(roomID)<br />
<br />
:Returns all the keys for user data items stored in the given room ID; will return an empty table if there is no data stored or nil if there is no such room with that ID. ''Can be useful if the user was not the one who put the data in the map in the first place!''<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getRoomUserDataKeys(3441))<br />
--might result in:--<br />
{<br />
"description",<br />
"doorname_up",<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==getRoomWeight==<br />
;getRoomWeight(roomID)<br />
<br />
:Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[#setRoomWeight|setRoomWeight()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display("Original weight of room 541: "..getRoomWeight(541))<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541))<br />
</syntaxhighlight><br />
<br />
==getSpecialExits==<br />
;exits = getSpecialExits(roomID)<br />
<br />
:Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
: See also: [[#getRoomExits|getRoomExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</syntaxhighlight><br />
<br />
==getSpecialExitsSwap==<br />
;getSpecialExitsSwap(roomID)<br />
<br />
:Very similar to [[#getSpecialExits|getSpecialExits()]] function, but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
;gotoRoom (roomID)<br />
:Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(".<br />
<br />
In case this isn't working, and you are coding your own mapping script, [[Mapping_script#Making_your_own_mapping_script|see here]] how to implement additional functionality necessary.<br />
<br />
==hasExitLock==<br />
;status = hasExitLock(roomID, direction)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
; Example<br />
<syntaxhighlight lang="lua"><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
display(hasExitLock(1201, "e"))<br />
display(hasExitLock(1201, "east"))<br />
</syntaxhighlight><br />
<br />
: See also: [[#lockExit|lockExit()]]<br />
<br />
==hasSpecialExitLock==<br />
;hasSpecialExitLock(from roomID, to roomID, moveCommand)<br />
<br />
:Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''moveCommand'' is the action to take to get through the gate.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- lock a special exit from 17463 to 7814 that uses the 'enter feather' command<br />
lockSpecialExit(17463, 7814, 'enter feather', true)<br />
<br />
-- see if it is locked: it will say 'true', it is<br />
display(hasSpecialExitLock(17463, 7814, 'enter feather'))<br />
</syntaxhighlight><br />
<br />
==highlightRoom==<br />
;highlightRoom( roomID, color1Red, color1Green, color1Blue, color2Red, color2Green, color2Blue, highlightRadius, color1Alpha, color2Alpha)<br />
<br />
:Highlights a room with the given color, which will override its environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. <br />
<br />
;Parameters<br />
* ''roomID''<br />
: ID of the room to be colored.<br />
* ''color1Red, color1Green, color1Blue''<br />
: RGB values of the first color.<br />
* ''color2Red, color2Green, color2Blue''<br />
: RGB values of the second color.<br />
* ''highlightRadius'' <br />
: The radius for the highlight circle - if you don't want rooms beside each other to overlap, use ''1'' as the radius. <br />
* ''color1Alpha'' and ''color2Alpha'' <br />
: Transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[#unHighlightRoom|unHighlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0.<br />
<br />
<syntaxhighlight lang="lua"><br />
-- color room #351 red to blue<br />
local r,g,b = unpack(color_table.red)<br />
local br,bg,bb = unpack(color_table.blue)<br />
highlightRoom(351, r,g,b,br,bg,bb, 1, 255, 255)<br />
</syntaxhighlight><br />
<br />
==loadMap==<br />
;loadMap(file location)<br />
<br />
:Loads the map file from a given location. The map file must be in Mudlet's format - saved with [[#saveMap|saveMap()]] or, as of the Mudlet 3.0 may be a MMP XML map conforming to the structure used by I.R.E. for their download-able maps for their MUDs. <br />
<br />
:Returns a boolean for whenever the loading succeeded. Note that the mapper must be open, or this will fail.<br />
<br />
<syntaxhighlight lang="lua"><br />
loadMap("/home/user/Desktop/Mudlet Map.dat")<br />
</syntaxhighlight><br />
<br />
==openMapWidget==<br />
;openMapWidget()<br />
;openMapWidget(dockingArea)<br />
;openMapWidget(Xpos, Ypos, width, height)<br />
:opens a map window with given options.<br />
<br />
: See also: [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
{{note}} If no parameter is given the map window will be opened with the saved layout or at the right docking position (similar to clicking the icon)<br />
* ''dockingArea:''<br />
: If only one parameter is given this parameter will be a string that contains one of the possible docking areas the map window will be created in (f" floating "t" top "b" bottom "r" right and "l" left)<br />
{{note}} If 4 parameters are given the map window will be created in floating state <br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''width:''<br />
: The width map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==lockExit==<br />
;lockExit(roomID, direction, lockIfTrue)<br />
<br />
:Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction can be specified as a number, short direction name ("nw") or long direction name ("northwest").<br />
<br />
: See also: [[#hasExitLock|hasExitLock()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</syntaxhighlight><br />
<br />
==lockRoom==<br />
;lockRoom (roomID, lockIfTrue)<br />
<br />
:Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[#roomLocked | roomLocked()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</syntaxhighlight><br />
<br />
==lockSpecialExit==<br />
;lockSpecialExit (from roomID, to roomID, special exit command, lockIfTrue)<br />
<br />
:Locks a given special exit, leading from one specific room to another that uses a certain command from future speed walks (thus the mapper will never path through that special exit).<br />
: See also: [[#hasSpecialExitLock | hasSpecialExitLock()]], [[#lockExit | lockExit()]], [[#lockRoom | lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
lockSpecialExit(1,2,'enter gate', true) -- locks the special exit that does 'enter gate' to get from room 1 to room 2<br />
lockSpecialExit(1,2,'enter gate', false) -- unlocks the said exit<br />
</syntaxhighlight><br />
<br />
==moveMapWidget==<br />
;moveMapWidget(Xpos, Ypos)<br />
:moves the map window to the given position.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#resizeMapWidget|resizeMapWidget()]]<br />
<br />
;Parameters<br />
* ''Xpos:''<br />
: X position of the map window. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the map window. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==resetRoomArea==<br />
;resetRoomArea (areaID)<br />
<br />
: Unassigns the room from its given area. While not assigned, its area ID will be -1. Note that since Mudlet 3.0 the "default area" which has the id of -1 may be selectable in the area selection widget on the mapper - although there is also an option to conceal this in the settings.<br />
<br />
: See also: [[#setRoomArea | setRoomArea()]], [[#getRoomArea | getRoomArea()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
resetRoomArea(3143)<br />
</syntaxhighlight><br />
<br />
==resizeMapWidget==<br />
;resizeMapWidget(width, height)<br />
:resizes a map window with given width, height.<br />
: See also: [[#openMapWidget|openMapWidget()]], [[#closeMapWidget|closeMapWidget()]], [[#moveMapWidget|moveMapWidget()]]<br />
<br />
;Parameters<br />
* ''width:''<br />
: The width of the map window, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the map window, in pixels. Passed as an integer number.<br />
<br />
{{note}} available in Mudlet 4.7+<br />
<br />
==removeMapEvent==<br />
;removeMapEvent (event name)<br />
<br />
:Removes the given menu entry from a mappers right-click menu. You can add custom ones with [[#addMapEvent | addMapEvent()]].<br />
: See also: [[#addMapEvent | addMapEvent()]], [[#addMapMenu | addMapMenu()]], [[#getMapEvents | getMapEvents()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addMapEvent("room a", "onFavorite") -- add one to the general menu<br />
removeMapEvent("room a") -- removes the said menu<br />
</syntaxhighlight><br />
<br />
==removeCustomLine==<br />
;removeCustomLine(roomID, direction) <br />
<br />
:Removes the custom exit line that's associated with a specific exit of a room.<br />
:See also: [[#addCustomLine|addCustomLine()]], [[#getCustomLines|getCustomLines()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- remove custom exit line that starts in room 315 going north<br />
removeCustomLine(315, "n")<br />
</syntaxhighlight><br />
<br />
==removeSpecialExit==<br />
;removeSpecialExit(roomID, command) <br />
<br />
:Removes the special exit which is accessed by ''command'' from the room with the given ''roomID''.<br />
:See also: [[#addSpecialExit|addSpecialExit()]], [[#clearSpecialExits|clearSpecialExits()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addSpecialExit(1, 2, "pull rope") -- add a special exit from room 1 to room 2<br />
removeSpecialExit(1, "pull rope") -- removes the exit again<br />
</syntaxhighlight><br />
<br />
==roomExists==<br />
;roomExists(roomID)<br />
<br />
:Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
;locked = roomLocked(roomID)<br />
<br />
:Returns true or false whenever a given room is locked.<br />
: See also: [[#lockRoom|lockRoom()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</syntaxhighlight><br />
<br />
==saveMap==<br />
;saveMap([location], [version])<br />
<br />
:Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work. You can also save the map in the Mapper settings tab.<br />
<br />
;Parameters<br />
* ''location''<br />
: (optional) save the map to the given location if provided, or the default one otherwise.<br />
* ''version''<br />
: (optional) map version as a number to use when saving (Mudlet 3.17+)<br />
<br />
: See also: [[#loadMap|loadMap()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
<br />
-- save with a particular map version<br />
saveMap(20)<br />
</syntaxhighlight><br />
<br />
==searchAreaUserData==<br />
:Searches Areas' User Data in a manner exactly the same as [[#searchRoomUserData|searchRoomUserData()]] does in all Rooms' User Data, refer to that command for the specific details except to replace references to rooms and room ID numbers there with areas and areas ID numbers.<br />
<br />
==searchRoom== <br />
;searchRoom (room name / room number)<br />
<br />
:Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname''.<br />
:If you pass it a number instead of a string, it'll act like [[#getRoomName|getRoomName()]] and return you the room name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(searchRoom("master"))<br />
{<br />
[17463] = 'in the branches of the Master Ravenwood'<br />
[3652] = 'master bedroom'<br />
[10361] = 'Hall of Cultural Masterpieces'<br />
[6324] = 'Exhibit of the Techniques of the Master Artisans'<br />
[5340] = 'office of the Guildmaster'<br />
[2004] = 'office of the guildmaster'<br />
[14457] = 'the Master Gear'<br />
[1337] = 'before the Master Ravenwood Tree'<br />
}<br />
</syntaxhighlight><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
{{note}} Additional parameters are available since Mudlet 3.0:<br />
<br />
;searchRoom (room name, [case-sensitive [, exact-match]])<br />
<br />
;Additional Parameters<br />
* ''case-sensitive:''<br />
: If true forces a case-sensitive search to be done on with the supplied room name argument, if false case is not considered.<br />
* ''exact-match:''<br />
: If true forces an exact match rather than a sub-string match, with a case sensitivity as set by previous option.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- shows all rooms containing these words in any case: --<br />
display(searchRoom("North road",false,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road",<br />
[3146] = "Bend in the North Road",<br />
[3088] = "The North Road South of Taren Ferry",<br />
[6229] = "Grassy Field By North Road"<br />
}<br />
<br />
-- shows all rooms containing these words in ONLY this case: --<br />
display(searchRoom("North road",true,false))<br />
{<br />
[3114] = "Bend in North road",<br />
[3115] = "North road",<br />
[3117] = "North road",<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in any case: --<br />
lua searchRoom("North road",false,true)<br />
{<br />
[3115] = "North road",<br />
[3116] = "North Road",<br />
[3117] = "North road"<br />
}<br />
<br />
-- shows all rooms containing ONLY these words in ONLY this case: --<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><br />
<br />
{{note}} Technically, with both options (case-sensitive and exact-match) set to true, one could just return a list of numbers as we know precisely what the string will be, but it was kept the same for maximum flexibility in user scripts.<br />
<br />
==searchRoomUserData== <br />
:A command with three variants that search though all the rooms in sequence (so '''not as fast as a user built/maintained ''index'' system''') and find/reports on the room user data stored:<br />
<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#getRoomUserDataKeys|getRoomUserDataKeys()]], [[#setRoomUserData|setRoomUserData()]]<br />
<br />
;searchRoomUserData(key, value)<br />
<br />
:Reports a (sorted) list of all room ids with user data with the given "value" for the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData(key)<br />
<br />
:Reports a (sorted) list of the unique values from all rooms with user data with the given (case sensitive) "key". Due to the lack of previous enforcement it is possible (though not recommended) to have a room user data item with an empty string "" as a key, this is handled correctly.<br />
<br />
;searchRoomUserData()<br />
<br />
:Reports a (sorted) list of the unique keys from all rooms with user data with any (case sensitive) "key", available since Mudlet 3.0.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- if I had stored the details of "named doors" as part of the room user data --<br />
display(searchRoomUserData("doorname_up"))<br />
<br />
--[[ could result in a list:<br />
{<br />
"Eastgate",<br />
"Northgate",<br />
"boulderdoor",<br />
"chamberdoor",<br />
"dirt",<br />
"floorboards",<br />
"floortrap",<br />
"grate",<br />
"irongrate",<br />
"rockwall",<br />
"tomb",<br />
"trap",<br />
"trapdoor"<br />
}]]<br />
<br />
-- then taking one of these keys --<br />
display(searchRoomUserData("doorname_up","trapdoor"))<br />
<br />
--[[ might result in a list:<br />
{<br />
3441,<br />
6113,<br />
6115,<br />
8890<br />
}<br />
]]</syntaxhighlight><br />
<br />
{{note}} Available since Mudlet 3.0.<br />
<br />
==setAreaName==<br />
;setAreaName(areaID or areaName, newName)<br />
<br />
:Names, or renames an existing area to the new name. The area must be created first with [[#addAreaName|addAreaName()]] and it must be unique.<br />
<br />
{{note}} areaName is available since Mudlet 3.0.<br />
<br />
:See also: [[#deleteArea|deleteArea()]], [[#addAreaName|addAreaName()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setAreaName(2, "My city")<br />
<br />
-- available since Mudlet 3.0<br />
setAreaName("My old city name", "My new city name")<br />
</syntaxhighlight><br />
<br />
==setAreaUserData==<br />
;setAreaUserData(areaID, key (as a string), value (as a string))<br />
<br />
:Stores information about an area under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. Returns a lua ''true'' value on success. You can have as many keys as you'd like, however a blank key will not be accepted and will produce a lua ''nil'' and an error message instead.<br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#getAreaUserData|getAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]]<br />
<br />
{{note}} Release (not Development) version 3.0 software made this function available, but was unable to load the prerequisite map formats 17 and 18 that can store map-level data - that had been fixed in Release 3.0.1 .<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store extra area details...<br />
setAreaUserData(34, "country", "Andor.")<br />
<br />
-- or a sound file to play in the background (with a script that checks a room's area when entered)...<br />
setAreaUserData(34, "backgroundSound", "/home/user/mudlet-data/soundFiles/birdsong.mp4")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setAreaUserData(101, "some table", yajl.to_string({ruler = "Queen Morgase Trakand", clan = "Lion Warden"}))<br />
display("The ruler's name is: "..yajl.to_value(getRoomUserData(34, "some table")).ruler)<br />
</syntaxhighlight><br />
<br />
==setCustomEnvColor==<br />
;setCustomEnvColor(environmentID, r,g,b,a)<br />
<br />
:Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
: See also: [[#getCustomEnvColorTable|getCustomEnvColorTable()]], [[#setRoomEnv|setRoomEnv()]]<br />
<br />
{{note}} Numbers 1-16 and 257-272 are reserved by Mudlet. 257-272 are the default colors the user can adjust in mapper settings, so feel free to use them if you'd like - but don't overwrite them with this function.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
local r,g,b = unpack(color_table.blue)<br />
setCustomEnvColor(200, r,g,b, 255) -- set the color of environmentID 200 to blue<br />
</syntaxhighlight><br />
<br />
==setDoor==<br />
;setDoor(roomID, exitCommand, doorStatus)<br />
<br />
:Creates or deletes a door in a room. Doors are purely visual - they don't affect pathfinding. You can use the information to change to adjust your speedwalking path based on the door information in a room, though.<br />
<br />
:Doors CAN be set on stub exits ''- so that map makers can note if there is an obvious door to somewhere even if they do not (yet) know where it goes, perhaps because they do not yet have the key to open it!''<br />
<br />
:Returns ''true'' if the change could be made, ''false'' if the input was valid but ineffective (door status was not changed), and ''nil'' with a message string on invalid input (value type errors).<br />
<br />
: See also: [[#getDoors|getDoors()]]<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to create the door in.<br />
* ''exitCommand:''<br />
: The cardinal direction for the door is in - it can be one of the following: '''n''', '''e''', '''s''', '''w''', '''ne''', '''se''', '''sw''', '''ne'''. ''{Plans are afoot to add support for doors on the other normal exits: '''up''', '''down''', '''in''' and '''out''', and also on special exits - though more work will be needed for them to be shown in the mapper.}'' It is important to ONLY use these direction codes as others e.g. "UP" will be accepted - because a special exit could have ANY name/lua script - but it will not be associated with the particular normal exit - recent map auditing code about to go into the code base will REMOVE door and other room exit items for which the appropriate exit (or stub) itself is not present, so in this case, in the absence of a special exit called "UP" that example door will not persist and not show on the normal "up" exit when that is possible later on.<br />
<br />
* ''doorStatus:''<br />
: The door status as a number - '''0''' means no (or remove) door, '''1''' means open door (will draw a green square on exit), '''2''' means closed door (yellow square) and '''3''' means locked door (red square). <br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a door on the east exit of room 4234 that is currently open<br />
setDoor(4234, 'e', 1)<br />
<br />
-- remove a door from room 923 that points north<br />
setDoor(923, 'n', 0)<br />
</syntaxhighlight><br />
<br />
==setExit==<br />
;setExit(from roomID, to roomID, direction)<br />
<br />
:Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', the long version of a direction, or a number which represents a direction. If there was an exit stub in that direction already, then it will be automatically deleted for you.<br />
<br />
:Returns ''false'' if the exit creation didn't work.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^exit (\d+) (\d+) (\w+)$<br />
-- so exit 1 2 5 will make an exit from room 1 to room 2 via north<br />
<br />
if setExit(tonumber(matches[2]), tonumber(matches[3]), matches[4]) then<br />
echo("\nExit set to room:"..matches[3].." from "..matches[2]..", direction:"..string.upper(matches[3]))<br />
else<br />
echo("Failed to set the exit.\n")<br />
end<br />
</syntaxhighlight><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
<br />
<syntaxhighlight lang="lua">setExit(from roomID, -1, direction)</syntaxhighlight><br />
<br />
- which will delete an outgoing exit in the specified direction from a room.<br />
<br />
==setExitStub==<br />
;setExitStub(roomID, direction, set/unset)<br />
<br />
Creates or removes an exit stub from a room in a given directions. You can use exit stubs later on to connect rooms that you're sure of are together. Exit stubs are also shown visually on the map, so the mapper can easily tell which rooms need finishing.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: The room to place an exit stub in, as a number.<br />
* ''direction:''<br />
: The direction the exit stub should lead in - as ashort direction name ("nw"), long direction name ("northwest") or a number.<br />
* ''set/unset:''<br />
: A boolean to create or delete the exit stub.<br />
<br />
: See also: [[#getExitStubs|getExitStubs()]], [[#connectExitStub|connectExitStub()]]<br />
<br />
;Example<br />
Create an exit stub to the south from room 8:<br />
<syntaxhighlight lang="lua"><br />
setExitStub(8, "s", true)<br />
</syntaxhighlight><br />
<br />
How to delete all exit stubs in a room:<br />
<syntaxhighlight lang="lua"><br />
for i,v in pairs(getExitStubs(roomID)) do<br />
setExitStub(roomID, v,false)<br />
end<br />
</syntaxhighlight><br />
<br />
==setExitWeight==<br />
;setExitWeight(roomID, exitCommand, weight)<br />
<br />
:Gives an exit a weight, which makes it less likely to be chosen for pathfinding. All exits have a weight of 0 by default, which you can increase. Exit weights are set one-way on an exit - if you'd like the weight to be applied both ways, set it from the reverse room and direction as well.<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set the weight in.<br />
* ''exitCommand:''<br />
: The direction for the exit is in - it can be one of the following: '''n''', '''ne''', '''e''', '''se''', '''s''', '''sw''', '''w''', '''nw''', '''up''', '''down''', '''in''', '''out''', or, if it's a special exit, the special exit command - note that the strings for normal exits are case-sensitive and must currently be exactly as given here.<br />
* ''weight:''<br />
: Exit weight - by default, all exits have a weight of 0 meaning that the weight of the ''destination room'' is use when the route finding code is considering whether to use that exit; setting a value for an exit can increase or decrease the chance of that exit/destination room being used for a route by the route-finding code. For example, if the destination room has very high weight compared to it's neighbors but the exit has a low value then that exit and thus the room is more likely to be used than if the exit was not weighted.<br />
<br />
: See also: [[#getExitWeights|getExitWeights()]]<br />
<br />
==setGridMode==<br />
;setGridMode(areaID, true/false)<br />
<br />
:Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode; for the 2D map the custom exit lines will also not be shown if this mode is enabled. <br />
:Returns true if the area exists, otherwise false.<br />
<br />
: See also: [[#getGridMode|getGridMode()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setGridMode(55, true) -- set area with ID 55 to be in grid mode<br />
</syntaxhighlight><br />
<br />
==setMapUserData==<br />
;setMapUserData(key (as a string), value (as a string))<br />
<br />
:Stores information about the map under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearMapUserData|clearMapUserData()]], [[#clearMapUserDataItem|clearMapUserDataItem()]], [[#getAllMapUserData|getAllMapUserData()]], [[#getMapUserData|getMapUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- store general meta information about the map...<br />
setMapUserData("game_name", "Achaea Mudlet map")<br />
<br />
-- or who the author was<br />
setMapUserData("author", "Bob")<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setMapUserData("some table", yajl.to_string({game = "mud.com", port = 23}))<br />
display("Available game info in the map: ")<br />
display(yajl.to_value(getMapUserData("some table")))<br />
</syntaxhighlight><br />
<br />
==setMapZoom==<br />
;setMapZoom(zoom)<br />
<br />
:Zooms the map in to a given zoom level. '''1''' is the closest you can get, and anything higher than that zooms the map out. Call [[#centerview|centerview()]] after you set the zoom to refresh the map.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setMapZoom(10) -- zoom to a somewhat acceptable level, a bit big but easily visible connections<br />
</syntaxhighlight><br />
<br />
==setRoomArea==<br />
;setRoomArea(roomID, newAreaID or newAreaName)<br />
<br />
:Assigns the given room to a new or different area. If the area is displayed in the mapper this will have the room be visually moved into the area as well.<br />
<br />
: See also: [[#resetRoomArea|resetRoomArea()]]<br />
<br />
==setRoomChar==<br />
;setRoomChar(roomID, character)<br />
<br />
:Originally designed for an area in grid mode, takes a single ASCII character and draws it on the rectangular background of the room in the 2D map. In versions prior to Mudlet 3.8, the symbol can be cleared by using "_" as the character. In Mudlet version 3.8 and higher, the symbol may be cleared with either a space <code>" "</code> or an empty string <code>""</code>.<br />
<br />
;MUD-related symbols for your map<br />
* [https://github.com/toddfast/game-icons-net-font toddfast's font] - 3000+ scalable vector RPG icons from [https://game-icons.net game-icons.net], as well as a script to download the latest icons and generate a new font.<br />
* Pixel Kitchen's [https://www.fontspace.com/donjonikons-font-f30607 Donjonikon Font] - 10x10 fantasy and RPG-related icons.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123, "$")<br />
<br />
-- emoji's work fine too, and if you'd like it colour, set the font to Nojo Emoji in settings<br />
setRoomChar(666, "👿")<br />
</syntaxhighlight><br />
<br />
:'''Since Mudlet version 3.8 :''' this facility has been extended:<br />
:* This function will now take a short string of any printable characters as a room ''symbol'', and they will be shrunk to fit them all in horizontally but if they become too small that ''symbol'' may not be shown if the zoom is such that the room symbol is too small to be legible.<br />
:* As "_" is now a valid character an existing symbol may be erased with either a space " " or an empty string "" although neither may be effective in some previous versions of Mudlet.<br />
:* Should the rooms be set to be drawn as circles this is now accommodated and the symbol will be resized to fit the reduce drawing area this will cause.<br />
:* The range of characters that are available are now dependent on the '''fonts''' present in the system and a setting on the "Mapper" tab in the preferences that control whether a specific font is to be used for all symbols (which is best if a font is included as part of a MUD server package, but has the issue that it may not be displayable if the user does not have that font or chooses a different one) or any font in the user's system may be used (which is the default, but may not display the ''glyph'' {the particular representation of a ''grapheme'' in a particular font} that the original map creator expected). Should it not be possible to display the wanted symbol in the map because one or more of the required glyphs are not available in either the specified or any font depending on the setting then the ''replacement character'' (Unicode ''code-point'' U+FFFD '�') will be shown instead. To allow such missing symbols to be handled the "Mapper" tab on the preferences dialogue has an option to display:<br />
::* an indicator to show whether the symbol can be made just from the selected font (green tick), from the fonts available in the system (yellow warning triangle) or not at all (red cross)<br />
::* all the symbols used on the map and how they will be displayed both only using the selected font and all fonts<br />
::* the sequence of code-points used to create the symbol which will be useful when used in conjunction with character selection utilities such as ''charmap.exe'' on Windows and ''gucharmap'' on unix-like system<br />
::* a count of the rooms using the particular symbol<br />
::* a list, limited in entries of the first rooms using that symbol<br />
:* The font that is chosen to be used as the primary (or only) one for the room symbols is stored in the Mudlet map data so that setting will be included if a binary map is shared to other Mudlet users or profiles on the same system.<br />
<br />
: See also: [[#getRoomChar|getRoomChar()]]<br />
<br />
==setRoomCoordinates==<br />
;setRoomCoordinates(roomID, x, y, z)<br />
<br />
:Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
{{note}} 0,0,0 is the center of the map.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
-- this sets the current room to the supplied coordinates<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
:You can make them relative as well:<br />
<br />
<syntaxhighlight lang="lua"><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</syntaxhighlight><br />
<br />
==setRoomEnv==<br />
;setRoomEnv(roomID, newEnvID)<br />
<br />
:Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
: See also: [[#setCustomEnvColor|setCustomEnvColor()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</syntaxhighlight><br />
<br />
==setRoomIDbyHash==<br />
;setRoomIDbyHash(roomID, hash)<br />
<br />
:Sets the hash to be associated with the given roomID. See also [[#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
;setRoomName(roomID, newName)<br />
<br />
:Renames an existing room to a new name.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</syntaxhighlight><br />
<br />
==setRoomUserData==<br />
;setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
:Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
:Returns true if successfully set.<br />
: See also: [[#clearRoomUserData|clearRoomUserData()]], [[#clearRoomUserDataItem|clearRoomUserDataItem()]], [[#getAllRoomUserData|getAllRoomUserData()]], [[#getRoomUserData|getRoomUserData()]], [[#searchRoomUserData|searchRoomUserData()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</syntaxhighlight><br />
<br />
==setRoomWeight==<br />
;setRoomWeight(roomID, weight)<br />
<br />
:Sets a weight to the given roomID. By default, all rooms have a weight of 1 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
{{note}} The minimum allowed room weight is 1. <br />
<br />
:To completely avoid a room, make use of [[#lockRoom|lockRoom()]].<br />
<br />
: See also: [[#getRoomWeight|getRoomWeight()]]<br />
<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</syntaxhighlight><br />
<br />
==speedwalk==<br />
;speedwalk(dirString, backwards, delay, show)<br />
<br />
:A speedwalking function will work on cardinal+ordinal directions (n, ne, e, etc.) as well as u (for up), d (for down), in and out. It can be called to execute all directions directly after each other, without delay, or with a custom delay, depending on how fast your mud allows you to walk. It can also be called with a switch to make the function reverse the whole path and lead you backwards.<br />
<br />
:Call the function by doing: <code>speedwalk("YourDirectionsString", true/false, delaytime, true/false)</code><br />
<br />
:The delaytime parameter will set a delay between each move (set it to 0.5 if you want the script to move every half second, for instance). It is optional: If you don't indicate it, the script will send all direction commands right after each other. (If you want to indicate a delay, you -have- to explicitly indicate true or false for the reverse flag.)<br />
<br />
:The show parameter will determine if the commands sent by this function are shown or hidden. It is optional: If you don't give a value, the script will show all commands sent. (If you want to use this option, you -have- to explicitly indicate true or false for the reverse flag, as well as either some number for the delay or nil if you do not want a delay.)<br />
<br />
:The "YourDirectionsString" contains your list of directions and steps (e.g.: "2n, 3w, u, 5ne"). Numbers indicate the number of steps you want it to walk in the direction specified after it. The directions must be separated by anything other than a letter that can appear in a direction itself. (I.e. you can separate with a comma, spaces, the letter x, etc. and any such combinations, but you cannot separate by the letter "e", or write two directions right next to each other with nothing in-between, such as "wn". If you write a number before every direction, you don't need any further separator. E.g. it's perfectly acceptable to write "3w1ne2e".) The function is not case-sensitive.<br />
<br />
:If your Mud only has cardinal directions (n,e,s,w and possibly u,d) and you wish to be able to write directions right next to each other like "enu2s3wdu", you'll have to change the pattern slightly. (See the link at the beginning of my post for something like that.)<br />
<br />
:Likewise, if your Mud has any other directions than n, ne, e, se, s, sw, w, nw, u, d, in, out, the function must be adapted to that.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
speedwalk("16d1se1u")<br />
-- Will walk 16 times down, once southeast, once up. All in immediate succession.<br />
<br />
speedwalk("2ne,3e,2n,e")<br />
-- Will walk twice northeast, thrice east, twice north, once east. All in immediate succession.<br />
<br />
speedwalk("IN N 3W 2U W", false, 0.5)<br />
-- Will walk in, north, thrice west, twice up, west, with half a second delay between every move.<br />
<br />
speedwalk("5sw - 3s - 2n - w", true)<br />
-- Will walk backwards: east, twice south, thrice, north, five times northeast. All in immediate succession.<br />
<br />
speedwalk("3w, 2ne, w, u", true, 1.25)<br />
-- Will walk backwards: down, east, twice southwest, thrice east, with 1.25 seconds delay between every move.<br />
</syntaxhighlight><br />
<br />
{{note}} The probably most logical usage of this would be to put it in an alias. For example, have the pattern ''^/(.+)$'' execute: <code>speedwalk(matches[2], false, 0.7)</code><br />
And have ''^//(.+)$'' execute: <code>speedwalk(matches[2], true, 0.7)</code><br />
Or make aliases like: ''^banktohome$'' to execute <syntaxhighlight lang="lua" inline>speedwalk("2ne,e,ne,e,3u,in", true, 0.5)</syntaxhighlight><br />
<br />
{{note}} The show parameter for this function will be available in Mudlet versions after 3.12.<br />
<br />
==unHighlightRoom==<br />
;unHighlightRoom(roomID)<br />
<br />
:Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[#highlightRoom|highlightRoom()]]<br />
<br />
{{note}} Available since Mudlet 2.0 final release<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==updateMap==<br />
;updateMap()<br />
<br />
:Updates the mapper display (redraws it). Use this function if you've edited the map via script and would like the changes to show.<br />
<br />
: See also: [[#centerview|centerview()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete a some room<br />
deleteRoom(500)<br />
-- now make the map show that it's gone<br />
updateMap()<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Smurfhttps://wiki.mudlet.org/index.php?title=Manual:Networking_Functions&diff=15486Manual:Networking Functions2020-07-23T16:25:42Z<p>Smurf: /* downloadFile */ Event descriptions were moved: fix links</p>
<hr />
<div>{{TOC right}}<br />
= Networking Functions =<br />
A collection of functions for managing networking.<br />
<br />
==connectToServer==<br />
;connectToServer(host, port, [save])<br />
: Connects to a given game.<br />
<br />
;Parameters:<br />
* ''host:''<br />
: Server domain or IP address.<br />
* ''port:''<br />
: Servers port.<br />
* ''save:''<br />
: (optional, boolean) if provided, saves the new connection parameters in the profile so they'll be used next time you open it.<br />
<br />
{{note}} ''save'' is available in Mudlet 3.2+.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
connectToServer("midnightsun2.org", 3000)<br />
<br />
-- save to disk so these parameters are used next time when opening the profile<br />
connectToServer("midnightsun2.org", 3000, true)<br />
</syntaxhighlight><br />
<br />
==disconnect==<br />
;disconnect()<br />
: Disconnects you from the game right away. Note that this will ''not'' properly log you out of the game - use an ingame command for that. Such commands vary, but typically QUIT will work.<br />
<br />
: See also: [[Manual:Networking_Functions#reconnect|reconnect()]]<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
disconnect()<br />
</syntaxhighlight><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Event_Engine#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Event_Engine#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
:See also: [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]]<br />
<br />
[[File:Downloadfile privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
{{note}} Since Mudlet 3.0, https downloads are supported and the actual url that was used for the download is returned - useful in case of redirects.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- just download a file and save it in our profile folder<br />
local saveto = getMudletHomeDir().."/dark-theme-mudlet.zip"<br />
local url = "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip"<br />
downloadFile(saveto, url)<br />
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")<br />
</syntaxhighlight><br />
<br />
<br />
<br />
<br />
A more advanced example that downloads a webpage, reads it, and prints a result from it:<br />
<syntaxhighlight lang="lua"><br />
-- create a function to parse the downloaded webpage and display a result<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:find("achaea-who-count.html", 1, true) then return end<br />
<br />
-- read the contents of the webpage in<br />
local f, s, webpage = io.open(filename)<br />
if f then webpage = f:read("*a"); io.close(f) end<br />
-- delete the file on disk, don't clutter<br />
os.remove(filename)<br />
<br />
-- parse our downloaded file for the player count<br />
local pc = webpage:match([[Total: (%d+) players online]])<br />
display("Achaea has "..tostring(pc).." players on right now.")<br />
end<br />
<br />
-- register our function to run on the event that something was downloaded<br />
registerAnonymousEventHandler("sysDownloadDone", "downloaded_file")<br />
<br />
-- download a list of fake users for a demo<br />
downloadFile(getMudletHomeDir().."/achaea-who-count.html", "https://www.achaea.com/game/who")<br />
</syntaxhighlight><br />
<br />
Result should look like this:<br />
<br />
[[File:DownloadFile_demo.png]].<br />
<br />
==getConnectionInfo==<br />
;getConnectionInfo()<br />
:Returns the server address and port that you're currently connected to.<br />
:See also: [[Manual:Networking_Functions#connectToServer|connectToServer()]]<br />
<br />
{{note}} Available in Mudlet 4.2+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Connected to <forest_green>%s:%s\n", host, port))<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- echo the new connection parameters whenever we connect to a different host with connectToServer()<br />
function echoInfo()<br />
local host, port = getConnectionInfo()<br />
cecho(string.format("<light_grey>Now connected to <forest_green>%s:%s\n", host, port))<br />
end<br />
<br />
registerAnonymousEventHandler("sysConnectionEvent", "echoInfo")<br />
</syntaxhighlight><br />
<br />
==getIrcChannels==<br />
;getIrcChannels()<br />
:Returns a list of channels the IRC client is joined to as a lua table. If the client is not yet started the value returned is loaded from disk and represents channels the client will auto-join when started.<br />
:See also: [[Manual:Networking_Functions#setIrcChannels|setIrcChannels()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getIrcChannels())<br />
-- Prints: {"#mudlet", "#lua"}<br />
</syntaxhighlight><br />
<br />
==getIrcConnectedHost==<br />
;getIrcConnectedHost()<br />
:Returns true+host where host is a string containing the host name of the IRC server, as given to the client by the server while starting the IRC connection. If the client has not yet started or finished connecting this will return false and an empty string. <br />
<br />
:This function can be particularly useful for testing if the IRC client has connected to a server prior to sending data, and it will not auto-start the IRC client.<br /> <br />
:The ''hostname'' value this function returns can be used to test if [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage]] events are sent from the server or a user on the network.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local status, hostname = getIrcConnectedHost()<br />
<br />
if status == true then<br />
-- do something with connected IRC, send IRC commands, store 'hostname' elsewhere.<br />
-- if sysIrcMessage sender = hostname from above, message is likely a status, command response, or an error from the Server.<br />
else <br />
-- print a status, change connection settings, or just continue waiting to send IRC data.<br />
end<br />
</syntaxhighlight><br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==getIrcNick==<br />
;getIrcNick()<br />
:Returns a string containing the IRC client nickname. If the client is not yet started, your default nickname is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcNick|setIrcNick()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local nick = getIrcNick()<br />
echo(nick)<br />
-- Prints: "Sheldor"<br />
</syntaxhighlight><br />
<br />
==getIrcServer==<br />
;getIrcServer()<br />
:Returns the IRC client server name and port as a string and a number respectively. If the client is not yet started your default server is loaded from IRC client configuration.<br />
:See also: [[Manual:Networking_Functions#setIrcServer|setIrcServer()]]<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local server, port = getIrcServer()<br />
echo("server: "..server..", port: "..port.."\n")<br />
</syntaxhighlight><br />
<br />
==getNetworkLatency==<br />
; getNetworkLatency()<br />
: Returns the last measured response time between the sent command and the server reply in seconds - e.g. 0.058 (=58 milliseconds lag) or 0.309 (=309 milliseconds). This is the ''N:'' number you see bottom-right of Mudlet.<br />
<br />
Also known as server lag.<br />
<br />
;Example<br />
''Need example''<br />
<br />
==openUrl==<br />
;openUrl (url)<br />
:Opens the default OS browser for the given URL.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
openUrl("http://google.com")<br />
openUrl("www.mudlet.org")<br />
</syntaxhighlight><br />
<br />
==receiveMSP==<br />
;receiveMSP(command)<br />
: Receives a well-formed Mud Sound Protocol (MSP) message to be processed by the Mudlet client. Reference the [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]] manual for more information on about what can be sent and example triggers.<br />
<br />
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Play a cow.wav media file stored in the media folder of the current profile. The sound would play twice at a normal volume.<br />
receiveMSP("!!SOUND(cow.wav L=2 V=50)")<br />
<br />
--Stop any SOUND media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!SOUND(Off)")<br />
<br />
--Play a city.mp3 media file stored in the media folder of the current profile. The music would play once at a low volume.<br />
--The music would continue playing if it was triggered earlier by another room, perhaps in the same area.<br />
receiveMSP([[!!MUSIC(city.mp3 L=1 V=25 C=1)]])<br />
<br />
--Stop any MUSIC media files playing stored in the media folder of the current profile.<br />
receiveMSP("!!MUSIC(Off)")<br />
</syntaxhighlight><br />
<br />
==reconnect==<br />
;reconnect()<br />
: Force-reconnects (so if you're connected, it'll disconnect) you to the game.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- you could trigger this on a log out message to reconnect, if you'd like<br />
reconnect()<br />
</syntaxhighlight><br />
<br />
==restartIrc==<br />
;restartIrc()<br />
:Restarts the IRC client connection, reloading configurations from disk before reconnecting the IRC client.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
==sendAll==<br />
; sendAll(list of things to send, [echo back or not])<br />
: sends multiple things to the game. If you'd like the commands not to be shown, include ''false'' at the end.<br />
<br />
:See also: [[Manual:Basic_Essentials#send|send()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- instead of using many send() calls, you can use one sendAll<br />
sendAll("outr paint", "outr canvas", "paint canvas")<br />
-- can also have the commands not be echoed<br />
sendAll("hi", "bye", false)<br />
</syntaxhighlight><br />
<br />
==sendATCP==<br />
;sendATCP(message, what)<br />
: ''Need description''<br />
<br />
: See also: [[Manual:Supported_Protocols#ATCP|ATCP Protocol]], [[Manual:ATCP_Extensions|ATCP Extensions]], [http://www.ironrealms.com/rapture/manual/files/FeatATCP-txt.html Achaea Telnet Client Protocol specification], [https://forums.mudlet.org/viewtopic.php?p=19502#p19502 Description by forum user KaVir (2013)], [https://forums.mudlet.org/viewtopic.php?p=2015#p2015 Description by forum user Iocun (2009)]<br />
<br />
;Parameters:<br />
* ''message:''<br />
: The message that you want to send.<br />
* ''what:''<br />
: ''Need description''<br />
<br />
;Example<br />
''Need example''<br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
: Note that this function is rarely used in practice. For most GMCP modules, the messages are automatically sent by the server when a relevant event happens in the game. For example, LOOKing in your room prompts the server to send the room description and contents, as well as the GMCP message gmcp.Room. A call to sendGMCP would not be required in this case.<br />
<br />
: See also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group = "vision"})<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP("Char.Skills.Get " .. yajl.to_string{group="MWP", name="block"})<br />
</syntaxhighlight><br />
<br />
==sendMSDP==<br />
;sendMSDP(variable[, value][, value...])<br />
: Sends a MSDP message to the server.<br />
<br />
;Parameters:<br />
* ''variable:''<br />
: The variable, in MSDP terms, that you want to request from the server.<br />
* ''value:''<br />
: The variables value that you want to request. You can request more than one value at a time.<br />
<br />
: See Also: [[Manual:Supported_Protocols#MSDP|MSDP support in Mudlet]], [http://tintin.sourceforge.net/msdp/ Mud Server Data Protocol specification]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- ask for a list of commands, lists, and reportable variables that the server supports<br />
sendMSDP("LIST", "COMMANDS", "LISTS", "REPORTABLE_VARIABLES")<br />
<br />
-- ask the server to start keeping you up to date on your health<br />
sendMSDP("REPORT", "HEALTH")<br />
<br />
-- or on your health and location<br />
sendMSDP("REPORT", "HEALTH", "ROOM_VNUM", "ROOM_NAME")<br />
</syntaxhighlight><br />
<br />
==sendIrc==<br />
;sendIrc(target, message)<br />
: Sends a message to an IRC channel or person. Returns ''true''+''status'' if message could be sent or was successfully processed by the client, or ''nil''+''error'' if the client is not ready for sending, and ''false''+''status'' if the client filtered the message or failed to send it for some reason. If the IRC client hasn't started yet, this function will initiate the IRC client and begin a connection.<br />
<br />
To receive an IRC message, check out the [[Manual:Event_Engine#sysIrcMessage|sysIrcMessage event]].<br />
<br />
{{note}} Since Mudlet 3.3, auto-opens the IRC window and returns the success status.<br />
<br />
;Parameters:<br />
* ''target:''<br />
: nick or channel name and if omitted will default to the first available channel in the list of joined channels.<br />
* ''message:''<br />
: The message to send, may contain IRC client commands which start with <code>/</code> and can use all commands which are available through the client window.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- this would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
-- this would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
<br />
-- use an in-built IRC command<br />
sendIrc("#mudlet", "/topic")<br />
</syntaxhighlight><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.3:<br />
* /ACTION <target> <message...><br />
* /ADMIN (<server>)<br />
* /AWAY (<reason...>)<br />
* /CLEAR (<buffer>) -- Clears the text log for the given buffer name. Uses the current active buffer if none are given.<br />
* /CLOSE (<buffer>) -- Closes the buffer and removes it from the Buffer list. Uses the current active buffer if none are given.<br />
* /HELP (<command>) -- Displays some help information about a given command or lists all available commands.<br />
* /INFO (<server>)<br />
* /INVITE <user> (<#channel>)<br />
* /JOIN <#channel> (<key>)<br />
* /KICK (<#channel>) <user> (<reason...>)<br />
* /KNOCK <#channel> (<message...>)<br />
* /LIST (<channels>) (<server>)<br />
* /ME [target] <message...><br />
* /MODE (<channel/user>) (<mode>) (<arg>)<br />
* /MOTD (<server>)<br />
* /MSG <target> <message...> -- Sends a message to target, can be used to send Private messages.<br />
* /NAMES (<#channel>)<br />
* /NICK <nick><br />
* /NOTICE <#channel/user> <message...><br />
* /PART (<#channel>) (<message...>)<br />
* /PING (<user>)<br />
* /RECONNECT -- Issues a Quit command to the IRC Server and closes the IRC connection then reconnects to the IRC server. The same as calling ircRestart() in Lua.<br />
* /QUIT (<message...>)<br />
* /QUOTE <command> (<parameters...>)<br />
* /STATS <query> (<server>)<br />
* /TIME (<user>)<br />
* /TOPIC (<#channel>) (<topic...>)<br />
* /TRACE (<target>)<br />
* /USERS (<server>)<br />
* /VERSION (<user>)<br />
* /WHO <mask><br />
* /WHOIS <user><br />
* /WHOWAS <user><br />
<br />
{{note}} The following IRC commands are available since Mudlet 3.15:<br />
* /MSGLIMIT <limit> (<buffer>) -- Sets the limit for messages to keep in the IRC client message buffers and saves this setting. If a specific buffer/channel name is given the limit is not saved and applies to the given buffer until the application is closed or the limit is changed again. For this reason, global settings should be applied first, before settings for specific channels/PM buffers.<br />
<br />
==sendTelnetChannel102==<br />
; sendTelnetChannel102(msg)<br />
: Sends a message via the 102 subchannel back to the MUD (that's used in Aardwolf). The msg is in a two byte format; see the link below to the Aardwolf Wiki for how that works.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- turn prompt flags on:<br />
sendTelnetChannel102("\52\1")<br />
<br />
-- turn prompt flags off:<br />
sendTelnetChannel102("\52\2")<br />
</syntaxhighlight><br />
<br />
To see the list of options that Aardwolf supports go to: [http://www.aardwolf.com/blog/2008/07/10/telnet-negotiation-control-mud-client-interaction/ Using Telnet negotiation to control MUD client interaction].<br />
<br />
==setIrcChannels==<br />
;setIrcChannels(channels)<br />
:Saves the given channels to disk as the new IRC client channel auto-join configuration. This value is not applied to the current active IRC client until it is restarted with [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
:See also: [[Manual:Networking_Functions#getIrcChannels|getIrcChannels()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''channels:''<br />
: A table containing strings which are valid channel names. Any channels in the list which aren't valid are removed from the list. <br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcChannels( {"#mudlet", "#lua", "irc"} )<br />
-- Only the first two will be accepted, as "irc" is not a valid channel name.<br />
</syntaxhighlight><br />
<br />
==setIrcNick==<br />
;setIrcNick(nickname)<br />
:Saves the given nickname to disk as the new IRC client configuration. This value is not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcNick|getIrcNick()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''nickname:''<br />
: A string with your new desired name in IRC.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcNick( "Sheldor" )<br />
</syntaxhighlight><br />
<br />
==setIrcServer==<br />
;setIrcServer(hostname, port)<br />
:Saves the given server's address to disk as the new IRC client connection configuration. These values are not applied to the current active IRC client until it is restarted with restartIrc()<br />
:See also: [[Manual:Networking_Functions#getIrcServer|getIrcServer()]], [[Manual:Networking_Functions#restartIrc|restartIrc()]]<br />
<br />
;Parameters:<br />
* ''hostname:''<br />
: A string containing the hostname of the IRC server.<br />
* ''port:''<br />
: (optional) A number indicating the port of the IRC server. Defaults to 6667, if not provided.<br />
<br />
{{note}} Available in Mudlet 3.3+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setIrcServer("chat.freenode.net", 6667)<br />
</syntaxhighlight><br />
<br />
==postHTTP==<br />
;postHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/POST_(HTTP) HTTP POST] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPostHttpDone|sysPostHttpDone]] on success or [[Manual:Event_Engine#sysPostHttpError|sysPostHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]].<br />
<br />
[[File:Posthttp privacy logging.png.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the POST request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
function onHttpPostDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPostHttpDone", onHttpPostDone)<br />
<br />
postHTTP("why hello there!", "https://httpbin.org/post")<br />
postHTTP("this us a request with custom headers", "https://httpbin.org/post", {["X-am-I-awesome"] = "yep I am"})<br />
postHTTP("https://httpbin.org/post", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
-- This will create a JSON message body. Many modern REST APIs expect a JSON body. <br />
local url = "http://postman-echo.com/post"<br />
local data = {message = "I am the banana", user = "admin"}<br />
local header = {["Content-Type"] = "application/json"}<br />
<br />
-- first we create something to handle the success, and tell us what we got<br />
registerAnonymousEventHandler('sysPostHttpDone', function(event, rurl, response)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
-- then we create something to handle the error message, and tell us what went wrong<br />
registerAnonymousEventHandler('sysPostHttpError', function(event, response, rurl)<br />
if rurl == url then display(r) else return true end -- this will show us the response body, or if it's not the right url, then do not delete the handler<br />
end, true) -- this sets it to delete itself after it fires<br />
<br />
-- Lastly, we make the request:<br />
postHTTP(yajl.to_string(data), url, header) -- yajl.to_string converts our Lua table into a JSON-like string so the server can understand it<br />
<br />
-- Pop this into an alias and try it yourself!<br />
</syntaxhighlight><br />
<br />
==putHTTP==<br />
;putHTTP(dataToSend, url, headersTable, file)<br />
: Sends an [https://en.wikipedia.org/wiki/PUT_(HTTP) HTTP PUT] request to the given URL, either as text or with a specific file you'd like to upload. Raises [[Manual:Event_Engine#sysPutHttpDone|sysPutHttpDone]] on success or [[Manual:Event_Engine#sysPutHttpError|sysPutHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#postHTTP|postHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''dataToSend:''<br />
: Text to send in the request (unless you provide a file to upload).<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
* ''file:''<br />
: (optional) file to upload as part of the PUT request. If provided, this will replace 'dataToSend'.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onHttpPutDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysPutHttpDone", onHttpPutDone)<br />
putHTTP("this us a request with custom headers", "https://httpbin.org/put", {["X-am-I-awesome"] = "yep I am"})<br />
putHTTP("https://httpbin.org/put", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
==deleteHTTP==<br />
;deleteHTTP(url, headersTable)<br />
: Sends an [https://en.wikipedia.org/wiki/DELETE_(HTTP) HTTP DELETE] request to the given URL. Raises [[Manual:Event_Engine#sysDeleteHttpDone|sysDeleteHttpDone]] on success or [[Manual:Event_Engine#sysDeleteHttpError|sysDeleteHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]].<br />
<br />
[[File:PutHTTP privacy logging.png|frame|For privacy transparency, URLs accessed are logged in the Central Debug Console]]<br />
<br />
;Parameters:<br />
* ''url:''<br />
: Location to send the request to.<br />
* ''headersTable:''<br />
: (optional) table of headers to send with your request.<br />
<br />
{{note}} Available in Mudlet 4.1+<br />
<br />
;Example<br />
function onHttpDeleteDone(_, url, body)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s", url, body))<br />
end<br />
<br />
registerAnonymousEventHandler("sysDeleteHttpDone", onHttpDeleteDone)<br />
<br />
deleteHTTP("https://httpbin.org/delete")<br />
deleteHTTP("https://httpbin.org/delete", {["X-am-I-awesome"] = "yep I am"})<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Smurf