https://wiki.mudlet.org/api.php?action=feedcontributions&user=Dargoth&feedformat=atomMudlet - User contributions [en]2024-03-29T14:06:08ZUser contributionsMediaWiki 1.35.0https://wiki.mudlet.org/index.php?title=Area_51&diff=20181Area 512022-10-16T23:15:06Z<p>Dargoth: /* UI Functions */</p>
<hr />
<div>{{TOC right}}<br />
<br />
This page is for the development of documentation for Lua API functions that are currently being worked on. Ideally the entries here can be created in the same format as will be eventually used in [[Manual:Lua_Functions|Lua Functions]] and its sub-sites. <br />
<br />
Please use the [[Area_51/Template]] to add new entries in the sections below.<br />
<br />
Links to other functions or parts in other sections (i.e. the main Wiki area) need to include the section details before the <nowiki>'#'</nowiki> character in the link identifier on the left side of the <nowiki>'|'</nowiki> divider between the identifier and the display text. e.g.<br />
:: <nowiki>[[Manual:Mapper_Functions#getCustomLines|getCustomLines()]]</nowiki><br />
rather than:<br />
:: <nowiki>[[#getCustomLines|getCustomLines()]]</nowiki><br />
which would refer to a link within the ''current'' (in this case '''Area 51''') section. Note that this ought to be removed once the article is moved to the main wiki area!<br />
<br />
The following headings reflect those present in the main Wiki area of the Lua API functions. It is suggested that new entries are added so as to maintain a sorted alphabetical order under the appropriate heading.<br />
<br />
<br />
=Basic Essential Functions=<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 />
=Database Functions=<br />
:A collection of functions for helping deal with the database.<br />
<br />
=Date/Time Functions=<br />
: A collection of functions for handling date & time.<br />
<br />
=File System Functions=<br />
: A collection of functions for interacting with the file system.<br />
<br />
=Mapper Functions=<br />
: A collection of functions that manipulate the mapper and its related features.<br />
<br />
==mapSymbolFontInfo, PR #4038 closed==<br />
;mapSymbolFontInfo()<br />
: See also: [[#setupMapSymbolFont|setupMapSymbolFont()]]<br />
<br />
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/4038<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 />
==moveMapLabel, PR #6014 open==<br />
;moveMapLabel(areaID/Name, labeID/Text, coordX/deltaX, coordY/deltaY[, coordZ/deltaZ][, absoluteNotRelativeMove])<br />
Re-positions a map label within an area in the 2D mapper, in a similar manner as the [[#moveRoom|moveRoom()]] function does for rooms and their custom exit lines. When moving a label to given coordinates this is the position that the top-left corner of the label will be positioned at; since the space allocated to a particular room on the map is ± 0.5 around the integer value of its x and y coordinates this means for a label which has a size of 1.0 x 1,0 (w x h) to position it centrally in the space for a single room at the coordinates (x, y, z) it should be positioned at (x - 0.5, y + 0.5, z).<br />
<br />
:See also: [[Manual:Mapper_Functions#getMapLabels|getMapLabels()]], [[Manual:Mapper_Functions#getMapLabel|getMapLabel()]].<br />
<br />
{{MudletVersion| ?.??}}<br />
<br />
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6014<br />
<br />
;Parameters<br />
* ''areaID/Name:''<br />
: Area ID as number or AreaName as string containing the map label.<br />
<br />
* ''labelID/Text:''<br />
: Label ID as number (which will be 0 or greater) or the LabelText on a text label. All labels will have a unique ID number but there may be more than one ''text'' labels with a non-empty text string; only the first matching one will be moved by this function and image labels also have no text and will match the empty string. with mo or AreaName as string containing the map label.<br />
<br />
* ''coordX/deltaX:''<br />
: A floating point number for the absolute coordinate to use or the relative amount to move the label in "room coordinates" along the X-axis.<br />
<br />
* ''coordY/deltaY:''<br />
: A floating point number for the absolute coordinate to use or the relative amount to move the label in "room coordinates" along the Y-axis.<br />
<br />
* ''coordZ/deltaZ:''<br />
: (Optional) A floating point number for the absolute coordinate to use or the relative amount to move the label in "room coordinates" along the Z-axis, if omitted the label is not moved in the z-axis at all.<br />
<br />
* ''absoluteNotRelativeMove:''<br />
: (Optional) a boolean value (defaults to ''false'' if omitted) as to whether to move the label to the absolute coordinates (''true'') or to move it the relative amount from its current location (''false'').<br />
<br />
;Returns<br />
: ''true'' on success or ''nil'' and an error message on failure, if successful it will also refresh the map display to show the result.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the first label in the area with the ID number of 2, three spaces to the east and four spaces to the north<br />
moveMapLabel(0, 2, 3.0, 4.0)<br />
<br />
-- move the first label in the area with the ID number of 2, one space to the west, note the final boolean argument is unneeded<br />
moveMapLabel(0, 2, -1.0, 0.0, false)<br />
<br />
-- move the second label in the area with the ID number of 2, three and a half spaces to the west, and two south **of the center of the current level it is on in the map**:<br />
moveRoom(1, 2, -3.5, -2.0, true)<br />
<br />
-- move the second label in the area with the ID number of 2, up three levels<br />
moveRoom(1, 2, 0.0, 0.0, 3.0)<br />
<br />
-- move the second label in the "Test 1" area one space to the west, note the last two arguments are unneeded<br />
moveRoom("Test 1", 1, -1.0, 0.0, 0.0, false)<br />
<br />
-- move the (top-left corner of the first) label with the text "Home" in the area with ID number 5 to the **center of the whole map**, note the last two arguments are required in this case:<br />
moveRoom(5, "Home", 0.0, 0.0, 0.0, true)<br />
<br />
-- all of the above will return the 'true' boolean value assuming there are the indicated labels and areas<br />
</syntaxhighlight><br />
<br />
==moveRoom, PR #6010 open==<br />
;moveRoom(roomID, coordX/deltaX, coordY/deltaY[, coordZ/deltaZ][, absoluteNotRelativeMove])<br />
Re-positions a room within an area, in the same manner as the "move to" context menu item for one or more rooms in the 2D mapper. Like that method this will also shift the entirety of any custom exit lines defined for the room concerned. This contrasts with the behavior of the [[Manual:Mapper_Functions#setRoomCoordinates|setRoomCoordinates()]] which only moves the starting point of such custom exit lines so that they still emerge from the room to which they belong but otherwise remain pointing to the original place.<br />
<br />
:See also: [[Manual:Mapper_Functions#setRoomCoordinates|setRoomCoordinates()]]<br />
<br />
{{MudletVersion| ?.??}}<br />
<br />
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6010<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID number to move.<br />
<br />
* ''coordX/deltaX:''<br />
: The absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the X-axis.<br />
<br />
* ''coordY/deltaY:''<br />
: The absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the Y-axis.<br />
<br />
* ''coordZ/deltaZ:''<br />
: (Optional) the absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the Z-axis, if omitted the room is not moved in the z-axis at all.<br />
<br />
* ''absoluteNotRelativeMove:''<br />
: (Optional) a boolean value (defaults to ''false'' if omitted) as to whether to move the room to the absolute coordinates (''true'') or the relative amount from its current location (''false'').<br />
<br />
;Returns<br />
: ''true'' on success or ''nil'' and an error message on failure, if successful it will also refresh the map display to show the result.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- move the first room one space to the east and two spaces to the north<br />
moveRoom(1, 1, 2)<br />
<br />
-- move the first room one space to the west, note the final boolean argument is unneeded<br />
moveRoom(1, -1, 0, false)<br />
<br />
-- move the first room three spaces to the west, and two south **of the center of the current level it is on in the map**:<br />
moveRoom(1, -3, -2, true)<br />
<br />
-- move the second room up three levels<br />
moveRoom(2, 0, 0, 3)<br />
<br />
-- move the second room one space to the west, note the last two arguments are unneeded<br />
moveRoom(2, -1, 0, 0, false)<br />
<br />
-- move the second room to the **center of the whole map**, note the last two arguments are required in this case:<br />
moveRoom(2, 0, 0, 0, true)<br />
<br />
-- all of the above will return the 'true' boolean value assuming there are rooms with 1 and 2 as ID numbers<br />
</syntaxhighlight><br />
<br />
==setupMapSymbolFont, PR #4038 closed==<br />
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])<br />
:configures the font used for symbols in the (2D) map.<br />
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]<br />
<br />
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/4038<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 />
=Miscellaneous Functions=<br />
: Miscellaneous functions.<br />
<br />
==setConfig==<br />
; setConfig(option, value)<br />
<br />
:Sets a Mudlet option to a certain value. This comes in handy for scripts that want to customise Mudlet settings to their preferences - for example, setting up mapper room and exit size to one that works for a certain map, or enabling MSDP for a certain game. For transparency reasons, the Debug window (when open) will show which options were modified by scripts.<br />
:To set many options at once, pass in a table of options. More options will be added over time / per request.<br />
<br />
{{MudletVersion|4.16}}<br />
<br />
;Parameters<br />
* ''option:''<br />
: Particular option to change - see list below for available ones.<br />
* ''value:''<br />
: Value to set - can be a boolean, number, or text depending on the option.<br />
<br />
{| class="wikitable sortable"<br />
|+ General options<br />
|-<br />
! Option !! Description !! Available in Mudlet<br />
|-<br />
| enableGMCP || Enable GMCP (on by default. Reconnect after changing) || 4.16 <br />
|-<br />
| enableMSDP || Enable MSDP (off by default. Reconnect after changing) || 4.16 <br />
|-<br />
| enableMSSP || Enable MSSP (on by default. Reconnect after changing) || 4.16 <br />
|-<br />
| enableMSP || Enable MSP (on by default. Reconnect after changing) || 4.16 <br />
|}<br />
<br />
{| class="wikitable sortable"<br />
|+ Input line<br />
|-<br />
! Option !! Description !! Available in Mudlet<br />
|-<br />
| inputLineStrictUnixEndings || Workaround option to use strict UNIX line endings for sending commands || 4.16 <br />
|-<br />
|}<br />
<br />
{| class="wikitable sortable"<br />
|+ Main display<br />
|-<br />
! Option !! Description !! Available in Mudlet<br />
|-<br />
| fixUnnecessaryLinebreaks || Remove extra linebreaks from output (mostly for IRE servers) || 4.16 <br />
|-<br />
|}<br />
<br />
{| class="wikitable sortable"<br />
|+ Mapper options<br />
|-<br />
! Option !! Description !! Available in Mudlet<br />
|-<br />
| mapRoomSize || Size of rooms on map (a good value is 5) || 4.16<br />
|-<br />
| mapExitSize || Size of exits on map (a good value is 10) || 4.16<br />
|-<br />
| mapRoundRooms || Draw rooms round or square || 4.16<br />
|-<br />
| showRoomIdsOnMap || Show room IDs on all rooms (if zoom permits) || 4.16<br />
|-<br />
| showMapInfo || Map overlay text ('Full' or 'Short', can have both at once) || 4.16<br />
|-<br />
| hideMapInfo || Map overlay text ('Full' or 'Short', hide both to hide info altogether) || 4.16<br />
|-<br />
| show3dMapView || Show map as 3D || 4.16<br />
|-<br />
| mapperPanelVisible || Map controls at the bottom || 4.16<br />
|-<br />
| mapShowRoomBorders || Draw a thin border for every room || 4.16<br />
|}<br />
<br />
{| class="wikitable sortable"<br />
|+ Special options<br />
|-<br />
! Option !! Description !! Available in Mudlet<br />
|-<br />
| specialForceCompressionOff || Workaround option to disable MCCP compression, in case the game server is not working correctly || 4.16 <br />
|-<br />
| specialForceGAOff || Workaround option to disable Telnet Go-Ahead, in case the game server is not working correctly || 4.16 <br />
|-<br />
| specialForceCharsetNegotiationOff || Workaround option to disable automatically setting the correct encoding, in case the game server is not working correctly || 4.16 <br />
|-<br />
| specialForceMxpNegotiationOff || Workaround option to disable MXP, in case the game server is not working correctly || 4.16 <br />
|-<br />
| caretShortcut || For visually-impaired players - set the key to switch between input line and main window (can be "none" (default), "tab", "ctrltab", "f6") || 4.17<br />
|-<br />
| blankLinesBehaviour || For visually impaired players options for dealing with blank lines (can be "show" (default), "hide", "replacewithspace") || 4.17<br />
|}<br />
<br />
;Returns <br />
* true if successful, or nil+msg if the option doesn't exist. Setting mapper options requires the mapper being open first.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
setConfig("mapRoomSize", 5)<br />
<br />
setConfig({mapRoomSize = 6, mapExitSize = 12})<br />
</syntaxhighlight><br />
<br />
<br />
==getCustomLoginTextId, PR #3952 open==<br />
;getCustomLoginTextId()<br />
<br />
Returns the Id number of the custom login text setting from the profile's preferences. Returns ''0'' if the option is disabled or a number greater than that for the item in the table; note it is possible if using an old saved profile in the future that the number might be higher than expected. As a design policy decision it is not permitted for a script to change the setting, this function is intended to allow a script or package to check that the setting is what it expects.<br />
<br />
Introduced along with four other functions to enable 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, a replacement for which is shown below.<br />
:See also: [[#getCharacterName|getCharacterName()]], [[#sendCharacterName|sendCharacterName()]], [[#sendCustomLoginText|sendCustomLoginText()]], [[#sendPassword|sendPassword()]].<br />
<br />
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952<br />
<br />
Only one custom login text has been defined initially:<br />
{| class="wikitable"<br />
|+ Predefined custom login texts<br />
|-<br />
! Id !! Custom text !! Introduced in Mudlet version<br />
|-<br />
| 1 || "connect {character name} {password}" || TBD<br />
|}<br />
<br />
The addition of further texts would be subject to negotiation with the Mudlet Makers.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- A replacement for the default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:<br />
function doLogin()<br />
if getCustomLoginTextId() ~= 1 then<br />
-- We need this particular option but it is not permitted for a script to change the setting, it can only check what it is<br />
echo("\nUnable to login - please select the 'connect {character name} {password}` custom login option in the profile preferences.\n")<br />
else<br />
tempTime(2.0, [[sendCustomLoginText()]], 1)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==sendCharacterName, PR #3952 open ==<br />
;sendCharacterName()<br />
<br />
Sends the name entered into the "Character name" field on the Connection Preferences form directly to the 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 four other functions to enable 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()]], [[#sendCustomLoginText|sendCustomLoginText()]], [[#getCustomLoginTextId|getCustomLoginTextId()]].<br />
<br />
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952<br />
<br />
==sendCharacterPassword, PR #3952 open==<br />
;sendCharacterPassword()<br />
<br />
Sends the password entered into the "Password" field on the Connection Preferences form directly to the 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 four other functions to enable 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()]], [[#sendCustomLoginText|sendCustomLoginText()]], [[#getCustomLoginTextId|getCustomLoginTextId()]], [[#sendCharacterName|sendCharacterName()]].<br />
<br />
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952<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 />
== sendCustomLoginText, PR #3952 open ==<br />
;sendCustomLoginText()<br />
<br />
Sends the custom login text (which does NOT depend on the user's choice of GUI language) selected in the preferences for this profile. The {password} (and {character name} if present) fields will be replaced with the values entered into the "Password" and "Character name" fields on the Connection Preferences form and then sent directly to the game server. Returns ''true'' unless there is nothing set in either of those entries (though only if required for the character name) or it is too long after (or before) a connection was successfully made or if the custom login feature is disabled, in which case a ''nil'' and an error message will be returned instead.<br />
<br />
Introduced along with four other functions to enable 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, a replacement for which is shown below.<br />
: See also: [[#getCharacterName|getCharacterName()]], [[#sendCharacterName|sendCharacterName()]], [[#sendPassword|sendPassword()]], [[#getCustomLoginTextId|getCustomLoginTextId()]].<br />
<br />
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952<br />
<br />
Only one custom login text has been defined initially:<br />
{| class="wikitable"<br />
|+Predefined custom login texts<br />
|-<br />
!Id!!Custom text!! Introduced in Mudlet version<br />
|-<br />
|1||"connect {character name} {password}"||TBD<br />
|}<br />
<br />
The addition of further texts would be subject to negotiation with the Mudlet Makers.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- A replacement for the default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:<br />
function doLogin()<br />
if getCustomLoginTextId() ~= 1 then<br />
-- We need this particular option but it is not permitted for a script to change the setting, it can only check what it is<br />
echo("\nUnable to login - please select the 'connect {character name} {password}` custom login option in the profile preferences.\n")<br />
else<br />
tempTime(2.0, [[sendCustomLoginText()]], 1)<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
=Mudlet Object Functions=<br />
:A collection of functions that manipulate Mudlets scripting objects - triggers, aliases, and so forth.<br />
<br />
=Networking Functions=<br />
:A collection of functions for managing networking.<br />
<br />
=String Functions=<br />
:These functions are used to manipulate strings.<br />
<br />
=Table Functions=<br />
:These functions are used to manipulate tables. Through them you can add to tables, remove values, check if a value is present in the table, check the size of a table, and more.<br />
<br />
=Text to Speech Functions =<br />
:These functions are used to create sound from written words. Check out our [[Special:MyLanguage/Manual:Text-to-Speech|Text-To-Speech Manual]] for more detail on how this all works together.<br />
<br />
=UI Functions=<br />
:These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation as well as displaying or formatting information on the screen.<br />
<br />
==setCommandBackgroundColor==<br />
;setCommandBackgroundColor([windowName], r, g, b, [transparency])<br />
: Sets the background color for echo of commands. 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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red command background color in main console.<br />
setCommandBackgroundColor(255,0,0,200)<br />
</syntaxhighlight><br />
<br />
==setCommandForegroundColor==<br />
;setCommandForegroundColor([windowName], r, g, b, [transparency])<br />
: Sets the foreground color for echo of commands. 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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- make a red command foreground color in main console.<br />
setCommandForegroundColor(255,0,0,200)<br />
</syntaxhighlight><br />
<br />
=Discord Functions=<br />
:All functions to customize the information Mudlet displays in Discord's rich presence interface. For an overview on how all of these functions tie in together, see our [[Special:MyLanguage/Manual:Scripting#Discord_Rich_Presence|Discord scripting overview]].</div>Dargothhttps://wiki.mudlet.org/index.php?title=Release_Checklist&diff=19954Release Checklist2022-04-07T20:22:22Z<p>Dargoth: /* Mudlet release checklist */</p>
<hr />
<div>= Mudlet release checklist =<br />
# 5 days before the release (14 if it's a long one)<br />
## ☐ announce start of testing in Discord channel #mudlet-testing with the list of additions/improvements/fixes (but not infrastructure), and add link to latest download builds (from [https://make.mudlet.org/snapshots Latest Branch Snapshots], but double check that sha matches [https://github.com/Mudlet/Mudlet/commits/development the latest commit]).<br />
## ☐ [automated] update <code>mudlet.ts</code> with the latest translations strings for translators to translate<br />
## ☐ update <code>mudlet_en_US.ts</code> with the latest translation strings, translate/update the few plural forms it contains as necessary and then generate the binary translation <code>mudlet_en_US.qm</code> file and merge it into the repo (see [https://wiki.mudlet.org/w/Translating_Mudlet#English_.28American.29_translation Translating Mudlet - English (American) translation]).<br />
## ☐ merge outstanding approved pull requests<br />
## ☐ create a new <code>release-<version></code> branch off <code>development</code><br />
## ☐ go through every single commit (in main repo and installers) and ensure all new functionality is documented<br />
## ☐ update http://www.mudlet.org/geyser/files/index.html (need to document how to upload)<br />
## ☐ [automated] update built-in packages and scripts (IRE mapping script, ...)<br />
## ☐ [automated] update edbee to latest in our fork, and the subsequent submodule<br />
## ☐ update Patreon supporters in About tab<br />
## ☐ check all [https://github.com/Mudlet/Mudlet/issues?q=is%3Aissue+is%3Aopen+label%3Aregression regressions] to see if any must be fixed before the release<br />
## ☐ get testers to sign off (via Discord reaction) that they tested the release and it is fine with them<br />
### if a tester doesn't sign off for 2 releases, notify them, if they don't do it on the next one, remove them from the testers team<br />
## ☐ go through every single commit and write up a newspost with the latest highlights<br />
# on release day<br />
## ☐ create a new release in the 'release' channel in [https://www.dblsqd.com/user/apps/30a30c47-b1cd-48fe-b93e-ab9041b88323 dblsqd]. Make sure to enter the changelog right away, as it cannot be edited after. Include the full version number and a link to the release post ([[Media:Creating a new Mudlet release.png|example]]). A command-line variant of this is: <code>dblsqd release -a mudlet -c release -m "<message>. <a href="https://mudlet.org/4-##">See the changelog</a>." <version, ie 4.11.0></code><br />
## ☐ merge latest translations from Crowdin<br />
## ☐ merge all Area 51 functions into main wiki<br />
## ☐ merge [[Update_lua_function_list|latest autocomplete json]]<br />
## ☐ update mudlet.pro and CMakeLists.txt to new version and strip out BUILD to be empty in release branch (release process starts here)<br />
## ☐ tag in git<br />
## ☐ manually create source code package [https://github.com/Mudlet/Mudlet/blob/33ad832253d6b6411d7c1132e68455742157d60d/CI/travis.linux.after_success.sh#L144 following this]<br />
## ☐ reset BUILD in release branch to be -dev<br />
## ☐ wait for the builds to complete...<br />
## ☐ manually upload artifacts to https://www.mudlet.org/wp-content/files/?C=M;O=D through webmin. Linux and macOS ones will be available as artifacts on the Github job, while Windows is an artifact on the Appveyor job.<br />
## ☐ manually link uploaded artifacts to dblsqd[1]:<br />
## ☐ test that all binaries launch and work<br />
## ☐ close github milestone<br />
## ☐ [[Howto:Update Downloads|update downloads on mudlet.org]]<br />
## ☐ [automated] create changelog with [https://github.com/Mudlet/Mudlet/actions/workflows/generate-changelog.yml a github action]<br />
## ☐ make a proper github release (it will be automatically posted to mudlet.org on publish)<br />
## ☐ post news to https://launchpad.net/mudlet<br />
## ☐ post thread on forums.mudlet.org<br />
## ☐ post update on achaea, starmourn, imperian, lusternia, pkuxkx.net, [http://linux.softpedia.com/get/GAMES-ENTERTAINMENT/MUD/Mudlet-45973.shtml softpedia]<br />
## ☐ post update on twitter, reddit, http://arkadia.rpg.pl, muder.ru<br />
## ☐ delay posting an announcement on Discord until 3-4 days past the release; post when there are no verified issues in update<br />
## ☐ email to releaseradar@github.com about the update<br />
## ☐ submit mudlet windows installer to avg and avast whitelisting<br />
## ☐ merge <code>development</code> into <code>master</code> branch<br />
## ☐ update Linux distro maintainers, [https://chocolatey.org/packages/mudlet/ContactOwners Chocolatey maintainer], flag package outdated on arch (release process ends here)<br />
## ☐ merge, don't squash or rebase, the release branch into development (but don't delete right away, keep it around for a potential hotfix if needed. Delete after the next release is done). Do it right away so next day's PTB's versions is the new release.<br />
## ☐ [https://www.mudlet.org/2021/10/trial-pay-out-to-popular-prs/ create polls] for most popular changes<br />
<br />
<br />
[1]:<br />
<br />
dblsqd push -a mudlet -c release -r "<release>" -s mudlet --type "standalone" --attach linux:x86_64 "https://www.mudlet.org/wp-content/files/Mudlet-<release>-linux-x64.AppImage.tar"<br />
dblsqd push -a mudlet -c release -r "<release>" -s mudlet --type "standalone" --attach mac:x86_64 "https://www.mudlet.org/wp-content/files/Mudlet-<release>.dmg"<br />
dblsqd push -a mudlet -c release -r "<release>" -s mudlet --type "standalone" --attach win:x86 "https://www.mudlet.org/wp-content/files/Mudlet-<release>-windows-installer.exe"<br />
<br />
<br />
= Individual contributor TODOs =<br />
* keneanung: https://github.com/users/keneanung/projects/1<br />
* vadi2: https://gist.github.com/vadi2/c4dd137010c1b969c011293eddfcee73<br />
<br />
[[Category: Mudlet Admin Manual]]</div>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=19870Manual:UI Functions2022-02-15T19:54:13Z<p>Dargoth: /* resetFormat */</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window,] label, eventName)<br />
<br />
Adds item to right click menu associated with command line.<br />
<br />
{{MudletVersion|4.14}}<br />
<br />
;See also: [[Manual:Lua_Functions#removeCommandLineMenuEvent|removeCommandLineMenuEvent()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that command line belongs to. Optional, will default to "main" (main window console)<br />
* ''label:''<br />
: Label of item<br />
* ''eventName:''<br />
: Event name that will be fired when clicked.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addCommandLineMenuEvent("My very own special paste from clipboard", "pasteFromClipboardWithoutLineBreaks" )<br />
registerAnonymousEventHandler("pasteFromClipboardWithoutLineBreaks", function()<br />
local text = string.gsub(getClipboardText(), "[\r|\n]", "")<br />
appendCmdLine(text)<br />
end)<br />
</syntaxhighlight><br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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.<br />
:See also: [[Manual:Lua_Functions#decho|decho()]]<br />
<br />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<br />
<br />
{{note}} underline, italics, overline, and strikethrough supported since Mudlet 4.15+<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, strikethrough, 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 />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you cecho it will erase any previous echo sent to the label.<br />
<br />
;Parameters<br />
*''window:''<br />
:Optional - the window name to echo to - can either be none or "main" for the main window, or a miniconsole, userwindow, or label 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>, <s>strikethrough</s>, <o>overline</o>, and <b>bold</b>.")<br />
<br />
cecho("\n<green><o><u>Green text with over and underline at the same time.</o></u>")<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cecho2ansi==<br />
;ansiFormattedString = cecho2ansi(text)<br />
<br />
:Converts cecho formatted text to ansi formatted text. Used by cfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cfeedTriggers|cfeedTriggers()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
{{note}} This function uses the ansi short colors (0-15) for color names which have base 16 ansi equivalents, such as 'red', 'blue', "lightBlue", "cyan", etc rather than the values defined in the color_table. If there is no base ansi equivalent then it will use the rgb values from the color_table for the color.<br />
<br />
;Parameters<br />
*''text:''<br />
:The cecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of cfeedTriggers() for a single line.<br />
-- you would most likely just use cfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(cecho2ansi("\n<red>This is red.<reset> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<br />
</syntaxhighlight><br />
<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<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)</syntaxhighlight><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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 />
==createScrollBox==<br />
;createScrollBox([name of parent window], name, x, y, width, height)<br />
<br />
: creates a graphical elements able to hold other graphical elements such as labels, miniconsoles, command lines etc. in it.<br />
If the added elements don't fit into the ScrollBox scrollbars appear and allow scrolling.<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#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setWindow|setWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''name of parent window:'' <br />
: (Optional) name of the parent window the scrollBox is created in. Defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the scrollBox. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a ScrollBox with the name sBox<br />
createScrollBox("SBox",0,0,300,200)<br />
<br />
-- create 3 Labels and put them into the ScrollBox<br />
createLabel("SBox","SBoxLabel",0,0,200,200,1)<br />
createLabel("SBox","SBoxLabel2",200,0,200,200,1)<br />
createLabel("SBox","SBoxLabel3",400,0,200,200,1)<br />
<br />
-- put some text on the labels<br />
echo("SBoxLabel","Label")<br />
echo("SBoxLabel2","Label2")<br />
echo("SBoxLabel3","Label3")<br />
<br />
-- change the colours of the labels to make it easier to distinguish them<br />
setBackgroundColor("SBoxLabel",255,0,0)<br />
setBackgroundColor("SBoxLabel2",0,255,0)<br />
setBackgroundColor("SBoxLabel3",0,0,255)<br />
</syntaxhighlight><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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code>, <code><nowiki><s>strikethrough</s></nowiki></code>, <code><nowiki><o>overline</o></nowiki></code>, and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you decho it will erase any previous echo sent to the label.<br />
<br />
:See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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>, <s>strikethrough</s>, and <b>bold</b> formatting.")<br />
<br />
decho("<\n<0,128,0><o><u>Green text with both over and underlines.</u></o>")<br />
</syntaxhighlight><br />
<br />
==decho2ansi==<br />
;ansiFormattedString = decho2ansi(text)<br />
<br />
:Converts decho formatted text to ansi formatted text. Used by dfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dfeedTriggers|dfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
; Parameters<br />
*''text:''<br />
:The decho formatted text for conversion<br />
<br />
;Returns<br />
* String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of dfeedTriggers() for a single line.<br />
-- you would most likely just use dfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(decho2ansi("\n<128,0,0>This is red.<r> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() send("hi") end, "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 - [[Manual:Lua_Functions#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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)<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 />
==getBackgroundColor==<br />
;getBackgroundColor([windowName])<br />
: Gets the background for the given label, miniconsole, or userwindow.<br />
: Returns 4 values - red, green, blue, transparency. Colors returned 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 getthe background color from, or "main" for the main window.<br />
<br />
: {{MudletVersion|4.15}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r, g, b, a = getBackgroundColor()<br />
local rW, gW, bW, aW = getBackgroundColor("myWindow")<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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getHTMLformat==<br />
;spanTag = getHTMLformat(formatTable)<br />
<br />
:Takes in a table of formatting options in the same style as [[Manual:Lua_Functions#getTextFormat|getTextFormat()]] and returns a span tag which will format text after it as the table describes.<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''formatTable:''<br />
:Table with formatting options configured. Keys are foreground, background, bold, underline, overline, strikeout, italic, and reverse. All except for foreground and background should be boolean (true/false) values. Foreground and background are either { r, g, b, a } tables, or strings with QSS formatting directives<br />
<br />
;Returns<br />
*A string with the html span tag to format text in accordance with the format table.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Returns a span tag for bold, red text on a green background<br />
local span = getHTMLformat({<br />
foreground = { 255, 0, 0 },<br />
background = "#00FF00",<br />
bold = true<br />
})<br />
<br />
-- span will be '<span style="color: rgb(255, 0, 0);background-color: #00FF00; font-weight: bold; font-style: normal; text-decoration: none;">'<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 />
==getLabelFormat==<br />
;formatTable = getLabelFormat(labelName)<br />
<br />
: Returns a format table like the one returned by getTextFormat and suitable for getHTMLspan which will format text the same way as simply doing an echo to the label would<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to scan the format of<br />
<br />
;Returns<br />
*A table with all the formatting options to achieve a default text format for label labelName.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- creates a test label, sets a stylesheet, and then returns the default format table for that label.<br />
createLabel("testLabel", 10, 10, 300, 200, 1)<br />
setLabelStyleSheet([[<br />
color: rgb(0,0,180);<br />
border-width: 1px;<br />
border-style: solid;<br />
border-color: gold;<br />
border-radius: 10px;<br />
font-size: 12.0pt;<br />
background: 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 />
]])<br />
local fmt = getLabelFormat("testLabel"))<br />
<br />
--[[<br />
{<br />
background = "rgba(0, 0, 0, 0)", -- this is transparent<br />
bold = false,<br />
foreground = "rgb(0,0,180)",<br />
italic = false,<br />
overline = false,<br />
reverse = false,<br />
strikeout = false,<br />
underline = false<br />
}<br />
--]]<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelSizeHint==<br />
;width, height = getLabelSizeHint(labelName)<br />
<br />
: Returns the suggested labelsize as width and height<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the suggested size from<br />
<br />
;Returns<br />
*suggested width and height (to fit text and/or an image on a label)<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- text resizing example<br />
-- create the label<br />
createLabel("textLabel",400,400,300,300,1)<br />
-- put some text on it<br />
echo("textLabel", "This is my Test.\nAnother Test")<br />
-- resizes the label to fit the text<br />
resizeWindow("textLabel", getLabelSizeHint("textLabel"))<br />
<br />
-- image resizing example<br />
-- create the label<br />
createLabel("imageLabel",400,400,300,300,1)<br />
-- put some image on it<br />
setBackgroundImage("imageLabel", getMudletHomeDir.."/myLabelImage.png")<br />
-- resizes the label to fit the image<br />
resizeWindow("imageLabel", getLabelSizeHint("imageLabel"))<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelStyleSheet==<br />
;getLabelStyleSheet(labelName)<br />
: Returns the stylesheet set on a given label, which is used to customise the labels look and feel.<br />
<br />
;See also:[[Manual:Lua_Functions#setLabelStyleSheet|getTextFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the stylesheet from<br />
<br />
;Returns<br />
*stylesheet as a string<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><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 />
<br />
-- now retrieve it and display:<br />
local stylesheet = getLabelStyleSheet("test")<br />
cecho(f"<green>the label's stylesheet is now: \n<white>{stylesheet}\n")<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([windowName])<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
*''windowName''<br />
: Optional name of the window to get the line count of. Defaults to the main window.<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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, strikethrough, and underline tags.<br />
:See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you hecho it will erase any previous echo sent to the label.<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, #ooverline#/o, #sstrikethrough#/s, and #bbold#/b formatting.")<br />
-- shows the various individual formatting options<br />
hecho("\n#008000#o#uGreen text with both over and underlines.#/o#/u")<br />
</syntaxhighlight><br />
<br />
==hecho2ansi==<br />
;ansiFormattedString = hecho2ansi(text)<br />
<br />
:Converts hecho formatted text to ansi formatted text. Used by hfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hfeedTriggers|hfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
;Parameters<br />
*''text:''<br />
:The hecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of hfeedTriggers() for a single line.<br />
-- you would most likely just use hfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(hecho2ansi("\n#800000This is red.#r #iitalic#/i, #bbold#/b, #sstrikethrough#/s, #uunderline#/u\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- # format also works<br />
hechoLink("#ca00040black!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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, as text or a function (since Mudlet 4.11).<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!", function() echo("you clicked me!\n") end, "Click me popup")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() echo("you clicked me!\n") end, "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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==pauseMovie==<br />
;pauseMovie(label name)<br />
<br />
: Pauses the gif animation on the label<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==removeCommandLineMenuEvent==<br />
;removeCommandLineMenuEvent([window,] label)<br />
<br />
:Removes an existing command line menu event.<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that item is associated with. Optional, defaults to "main" (main window console).<br />
* ''label:''<br />
: Label under which element is registered<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<br />
<br />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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([windowName])<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 />
* ''windowName''<br />
: (optional) name of the console to reset formatting. Defaults to "main" if missing.<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). Also works with named capture group. It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumberOrName:''<br />
: number of the capture group you want to select, or the name of the capture group as a string<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 />
<br />
-- Or perhaps instead if you were to use "you have (?<euro>\d+) Euro"<br />
selectCaptureGroup("euro")<br />
fg("green")<br />
</syntaxhighlight><br />
<br />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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, as text or Lua function.<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 />
-- example of selecting text in a miniconsole and turning it into a link:<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 />
==setMovie==<br />
;setMovie(label name, path to gif)<br />
<br />
: Adds a gif to the selected label and animates it. Note that gifs are pretty expensive to play, so don't add too many at once.<br />
: Some websites you can get gifs from are [https://tenor.com/search/stickers-gifs Tenor] and [https://giphy.com/stickers Giphy] (not officially endorsed).<br />
<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the label the gif will be animated on<br />
* ''path:''<br />
: path of the gif file<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- download & show a gif within mudlet<br />
local saveto = getMudletHomeDir().."/kymip.gif"<br />
-- animation credit to https://opengameart.org/content/kymiball-ii-third-prototype-scraps<br />
local url = "https://opengameart.org/sites/default/files/kymip_0.gif"<br />
<br />
if downloadHandler then killAnonymousEventHandler(downloadHandler) end<br />
downloadHandler = registerAnonymousEventHandler("sysDownloadDone",<br />
function(_, filename)<br />
if filename ~= saveto then<br />
return true<br />
end<br />
<br />
local width, height = getImageSize(saveto)<br />
<br />
createLabel("kymip", 300, 300, width, height, 0)<br />
setMovie("kymip", saveto)<br />
setLabelReleaseCallback("kymip", function() deleteLabel("kymip") end)<br />
end, true)<br />
<br />
downloadFile(saveto, url)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
local gifpath = getMudletHomeDir().."/movie.gif"<br />
<br />
local width, height = getImageSize(gifpath)<br />
<br />
-- create a label with the name mygif<br />
createLabel("mygif", 0, 0, width, height,0)<br />
-- put the gif on the label and animate it<br />
setMovie("mygif", gifpath)<br />
</syntaxhighlight><br />
<br />
==setMovieFrame==<br />
;setMovieFrame(label name, frame nr)<br />
<br />
: Jump to a specific frame in the gif.<br />
: Returns true if successful, and false if frame doesn't exist.<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''frame nr:''<br />
: the gif animations frame nr to jump to<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
-- jumps to frame 12 of the animation<br />
setMovieFrame("myMovie", 12)<br />
--start the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><br />
<br />
==setMovieSpeed==<br />
;setMovieSpeed(label name, speed in percent)<br />
<br />
: Set the animation speed, in percent.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''speed in percent:''<br />
: the gif animations speed in percent for example 50 for 50% speed<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--accelerates the animation to a speed of 150%<br />
setMovieSpeed("myMovie",150)<br />
<br />
<br />
</syntaxhighlight><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], {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 />
* ''{lua code}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send("bye") end, function() echo("hi!") end}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<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 />
==startMovie==<br />
;startMovie(label name)<br />
<br />
: Starts the gif animation - if it was previously stopped or paused.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
--restart the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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 />
==windowType==<br />
;typeOfWindow = windowType(windowName)<br />
<br />
:Given the name of a window, will return if it's a label, miniconsole, userwindow or a commandline.<br />
<br />
;See also:[[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''windowName:''<br />
:The name used to create the window element. Use "main" for the main console<br />
<br />
<br />
;Returns<br />
*Window type as string ("label", "miniconsole", "userwindow", or "commandline") or nil+error if it does not exist.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a Geyser label and and check its type<br />
testLabel = Geyser.Label:new({name = "testLabel"})<br />
display(windowType(testLabel.name)) -- displays "label"<br />
<br />
-- the main console returns "miniconsole" because it uses the same formatting functions<br />
display(windowType("main")) -- displays "miniconsole"<br />
<br />
-- check for the existence of a window<br />
local windowName = "this thing does not exist"<br />
local ok, err = windowType(windowName)<br />
if ok then<br />
-- do things with it, as it does exist.<br />
-- the ok variable will hold the type of window it is ("label", "commandline", etc)<br />
else<br />
cecho("<red>ALERT!! window does not exist")<br />
end<br />
</syntaxhighlight><br />
<br />
;Additional development notes<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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=19869Manual:UI Functions2022-02-15T19:51:41Z<p>Dargoth: /* resetFormat */</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window,] label, eventName)<br />
<br />
Adds item to right click menu associated with command line.<br />
<br />
{{MudletVersion|4.14}}<br />
<br />
;See also: [[Manual:Lua_Functions#removeCommandLineMenuEvent|removeCommandLineMenuEvent()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that command line belongs to. Optional, will default to "main" (main window console)<br />
* ''label:''<br />
: Label of item<br />
* ''eventName:''<br />
: Event name that will be fired when clicked.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addCommandLineMenuEvent("My very own special paste from clipboard", "pasteFromClipboardWithoutLineBreaks" )<br />
registerAnonymousEventHandler("pasteFromClipboardWithoutLineBreaks", function()<br />
local text = string.gsub(getClipboardText(), "[\r|\n]", "")<br />
appendCmdLine(text)<br />
end)<br />
</syntaxhighlight><br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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.<br />
:See also: [[Manual:Lua_Functions#decho|decho()]]<br />
<br />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<br />
<br />
{{note}} underline, italics, overline, and strikethrough supported since Mudlet 4.15+<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, strikethrough, 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 />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you cecho it will erase any previous echo sent to the label.<br />
<br />
;Parameters<br />
*''window:''<br />
:Optional - the window name to echo to - can either be none or "main" for the main window, or a miniconsole, userwindow, or label 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>, <s>strikethrough</s>, <o>overline</o>, and <b>bold</b>.")<br />
<br />
cecho("\n<green><o><u>Green text with over and underline at the same time.</o></u>")<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cecho2ansi==<br />
;ansiFormattedString = cecho2ansi(text)<br />
<br />
:Converts cecho formatted text to ansi formatted text. Used by cfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cfeedTriggers|cfeedTriggers()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
{{note}} This function uses the ansi short colors (0-15) for color names which have base 16 ansi equivalents, such as 'red', 'blue', "lightBlue", "cyan", etc rather than the values defined in the color_table. If there is no base ansi equivalent then it will use the rgb values from the color_table for the color.<br />
<br />
;Parameters<br />
*''text:''<br />
:The cecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of cfeedTriggers() for a single line.<br />
-- you would most likely just use cfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(cecho2ansi("\n<red>This is red.<reset> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<br />
</syntaxhighlight><br />
<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<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)</syntaxhighlight><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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 />
==createScrollBox==<br />
;createScrollBox([name of parent window], name, x, y, width, height)<br />
<br />
: creates a graphical elements able to hold other graphical elements such as labels, miniconsoles, command lines etc. in it.<br />
If the added elements don't fit into the ScrollBox scrollbars appear and allow scrolling.<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#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setWindow|setWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''name of parent window:'' <br />
: (Optional) name of the parent window the scrollBox is created in. Defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the scrollBox. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a ScrollBox with the name sBox<br />
createScrollBox("SBox",0,0,300,200)<br />
<br />
-- create 3 Labels and put them into the ScrollBox<br />
createLabel("SBox","SBoxLabel",0,0,200,200,1)<br />
createLabel("SBox","SBoxLabel2",200,0,200,200,1)<br />
createLabel("SBox","SBoxLabel3",400,0,200,200,1)<br />
<br />
-- put some text on the labels<br />
echo("SBoxLabel","Label")<br />
echo("SBoxLabel2","Label2")<br />
echo("SBoxLabel3","Label3")<br />
<br />
-- change the colours of the labels to make it easier to distinguish them<br />
setBackgroundColor("SBoxLabel",255,0,0)<br />
setBackgroundColor("SBoxLabel2",0,255,0)<br />
setBackgroundColor("SBoxLabel3",0,0,255)<br />
</syntaxhighlight><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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code>, <code><nowiki><s>strikethrough</s></nowiki></code>, <code><nowiki><o>overline</o></nowiki></code>, and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you decho it will erase any previous echo sent to the label.<br />
<br />
:See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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>, <s>strikethrough</s>, and <b>bold</b> formatting.")<br />
<br />
decho("<\n<0,128,0><o><u>Green text with both over and underlines.</u></o>")<br />
</syntaxhighlight><br />
<br />
==decho2ansi==<br />
;ansiFormattedString = decho2ansi(text)<br />
<br />
:Converts decho formatted text to ansi formatted text. Used by dfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dfeedTriggers|dfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
; Parameters<br />
*''text:''<br />
:The decho formatted text for conversion<br />
<br />
;Returns<br />
* String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of dfeedTriggers() for a single line.<br />
-- you would most likely just use dfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(decho2ansi("\n<128,0,0>This is red.<r> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() send("hi") end, "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 - [[Manual:Lua_Functions#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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)<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 />
==getBackgroundColor==<br />
;getBackgroundColor([windowName])<br />
: Gets the background for the given label, miniconsole, or userwindow.<br />
: Returns 4 values - red, green, blue, transparency. Colors returned 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 getthe background color from, or "main" for the main window.<br />
<br />
: {{MudletVersion|4.15}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r, g, b, a = getBackgroundColor()<br />
local rW, gW, bW, aW = getBackgroundColor("myWindow")<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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getHTMLformat==<br />
;spanTag = getHTMLformat(formatTable)<br />
<br />
:Takes in a table of formatting options in the same style as [[Manual:Lua_Functions#getTextFormat|getTextFormat()]] and returns a span tag which will format text after it as the table describes.<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''formatTable:''<br />
:Table with formatting options configured. Keys are foreground, background, bold, underline, overline, strikeout, italic, and reverse. All except for foreground and background should be boolean (true/false) values. Foreground and background are either { r, g, b, a } tables, or strings with QSS formatting directives<br />
<br />
;Returns<br />
*A string with the html span tag to format text in accordance with the format table.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Returns a span tag for bold, red text on a green background<br />
local span = getHTMLformat({<br />
foreground = { 255, 0, 0 },<br />
background = "#00FF00",<br />
bold = true<br />
})<br />
<br />
-- span will be '<span style="color: rgb(255, 0, 0);background-color: #00FF00; font-weight: bold; font-style: normal; text-decoration: none;">'<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 />
==getLabelFormat==<br />
;formatTable = getLabelFormat(labelName)<br />
<br />
: Returns a format table like the one returned by getTextFormat and suitable for getHTMLspan which will format text the same way as simply doing an echo to the label would<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to scan the format of<br />
<br />
;Returns<br />
*A table with all the formatting options to achieve a default text format for label labelName.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- creates a test label, sets a stylesheet, and then returns the default format table for that label.<br />
createLabel("testLabel", 10, 10, 300, 200, 1)<br />
setLabelStyleSheet([[<br />
color: rgb(0,0,180);<br />
border-width: 1px;<br />
border-style: solid;<br />
border-color: gold;<br />
border-radius: 10px;<br />
font-size: 12.0pt;<br />
background: 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 />
]])<br />
local fmt = getLabelFormat("testLabel"))<br />
<br />
--[[<br />
{<br />
background = "rgba(0, 0, 0, 0)", -- this is transparent<br />
bold = false,<br />
foreground = "rgb(0,0,180)",<br />
italic = false,<br />
overline = false,<br />
reverse = false,<br />
strikeout = false,<br />
underline = false<br />
}<br />
--]]<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelSizeHint==<br />
;width, height = getLabelSizeHint(labelName)<br />
<br />
: Returns the suggested labelsize as width and height<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the suggested size from<br />
<br />
;Returns<br />
*suggested width and height (to fit text and/or an image on a label)<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- text resizing example<br />
-- create the label<br />
createLabel("textLabel",400,400,300,300,1)<br />
-- put some text on it<br />
echo("textLabel", "This is my Test.\nAnother Test")<br />
-- resizes the label to fit the text<br />
resizeWindow("textLabel", getLabelSizeHint("textLabel"))<br />
<br />
-- image resizing example<br />
-- create the label<br />
createLabel("imageLabel",400,400,300,300,1)<br />
-- put some image on it<br />
setBackgroundImage("imageLabel", getMudletHomeDir.."/myLabelImage.png")<br />
-- resizes the label to fit the image<br />
resizeWindow("imageLabel", getLabelSizeHint("imageLabel"))<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelStyleSheet==<br />
;getLabelStyleSheet(labelName)<br />
: Returns the stylesheet set on a given label, which is used to customise the labels look and feel.<br />
<br />
;See also:[[Manual:Lua_Functions#setLabelStyleSheet|getTextFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the stylesheet from<br />
<br />
;Returns<br />
*stylesheet as a string<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><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 />
<br />
-- now retrieve it and display:<br />
local stylesheet = getLabelStyleSheet("test")<br />
cecho(f"<green>the label's stylesheet is now: \n<white>{stylesheet}\n")<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([windowName])<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
*''windowName''<br />
: Optional name of the window to get the line count of. Defaults to the main window.<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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, strikethrough, and underline tags.<br />
:See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you hecho it will erase any previous echo sent to the label.<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, #ooverline#/o, #sstrikethrough#/s, and #bbold#/b formatting.")<br />
-- shows the various individual formatting options<br />
hecho("\n#008000#o#uGreen text with both over and underlines.#/o#/u")<br />
</syntaxhighlight><br />
<br />
==hecho2ansi==<br />
;ansiFormattedString = hecho2ansi(text)<br />
<br />
:Converts hecho formatted text to ansi formatted text. Used by hfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hfeedTriggers|hfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
;Parameters<br />
*''text:''<br />
:The hecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of hfeedTriggers() for a single line.<br />
-- you would most likely just use hfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(hecho2ansi("\n#800000This is red.#r #iitalic#/i, #bbold#/b, #sstrikethrough#/s, #uunderline#/u\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- # format also works<br />
hechoLink("#ca00040black!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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, as text or a function (since Mudlet 4.11).<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!", function() echo("you clicked me!\n") end, "Click me popup")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() echo("you clicked me!\n") end, "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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==pauseMovie==<br />
;pauseMovie(label name)<br />
<br />
: Pauses the gif animation on the label<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==removeCommandLineMenuEvent==<br />
;removeCommandLineMenuEvent([window,] label)<br />
<br />
:Removes an existing command line menu event.<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that item is associated with. Optional, defaults to "main" (main window console).<br />
* ''label:''<br />
: Label under which element is registered<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<br />
<br />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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([windowName])<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 />
* ''windowName''<br />
: (optional) name of the console to reset formatting.<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). Also works with named capture group. It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumberOrName:''<br />
: number of the capture group you want to select, or the name of the capture group as a string<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 />
<br />
-- Or perhaps instead if you were to use "you have (?<euro>\d+) Euro"<br />
selectCaptureGroup("euro")<br />
fg("green")<br />
</syntaxhighlight><br />
<br />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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, as text or Lua function.<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 />
-- example of selecting text in a miniconsole and turning it into a link:<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 />
==setMovie==<br />
;setMovie(label name, path to gif)<br />
<br />
: Adds a gif to the selected label and animates it. Note that gifs are pretty expensive to play, so don't add too many at once.<br />
: Some websites you can get gifs from are [https://tenor.com/search/stickers-gifs Tenor] and [https://giphy.com/stickers Giphy] (not officially endorsed).<br />
<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the label the gif will be animated on<br />
* ''path:''<br />
: path of the gif file<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- download & show a gif within mudlet<br />
local saveto = getMudletHomeDir().."/kymip.gif"<br />
-- animation credit to https://opengameart.org/content/kymiball-ii-third-prototype-scraps<br />
local url = "https://opengameart.org/sites/default/files/kymip_0.gif"<br />
<br />
if downloadHandler then killAnonymousEventHandler(downloadHandler) end<br />
downloadHandler = registerAnonymousEventHandler("sysDownloadDone",<br />
function(_, filename)<br />
if filename ~= saveto then<br />
return true<br />
end<br />
<br />
local width, height = getImageSize(saveto)<br />
<br />
createLabel("kymip", 300, 300, width, height, 0)<br />
setMovie("kymip", saveto)<br />
setLabelReleaseCallback("kymip", function() deleteLabel("kymip") end)<br />
end, true)<br />
<br />
downloadFile(saveto, url)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
local gifpath = getMudletHomeDir().."/movie.gif"<br />
<br />
local width, height = getImageSize(gifpath)<br />
<br />
-- create a label with the name mygif<br />
createLabel("mygif", 0, 0, width, height,0)<br />
-- put the gif on the label and animate it<br />
setMovie("mygif", gifpath)<br />
</syntaxhighlight><br />
<br />
==setMovieFrame==<br />
;setMovieFrame(label name, frame nr)<br />
<br />
: Jump to a specific frame in the gif.<br />
: Returns true if successful, and false if frame doesn't exist.<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''frame nr:''<br />
: the gif animations frame nr to jump to<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
-- jumps to frame 12 of the animation<br />
setMovieFrame("myMovie", 12)<br />
--start the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><br />
<br />
==setMovieSpeed==<br />
;setMovieSpeed(label name, speed in percent)<br />
<br />
: Set the animation speed, in percent.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''speed in percent:''<br />
: the gif animations speed in percent for example 50 for 50% speed<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--accelerates the animation to a speed of 150%<br />
setMovieSpeed("myMovie",150)<br />
<br />
<br />
</syntaxhighlight><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], {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 />
* ''{lua code}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send("bye") end, function() echo("hi!") end}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<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 />
==startMovie==<br />
;startMovie(label name)<br />
<br />
: Starts the gif animation - if it was previously stopped or paused.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
--restart the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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 />
==windowType==<br />
;typeOfWindow = windowType(windowName)<br />
<br />
:Given the name of a window, will return if it's a label, miniconsole, userwindow or a commandline.<br />
<br />
;See also:[[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''windowName:''<br />
:The name used to create the window element. Use "main" for the main console<br />
<br />
<br />
;Returns<br />
*Window type as string ("label", "miniconsole", "userwindow", or "commandline") or nil+error if it does not exist.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a Geyser label and and check its type<br />
testLabel = Geyser.Label:new({name = "testLabel"})<br />
display(windowType(testLabel.name)) -- displays "label"<br />
<br />
-- the main console returns "miniconsole" because it uses the same formatting functions<br />
display(windowType("main")) -- displays "miniconsole"<br />
<br />
-- check for the existence of a window<br />
local windowName = "this thing does not exist"<br />
local ok, err = windowType(windowName)<br />
if ok then<br />
-- do things with it, as it does exist.<br />
-- the ok variable will hold the type of window it is ("label", "commandline", etc)<br />
else<br />
cecho("<red>ALERT!! window does not exist")<br />
end<br />
</syntaxhighlight><br />
<br />
;Additional development notes<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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=19868Manual:UI Functions2022-02-15T19:50:59Z<p>Dargoth: /* resetFormat */</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window,] label, eventName)<br />
<br />
Adds item to right click menu associated with command line.<br />
<br />
{{MudletVersion|4.14}}<br />
<br />
;See also: [[Manual:Lua_Functions#removeCommandLineMenuEvent|removeCommandLineMenuEvent()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that command line belongs to. Optional, will default to "main" (main window console)<br />
* ''label:''<br />
: Label of item<br />
* ''eventName:''<br />
: Event name that will be fired when clicked.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addCommandLineMenuEvent("My very own special paste from clipboard", "pasteFromClipboardWithoutLineBreaks" )<br />
registerAnonymousEventHandler("pasteFromClipboardWithoutLineBreaks", function()<br />
local text = string.gsub(getClipboardText(), "[\r|\n]", "")<br />
appendCmdLine(text)<br />
end)<br />
</syntaxhighlight><br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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.<br />
:See also: [[Manual:Lua_Functions#decho|decho()]]<br />
<br />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<br />
<br />
{{note}} underline, italics, overline, and strikethrough supported since Mudlet 4.15+<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, strikethrough, 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 />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you cecho it will erase any previous echo sent to the label.<br />
<br />
;Parameters<br />
*''window:''<br />
:Optional - the window name to echo to - can either be none or "main" for the main window, or a miniconsole, userwindow, or label 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>, <s>strikethrough</s>, <o>overline</o>, and <b>bold</b>.")<br />
<br />
cecho("\n<green><o><u>Green text with over and underline at the same time.</o></u>")<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cecho2ansi==<br />
;ansiFormattedString = cecho2ansi(text)<br />
<br />
:Converts cecho formatted text to ansi formatted text. Used by cfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cfeedTriggers|cfeedTriggers()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
{{note}} This function uses the ansi short colors (0-15) for color names which have base 16 ansi equivalents, such as 'red', 'blue', "lightBlue", "cyan", etc rather than the values defined in the color_table. If there is no base ansi equivalent then it will use the rgb values from the color_table for the color.<br />
<br />
;Parameters<br />
*''text:''<br />
:The cecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of cfeedTriggers() for a single line.<br />
-- you would most likely just use cfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(cecho2ansi("\n<red>This is red.<reset> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<br />
</syntaxhighlight><br />
<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<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)</syntaxhighlight><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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 />
==createScrollBox==<br />
;createScrollBox([name of parent window], name, x, y, width, height)<br />
<br />
: creates a graphical elements able to hold other graphical elements such as labels, miniconsoles, command lines etc. in it.<br />
If the added elements don't fit into the ScrollBox scrollbars appear and allow scrolling.<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#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setWindow|setWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''name of parent window:'' <br />
: (Optional) name of the parent window the scrollBox is created in. Defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the scrollBox. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a ScrollBox with the name sBox<br />
createScrollBox("SBox",0,0,300,200)<br />
<br />
-- create 3 Labels and put them into the ScrollBox<br />
createLabel("SBox","SBoxLabel",0,0,200,200,1)<br />
createLabel("SBox","SBoxLabel2",200,0,200,200,1)<br />
createLabel("SBox","SBoxLabel3",400,0,200,200,1)<br />
<br />
-- put some text on the labels<br />
echo("SBoxLabel","Label")<br />
echo("SBoxLabel2","Label2")<br />
echo("SBoxLabel3","Label3")<br />
<br />
-- change the colours of the labels to make it easier to distinguish them<br />
setBackgroundColor("SBoxLabel",255,0,0)<br />
setBackgroundColor("SBoxLabel2",0,255,0)<br />
setBackgroundColor("SBoxLabel3",0,0,255)<br />
</syntaxhighlight><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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code>, <code><nowiki><s>strikethrough</s></nowiki></code>, <code><nowiki><o>overline</o></nowiki></code>, and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you decho it will erase any previous echo sent to the label.<br />
<br />
:See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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>, <s>strikethrough</s>, and <b>bold</b> formatting.")<br />
<br />
decho("<\n<0,128,0><o><u>Green text with both over and underlines.</u></o>")<br />
</syntaxhighlight><br />
<br />
==decho2ansi==<br />
;ansiFormattedString = decho2ansi(text)<br />
<br />
:Converts decho formatted text to ansi formatted text. Used by dfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dfeedTriggers|dfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
; Parameters<br />
*''text:''<br />
:The decho formatted text for conversion<br />
<br />
;Returns<br />
* String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of dfeedTriggers() for a single line.<br />
-- you would most likely just use dfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(decho2ansi("\n<128,0,0>This is red.<r> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() send("hi") end, "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 - [[Manual:Lua_Functions#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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)<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 />
==getBackgroundColor==<br />
;getBackgroundColor([windowName])<br />
: Gets the background for the given label, miniconsole, or userwindow.<br />
: Returns 4 values - red, green, blue, transparency. Colors returned 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 getthe background color from, or "main" for the main window.<br />
<br />
: {{MudletVersion|4.15}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r, g, b, a = getBackgroundColor()<br />
local rW, gW, bW, aW = getBackgroundColor("myWindow")<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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getHTMLformat==<br />
;spanTag = getHTMLformat(formatTable)<br />
<br />
:Takes in a table of formatting options in the same style as [[Manual:Lua_Functions#getTextFormat|getTextFormat()]] and returns a span tag which will format text after it as the table describes.<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''formatTable:''<br />
:Table with formatting options configured. Keys are foreground, background, bold, underline, overline, strikeout, italic, and reverse. All except for foreground and background should be boolean (true/false) values. Foreground and background are either { r, g, b, a } tables, or strings with QSS formatting directives<br />
<br />
;Returns<br />
*A string with the html span tag to format text in accordance with the format table.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Returns a span tag for bold, red text on a green background<br />
local span = getHTMLformat({<br />
foreground = { 255, 0, 0 },<br />
background = "#00FF00",<br />
bold = true<br />
})<br />
<br />
-- span will be '<span style="color: rgb(255, 0, 0);background-color: #00FF00; font-weight: bold; font-style: normal; text-decoration: none;">'<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 />
==getLabelFormat==<br />
;formatTable = getLabelFormat(labelName)<br />
<br />
: Returns a format table like the one returned by getTextFormat and suitable for getHTMLspan which will format text the same way as simply doing an echo to the label would<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to scan the format of<br />
<br />
;Returns<br />
*A table with all the formatting options to achieve a default text format for label labelName.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- creates a test label, sets a stylesheet, and then returns the default format table for that label.<br />
createLabel("testLabel", 10, 10, 300, 200, 1)<br />
setLabelStyleSheet([[<br />
color: rgb(0,0,180);<br />
border-width: 1px;<br />
border-style: solid;<br />
border-color: gold;<br />
border-radius: 10px;<br />
font-size: 12.0pt;<br />
background: 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 />
]])<br />
local fmt = getLabelFormat("testLabel"))<br />
<br />
--[[<br />
{<br />
background = "rgba(0, 0, 0, 0)", -- this is transparent<br />
bold = false,<br />
foreground = "rgb(0,0,180)",<br />
italic = false,<br />
overline = false,<br />
reverse = false,<br />
strikeout = false,<br />
underline = false<br />
}<br />
--]]<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelSizeHint==<br />
;width, height = getLabelSizeHint(labelName)<br />
<br />
: Returns the suggested labelsize as width and height<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the suggested size from<br />
<br />
;Returns<br />
*suggested width and height (to fit text and/or an image on a label)<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- text resizing example<br />
-- create the label<br />
createLabel("textLabel",400,400,300,300,1)<br />
-- put some text on it<br />
echo("textLabel", "This is my Test.\nAnother Test")<br />
-- resizes the label to fit the text<br />
resizeWindow("textLabel", getLabelSizeHint("textLabel"))<br />
<br />
-- image resizing example<br />
-- create the label<br />
createLabel("imageLabel",400,400,300,300,1)<br />
-- put some image on it<br />
setBackgroundImage("imageLabel", getMudletHomeDir.."/myLabelImage.png")<br />
-- resizes the label to fit the image<br />
resizeWindow("imageLabel", getLabelSizeHint("imageLabel"))<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelStyleSheet==<br />
;getLabelStyleSheet(labelName)<br />
: Returns the stylesheet set on a given label, which is used to customise the labels look and feel.<br />
<br />
;See also:[[Manual:Lua_Functions#setLabelStyleSheet|getTextFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the stylesheet from<br />
<br />
;Returns<br />
*stylesheet as a string<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><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 />
<br />
-- now retrieve it and display:<br />
local stylesheet = getLabelStyleSheet("test")<br />
cecho(f"<green>the label's stylesheet is now: \n<white>{stylesheet}\n")<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([windowName])<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
*''windowName''<br />
: Optional name of the window to get the line count of. Defaults to the main window.<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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, strikethrough, and underline tags.<br />
:See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you hecho it will erase any previous echo sent to the label.<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, #ooverline#/o, #sstrikethrough#/s, and #bbold#/b formatting.")<br />
-- shows the various individual formatting options<br />
hecho("\n#008000#o#uGreen text with both over and underlines.#/o#/u")<br />
</syntaxhighlight><br />
<br />
==hecho2ansi==<br />
;ansiFormattedString = hecho2ansi(text)<br />
<br />
:Converts hecho formatted text to ansi formatted text. Used by hfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hfeedTriggers|hfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
;Parameters<br />
*''text:''<br />
:The hecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of hfeedTriggers() for a single line.<br />
-- you would most likely just use hfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(hecho2ansi("\n#800000This is red.#r #iitalic#/i, #bbold#/b, #sstrikethrough#/s, #uunderline#/u\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- # format also works<br />
hechoLink("#ca00040black!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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, as text or a function (since Mudlet 4.11).<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!", function() echo("you clicked me!\n") end, "Click me popup")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() echo("you clicked me!\n") end, "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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==pauseMovie==<br />
;pauseMovie(label name)<br />
<br />
: Pauses the gif animation on the label<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==removeCommandLineMenuEvent==<br />
;removeCommandLineMenuEvent([window,] label)<br />
<br />
:Removes an existing command line menu event.<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that item is associated with. Optional, defaults to "main" (main window console).<br />
* ''label:''<br />
: Label under which element is registered<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<br />
<br />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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([windowName])<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 />
:windowName<br />
(optional) name of the console to reset formatting<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). Also works with named capture group. It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumberOrName:''<br />
: number of the capture group you want to select, or the name of the capture group as a string<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 />
<br />
-- Or perhaps instead if you were to use "you have (?<euro>\d+) Euro"<br />
selectCaptureGroup("euro")<br />
fg("green")<br />
</syntaxhighlight><br />
<br />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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, as text or Lua function.<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 />
-- example of selecting text in a miniconsole and turning it into a link:<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 />
==setMovie==<br />
;setMovie(label name, path to gif)<br />
<br />
: Adds a gif to the selected label and animates it. Note that gifs are pretty expensive to play, so don't add too many at once.<br />
: Some websites you can get gifs from are [https://tenor.com/search/stickers-gifs Tenor] and [https://giphy.com/stickers Giphy] (not officially endorsed).<br />
<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the label the gif will be animated on<br />
* ''path:''<br />
: path of the gif file<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- download & show a gif within mudlet<br />
local saveto = getMudletHomeDir().."/kymip.gif"<br />
-- animation credit to https://opengameart.org/content/kymiball-ii-third-prototype-scraps<br />
local url = "https://opengameart.org/sites/default/files/kymip_0.gif"<br />
<br />
if downloadHandler then killAnonymousEventHandler(downloadHandler) end<br />
downloadHandler = registerAnonymousEventHandler("sysDownloadDone",<br />
function(_, filename)<br />
if filename ~= saveto then<br />
return true<br />
end<br />
<br />
local width, height = getImageSize(saveto)<br />
<br />
createLabel("kymip", 300, 300, width, height, 0)<br />
setMovie("kymip", saveto)<br />
setLabelReleaseCallback("kymip", function() deleteLabel("kymip") end)<br />
end, true)<br />
<br />
downloadFile(saveto, url)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
local gifpath = getMudletHomeDir().."/movie.gif"<br />
<br />
local width, height = getImageSize(gifpath)<br />
<br />
-- create a label with the name mygif<br />
createLabel("mygif", 0, 0, width, height,0)<br />
-- put the gif on the label and animate it<br />
setMovie("mygif", gifpath)<br />
</syntaxhighlight><br />
<br />
==setMovieFrame==<br />
;setMovieFrame(label name, frame nr)<br />
<br />
: Jump to a specific frame in the gif.<br />
: Returns true if successful, and false if frame doesn't exist.<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''frame nr:''<br />
: the gif animations frame nr to jump to<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
-- jumps to frame 12 of the animation<br />
setMovieFrame("myMovie", 12)<br />
--start the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><br />
<br />
==setMovieSpeed==<br />
;setMovieSpeed(label name, speed in percent)<br />
<br />
: Set the animation speed, in percent.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''speed in percent:''<br />
: the gif animations speed in percent for example 50 for 50% speed<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--accelerates the animation to a speed of 150%<br />
setMovieSpeed("myMovie",150)<br />
<br />
<br />
</syntaxhighlight><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], {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 />
* ''{lua code}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send("bye") end, function() echo("hi!") end}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<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 />
==startMovie==<br />
;startMovie(label name)<br />
<br />
: Starts the gif animation - if it was previously stopped or paused.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
--restart the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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 />
==windowType==<br />
;typeOfWindow = windowType(windowName)<br />
<br />
:Given the name of a window, will return if it's a label, miniconsole, userwindow or a commandline.<br />
<br />
;See also:[[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''windowName:''<br />
:The name used to create the window element. Use "main" for the main console<br />
<br />
<br />
;Returns<br />
*Window type as string ("label", "miniconsole", "userwindow", or "commandline") or nil+error if it does not exist.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a Geyser label and and check its type<br />
testLabel = Geyser.Label:new({name = "testLabel"})<br />
display(windowType(testLabel.name)) -- displays "label"<br />
<br />
-- the main console returns "miniconsole" because it uses the same formatting functions<br />
display(windowType("main")) -- displays "miniconsole"<br />
<br />
-- check for the existence of a window<br />
local windowName = "this thing does not exist"<br />
local ok, err = windowType(windowName)<br />
if ok then<br />
-- do things with it, as it does exist.<br />
-- the ok variable will hold the type of window it is ("label", "commandline", etc)<br />
else<br />
cecho("<red>ALERT!! window does not exist")<br />
end<br />
</syntaxhighlight><br />
<br />
;Additional development notes<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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=19861Manual:UI Functions2022-02-02T17:36:30Z<p>Dargoth: /* getBackgroundColor */</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window,] label, eventName)<br />
<br />
Adds item to right click menu associated with command line.<br />
<br />
{{MudletVersion|4.14}}<br />
<br />
;See also: [[Manual:Lua_Functions#removeCommandLineMenuEvent|removeCommandLineMenuEvent()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that command line belongs to. Optional, will default to "main" (main window console)<br />
* ''label:''<br />
: Label of item<br />
* ''eventName:''<br />
: Event name that will be fired when clicked.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addCommandLineMenuEvent("My very own special paste from clipboard", "pasteFromClipboardWithoutLineBreaks" )<br />
registerAnonymousEventHandler("pasteFromClipboardWithoutLineBreaks", function()<br />
local text = string.gsub(getClipboardText(), "[\r|\n]", "")<br />
appendCmdLine(text)<br />
end)<br />
</syntaxhighlight><br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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.<br />
:See also: [[Manual:Lua_Functions#decho|decho()]]<br />
<br />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<br />
<br />
{{note}} underline, italics, overline, and strikethrough supported since Mudlet 4.15+<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, strikethrough, 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 />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you cecho it will erase any previous echo sent to the label.<br />
<br />
;Parameters<br />
*''window:''<br />
:Optional - the window name to echo to - can either be none or "main" for the main window, or a miniconsole, userwindow, or label 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>, <s>strikethrough</s>, <o>overline</o>, and <b>bold</b>.")<br />
<br />
cecho("\n<green><o><u>Green text with over and underline at the same time.</o></u>")<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cecho2ansi==<br />
;ansiFormattedString = cecho2ansi(text)<br />
<br />
:Converts cecho formatted text to ansi formatted text. Used by cfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cfeedTriggers|cfeedTriggers()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
{{note}} This function uses the ansi short colors (0-15) for color names which have base 16 ansi equivalents, such as 'red', 'blue', "lightBlue", "cyan", etc rather than the values defined in the color_table. If there is no base ansi equivalent then it will use the rgb values from the color_table for the color.<br />
<br />
;Parameters<br />
*''text:''<br />
:The cecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of cfeedTriggers() for a single line.<br />
-- you would most likely just use cfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(cecho2ansi("\n<red>This is red.<reset> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<br />
</syntaxhighlight><br />
<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<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)</syntaxhighlight><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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 />
==createScrollBox==<br />
;createScrollBox([name of parent window], name, x, y, width, height)<br />
<br />
: creates a graphical elements able to hold other graphical elements such as labels, miniconsoles, command lines etc. in it.<br />
If the added elements don't fit into the ScrollBox scrollbars appear and allow scrolling.<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#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setWindow|setWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''name of parent window:'' <br />
: (Optional) name of the parent window the scrollBox is created in. Defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the scrollBox. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a ScrollBox with the name sBox<br />
createScrollBox("SBox",0,0,300,200)<br />
<br />
-- create 3 Labels and put them into the ScrollBox<br />
createLabel("SBox","SBoxLabel",0,0,200,200,1)<br />
createLabel("SBox","SBoxLabel2",200,0,200,200,1)<br />
createLabel("SBox","SBoxLabel3",400,0,200,200,1)<br />
<br />
-- put some text on the labels<br />
echo("SBoxLabel","Label")<br />
echo("SBoxLabel2","Label2")<br />
echo("SBoxLabel3","Label3")<br />
<br />
-- change the colours of the labels to make it easier to distinguish them<br />
setBackgroundColor("SBoxLabel",255,0,0)<br />
setBackgroundColor("SBoxLabel2",0,255,0)<br />
setBackgroundColor("SBoxLabel3",0,0,255)<br />
</syntaxhighlight><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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code>, <code><nowiki><s>strikethrough</s></nowiki></code>, <code><nowiki><o>overline</o></nowiki></code>, and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you decho it will erase any previous echo sent to the label.<br />
<br />
:See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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>, <s>strikethrough</s>, and <b>bold</b> formatting.")<br />
<br />
decho("<\n<0,128,0><o><u>Green text with both over and underlines.</u></o>")<br />
</syntaxhighlight><br />
<br />
==decho2ansi==<br />
;ansiFormattedString = decho2ansi(text)<br />
<br />
:Converts decho formatted text to ansi formatted text. Used by dfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dfeedTriggers|dfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
; Parameters<br />
*''text:''<br />
:The decho formatted text for conversion<br />
<br />
;Returns<br />
* String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of dfeedTriggers() for a single line.<br />
-- you would most likely just use dfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(decho2ansi("\n<128,0,0>This is red.<r> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() send("hi") end, "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 - [[Manual:Lua_Functions#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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)<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 />
==getBackgroundColor==<br />
;getBackgroundColor([windowName])<br />
: Gets the background for the given label, miniconsole, or userwindow.<br />
: Returns 4 values - red, green, blue, transparency. Colors returned 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 getthe background color from, or "main" for the main window.<br />
<br />
: {{MudletVersion|4.15}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r, g, b, a = getBackgroundColor()<br />
local rW, gW, bW, aW = getBackgroundColor("myWindow")<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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getHTMLformat==<br />
;spanTag = getHTMLformat(formatTable)<br />
<br />
:Takes in a table of formatting options in the same style as [[Manual:Lua_Functions#getTextFormat|getTextFormat()]] and returns a span tag which will format text after it as the table describes.<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''formatTable:''<br />
:Table with formatting options configured. Keys are foreground, background, bold, underline, overline, strikeout, italic, and reverse. All except for foreground and background should be boolean (true/false) values. Foreground and background are either { r, g, b, a } tables, or strings with QSS formatting directives<br />
<br />
;Returns<br />
*A string with the html span tag to format text in accordance with the format table.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Returns a span tag for bold, red text on a green background<br />
local span = getHTMLformat({<br />
foreground = { 255, 0, 0 },<br />
background = "#00FF00",<br />
bold = true<br />
})<br />
<br />
-- span will be '<span style="color: rgb(255, 0, 0);background-color: #00FF00; font-weight: bold; font-style: normal; text-decoration: none;">'<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 />
==getLabelFormat==<br />
;formatTable = getLabelFormat(labelName)<br />
<br />
: Returns a format table like the one returned by getTextFormat and suitable for getHTMLspan which will format text the same way as simply doing an echo to the label would<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to scan the format of<br />
<br />
;Returns<br />
*A table with all the formatting options to achieve a default text format for label labelName.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- creates a test label, sets a stylesheet, and then returns the default format table for that label.<br />
createLabel("testLabel", 10, 10, 300, 200, 1)<br />
setLabelStyleSheet([[<br />
color: rgb(0,0,180);<br />
border-width: 1px;<br />
border-style: solid;<br />
border-color: gold;<br />
border-radius: 10px;<br />
font-size: 12.0pt;<br />
background: 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 />
]])<br />
local fmt = getLabelFormat("testLabel"))<br />
<br />
--[[<br />
{<br />
background = "rgba(0, 0, 0, 0)", -- this is transparent<br />
bold = false,<br />
foreground = "rgb(0,0,180)",<br />
italic = false,<br />
overline = false,<br />
reverse = false,<br />
strikeout = false,<br />
underline = false<br />
}<br />
--]]<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelSizeHint==<br />
;width, height = getLabelSizeHint(labelName)<br />
<br />
: Returns the suggested labelsize as width and height<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the suggested size from<br />
<br />
;Returns<br />
*suggested width and height (to fit text and/or an image on a label)<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- text resizing example<br />
-- create the label<br />
createLabel("textLabel",400,400,300,300,1)<br />
-- put some text on it<br />
echo("textLabel", "This is my Test.\nAnother Test")<br />
-- resizes the label to fit the text<br />
resizeWindow("textLabel", getLabelSizeHint("textLabel"))<br />
<br />
-- image resizing example<br />
-- create the label<br />
createLabel("imageLabel",400,400,300,300,1)<br />
-- put some image on it<br />
setBackgroundImage("imageLabel", getMudletHomeDir.."/myLabelImage.png")<br />
-- resizes the label to fit the image<br />
resizeWindow("imageLabel", getLabelSizeHint("imageLabel"))<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelStyleSheet==<br />
;getLabelStyleSheet(labelName)<br />
: Returns the stylesheet set on a given label, which is used to customise the labels look and feel.<br />
<br />
;See also:[[Manual:Lua_Functions#setLabelStyleSheet|getTextFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the stylesheet from<br />
<br />
;Returns<br />
*stylesheet as a string<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><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 />
<br />
-- now retrieve it and display:<br />
local stylesheet = getLabelStyleSheet("test")<br />
cecho(f"<green>the label's stylesheet is now: \n<white>{stylesheet}\n")<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([windowName])<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
*''windowName''<br />
: Optional name of the window to get the line count of. Defaults to the main window.<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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, strikethrough, and underline tags.<br />
:See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you hecho it will erase any previous echo sent to the label.<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, #ooverline#/o, #sstrikethrough#/s, and #bbold#/b formatting.")<br />
-- shows the various individual formatting options<br />
hecho("\n#008000#o#uGreen text with both over and underlines.#/o#/u")<br />
</syntaxhighlight><br />
<br />
==hecho2ansi==<br />
;ansiFormattedString = hecho2ansi(text)<br />
<br />
:Converts hecho formatted text to ansi formatted text. Used by hfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hfeedTriggers|hfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
;Parameters<br />
*''text:''<br />
:The hecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of hfeedTriggers() for a single line.<br />
-- you would most likely just use hfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(hecho2ansi("\n#800000This is red.#r #iitalic#/i, #bbold#/b, #sstrikethrough#/s, #uunderline#/u\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- # format also works<br />
hechoLink("#ca00040black!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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, as text or a function (since Mudlet 4.11).<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!", function() echo("you clicked me!\n") end, "Click me popup")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() echo("you clicked me!\n") end, "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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==pauseMovie==<br />
;pauseMovie(label name)<br />
<br />
: Pauses the gif animation on the label<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==removeCommandLineMenuEvent==<br />
;removeCommandLineMenuEvent([window,] label)<br />
<br />
:Removes an existing command line menu event.<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that item is associated with. Optional, defaults to "main" (main window console).<br />
* ''label:''<br />
: Label under which element is registered<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<br />
<br />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). Also works with named capture group. It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumberOrName:''<br />
: number of the capture group you want to select, or the name of the capture group as a string<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 />
<br />
-- Or perhaps instead if you were to use "you have (?<euro>\d+) Euro"<br />
selectCaptureGroup("euro")<br />
fg("green")<br />
</syntaxhighlight><br />
<br />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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, as text or Lua function.<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 />
-- example of selecting text in a miniconsole and turning it into a link:<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 />
==setMovie==<br />
;setMovie(label name, path to gif)<br />
<br />
: Adds a gif to the selected label and animates it. Note that gifs are pretty expensive to play, so don't add too many at once.<br />
: Some websites you can get gifs from are [https://tenor.com/search/stickers-gifs Tenor] and [https://giphy.com/stickers Giphy] (not officially endorsed).<br />
<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the label the gif will be animated on<br />
* ''path:''<br />
: path of the gif file<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- download & show a gif within mudlet<br />
local saveto = getMudletHomeDir().."/kymip.gif"<br />
-- animation credit to https://opengameart.org/content/kymiball-ii-third-prototype-scraps<br />
local url = "https://opengameart.org/sites/default/files/kymip_0.gif"<br />
<br />
if downloadHandler then killAnonymousEventHandler(downloadHandler) end<br />
downloadHandler = registerAnonymousEventHandler("sysDownloadDone",<br />
function(_, filename)<br />
if filename ~= saveto then<br />
return true<br />
end<br />
<br />
local width, height = getImageSize(saveto)<br />
<br />
createLabel("kymip", 300, 300, width, height, 0)<br />
setMovie("kymip", saveto)<br />
setLabelReleaseCallback("kymip", function() deleteLabel("kymip") end)<br />
end, true)<br />
<br />
downloadFile(saveto, url)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
local gifpath = getMudletHomeDir().."/movie.gif"<br />
<br />
local width, height = getImageSize(gifpath)<br />
<br />
-- create a label with the name mygif<br />
createLabel("mygif", 0, 0, width, height,0)<br />
-- put the gif on the label and animate it<br />
setMovie("mygif", gifpath)<br />
</syntaxhighlight><br />
<br />
==setMovieFrame==<br />
;setMovieFrame(label name, frame nr)<br />
<br />
: Jump to a specific frame in the gif.<br />
: Returns true if successful, and false if frame doesn't exist.<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''frame nr:''<br />
: the gif animations frame nr to jump to<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
-- jumps to frame 12 of the animation<br />
setMovieFrame("myMovie", 12)<br />
--start the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><br />
<br />
==setMovieSpeed==<br />
;setMovieSpeed(label name, speed in percent)<br />
<br />
: Set the animation speed, in percent.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''speed in percent:''<br />
: the gif animations speed in percent for example 50 for 50% speed<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--accelerates the animation to a speed of 150%<br />
setMovieSpeed("myMovie",150)<br />
<br />
<br />
</syntaxhighlight><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], {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 />
* ''{lua code}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send("bye") end, function() echo("hi!") end}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<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 />
==startMovie==<br />
;startMovie(label name)<br />
<br />
: Starts the gif animation - if it was previously stopped or paused.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
--restart the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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 />
==windowType==<br />
;typeOfWindow = windowType(windowName)<br />
<br />
:Given the name of a window, will return if it's a label, miniconsole, userwindow or a commandline.<br />
<br />
;See also:[[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''windowName:''<br />
:The name used to create the window element. Use "main" for the main console<br />
<br />
<br />
;Returns<br />
*Window type as string ("label", "miniconsole", "userwindow", or "commandline") or nil+error if it does not exist.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a Geyser label and and check its type<br />
testLabel = Geyser.Label:new({name = "testLabel"})<br />
display(windowType(testLabel.name)) -- displays "label"<br />
<br />
-- the main console returns "miniconsole" because it uses the same formatting functions<br />
display(windowType("main")) -- displays "miniconsole"<br />
<br />
-- check for the existence of a window<br />
local windowName = "this thing does not exist"<br />
local ok, err = windowType(windowName)<br />
if ok then<br />
-- do things with it, as it does exist.<br />
-- the ok variable will hold the type of window it is ("label", "commandline", etc)<br />
else<br />
cecho("<red>ALERT!! window does not exist")<br />
end<br />
</syntaxhighlight><br />
<br />
;Additional development notes<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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=19860Manual:UI Functions2022-02-02T17:31:48Z<p>Dargoth: /* UI Functions */ getBackgroundColor</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window,] label, eventName)<br />
<br />
Adds item to right click menu associated with command line.<br />
<br />
{{MudletVersion|4.14}}<br />
<br />
;See also: [[Manual:Lua_Functions#removeCommandLineMenuEvent|removeCommandLineMenuEvent()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that command line belongs to. Optional, will default to "main" (main window console)<br />
* ''label:''<br />
: Label of item<br />
* ''eventName:''<br />
: Event name that will be fired when clicked.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addCommandLineMenuEvent("My very own special paste from clipboard", "pasteFromClipboardWithoutLineBreaks" )<br />
registerAnonymousEventHandler("pasteFromClipboardWithoutLineBreaks", function()<br />
local text = string.gsub(getClipboardText(), "[\r|\n]", "")<br />
appendCmdLine(text)<br />
end)<br />
</syntaxhighlight><br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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.<br />
:See also: [[Manual:Lua_Functions#decho|decho()]]<br />
<br />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<br />
<br />
{{note}} underline, italics, overline, and strikethrough supported since Mudlet 4.15+<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, strikethrough, 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 />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you cecho it will erase any previous echo sent to the label.<br />
<br />
;Parameters<br />
*''window:''<br />
:Optional - the window name to echo to - can either be none or "main" for the main window, or a miniconsole, userwindow, or label 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>, <s>strikethrough</s>, <o>overline</o>, and <b>bold</b>.")<br />
<br />
cecho("\n<green><o><u>Green text with over and underline at the same time.</o></u>")<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><br />
<br />
==cecho2ansi==<br />
;ansiFormattedString = cecho2ansi(text)<br />
<br />
:Converts cecho formatted text to ansi formatted text. Used by cfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cfeedTriggers|cfeedTriggers()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
{{note}} This function uses the ansi short colors (0-15) for color names which have base 16 ansi equivalents, such as 'red', 'blue', "lightBlue", "cyan", etc rather than the values defined in the color_table. If there is no base ansi equivalent then it will use the rgb values from the color_table for the color.<br />
<br />
;Parameters<br />
*''text:''<br />
:The cecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of cfeedTriggers() for a single line.<br />
-- you would most likely just use cfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(cecho2ansi("\n<red>This is red.<reset> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<br />
</syntaxhighlight><br />
<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<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)</syntaxhighlight><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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 />
==createScrollBox==<br />
;createScrollBox([name of parent window], name, x, y, width, height)<br />
<br />
: creates a graphical elements able to hold other graphical elements such as labels, miniconsoles, command lines etc. in it.<br />
If the added elements don't fit into the ScrollBox scrollbars appear and allow scrolling.<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#moveWindow|moveWindow()]], [[Manual:Lua_Functions#setWindow|setWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''name of parent window:'' <br />
: (Optional) name of the parent window the scrollBox is created in. Defaults to the main window if not provided.<br />
* ''name:''<br />
: The name of the scrollBox. Must be unique. Passed as a string.<br />
* ''x'', ''y'', ''width'', ''height''<br />
: Parameters to set set the window size and location<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a ScrollBox with the name sBox<br />
createScrollBox("SBox",0,0,300,200)<br />
<br />
-- create 3 Labels and put them into the ScrollBox<br />
createLabel("SBox","SBoxLabel",0,0,200,200,1)<br />
createLabel("SBox","SBoxLabel2",200,0,200,200,1)<br />
createLabel("SBox","SBoxLabel3",400,0,200,200,1)<br />
<br />
-- put some text on the labels<br />
echo("SBoxLabel","Label")<br />
echo("SBoxLabel2","Label2")<br />
echo("SBoxLabel3","Label3")<br />
<br />
-- change the colours of the labels to make it easier to distinguish them<br />
setBackgroundColor("SBoxLabel",255,0,0)<br />
setBackgroundColor("SBoxLabel2",0,255,0)<br />
setBackgroundColor("SBoxLabel3",0,0,255)<br />
</syntaxhighlight><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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code>, <code><nowiki><s>strikethrough</s></nowiki></code>, <code><nowiki><o>overline</o></nowiki></code>, and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you decho it will erase any previous echo sent to the label.<br />
<br />
:See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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>, <s>strikethrough</s>, and <b>bold</b> formatting.")<br />
<br />
decho("<\n<0,128,0><o><u>Green text with both over and underlines.</u></o>")<br />
</syntaxhighlight><br />
<br />
==decho2ansi==<br />
;ansiFormattedString = decho2ansi(text)<br />
<br />
:Converts decho formatted text to ansi formatted text. Used by dfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dfeedTriggers|dfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
; Parameters<br />
*''text:''<br />
:The decho formatted text for conversion<br />
<br />
;Returns<br />
* String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of dfeedTriggers() for a single line.<br />
-- you would most likely just use dfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(decho2ansi("\n<128,0,0>This is red.<r> <i>italic</i>, <b>bold</b>, <s>strikethrough</s>, <u>underline</u>\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() send("hi") end, "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 - [[Manual:Lua_Functions#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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)<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 />
==getBackgroundColor==<br />
;setBackgroundColor([windowName])<br />
: Gets the background for the given label, miniconsole, or userwindow.<br />
: Returns 4 values - red, green, blue, transparency. Colors returned 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 getthe background color from, or "main" for the main window.<br />
<br />
: {{MudletVersion|4.15}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local r, g, b, a = getBackgroundColor()<br />
local rW, gW, bW, aW = getBackgroundColor("myWindow")<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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getHTMLformat==<br />
;spanTag = getHTMLformat(formatTable)<br />
<br />
:Takes in a table of formatting options in the same style as [[Manual:Lua_Functions#getTextFormat|getTextFormat()]] and returns a span tag which will format text after it as the table describes.<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''formatTable:''<br />
:Table with formatting options configured. Keys are foreground, background, bold, underline, overline, strikeout, italic, and reverse. All except for foreground and background should be boolean (true/false) values. Foreground and background are either { r, g, b, a } tables, or strings with QSS formatting directives<br />
<br />
;Returns<br />
*A string with the html span tag to format text in accordance with the format table.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Returns a span tag for bold, red text on a green background<br />
local span = getHTMLformat({<br />
foreground = { 255, 0, 0 },<br />
background = "#00FF00",<br />
bold = true<br />
})<br />
<br />
-- span will be '<span style="color: rgb(255, 0, 0);background-color: #00FF00; font-weight: bold; font-style: normal; text-decoration: none;">'<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 />
==getLabelFormat==<br />
;formatTable = getLabelFormat(labelName)<br />
<br />
: Returns a format table like the one returned by getTextFormat and suitable for getHTMLspan which will format text the same way as simply doing an echo to the label would<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to scan the format of<br />
<br />
;Returns<br />
*A table with all the formatting options to achieve a default text format for label labelName.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- creates a test label, sets a stylesheet, and then returns the default format table for that label.<br />
createLabel("testLabel", 10, 10, 300, 200, 1)<br />
setLabelStyleSheet([[<br />
color: rgb(0,0,180);<br />
border-width: 1px;<br />
border-style: solid;<br />
border-color: gold;<br />
border-radius: 10px;<br />
font-size: 12.0pt;<br />
background: 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 />
]])<br />
local fmt = getLabelFormat("testLabel"))<br />
<br />
--[[<br />
{<br />
background = "rgba(0, 0, 0, 0)", -- this is transparent<br />
bold = false,<br />
foreground = "rgb(0,0,180)",<br />
italic = false,<br />
overline = false,<br />
reverse = false,<br />
strikeout = false,<br />
underline = false<br />
}<br />
--]]<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelSizeHint==<br />
;width, height = getLabelSizeHint(labelName)<br />
<br />
: Returns the suggested labelsize as width and height<br />
<br />
;See also:[[Manual:Lua_Functions#getTextFormat|getTextFormat()]], [[Manual:Lua_Functions#getHTMLspan|getHTMLspan()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the suggested size from<br />
<br />
;Returns<br />
*suggested width and height (to fit text and/or an image on a label)<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- text resizing example<br />
-- create the label<br />
createLabel("textLabel",400,400,300,300,1)<br />
-- put some text on it<br />
echo("textLabel", "This is my Test.\nAnother Test")<br />
-- resizes the label to fit the text<br />
resizeWindow("textLabel", getLabelSizeHint("textLabel"))<br />
<br />
-- image resizing example<br />
-- create the label<br />
createLabel("imageLabel",400,400,300,300,1)<br />
-- put some image on it<br />
setBackgroundImage("imageLabel", getMudletHomeDir.."/myLabelImage.png")<br />
-- resizes the label to fit the image<br />
resizeWindow("imageLabel", getLabelSizeHint("imageLabel"))<br />
<br />
</syntaxhighlight><br />
<br />
==getLabelStyleSheet==<br />
;getLabelStyleSheet(labelName)<br />
: Returns the stylesheet set on a given label, which is used to customise the labels look and feel.<br />
<br />
;See also:[[Manual:Lua_Functions#setLabelStyleSheet|getTextFormat()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''labelName:''<br />
: The name of the label to get the stylesheet from<br />
<br />
;Returns<br />
*stylesheet as a string<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><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 />
<br />
-- now retrieve it and display:<br />
local stylesheet = getLabelStyleSheet("test")<br />
cecho(f"<green>the label's stylesheet is now: \n<white>{stylesheet}\n")<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([windowName])<br />
:Gets the absolute amount of lines in the current console buffer<br />
<br />
; Parameters<br />
*''windowName''<br />
: Optional name of the window to get the line count of. Defaults to the main window.<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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, strikethrough, and underline tags.<br />
:See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]<br />
<br />
{{Note}} Support for labels added in Mudlet 4.15; however, it does not turn a label into a miniconsole and every time you hecho it will erase any previous echo sent to the label.<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, #ooverline#/o, #sstrikethrough#/s, and #bbold#/b formatting.")<br />
-- shows the various individual formatting options<br />
hecho("\n#008000#o#uGreen text with both over and underlines.#/o#/u")<br />
</syntaxhighlight><br />
<br />
==hecho2ansi==<br />
;ansiFormattedString = hecho2ansi(text)<br />
<br />
:Converts hecho formatted text to ansi formatted text. Used by hfeedTriggers, but useful if you want ansi formatted text for any other reason.<br />
<br />
;See also:[[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hfeedTriggers|hfeedTriggers()]]<br />
<br />
{{MudletVersion|4.10+}}<br />
<br />
{{Note}} non-color formatting added in Mudlet 4.15+<br />
<br />
;Parameters<br />
*''text:''<br />
:The hecho formatted text for conversion<br />
<br />
;Returns<br />
*String converted to ansi formatting<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- replicates the functionality of hfeedTriggers() for a single line.<br />
-- you would most likely just use hfeedTriggers, but it makes for a tidy example.<br />
feedTriggers(hecho2ansi("\n#800000This is red.#r #iitalic#/i, #bbold#/b, #sstrikethrough#/s, #uunderline#/u\n"))<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- # format also works<br />
hechoLink("#ca00040black!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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, as text or a function (since Mudlet 4.11).<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!", function() echo("you clicked me!\n") end, "Click me popup")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() echo("you clicked me!\n") end, "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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==pauseMovie==<br />
;pauseMovie(label name)<br />
<br />
: Pauses the gif animation on the label<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==removeCommandLineMenuEvent==<br />
;removeCommandLineMenuEvent([window,] label)<br />
<br />
:Removes an existing command line menu event.<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that item is associated with. Optional, defaults to "main" (main window console).<br />
* ''label:''<br />
: Label under which element is registered<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<br />
<br />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). Also works with named capture group. It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumberOrName:''<br />
: number of the capture group you want to select, or the name of the capture group as a string<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 />
<br />
-- Or perhaps instead if you were to use "you have (?<euro>\d+) Euro"<br />
selectCaptureGroup("euro")<br />
fg("green")<br />
</syntaxhighlight><br />
<br />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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, as text or Lua function.<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 />
-- example of selecting text in a miniconsole and turning it into a link:<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 />
==setMovie==<br />
;setMovie(label name, path to gif)<br />
<br />
: Adds a gif to the selected label and animates it. Note that gifs are pretty expensive to play, so don't add too many at once.<br />
: Some websites you can get gifs from are [https://tenor.com/search/stickers-gifs Tenor] and [https://giphy.com/stickers Giphy] (not officially endorsed).<br />
<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the label the gif will be animated on<br />
* ''path:''<br />
: path of the gif file<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- download & show a gif within mudlet<br />
local saveto = getMudletHomeDir().."/kymip.gif"<br />
-- animation credit to https://opengameart.org/content/kymiball-ii-third-prototype-scraps<br />
local url = "https://opengameart.org/sites/default/files/kymip_0.gif"<br />
<br />
if downloadHandler then killAnonymousEventHandler(downloadHandler) end<br />
downloadHandler = registerAnonymousEventHandler("sysDownloadDone",<br />
function(_, filename)<br />
if filename ~= saveto then<br />
return true<br />
end<br />
<br />
local width, height = getImageSize(saveto)<br />
<br />
createLabel("kymip", 300, 300, width, height, 0)<br />
setMovie("kymip", saveto)<br />
setLabelReleaseCallback("kymip", function() deleteLabel("kymip") end)<br />
end, true)<br />
<br />
downloadFile(saveto, url)<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang="lua"><br />
local gifpath = getMudletHomeDir().."/movie.gif"<br />
<br />
local width, height = getImageSize(gifpath)<br />
<br />
-- create a label with the name mygif<br />
createLabel("mygif", 0, 0, width, height,0)<br />
-- put the gif on the label and animate it<br />
setMovie("mygif", gifpath)<br />
</syntaxhighlight><br />
<br />
==setMovieFrame==<br />
;setMovieFrame(label name, frame nr)<br />
<br />
: Jump to a specific frame in the gif.<br />
: Returns true if successful, and false if frame doesn't exist.<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''frame nr:''<br />
: the gif animations frame nr to jump to<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
-- jumps to frame 12 of the animation<br />
setMovieFrame("myMovie", 12)<br />
--start the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><br />
<br />
==setMovieSpeed==<br />
;setMovieSpeed(label name, speed in percent)<br />
<br />
: Set the animation speed, in percent.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#startMovie|startMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label<br />
* ''speed in percent:''<br />
: the gif animations speed in percent for example 50 for 50% speed<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--accelerates the animation to a speed of 150%<br />
setMovieSpeed("myMovie",150)<br />
<br />
<br />
</syntaxhighlight><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], {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 />
* ''{lua code}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send("bye") end, function() echo("hi!") end}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<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 />
==startMovie==<br />
;startMovie(label name)<br />
<br />
: Starts the gif animation - if it was previously stopped or paused.<br />
: Returns true<br />
<br />
: See also: [[Manual:Lua_Functions#setMovie|setMovie()]], [[Manual:Lua_Functions#pauseMovie|pauseMovie()]], [[Manual:Lua_Functions#setMovieFrame|setMovieFrame()]], [[Manual:Lua_Functions#setMovieSpeed|setMovieSpeed()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
* ''label name:'' <br />
: name of the gif label <br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- create a label with the name myMovie<br />
createLabel("myMovie",0,0,200,200,0)<br />
<br />
-- puts the gif on the label and animates it<br />
setMovie("myMovie", getMudletHomeDir().."/movie.gif")<br />
--stops the animation<br />
pauseMovie("myMovie")<br />
--restart the animation<br />
startMovie("myMovie")<br />
<br />
</syntaxhighlight><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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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 />
==windowType==<br />
;typeOfWindow = windowType(windowName)<br />
<br />
:Given the name of a window, will return if it's a label, miniconsole, userwindow or a commandline.<br />
<br />
;See also:[[Manual:Lua_Functions#createLabel|createLabel()]], [[Manual:Lua_Functions#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|4.15}}<br />
<br />
;Parameters<br />
*''windowName:''<br />
:The name used to create the window element. Use "main" for the main console<br />
<br />
<br />
;Returns<br />
*Window type as string ("label", "miniconsole", "userwindow", or "commandline") or nil+error if it does not exist.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- Create a Geyser label and and check its type<br />
testLabel = Geyser.Label:new({name = "testLabel"})<br />
display(windowType(testLabel.name)) -- displays "label"<br />
<br />
-- the main console returns "miniconsole" because it uses the same formatting functions<br />
display(windowType("main")) -- displays "miniconsole"<br />
<br />
-- check for the existence of a window<br />
local windowName = "this thing does not exist"<br />
local ok, err = windowType(windowName)<br />
if ok then<br />
-- do things with it, as it does exist.<br />
-- the ok variable will hold the type of window it is ("label", "commandline", etc)<br />
else<br />
cecho("<red>ALERT!! window does not exist")<br />
end<br />
</syntaxhighlight><br />
<br />
;Additional development notes<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>Dargothhttps://wiki.mudlet.org/index.php?title=Compiling_Mudlet&diff=19774Compiling Mudlet2022-01-19T23:15:23Z<p>Dargoth: /* CLion setup on Windows */</p>
<hr />
<div>{{TOC right}}<br />
<br />
If you just want to use Mudlet, you can skip these steps, and use one of the already ready (pre-compiled) installers [https://www.mudlet.org/download ready for download].<br />
<br />
Otherwise, hop in for new adventure! <br />
<br />
[[File:Easy Mudlet code understanding.png|frame|none]]<br />
<br />
= Key contributing information =<br />
<br />
Clang format is used to automatically format code submissions using the [https://github.com/Mudlet/Mudlet/blob/development/src/.clang-format src/.clang-format] style. [http://doc.qt.io/qtcreator/creator-beautifier.html See here] how to enable clang-format with Qt Creator - and make sure to specify the 'File' option for the configuration style.<br />
<br />
Branches:<br />
<br />
'''development''' is the development branch where new features can go.<br />
<br />
Workflow:<br />
<br />
Fork and submit a PR with your changes ([https://guides.github.com/activities/forking/ Github tutorial]).<br />
<br />
Here is a list of package versions delivered with different Linux distros. You may want to upgrade these: <br />
https://repology.org/project/mudlet/versions<br />
<br />
= Compiling =<br />
<br />
== Compiling on Ubuntu ==<br />
<br />
These instructions will get you setup compiling on Ubuntu. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
===Ubuntu 21.10===<br />
Following instructions will work on Ubuntu 21.10 as well as all it's flavours and derivatives (such as KDE Neon, for example)<br />
Important thing is to have ''Universe'' repository enabled in your package manager. (on Ubuntu you will have all the repositories that you need already enabled by default.)<br />
<br />
'''1. necessary dependencies'''<br />
<br />
Majority of required dependencies can be obtained from repositories, and can be installed with following command:<br />
<br />
sudo apt install ubuntu-restricted-extras qtcreator build-essential git zlib1g-dev libhunspell-dev \<br />
libpcre3-dev libzip-dev libboost-dev libboost-all-dev libyajl-dev libpulse-dev libpugixml-dev \<br />
liblua5.1-0-dev lua-filesystem lua-zip lua-sql-sqlite3 luarocks ccache lua-rex-pcre lua5.1 \<br />
libglu1-mesa-dev mesa-common-dev libglib2.0-dev libgstreamer1.0-dev libqt5opengl5-dev \<br />
qtmultimedia5-dev qttools5-dev qt5keychain-dev libsecret-1-dev \<br />
libqt5texttospeech5-dev qtspeech5-flite-plugin qtspeech5-speechd-plugin \<br />
qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtmultimedia5-dev<br />
<br />
Few of required Lua modules are not available in official repositories, so they have to be installed using ''luarocks''<br />
sudo luarocks install lcf<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''2. obtaining the source code'''<br />
<br />
If you're compiling Mudlet from source for everyday use with few more features that are not present in official AppImage, it is strongly advised that you obtain and compile the source code latest ''stable'' release of Mudlet. At the moment of writing this article, current stable version is 4.10.1, you'll need to adjust version number if new release comes out at later date.<br />
mkdir build && cd build<br />
wget https://www.mudlet.org/wp-content/files/Mudlet-4.10.1.tar.xz<br />
tar xvf Mudlet-4.10.1.tar.xz<br />
cd src<br />
<br />
However, if you're feeling adventurous and wish to play with the latest development code, you can obtain it directly from Mudlet's Git repository:<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
mkdir Mudlet/build<br />
cd Mudlet/build<br />
<br />
'''3. compiling the code'''<br />
<br />
There below are two ways to build with qmake, the first is for general use, the second is for developers:<br />
qmake ../src/mudlet.pro<br />
'''*OR*'''<br />
qmake CONFIG+=debug ../src/mudlet.pro<br />
<br />
'''Now finish compiling:'''<br />
make -j `nproc`<br />
<br />
4. '''installing compiled code'''<br />
<br />
After successful code compilation, next few commands will install resulting binaries, desktop file for menus and appropriate icon.<br />
sudo make install<br />
sudo cp ../mudlet.png /usr/share/pixmaps<br />
sudo cp ../mudlet.desktop /usr/share/applications<br />
<br />
5. '''optional additional software'''<br />
<br />
One of the major reasons for compiling Mudlet from source is the ability to unlock more features that are not enabled in official AppImage.<br />
Manual compilation will resolve the issues with sound by using system provided libraries, as well as enable more detailed theming of Mudlet application itself.<br />
However, do take note that Mudlet is a Qt based program, and that theming will not 'just work' in GTK based desktop environments (Gnome, XFCE, MATE, Budgie).<br />
sudo apt install qt5ct<br />
will install a tool for configuration of look and feel of Qt programs inside those desktop environments.<br />
Users of Qt based Desktop environments (KDE Plasma, LXQT) can simply use settings provided by environment itself.<br />
<br />
Many of Qt widget styles and color schemes are available in official repositories, and will make Mudlet better.<br />
<br />
6. '''Mudlet on Wayland'''<br />
<br />
Mudlet compiled like this will run and work on Wayland, however, there are a few quirks with Keybidings (Numpad may not work as expected).<br />
Until that is resolved you may wish to start mudlet with:<br />
QT_QPA_PLATFORM=xcb mudlet<br />
(enter in terminal or simply change the Exec= line in /usr/share/applications/mudlet.desktop)<br />
<br />
7. '''uninstallation'''<br />
<br />
You can reverse the process described in this guide with following command:<br />
<br />
sudo rm -fr /usr/bin/mudlet /usr/share/mudlet /usr/share/applications/mudlet.desktop /usr/share/pixmaps/mudlet.png<br />
<br />
===Ubuntu 20.10===<br />
Following instructions will work on Ubuntu 20.10 as well as all it's flavours and derivatives (such as KDE Neon, for example)<br />
Important thing is to have ''Universe'' repository enabled in your package manager.<br />
<br />
1. '''necessary dependencies'''<br />
<br />
Majority of required dependencies can be obtained from repositories, and can be installed with following command:<br />
<br />
sudo apt install qtcreator build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev libzip-dev libboost-dev libboost-all-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev lua5.1 libqt5opengl5-dev libglu1-mesa-dev mesa-common-dev libglib2.0-dev libgstreamer1.0-dev qt5keychain-dev libsecret-1-dev libqt5texttospeech5-dev qtspeech5-flite-plugin qtspeech5-speechd-plugin<br />
<br />
Few of required Lua modules are not available in official repositories, so they have to be installed using ''luarocks'' <br />
sudo luarocks install lcf<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
2. '''obtaining the source code'''<br />
<br />
If you're compiling Mudlet from source for everyday use with few more features that are not present in official AppImage, it is strongly advised that you obtain and compile the source code latest ''stable'' release of Mudlet. At the moment of writing this article, current stable version is 4.10.1, you'll need to adjust version number if new release comes out at later date.<br />
mkdir build && cd build<br />
wget https://www.mudlet.org/wp-content/files/Mudlet-4.10.1.tar.xz<br />
tar xvf Mudlet-4.10.1.tar.xz<br />
cd src<br />
<br />
However, if you're feeling adventurous and wish to play with the latest development code, you can obtain it directly from Mudlet's Git repository:<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
cd Mudlet/src/<br />
<br />
3. '''compiling the code'''<br />
<br />
Following commands will configure the code to install Mudlet on a system level and compile it.<br />
If you wish to install it somewhere else, you may adjust both paths in following command to point to desired destination before compiling it with make. (Rest of this guide will assume you're installing on a system level)<br />
WITH_FONTS=NO WITH_OWN_QTKEYCHAIN=NO WITH_UPDATER=NO WITH_VARIABLE_SPLASH_SCREEN=NO XDG_DATA_DIRS=/usr/share qmake PREFIX=/usr<br />
make -j `nproc`<br />
<br />
4. '''compiling on Ubuntu for Raspberry Pi'''<br />
<br />
Ubuntu for Raspberry Pi is essentially the same as Ubuntu for regular PC, however, due to sketchy state of OpenGL drivers on RPi 4, you'll likely need to disable Mudlet's 3D Mapper or code will just not compile. Adjusted commands are:<br />
WITH_3DMAPPER=NO WITH_FONTS=NO WITH_OWN_QTKEYCHAIN=NO WITH_UPDATER=NO WITH_VARIABLE_SPLASH_SCREEN=NO XDG_DATA_DIRS=/usr/share qmake PREFIX=/usr<br />
make<br />
<br />
5. '''installing compiled code'''<br />
<br />
After successful code compilation, next few commands will install resulting binaries, desktop file for menus and appropriate icon.<br />
sudo make install<br />
sudo cp ../mudlet.png /usr/share/pixmaps<br />
sudo cp ../mudlet.desktop /usr/share/applications<br />
<br />
6. '''optional additional software'''<br />
<br />
One of the major reasons for compiling Mudlet from source is the ability to unlock more features that are not enabled in official AppImage.<br />
Manual compilation will resolve the issues with sound by using system provided libraries, as well as enable more detailed theming of Mudlet application itself.<br />
However, do take note that Mudlet is a Qt based program, and that theming will not 'just work' in GTK based desktop environments (Gnome, XFCE, MATE, Budgie).<br />
sudo apt install qt5ct<br />
will install a tool for configuration of look and feel of Qt programs inside those desktop environments.<br />
Users of Qt based Desktop environments (KDE Plasma, LXQT) can simply use settings provided by environment itself.<br />
<br />
Many of Qt widget styles and color schemes are available in official repositories, and will make Mudlet better.<br />
<br />
7. '''Mudlet on Wayland'''<br />
<br />
Mudlet compiled like this will run and work on Wayland, however, there are a few quirks with Keybidings (Numpad may not work as expected). <br />
Until that is resolved you may wish to start mudlet with:<br />
QT_QPA_PLATFORM=xcb mudlet<br />
(enter in terminal or simply change the Exec= line in /usr/share/applications/mudlet.desktop)<br />
<br />
8. '''uninstallation'''<br />
<br />
You can reverse the process described in this guide with following command:<br />
<br />
sudo rm -fr /usr/bin/mudlet /usr/share/mudlet /usr/share/applications/mudlet.desktop /usr/share/pixmaps/mudlet.png<br />
<br />
===Ubuntu 18.04 setup===<br />
<br />
For Ubuntu 18.04 see the instructions for [[#Compiling_on_Debian_9_.27Stretch.27|Compiling on Debian 9 'Stretch']] (tested working perfectly).<br />
<br />
<br />
'''1. Ubuntu 18.04 setup'''<br />
<br />
If you're on Ubuntu 18.04 (Bionic Beaver), install the following. If you're on a newer Ubuntu, skip this step and go to ''2. Install dependencies''.<br />
<br />
sudo add-apt-repository ppa:beineri/opt-qt-5.12.3-bionic<br />
sudo apt update<br />
sudo apt install qt512-meta-full qt512creator<br />
source /opt/qt512/bin/qt512-env.sh<br />
<br />
'''2. Install dependencies'''<br />
<br />
sudo apt install git build-essential qt5-default qtmultimedia5-dev qttools5-dev \<br />
lua5.1 liblua5.1-0-dev libpcre3-dev libboost-dev zlib1g-dev cmake \<br />
libhunspell-dev lua-rex-pcre lua-sql-sqlite3 lua-filesystem lua-zip libyajl-dev \<br />
libzip-dev libgstreamer0.10-0 libglu1-mesa-dev ccache libpugixml-dev \<br />
mesa-common-dev qtcreator libpulse-dev libglib2.0-dev luarocks libboost-all-dev \<br />
libsecret-1-dev<br />
sudo apt install gstreamer0.10-fluendo-mp3 # may not work on newer Ubuntu<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''3. Get Mudlet source'''<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''4. Create a build directory'''<br />
<br />
cd mudlet<br />
mkdir build<br />
cd build<br />
<br />
'''5. Run the following commands, depending on which build system you want to use '''<br />
<br />
'''EITHER:'''<br />
<br />
cmake ..<br />
<br />
'''OR:'''<br />
<br />
qmake CONFIG+=debug ../src/mudlet.pro<br />
<br />
'''THEN:'''<br />
<br />
make -j `nproc`<br />
<br />
'''5. Start the application you have just compiled - enjoy'''<br />
<br />
cd src<br />
./mudlet<br />
<br />
== Compiling on Chrome OS ==<br />
<br />
These instructions will get you setup compiling on Chrome OS. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
'''1. Install dependencies'''<br />
<br />
sudo apt install git build-essential qt5-default qtmultimedia5-dev qttools5-dev \<br />
lua5.1 liblua5.1-0-dev libpcre3-dev libboost-dev zlib1g-dev cmake \<br />
libhunspell-dev lua-rex-pcre lua-sql-sqlite3 lua-filesystem lua-zip libyajl-dev \<br />
libzip-dev libglu1-mesa-dev ccache libpugixml-dev mesa-common-dev qtcreator \<br />
libpulse-dev libglib2.0-dev luarocks libboost-all-dev libsecret-1-dev \<br />
ninja-build libsecret-1-dev<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''3. Get Mudlet source'''<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''4. Create a build directory'''<br />
<br />
cd mudlet<br />
mkdir build && cd build<br />
<br />
'''5. Run the following command '''<br />
<br />
cmake .. -G Ninja<br />
<br />
'''then:'''<br />
<br />
ninja<br />
<br />
'''5. Start the application you have just compiled - enjoy'''<br />
<br />
src/mudlet<br />
{{Note}}Did <code>ninja</code> fail with <code>c++: fatal error: Killed signal terminated program cclplus</code>? Try again with <code>ninja -j 2</code><br />
<br />
== Compiling on macOS ==<br />
<br />
These instructions will get you setup compiling on macOS. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord server] or [http://forums.mudlet.org/viewforum.php?f=7 forums] otherwise.<br />
<br />
<br />
'''1. Install prerequisites'''<br />
<br />
Install [https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12 XCode], command line tools for XCode, and [http://brew.sh HomeBrew].<br />
<br />
Once everything is installed, do:<br />
<br />
brew doctor<br />
brew update<br />
brew install git<br />
<br />
'''2. Get Mudlet source'''<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git <br />
<br />
'''3. Go to the parent of the mudlet "src" folder and create (if necessary) a build subdirectory (this is so that we can build out of source which keeps the source code clean)'''<br />
cd Mudlet && mkdir build<br />
<br />
'''3. Setup your environment'''<br />
./CI/travis.osx.before_install.sh<br />
./CI/travis.osx.install.sh<br />
<br />
luarocks config lua_version 5.1<br />
eval `luarocks path --lua-version=5.1`<br />
For the following, one may have to add <code>''_DIR="/opt/homebrew/"''</code> such as <code>PCRE_DIR="/opt/homebrew/"</code> or <code>ZIP_DIR="/opt/homebrew/"</code> if the installation could not find header files.<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lrexlib-pcre<br />
brew install sqlite<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luasql-sqlite3 SQLITE_DIR=`brew --prefix sqlite` <br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luautf8<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lua-yajl<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luafilesystem<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lua-zip<br />
<br />
brew install p7zip<br />
export BOOST_ROOT="$(pwd)/../Mudlet/3rdparty/boost"<br />
export BOOST_URL="https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2/download"<br />
mkdir -p $BOOST_ROOT<br />
curl --progress-bar --location --output $BOOST_ROOT/download.tar.bz2 $BOOST_URL<br />
7z -o$BOOST_ROOT x $BOOST_ROOT/download.tar.bz2 -y -bd<br />
7z -o$BOOST_ROOT x $BOOST_ROOT/download.tar -y -bd<br />
cd $BOOST_ROOT && cp -r boost_*/* .<br />
rm -rf boost_*/* download.tar.bz2 download.tar<br />
OK to answer yes to delete files if prompted for the <code>rm</code> command above.<br />
<br />
'''4. Run the following commands'''<br />
<br />
cd ../../build<br />
cmake ../../Mudlet -DCMAKE_PREFIX_PATH=`brew --prefix qt5`<br />
make -j `sysctl -n hw.ncpu`<br />
<br />
<br />
'''5. Enjoy'''<br />
<br />
The mudlet.app is now available in <code>src/</code> for launching:<br />
<br />
open src/Mudlet.app<br />
<br />
== Compiling on Debian 'Sid' ==<br />
<br />
'''1. Install required packages from main repo.'''<br />
<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev<br />
<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''2. Grab latest Mudlet source.'''<br />
<br />
mkdir ~/projects && cd ~/projects && git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''3. Build Mudlet.'''<br />
<br />
cd ~/projects/mudlet/src<br />
<br />
qmake<br />
<br />
make<br />
<br />
sudo make install<br />
<br />
== Compiling on Debian 11 'Bullseye' ==<br />
<br />
'''1. Install required packages.'''<br />
<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtmultimedia5-dev \<br />
qttools5-dev luarocks ccache libpugixml-dev libqt5texttospeech5-dev qtspeech5-flite-plugin \<br />
qtspeech5-speechd-plugin libqt5opengl5-dev<br />
<br />
sudo luarocks install luautf8 <br />
sudo luarocks install lua-yajl<br />
<br />
'''2. Get Mudlet source.'''<br />
<br />
mkdir ~/source && cd ~/source<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git<br />
<br />
Note: the line above will check out `development` branch source code, and this might not always be stable. You can check out the latest release source code using this command:<br />
<br />
git clone --recursive --branch main https://github.com/Mudlet/Mudlet.git<br />
<br />
'''3. Build Mudlet.'''<br />
<br />
mkdir ~/source/Mudlet/build && cd ~/source/Mudlet/build<br />
<br />
qmake ../src/mudlet.pro<br />
<br />
make -j `nproc`<br />
<br />
sudo make install<br />
<br />
After these steps you can run Mudlet by typing:<br />
<br />
mudlet<br />
<br />
== Compiling on Raspberry Pi OS ==<br />
<br />
These instructions will get you compiling and running Mudlet on Raspberry Pi OS (Buster). Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
''' 1.a Install apt dependencies '''<br />
<br />
sudo apt-get update<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-graph-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev cmake<br />
<br />
<br />
[[File:Apt-get-install-y-n.png|center|thumb|installing apt dependencies]]<br />
<br />
''' 1.b Install luarocks dependencies '''<br />
<br />
sudo luarocks install luautf8 <br />
sudo luarocks install lua-yajl YAJL_LIBDIR=/usr/lib/arm-linux-gnueabihf/ YAJL_INCDIR=/usr/include<br />
<br />
<br />
[[File:After-luarocks-dependencies.png|center|thumb|after luarocks dependencies]]<br />
<br />
''' 2. Get Mudlet source '''<br />
<br />
mkdir ~/source && cd ~/source <br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
<br />
[[File:After-get-mudlet-source.png|center|thumb|After cloning]]<br />
<br />
''' 3. Create a build directory '''<br />
<br />
cd Mudlet && mkdir build && cd build<br />
<br />
''' 4. Run the following commands to build '''<br />
<br />
WITH_UPDATER=NO WITH_3DMAPPER=NO qmake ../src/mudlet.pro<br />
<br />
:If you get a response along the lines of:<br />
<br />
qmake: could not find a Qt installation of ''<br />
<br />
:then you likely have ''qtchooser'' present in your system that allows for both Qt4 and Qt5 (or more than one Qt5 version) and it modifiers qmake and some other Qt development programs to take an additional argument to specify which version to use. In that case you should use:<br />
<br />
WITH_UPDATER=NO WITH_3DMAPPER=NO qmake -qt=qt5 ../src/mudlet.pro<br />
<br />
[[File:After-qmake.png|center|thumb|After qmake]]<br />
<br />
''' THEN: '''<br />
:For the fastest compile time, 15-20min on a RPi4 with 4GB of ram<br />
make -j `nproc`<br />
<br />
''' OR: '''<br />
<br />
:If you want to use your Pi while it builds or have an older Raspberry Pi, be prepared for it to take a while (over an hour) - ''it is not recommended to try to more than one compilation task at a time on the older systems with the '''-j''' option as they will only have a system memory with enough space for one of some of those tasks'':<br />
make<br />
<br />
[[File:Success.png|center|thumb|Success!]]<br />
<br />
''' 4. Install the application you have just compiled '''<br />
<br />
sudo make install<br />
<br />
[[File:Installed.png|center|thumb|Installed now]]<br />
<br />
''' 5. Enjoy! '''<br />
<br />
# mudlet is in the path, can just run it<br />
mudlet<br />
<br />
== Compiling on ArchLinux ==<br />
<br />
Mudlet is available in the [https://aur.archlinux.org Arch User Repository]. <br />
<br />
To install it use your favourite AUR helper (helper tool will automatically resove dependancies); example using ''yay'' :<br />
yay -S mudlet<br />
<br />
For more info on this process, visit [https://wiki.archlinux.org/index.php/Arch_User_Repository Arch User Repository - ArchWiki].<br />
<br />
''Note: For the most recent development version of Mudlet, replace 'mudlet' with 'mudlet-git' in the above commands and proceed as described.''<br />
<br />
''Built in fonts have been disabled, but are available in packages listed as optional dependancies.''<br />
<br />
''Discord support in Mudlet depends on an extrenal library provided by discord-rpc-api, which is also available in AUR, choose whichever variant suits you best.''<br />
<br />
== Compiling on Gentoo ==<br />
An [https://github.com/toaster/gentoo-overlay overlay containing Mudlet is available] for compiling Mudlet on Gentoo.<br />
<br />
== Compiling on Windows ==<br />
<br />
These instructions will get you setup compiling on Windows. <br />
<br />
Need a hand? Join us on the Mudlet [https://discord.gg/BwgJpMj Discord server] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
'''1. Download Mudlet source code'''<br />
<br />
# Install [https://desktop.github.com/ Github Desktop].<br />
# Clone ([https://help.github.com/desktop/guides/contributing-to-projects/cloning-a-repository-from-github-to-github-desktop/#platform-windows instructions]) Mudlet's [https://github.com/mudlet/mudlet repository] to your local drive.<br />
{{note}} You must use a location on <code>C:\</code> without any spaces in folder names! <br />
<br />
'''2. Perform a one-time setup'''<br />
<br />
Right-click on <code>setup-windows-sdk.ps1</code> and select <code>Run with PowerShell</code>. This will automatically download all of the requires tools (including Python 2) and libraries, set them up for you, build Mudlet, and launch it! If this script exits immediately, please [https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-7.1#upgrading-existing-windows-powershell upgrade your PowerShell version] first.<br />
<br />
{{note}} Depending on your Internet connection and computer speed, this one-time setup will take 30 minutes or more - so grab a cup of tea or coffee.<br />
<br />
[[File:Start-of-installation.gif|frame|none|Sometimes the output will get stuck and not progress - just press Enter to make it continue. This is a well-known [https://serverfault.com/questions/204150/sometimes-powershell-stops-sending-output-until-i-press-enter-why Powershell bug.]]]<br />
<br />
During the installation, you'll see the Qt installer window pop-up - this is normal:<br />
<br />
[[File:Qt-installer.gif|thumb|none]]<br />
<br />
The Qt installer might ask you about your data collection preferences - answer as you wish and the automated install will continue:<br />
<br />
[[File:Qt-installer-data-collection.png|thumb|none]]<br />
<br />
The installer's final step will be compiling all of the source code, which looks like this:<br />
<br />
[[File:Compiling-step.gif|thumb|none]]<br />
<br />
After it's all done, a Mudlet version ending in "-dev" will launch automatically:<br />
<br />
[[File:Mudlet-launching.gif|frame|none]]<br />
<br />
If something didn't work right, you can check out the verbose log that is available at <code>C:\src\verbose_output.log</code>.<br />
<br />
=== Coding on Mudlet ===<br />
<br />
Open <code>C:\<path to repository>\src\mudlet.pro</code> in Qt Creator, which resides here: <code>C:\Qt\Tools\QtCreator\bin\qtcreator.exe</code>. Then enable Debug and Release builds and hit ''Configure Project'':<br />
<br />
[[File:Selection_173.png|frame|none]]<br />
<br />
Press <code>Ctrl+5</code> and update project settings. Check how many logical processors are available in your system with the Task Manager:<br />
<br />
[[File:Task-manager.png|thumb|none|2 processors are available in this example]]<br />
<br />
And set this amount in Qt Creator:<br />
<br />
[[File:Change Qt Creator to use many cores.gif|frame|none]]<br />
<br />
Hit run:<br />
<br />
[[File:Selection 176.png|frame|none]]<br />
<br />
Click on '''Compile Output''' to see progress on compiling:<br />
<br />
[[File:Selection 177.png|frame|none]]<br />
<br />
When it's all ready, the new Mudlet with your changes will launch. '''You're all done'''!<br />
<br />
=== Contributing changes ===<br />
<br />
Once you're all done with your changes, contribute them to Mudlet using a [https://help.github.com/desktop/guides/contributing-to-projects/creating-a-pull-request/#platform-windows pull request]. Thanks for improving open-source!<br />
<br />
=== Uninstalling ===<br />
To get rid of everything, uninstall Qt using the <code>C:\Qt\MaintenanceTool.exe</code> and remove the following folders:<br />
<br />
C:\Libraries<br />
C:\LuaRocks<br />
C:\MinGW<br />
C:\Python27<br />
C:\Qt<br />
C:\src<br />
<br />
== Compiling on Github Codespaces ==<br />
<br />
Github Codespaces allow you to code and run Mudlet all from the browser - makes it a lot easier to get started. It also allows you to code Mudlet itself from any computer in the world! As for this time Github Codespaces is in a private beta, so make sure to [https://github.com/features/codespaces/signup apply here]. <br />
<br />
'''1. Create a new codespace'''<br />
<br />
Create a new Codespace by going to https://github.com/Mudlet/Mudlet using Google Chrome or Microsoft Edge (Firefox at the time of the writing doesn't have working copy/paste). There, click the green "Code" button, select the "Codespaces" tab and click "New codespace".<br />
<br />
[[File:New codespace.png|alt=New codespace screenshot|frameless]]<br />
<br />
'''2. Wait for it to load'''<br />
<br />
This will take a while (~5min) so grab a tea:<br />
<br />
[[File:Building Visual Studio Codespace.png|frameless]]<br />
<br />
'''3. Connect to the environment'''<br />
<br />
Go to the <code>Ports</code> section at the bottom and change the Port Privacy of the Open Mudlet port to Public:<br />
<br />
[[File:Port privacy in Github Codespaces.png|900x900px]]<br />
<br />
<br />
Then connect to your online Linux desktop with <code>mudlet</code> as the password by clicking on the web icon. <br />
<br />
[[File:Connect to remote machine.png|frameless]]<br />
<br />
<br />
In case it can't connect, make sure the port privacy is set to <code>Public</code>. If it still can't connect, try 4-5 more times - eventually it'll work.<br />
<br />
<br />
<br />
We chose a retro 90's look here to fit with the whole hacking theme, so if you see this you're good 😉<br />
<br />
[[File:Github_codespaces_desktop.png|alt=|frameless|400x400px]]<br />
<br />
'''4. Build Mudlet'''<br />
<br />
In Codespaces, hit <code>F7</code> and select <code>Let CMake guess...</code><br />
<br />
[[File:CMake configuration.png|none]]<br />
<br />
It will then start building Mudlet automatically. Using the [https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/about-billing-for-codespaces Basic instance] (only kind available in beta) the first-time build will take ~25min, so take a break here - you've made excellent progress. All follow-up compiles after this will be quicker, by the way.<br />
<br />
[[File:Building Mudlet in codespaces.png|none]]<br />
<br />
'''5. Run Mudlet'''<br />
<br />
[[File:Launch Mudlet.png|none]]<br />
<br />
Hit the little play button at the bottom of the screen, and Mudlet will now launch in the remote connection tab. Not working? [https://discord.gg/kuYvMQ9 We can help]. Otherwise, enjoy!<br />
<br />
[[File:Mudlet running remotely.png |500px]]<br />
<br />
Note: When the codespace is unused for a while, it will disconnect. It'll never disconnect while you're actively using it. See [https://github.com/microsoft/vscode-dev-containers/issues/588 Github issue] for details.<br />
<br />
== Developing with Docker ==<br />
<br />
Docker is a system designed for more reproducible and isolated builds. A docker setup exists and has been tested using Pop OS! 20.04 (which is derived from Ubuntu 20.04). First, follow the instructions to install both [https://docs.docker.com/get-docker/ docker] and [https://docs.docker.com/compose/install/ docker-compose].<br />
<br />
Clone the development branch<br />
<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
cd Mudlet/docker<br />
<br />
Make a local copy of the .env.template file:<br />
<br />
cp .env.template .env<br />
<br />
If you wish to customize things like the number of cores to use for building mudlet, feel free to change the corresponding values in the .env file.<br />
<br />
To run Qt-Creator and develop Mudlet, simply run `docker-compose up dev`.<br />
To run Mudlet, simply run `docker-compose up mudlet`. Note: At the moment, the mudlet build will not persist settings past container rebuilds.<br />
<br />
== Compiling on Windows 7+ (MSYS2 Alternative)==<br />
<br />
''INCOMPLETE, IN PROGRESS''<br />
<br />
Go to http://www.msys2.org/ to download the 64 bit MSYS2 installer (as of 2020/05/24 32 bit hosts - for '''compiling''' software, but ''not'' for using code built with it have been deprecated, the last installer for that 32-bit systems is held at: http://repo.msys2.org/distrib/i686/msys2-i686-20200517.exe) and follow the installation instructions (Steps 1 to 8 on that page), these instructions assume that "C:\msys64" or "C:\msys32" is used depending on the bitness of the system it is being installed on.<br />
<br />
Install the following packages (using "pacman -S ''packageName''"), the ones with a '''-i686-''' in the middle are the ones for 32-bit (i686) targets and '''-x86_64-''' are the ones for 64-bit targets - it is possible to install both for building Mudlet for target PCs of both bitnesses on a 64-bit host, it is not clear whether the reverse is true with a 32-bit host. These will pull in a number of other required packages as well (the ''--needed'' option prevents the re-installation of packages that have already been installed by MSYS2/Mingw-w64's own setup/installation process) - as some of the packages, e.g. ''base-devel'' are actually ''groups'' you will be requested to select which members of that group are actually required, it is easiest to just go with the default which is to install ALL of the packages in that group!<br />
<br />
: For 32-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ pacman -S --needed base-devel git mercurial cvs wget ruby zip p7zip python mingw-w64-i686-toolchain mingw-w64-i686-qt-creator mingw-w64-i686-qt5-multimedia mingw-w64-i686-libzip mingw-w64-i686-pugixml mingw-w64-i686-lua51 mingw-w64-i686-lua51-lpeg mingw-w64-i686-lua51-lsqlite3 mingw-w64-i686-hunspell mingw-w64-i686-boost mingw-w64-i686-yajl mingw-w64-i686-clang mingw-w64-i686-cmake mingw-w64-i686-SDL unzip<br />
</syntaxhighlight><br />
<br />
: For 64-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ pacman -S --needed base-devel git mercurial cvs wget ruby zip p7zip python mingw-w64-x86_64-toolchain mingw-w64-x86_64-qt-creator mingw-w64-x86_64-qt5-multimedia mingw-w64-x86_64-libzip mingw-w64-x86_64-pugixml mingw-w64-x86_64-lua51 mingw-w64-x86_64-lua51-lpeg mingw-w64-x86_64-lua51-lsqlite3 mingw-w64-x86_64-hunspell mingw-w64-x86_64-boost mingw-w64-x86_64-yajl mingw-w64-x86_64-clang mingw-w64-x86_64-cmake mingw-w64-x86_64-SDL unzip<br />
</syntaxhighlight><br />
<br />
::The ''*-zziplib'' libraries are used by the ''luazip'' luarock {from the Kepler project} but Mudlet will work perfectly well with the alternative ''lua-zip'' {from the brimworks GitHub repository - which also provides the ''lua-yajl'' rock} which does not require this library - although it is possible that it might still be pulled into the system as a dependency of another MSYS2 package.<br />
<br />
:Note that this will install the MSYS2 builds of the Qt Libraries and Creator IDE - ''THE ON/OFF-LINE INSTALLER OF THE QT LIBRARIES AND CREATOR VIA DOWNLOADS FROM QT ARE NOT USEFUL IN THIS SETUP!''<br />
<br />
:{| class="wikitable"<br />
|-<br />
|'''Attention - Luarocks packages problem'''<br />
|-<br />
| Recently the Luarocks project attempted to adopt the MSYS2/Mingw-w64 platform as one it would supported natively and the MSYS2/Mingw-w64 project went and upgraded its luarocks packages to make use of the changes and also on-board other improvements (and the version number increased from ''2.4.4-2'' to ''3.5.0-1'') unfortunately this completely broke them and although the issue has been reported ([https://github.com/msys2/MINGW-packages/issues/9037 MSYS2 Issue 9037]) a fix has not yet materialised. The only way to work around this in the meantime is to download the older package (with '''wget''') and install it manually (with '''pacman -U):<br />
|-<br />
|For 32-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ wget https://repo.msys2.org/mingw/mingw32/mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
--2021-07-07 22:19:09-- https://repo.msys2.org/mingw/mingw32/mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
Resolving repo.msys2.org (repo.msys2.org)... 178.63.98.68<br />
Connecting to repo.msys2.org (repo.msys2.org)|178.63.98.68|:443... connected.<br />
HTTP request sent, awaiting response... 200 OK<br />
Length: 97905 (96K) [application/octet-stream]<br />
Saving to: ‘mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’<br />
<br />
mingw-w64-i686-lua51-luarocks-2.4.4-2- 100%[===========================================================================>] 95.61K --.-KB/s in 0.07s<br />
<br />
2021-07-07 22:19:10 (1.43 MB/s) - ‘mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’ saved [97905/97905]<br />
<br />
<br />
MSYS user@computer ~<br />
$ pacman -U mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
loading packages...<br />
resolving dependencies...<br />
looking for conflicting packages...<br />
<br />
Packages (1) mingw-w64-i686-lua51-luarocks-2.4.4-2<br />
<br />
Total Installed Size: 0.46 MiB<br />
<br />
:: Proceed with installation? [Y/n] y<br />
(1/1) checking keys in keyring [#####################################################] 100%<br />
(1/1) checking package integrity [#####################################################] 100%<br />
(1/1) loading package files [#####################################################] 100%<br />
(1/1) checking for file conflicts [#####################################################] 100%<br />
(1/1) checking available disk space [#####################################################] 100%<br />
:: Processing package changes...<br />
(1/1) installing mingw-w64-i686-lua51-luarocks [#####################################################] 100%<br />
<br />
MSYS user@computer ~<br />
</syntaxhighlight><br />
|-<br />
|For 64-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ wget https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
--2021-07-07 22:17:32-- https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
Resolving repo.msys2.org (repo.msys2.org)... 178.63.98.68<br />
Connecting to repo.msys2.org (repo.msys2.org)|178.63.98.68|:443... connected.<br />
HTTP request sent, awaiting response... 200 OK<br />
Length: 97935 (96K) [application/octet-stream]<br />
Saving to: ‘mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’<br />
<br />
mingw-w64-x86_64-lua51-luarocks-2.4.4- 100%[===========================================================================>] 95.64K --.-KB/s in 0.07s<br />
<br />
2021-07-07 22:17:32 (1.28 MB/s) - ‘mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’ saved [97935/97935]<br />
<br />
<br />
MSYS user@computer ~<br />
$ pacman -U mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
loading packages...<br />
resolving dependencies...<br />
looking for conflicting packages...<br />
<br />
Packages (1) mingw-w64-x86_64-lua51-luarocks-2.4.4-2<br />
<br />
Total Installed Size: 0.46 MiB<br />
<br />
:: Proceed with installation? [Y/n] y<br />
(1/1) checking keys in keyring [#####################################################] 100%<br />
(1/1) checking package integrity [#####################################################] 100%<br />
(1/1) loading package files [#####################################################] 100%<br />
(1/1) checking for file conflicts [#####################################################] 100%<br />
(1/1) checking available disk space [#####################################################] 100%<br />
:: Processing package changes...<br />
(1/1) installing mingw-w64-x86_64-lua51-luarocks [#####################################################] 100%<br />
<br />
MSYS user@computer ~<br />
</syntaxhighlight><br />
|}<br />
<br />
::{| class="wikitable"<br />
|-<br />
|'''Warning for those planning to build ''both'' 32 and 64 bit versions'''<br />
|-<br />
|If one is planning to build ''both'' bitness binaries an additional step is necessary as, by default, the MSYS2/Mingw-w64 ''luarocks'' setup seems to place any ''.lua'' or ''.dll'' modules it builds/installs on a per user (the so-called ''local'' basis) into the same directories with the same names. This is no good for two reasons:<br />
* It is difficult to work out which bitness a particular module is for and whilst 32-bit modules ''might'' work in a 64-bit environment the reverse is definitely not the case<br />
* It confuses the Luarocks package management systems (as effectively there will be two different luarocks systems operated side-by-side)<br />
<br />
This can be worked around by:<br />
* Editing the '''.\etc\luarocks\config-5.1.lua''' for each bitness so that the ''rocks_trees'' table entry for the ''user'' key is changed from this in '''both''' files:<br />
:<syntaxhighlight lang="lua"> { name = [[user]], root = home..[[/.luarocks]] },</syntaxhighlight><br />
to something different for each of them, say, for example, for the the 64-bit one:<br />
:<syntaxhighlight lang="lua"> { name = [[user]], root = home..[[/.luarocks-x64]] },</syntaxhighlight><br />
* Then by specifying the ''rocktree'' name ('''user''') on the command line when '''installing''' or '''building''' a luarock with the ''--tree user'' argument - note that for some inexplicable reason the ''--local'' argument that '''''should''''' do the same thing does not seem to work for these two actions, it is not clear whether this is a MSYS2/Mingw-w64 specific issue or it goes further upstream to Luarocks in general. Thus, in the next step it will be necessary to change from using:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install --local rockname<br />
</syntaxhighlight><br />
to, for the example given:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install --tree user rockname<br />
</syntaxhighlight><br />
where ''user'' is the literal string "user" to match the Lua table key in the rock_trees and not, in this case, a representation of the user-name/account of the person performing the action.<br />
|}<br />
<br />
From the Windows ''Start menu'' start a shell appropriate for the target with the bitness to be built for i.e. '''"MSYS2 Mingw 32-Bit"''' or '''"MSYS2 Mingw 64-Bit"'''. This will likely position the current directory to the root directory of the MSYS2 environment, the text about the prompt line (the one with the "$") will contain three different bits of colored text '''username@computername'''; one of '''MSYS2'''/'''MINGW32'''/'''MINGW''' depending on the type of shell you currently in use and '''/''' representing the root directory (which will actually be the directory MSYS2 was installed to, for example on the author's system this is "C:/msys64"). Change to the home directory in MYSY by entering "cd" on its own with no argument (it will show up as '''~''' and it would work out to be, for '''user''' to be '''c:/msys64/home/user''' or '''c:/msys32/home/user''' (if both bitnessess are to be built it will be necessary to repeat the following step twice, one for each and also observe the steps in the above warning) install the following luarocks:<br />
<br />
:{| class="wikitable sortable"<br />
|-<br />
! rockname<br />
|-<br />
| lrexlib-pcre<br />
|-<br />
| lua-yajl<br />
|-<br />
| luafilesystem<br />
|-<br />
| luasql-sqlite3<br />
|-<br />
| luautf8<br />
|-<br />
| luazip or lua-zip<br />
|}<br />
by using:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install [--local] rockname<br />
</syntaxhighlight><br />
The ''--local'' argument is an optional one that causes the luarock and the lua module to be installed on a per-user basis rather than on a system wide one, this may be important if the PC is used by multiple users and more than one of them uses Lua in any form.<br />
<br />
Now create somewhere to work on the Mudlet source, assuming that other software coding with other pieces of software will be done, create a sub-directory in the home directory, and then make one just for Mudlet under that:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ mkdir ./src<br />
<br />
MINGW64 user@computer ~<br />
$ mkdir ./src/mudlet<br />
</syntaxhighlight><br />
<br />
Change to that directory and get the source code:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ cd ./src/mudlet<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git clone git://github.com/Mudlet/Mudlet.git .<br />
</syntaxhighlight><br />
<br />
If you are planning to contribute to the Mudlet code you will want to visit Github and create your own GitHub repository, you can then push commits (changes to the code) to there and raise a Pull Request for a Mudlet Maker to drag the changes over to the above repository. You will want to add your repository and perhaps those of some other contributors so you can track what they are doing and see/try/experiment with their PRs before they get merged. Therefore you will want to add some other repositories into the mix. The names you use to identify those other repositories will show up in any utility that works with the repository you have just created in the above "clone" operation and can be anything you like but it makes sense to have clear names. So to add "myName", and those of the leading active contributors to the Mudlet codebase you will use:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Mine https://github.com/myName/Mudlet.git<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Vadim https://github.com/vadi2/Mudlet.git <br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add SlySven https://github.com/SlySven/Mudlet.git<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Kebap https://github.com/Kebap/Mudlet.git<br />
</syntaxhighlight><br />
<br />
Now obtain ''all'' the versions of the code with:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ git fetch --all<br />
</syntaxhighlight><br />
<br />
This will produce a lot of lines of output the first time and it might take a little while on a slow connection...<br />
<br />
{Section missing - it turns out that the default GUI git tools that the author of this section would normally use: "gitk" and "git gui" have some problems in the versions currently supplied from the MSYS2 system - and it was necessary to import them from the set that the Git4Win have patched - see https://github.com/git-for-windows/git/wiki/Install-inside-MSYS2-proper }<br />
<br />
Some modifications to the qmake/cmake project files are needed and these are now supported in the main ''development'' branch in the upstream {the Mudlet organisation's own GitHub repository} which requires that there is an environmental variable '''WITH_MAIN_BUILD_SYSTEM''' and it is set to the (case-insensitive) value '''NO''':<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ export WITH_MAIN_BUILD_SYSTEM=NO<br />
</syntaxhighlight><br />
<br />
Also the '''MINGW_BASE_DIR''' environmental variable will need to be set to the root directory for the MINGW-W64 installation for the appropriate bitness of the target to be made. For building on a 64-Bit Host {the PC that is ''compiling'' the code} to make a 64-Bit application this will likely be '''C:/msys64/mingw64''' and for a 32-Bit application it will probably be '''C:/msys64/ming32'''.<br />
: E.g. <syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ export MINGW_BASE_DIR=C:/msys64/mingw64 # To build a 64-Bit Application with a 64-Bit system<br />
</syntaxhighlight><br />
<br />
: Or: <syntaxhighlight lang="shell"><br />
MINGW32 user@computer ~/src/mudlet<br />
$ export MINGW_BASE_DIR=C:/msys64/mingw32 # To build a 32-Bit Application with a 64-Bit system<br />
</syntaxhighlight><br />
<br />
Now checkout a branch {ideally, if working on solving a new issue, or adding a feature or resolving a bug, one should create a new branch that is a copy of the current, upstream ''development'' branch} and then work on it with Qt Creator:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ qtcreator &<br />
</syntaxhighlight><br />
<br />
Load in the '''mudlet.pro''' ''qmake'' project file in the '''src''' subdirectory (e.g. for this example: '''c:/msys64/home/user/src/mudlet/src/mudlet.pro''') and get hacking...<br />
<br />
= Setting up IDEs =<br />
== CLion ==<br />
=== Qt not detected ===<br />
If you'd like to use CLion and it is giving the following error:<br />
<br />
<nowiki><br />
By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has<br />
asked CMake to find a package configuration file provided by "Qt5Core", but<br />
CMake did not find one.<br />
<br />
...<br />
</nowiki><br />
<br />
You can fix this by setting <code>-DCMAKE_PREFIX_PATH=<your Qt + version + compiler location></code>. For example: <code>-DCMAKE_PREFIX_PATH=/media/vadi/SSDer/Programs/Qt/5.15.2/gcc_64/</code> [[File:CLion CMake settings - finidng Qt.png|700px|none]]<br />
<br />
=== CLion setup on Windows ===<br />
After running <code>setup-windows-sdk.ps1</code> make sure to set Cmake options to:<br />
-DCMAKE_PREFIX_PATH=C:\Qt\Tools\mingw730_32;C:\Qt\5.14.2\mingw73_32 -DBoost_INCLUDE_DIR=C:\Libraries\boost_1_71_0<br />
''Directories might vary slightly, when different Qt, Boost or MinGW version will be used.''<br />
<br />
[[File:Clion Settings - Cmake.png|frameless|700x700px]]<br />
<br />
<br />
<br />
You will need 32 bit version of MinGW. Set it in the <code>Toolset</code> field to:<br />
C:\Qt\Tools\mingw730_32<br />
<br />
''Directory may be slightly different if MinGW version used will change.''<br />
<br />
[[File:Toolchain.png|frameless|700x700px]]<br />
<br />
=== Clang Tidy ===<br />
Ensure that CLion is set to run the project's [https://www.jetbrains.com/help/clion/clang-tidy-checks-support.html#paticularcheck .clang-tidy checks] with the <code>Prefer .clang-tidy files over IDE settings</code> option:<br />
<br />
[[File:Clang Tidy CLIon.png|700px|none]]<br />
<br />
This helps us catch any issues just a bit earlier.<br />
<br />
=== Clang Format ===<br />
Ensure that [https://www.jetbrains.com/help/clion/clangformat-as-alternative-formatter.html#clion-support CLion is set to use] the <code>.clang-format</code> formatting style:<br />
<br />
[[File:Clang-format CLion.png]]<br />
<br />
This helps keep the look'n'feel of the source code in a consistent manner, even with many people contributing to Mudlet.<br />
<br />
== Visual Studio Code ==<br />
<br />
To set the path in Visual Studio Code, open settings, search for <code>cmake environment</code> and set the <code>CMAKE_PREFIX_PATH</code> to your path, such as <code>/media/vadi/SSDer/Programs/Qt/5.14.1/gcc_64/</code>:<br />
<br />
[[File:CMake path in Visual Studio Code.png|none]]<br />
<br />
===Clang Tidy===<br />
clang-tidy catches common programming issues, run it by selecting 'Analysis' from the command palette (Ctrl+Shift+P by default):<br />
<br />
[[File:Clang-tidy in vscode.png|none]]<br />
<br />
It is also possible [https://devblogs.microsoft.com/cppblog/visual-studio-code-c-december-2021-update-clang-tidy/ check status of analysis and cancel if needed].<br />
<br />
===Checking memory leaks & other issues (sanitizers)===<br />
Besides clang-tidy, it's also possible to enable clang sanitizers to double-check for issues:<br />
<br />
* [https://clang.llvm.org/docs/LeakSanitizer.html LeakSanitizer] for detecting memory leaks<br />
* [https://clang.llvm.org/docs/AddressSanitizer.html AddressSanitizer] for detecting most issues dealing with memory, such as out of bounds accesses to heap, stack, global and more<br />
* [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html UndefinedBehaviourSanitizer] for detecting the use of various features of C/C++ that are explicitly listed as resulting in undefined behaviour (such as using misaligned or null pointer, conversion to, from, or between floating-point types which would overflow the destination, division by zero, etc)<br />
* [https://clang.llvm.org/docs/MemorySanitizer.html MemorySanitizer] for detecting reading uninitialised memory<br />
* [https://clang.llvm.org/docs/ThreadSanitizer.html ThreadSanitizer] for detecting threading issues<br />
<br />
To use the sanitisers, set the <code>USE_SANITIZER</code> CMake variable to one or several variables (separate by comma): <code>Address</code>, <code>Memory</code>, <code>MemoryWithOrigins</code>, <code>Undefined</code>, <code>Thread</code>, or <code>Leak</code><br />
<br />
To use them in VSCode, set the <code>cmake.configureSettings</code> variable:<br />
<br />
[[File:Cmake.configureSettings option in vscode.png|frameless|890x890px]]<br />
<br />
[[File:Choosing which sanitizers in vscode to use.png|frameless|891x891px]]<br />
<br />
Not all sanitisers can be used with each other - in that case the cmake configuration won't allow you to continue.<br />
<br />
== Qt Creator==<br />
===Clang Tidy and Clazy===<br />
<br />
Configure Mudlet-specific checks for [https://clang.llvm.org/extra/clang-tidy/ clang-tidy] and [https://github.com/KDE/clazy clazy] tools help catch any issues early on. See [https://doc.qt.io/qtcreator/creator-clang-tools.html Qt Creator's instructions] for setting this up - clang-tidy can use the <code>.clang-tidy</code> file that's available at the root of the repository, and for clazy enable <code>level0</code> and <code>level1</code> checks.<br />
<br />
[[File:Clang tidy configuration.png|frame|none]]<br />
[[File:Clazy configuration.png|frame|none]]<br />
<br />
===Checking memory leaks & other issues (sanitizers)===<br />
Besides clang-tidy, it's also possible to enable clang sanitizers to double-check for issues:<br />
<br />
* [https://clang.llvm.org/docs/LeakSanitizer.html LeakSanitizer] for detecting memory leaks<br />
* [https://clang.llvm.org/docs/AddressSanitizer.html AddressSanitizer] for detecting most issues dealing with memory, such as out of bounds accesses to heap, stack, global and more<br />
* [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html UndefinedBehaviourSanitizer] for detecting the use of various features of C/C++ that are explicitly listed as resulting in undefined behaviour (such as using misaligned or null pointer, conversion to, from, or between floating-point types which would overflow the destination, division by zero, etc)<br />
* [https://clang.llvm.org/docs/MemorySanitizer.html MemorySanitizer] for detecting reading uninitialised memory<br />
* [https://clang.llvm.org/docs/ThreadSanitizer.html ThreadSanitizer] for detecting threading issues<br />
<br />
To use the sanitisers, set the <code>USE_SANITIZER</code> CMake variable to one or several variables (separate by comma): <code>Address</code>, <code>Memory</code>, <code>MemoryWithOrigins</code>, <code>Undefined</code>, <code>Thread</code>, or <code>Leak</code><br />
<br />
To use them in Qt creator, head to <code>Projects</code> - <code>Build</code>: <br />
<br />
[[File:Sanitisers in qt creator.png|frameless|890x890px]]<br />
<br />
Not all sanitisers can be used with each other - in that case the cmake configuration won't allow you to continue.<br />
<br />
==Clang Format==<br />
Ensure that Qt Creator is set to use the <code>.clang-format</code> formatting style in the C++ settings. Turn on <code>Format instead of indenting</code> for <code>Ctrl+I</code> to format code, and ensure <code>Override Clang Format configuration file</code> is disabled:<br />
<br />
[[File:Qt Creator clang format.png]]<br />
<br />
This helps keep the look'n'feel of the source code in a consistent manner, even with many people contributing to Mudlet.<br />
<br />
<br />
=Building with multiple versions of Lua=<br />
Mudlet uses Lua 5.1 only, so if you are compiling on a system that also has later versions installed, you might get the following error: <code>‘LUA_GLOBALSINDEX’ was not declared in this scope</code>.<br />
<br />
To fix this, pass the path to Lua headers explicitly. For CMake: <code>-DLUA_INCLUDE_DIR=/usr/include/lua5.1</code> (adjust as needed).</div>Dargothhttps://wiki.mudlet.org/index.php?title=Compiling_Mudlet&diff=19773Compiling Mudlet2022-01-19T23:14:53Z<p>Dargoth: /* CLion setup on Windows */</p>
<hr />
<div>{{TOC right}}<br />
<br />
If you just want to use Mudlet, you can skip these steps, and use one of the already ready (pre-compiled) installers [https://www.mudlet.org/download ready for download].<br />
<br />
Otherwise, hop in for new adventure! <br />
<br />
[[File:Easy Mudlet code understanding.png|frame|none]]<br />
<br />
= Key contributing information =<br />
<br />
Clang format is used to automatically format code submissions using the [https://github.com/Mudlet/Mudlet/blob/development/src/.clang-format src/.clang-format] style. [http://doc.qt.io/qtcreator/creator-beautifier.html See here] how to enable clang-format with Qt Creator - and make sure to specify the 'File' option for the configuration style.<br />
<br />
Branches:<br />
<br />
'''development''' is the development branch where new features can go.<br />
<br />
Workflow:<br />
<br />
Fork and submit a PR with your changes ([https://guides.github.com/activities/forking/ Github tutorial]).<br />
<br />
Here is a list of package versions delivered with different Linux distros. You may want to upgrade these: <br />
https://repology.org/project/mudlet/versions<br />
<br />
= Compiling =<br />
<br />
== Compiling on Ubuntu ==<br />
<br />
These instructions will get you setup compiling on Ubuntu. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
===Ubuntu 21.10===<br />
Following instructions will work on Ubuntu 21.10 as well as all it's flavours and derivatives (such as KDE Neon, for example)<br />
Important thing is to have ''Universe'' repository enabled in your package manager. (on Ubuntu you will have all the repositories that you need already enabled by default.)<br />
<br />
'''1. necessary dependencies'''<br />
<br />
Majority of required dependencies can be obtained from repositories, and can be installed with following command:<br />
<br />
sudo apt install ubuntu-restricted-extras qtcreator build-essential git zlib1g-dev libhunspell-dev \<br />
libpcre3-dev libzip-dev libboost-dev libboost-all-dev libyajl-dev libpulse-dev libpugixml-dev \<br />
liblua5.1-0-dev lua-filesystem lua-zip lua-sql-sqlite3 luarocks ccache lua-rex-pcre lua5.1 \<br />
libglu1-mesa-dev mesa-common-dev libglib2.0-dev libgstreamer1.0-dev libqt5opengl5-dev \<br />
qtmultimedia5-dev qttools5-dev qt5keychain-dev libsecret-1-dev \<br />
libqt5texttospeech5-dev qtspeech5-flite-plugin qtspeech5-speechd-plugin \<br />
qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtmultimedia5-dev<br />
<br />
Few of required Lua modules are not available in official repositories, so they have to be installed using ''luarocks''<br />
sudo luarocks install lcf<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''2. obtaining the source code'''<br />
<br />
If you're compiling Mudlet from source for everyday use with few more features that are not present in official AppImage, it is strongly advised that you obtain and compile the source code latest ''stable'' release of Mudlet. At the moment of writing this article, current stable version is 4.10.1, you'll need to adjust version number if new release comes out at later date.<br />
mkdir build && cd build<br />
wget https://www.mudlet.org/wp-content/files/Mudlet-4.10.1.tar.xz<br />
tar xvf Mudlet-4.10.1.tar.xz<br />
cd src<br />
<br />
However, if you're feeling adventurous and wish to play with the latest development code, you can obtain it directly from Mudlet's Git repository:<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
mkdir Mudlet/build<br />
cd Mudlet/build<br />
<br />
'''3. compiling the code'''<br />
<br />
There below are two ways to build with qmake, the first is for general use, the second is for developers:<br />
qmake ../src/mudlet.pro<br />
'''*OR*'''<br />
qmake CONFIG+=debug ../src/mudlet.pro<br />
<br />
'''Now finish compiling:'''<br />
make -j `nproc`<br />
<br />
4. '''installing compiled code'''<br />
<br />
After successful code compilation, next few commands will install resulting binaries, desktop file for menus and appropriate icon.<br />
sudo make install<br />
sudo cp ../mudlet.png /usr/share/pixmaps<br />
sudo cp ../mudlet.desktop /usr/share/applications<br />
<br />
5. '''optional additional software'''<br />
<br />
One of the major reasons for compiling Mudlet from source is the ability to unlock more features that are not enabled in official AppImage.<br />
Manual compilation will resolve the issues with sound by using system provided libraries, as well as enable more detailed theming of Mudlet application itself.<br />
However, do take note that Mudlet is a Qt based program, and that theming will not 'just work' in GTK based desktop environments (Gnome, XFCE, MATE, Budgie).<br />
sudo apt install qt5ct<br />
will install a tool for configuration of look and feel of Qt programs inside those desktop environments.<br />
Users of Qt based Desktop environments (KDE Plasma, LXQT) can simply use settings provided by environment itself.<br />
<br />
Many of Qt widget styles and color schemes are available in official repositories, and will make Mudlet better.<br />
<br />
6. '''Mudlet on Wayland'''<br />
<br />
Mudlet compiled like this will run and work on Wayland, however, there are a few quirks with Keybidings (Numpad may not work as expected).<br />
Until that is resolved you may wish to start mudlet with:<br />
QT_QPA_PLATFORM=xcb mudlet<br />
(enter in terminal or simply change the Exec= line in /usr/share/applications/mudlet.desktop)<br />
<br />
7. '''uninstallation'''<br />
<br />
You can reverse the process described in this guide with following command:<br />
<br />
sudo rm -fr /usr/bin/mudlet /usr/share/mudlet /usr/share/applications/mudlet.desktop /usr/share/pixmaps/mudlet.png<br />
<br />
===Ubuntu 20.10===<br />
Following instructions will work on Ubuntu 20.10 as well as all it's flavours and derivatives (such as KDE Neon, for example)<br />
Important thing is to have ''Universe'' repository enabled in your package manager.<br />
<br />
1. '''necessary dependencies'''<br />
<br />
Majority of required dependencies can be obtained from repositories, and can be installed with following command:<br />
<br />
sudo apt install qtcreator build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev libzip-dev libboost-dev libboost-all-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev lua5.1 libqt5opengl5-dev libglu1-mesa-dev mesa-common-dev libglib2.0-dev libgstreamer1.0-dev qt5keychain-dev libsecret-1-dev libqt5texttospeech5-dev qtspeech5-flite-plugin qtspeech5-speechd-plugin<br />
<br />
Few of required Lua modules are not available in official repositories, so they have to be installed using ''luarocks'' <br />
sudo luarocks install lcf<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
2. '''obtaining the source code'''<br />
<br />
If you're compiling Mudlet from source for everyday use with few more features that are not present in official AppImage, it is strongly advised that you obtain and compile the source code latest ''stable'' release of Mudlet. At the moment of writing this article, current stable version is 4.10.1, you'll need to adjust version number if new release comes out at later date.<br />
mkdir build && cd build<br />
wget https://www.mudlet.org/wp-content/files/Mudlet-4.10.1.tar.xz<br />
tar xvf Mudlet-4.10.1.tar.xz<br />
cd src<br />
<br />
However, if you're feeling adventurous and wish to play with the latest development code, you can obtain it directly from Mudlet's Git repository:<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
cd Mudlet/src/<br />
<br />
3. '''compiling the code'''<br />
<br />
Following commands will configure the code to install Mudlet on a system level and compile it.<br />
If you wish to install it somewhere else, you may adjust both paths in following command to point to desired destination before compiling it with make. (Rest of this guide will assume you're installing on a system level)<br />
WITH_FONTS=NO WITH_OWN_QTKEYCHAIN=NO WITH_UPDATER=NO WITH_VARIABLE_SPLASH_SCREEN=NO XDG_DATA_DIRS=/usr/share qmake PREFIX=/usr<br />
make -j `nproc`<br />
<br />
4. '''compiling on Ubuntu for Raspberry Pi'''<br />
<br />
Ubuntu for Raspberry Pi is essentially the same as Ubuntu for regular PC, however, due to sketchy state of OpenGL drivers on RPi 4, you'll likely need to disable Mudlet's 3D Mapper or code will just not compile. Adjusted commands are:<br />
WITH_3DMAPPER=NO WITH_FONTS=NO WITH_OWN_QTKEYCHAIN=NO WITH_UPDATER=NO WITH_VARIABLE_SPLASH_SCREEN=NO XDG_DATA_DIRS=/usr/share qmake PREFIX=/usr<br />
make<br />
<br />
5. '''installing compiled code'''<br />
<br />
After successful code compilation, next few commands will install resulting binaries, desktop file for menus and appropriate icon.<br />
sudo make install<br />
sudo cp ../mudlet.png /usr/share/pixmaps<br />
sudo cp ../mudlet.desktop /usr/share/applications<br />
<br />
6. '''optional additional software'''<br />
<br />
One of the major reasons for compiling Mudlet from source is the ability to unlock more features that are not enabled in official AppImage.<br />
Manual compilation will resolve the issues with sound by using system provided libraries, as well as enable more detailed theming of Mudlet application itself.<br />
However, do take note that Mudlet is a Qt based program, and that theming will not 'just work' in GTK based desktop environments (Gnome, XFCE, MATE, Budgie).<br />
sudo apt install qt5ct<br />
will install a tool for configuration of look and feel of Qt programs inside those desktop environments.<br />
Users of Qt based Desktop environments (KDE Plasma, LXQT) can simply use settings provided by environment itself.<br />
<br />
Many of Qt widget styles and color schemes are available in official repositories, and will make Mudlet better.<br />
<br />
7. '''Mudlet on Wayland'''<br />
<br />
Mudlet compiled like this will run and work on Wayland, however, there are a few quirks with Keybidings (Numpad may not work as expected). <br />
Until that is resolved you may wish to start mudlet with:<br />
QT_QPA_PLATFORM=xcb mudlet<br />
(enter in terminal or simply change the Exec= line in /usr/share/applications/mudlet.desktop)<br />
<br />
8. '''uninstallation'''<br />
<br />
You can reverse the process described in this guide with following command:<br />
<br />
sudo rm -fr /usr/bin/mudlet /usr/share/mudlet /usr/share/applications/mudlet.desktop /usr/share/pixmaps/mudlet.png<br />
<br />
===Ubuntu 18.04 setup===<br />
<br />
For Ubuntu 18.04 see the instructions for [[#Compiling_on_Debian_9_.27Stretch.27|Compiling on Debian 9 'Stretch']] (tested working perfectly).<br />
<br />
<br />
'''1. Ubuntu 18.04 setup'''<br />
<br />
If you're on Ubuntu 18.04 (Bionic Beaver), install the following. If you're on a newer Ubuntu, skip this step and go to ''2. Install dependencies''.<br />
<br />
sudo add-apt-repository ppa:beineri/opt-qt-5.12.3-bionic<br />
sudo apt update<br />
sudo apt install qt512-meta-full qt512creator<br />
source /opt/qt512/bin/qt512-env.sh<br />
<br />
'''2. Install dependencies'''<br />
<br />
sudo apt install git build-essential qt5-default qtmultimedia5-dev qttools5-dev \<br />
lua5.1 liblua5.1-0-dev libpcre3-dev libboost-dev zlib1g-dev cmake \<br />
libhunspell-dev lua-rex-pcre lua-sql-sqlite3 lua-filesystem lua-zip libyajl-dev \<br />
libzip-dev libgstreamer0.10-0 libglu1-mesa-dev ccache libpugixml-dev \<br />
mesa-common-dev qtcreator libpulse-dev libglib2.0-dev luarocks libboost-all-dev \<br />
libsecret-1-dev<br />
sudo apt install gstreamer0.10-fluendo-mp3 # may not work on newer Ubuntu<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''3. Get Mudlet source'''<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''4. Create a build directory'''<br />
<br />
cd mudlet<br />
mkdir build<br />
cd build<br />
<br />
'''5. Run the following commands, depending on which build system you want to use '''<br />
<br />
'''EITHER:'''<br />
<br />
cmake ..<br />
<br />
'''OR:'''<br />
<br />
qmake CONFIG+=debug ../src/mudlet.pro<br />
<br />
'''THEN:'''<br />
<br />
make -j `nproc`<br />
<br />
'''5. Start the application you have just compiled - enjoy'''<br />
<br />
cd src<br />
./mudlet<br />
<br />
== Compiling on Chrome OS ==<br />
<br />
These instructions will get you setup compiling on Chrome OS. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
'''1. Install dependencies'''<br />
<br />
sudo apt install git build-essential qt5-default qtmultimedia5-dev qttools5-dev \<br />
lua5.1 liblua5.1-0-dev libpcre3-dev libboost-dev zlib1g-dev cmake \<br />
libhunspell-dev lua-rex-pcre lua-sql-sqlite3 lua-filesystem lua-zip libyajl-dev \<br />
libzip-dev libglu1-mesa-dev ccache libpugixml-dev mesa-common-dev qtcreator \<br />
libpulse-dev libglib2.0-dev luarocks libboost-all-dev libsecret-1-dev \<br />
ninja-build libsecret-1-dev<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''3. Get Mudlet source'''<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''4. Create a build directory'''<br />
<br />
cd mudlet<br />
mkdir build && cd build<br />
<br />
'''5. Run the following command '''<br />
<br />
cmake .. -G Ninja<br />
<br />
'''then:'''<br />
<br />
ninja<br />
<br />
'''5. Start the application you have just compiled - enjoy'''<br />
<br />
src/mudlet<br />
{{Note}}Did <code>ninja</code> fail with <code>c++: fatal error: Killed signal terminated program cclplus</code>? Try again with <code>ninja -j 2</code><br />
<br />
== Compiling on macOS ==<br />
<br />
These instructions will get you setup compiling on macOS. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord server] or [http://forums.mudlet.org/viewforum.php?f=7 forums] otherwise.<br />
<br />
<br />
'''1. Install prerequisites'''<br />
<br />
Install [https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12 XCode], command line tools for XCode, and [http://brew.sh HomeBrew].<br />
<br />
Once everything is installed, do:<br />
<br />
brew doctor<br />
brew update<br />
brew install git<br />
<br />
'''2. Get Mudlet source'''<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git <br />
<br />
'''3. Go to the parent of the mudlet "src" folder and create (if necessary) a build subdirectory (this is so that we can build out of source which keeps the source code clean)'''<br />
cd Mudlet && mkdir build<br />
<br />
'''3. Setup your environment'''<br />
./CI/travis.osx.before_install.sh<br />
./CI/travis.osx.install.sh<br />
<br />
luarocks config lua_version 5.1<br />
eval `luarocks path --lua-version=5.1`<br />
For the following, one may have to add <code>''_DIR="/opt/homebrew/"''</code> such as <code>PCRE_DIR="/opt/homebrew/"</code> or <code>ZIP_DIR="/opt/homebrew/"</code> if the installation could not find header files.<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lrexlib-pcre<br />
brew install sqlite<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luasql-sqlite3 SQLITE_DIR=`brew --prefix sqlite` <br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luautf8<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lua-yajl<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luafilesystem<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lua-zip<br />
<br />
brew install p7zip<br />
export BOOST_ROOT="$(pwd)/../Mudlet/3rdparty/boost"<br />
export BOOST_URL="https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2/download"<br />
mkdir -p $BOOST_ROOT<br />
curl --progress-bar --location --output $BOOST_ROOT/download.tar.bz2 $BOOST_URL<br />
7z -o$BOOST_ROOT x $BOOST_ROOT/download.tar.bz2 -y -bd<br />
7z -o$BOOST_ROOT x $BOOST_ROOT/download.tar -y -bd<br />
cd $BOOST_ROOT && cp -r boost_*/* .<br />
rm -rf boost_*/* download.tar.bz2 download.tar<br />
OK to answer yes to delete files if prompted for the <code>rm</code> command above.<br />
<br />
'''4. Run the following commands'''<br />
<br />
cd ../../build<br />
cmake ../../Mudlet -DCMAKE_PREFIX_PATH=`brew --prefix qt5`<br />
make -j `sysctl -n hw.ncpu`<br />
<br />
<br />
'''5. Enjoy'''<br />
<br />
The mudlet.app is now available in <code>src/</code> for launching:<br />
<br />
open src/Mudlet.app<br />
<br />
== Compiling on Debian 'Sid' ==<br />
<br />
'''1. Install required packages from main repo.'''<br />
<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev<br />
<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''2. Grab latest Mudlet source.'''<br />
<br />
mkdir ~/projects && cd ~/projects && git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''3. Build Mudlet.'''<br />
<br />
cd ~/projects/mudlet/src<br />
<br />
qmake<br />
<br />
make<br />
<br />
sudo make install<br />
<br />
== Compiling on Debian 11 'Bullseye' ==<br />
<br />
'''1. Install required packages.'''<br />
<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtmultimedia5-dev \<br />
qttools5-dev luarocks ccache libpugixml-dev libqt5texttospeech5-dev qtspeech5-flite-plugin \<br />
qtspeech5-speechd-plugin libqt5opengl5-dev<br />
<br />
sudo luarocks install luautf8 <br />
sudo luarocks install lua-yajl<br />
<br />
'''2. Get Mudlet source.'''<br />
<br />
mkdir ~/source && cd ~/source<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git<br />
<br />
Note: the line above will check out `development` branch source code, and this might not always be stable. You can check out the latest release source code using this command:<br />
<br />
git clone --recursive --branch main https://github.com/Mudlet/Mudlet.git<br />
<br />
'''3. Build Mudlet.'''<br />
<br />
mkdir ~/source/Mudlet/build && cd ~/source/Mudlet/build<br />
<br />
qmake ../src/mudlet.pro<br />
<br />
make -j `nproc`<br />
<br />
sudo make install<br />
<br />
After these steps you can run Mudlet by typing:<br />
<br />
mudlet<br />
<br />
== Compiling on Raspberry Pi OS ==<br />
<br />
These instructions will get you compiling and running Mudlet on Raspberry Pi OS (Buster). Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
''' 1.a Install apt dependencies '''<br />
<br />
sudo apt-get update<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-graph-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev cmake<br />
<br />
<br />
[[File:Apt-get-install-y-n.png|center|thumb|installing apt dependencies]]<br />
<br />
''' 1.b Install luarocks dependencies '''<br />
<br />
sudo luarocks install luautf8 <br />
sudo luarocks install lua-yajl YAJL_LIBDIR=/usr/lib/arm-linux-gnueabihf/ YAJL_INCDIR=/usr/include<br />
<br />
<br />
[[File:After-luarocks-dependencies.png|center|thumb|after luarocks dependencies]]<br />
<br />
''' 2. Get Mudlet source '''<br />
<br />
mkdir ~/source && cd ~/source <br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
<br />
[[File:After-get-mudlet-source.png|center|thumb|After cloning]]<br />
<br />
''' 3. Create a build directory '''<br />
<br />
cd Mudlet && mkdir build && cd build<br />
<br />
''' 4. Run the following commands to build '''<br />
<br />
WITH_UPDATER=NO WITH_3DMAPPER=NO qmake ../src/mudlet.pro<br />
<br />
:If you get a response along the lines of:<br />
<br />
qmake: could not find a Qt installation of ''<br />
<br />
:then you likely have ''qtchooser'' present in your system that allows for both Qt4 and Qt5 (or more than one Qt5 version) and it modifiers qmake and some other Qt development programs to take an additional argument to specify which version to use. In that case you should use:<br />
<br />
WITH_UPDATER=NO WITH_3DMAPPER=NO qmake -qt=qt5 ../src/mudlet.pro<br />
<br />
[[File:After-qmake.png|center|thumb|After qmake]]<br />
<br />
''' THEN: '''<br />
:For the fastest compile time, 15-20min on a RPi4 with 4GB of ram<br />
make -j `nproc`<br />
<br />
''' OR: '''<br />
<br />
:If you want to use your Pi while it builds or have an older Raspberry Pi, be prepared for it to take a while (over an hour) - ''it is not recommended to try to more than one compilation task at a time on the older systems with the '''-j''' option as they will only have a system memory with enough space for one of some of those tasks'':<br />
make<br />
<br />
[[File:Success.png|center|thumb|Success!]]<br />
<br />
''' 4. Install the application you have just compiled '''<br />
<br />
sudo make install<br />
<br />
[[File:Installed.png|center|thumb|Installed now]]<br />
<br />
''' 5. Enjoy! '''<br />
<br />
# mudlet is in the path, can just run it<br />
mudlet<br />
<br />
== Compiling on ArchLinux ==<br />
<br />
Mudlet is available in the [https://aur.archlinux.org Arch User Repository]. <br />
<br />
To install it use your favourite AUR helper (helper tool will automatically resove dependancies); example using ''yay'' :<br />
yay -S mudlet<br />
<br />
For more info on this process, visit [https://wiki.archlinux.org/index.php/Arch_User_Repository Arch User Repository - ArchWiki].<br />
<br />
''Note: For the most recent development version of Mudlet, replace 'mudlet' with 'mudlet-git' in the above commands and proceed as described.''<br />
<br />
''Built in fonts have been disabled, but are available in packages listed as optional dependancies.''<br />
<br />
''Discord support in Mudlet depends on an extrenal library provided by discord-rpc-api, which is also available in AUR, choose whichever variant suits you best.''<br />
<br />
== Compiling on Gentoo ==<br />
An [https://github.com/toaster/gentoo-overlay overlay containing Mudlet is available] for compiling Mudlet on Gentoo.<br />
<br />
== Compiling on Windows ==<br />
<br />
These instructions will get you setup compiling on Windows. <br />
<br />
Need a hand? Join us on the Mudlet [https://discord.gg/BwgJpMj Discord server] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
'''1. Download Mudlet source code'''<br />
<br />
# Install [https://desktop.github.com/ Github Desktop].<br />
# Clone ([https://help.github.com/desktop/guides/contributing-to-projects/cloning-a-repository-from-github-to-github-desktop/#platform-windows instructions]) Mudlet's [https://github.com/mudlet/mudlet repository] to your local drive.<br />
{{note}} You must use a location on <code>C:\</code> without any spaces in folder names! <br />
<br />
'''2. Perform a one-time setup'''<br />
<br />
Right-click on <code>setup-windows-sdk.ps1</code> and select <code>Run with PowerShell</code>. This will automatically download all of the requires tools (including Python 2) and libraries, set them up for you, build Mudlet, and launch it! If this script exits immediately, please [https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-7.1#upgrading-existing-windows-powershell upgrade your PowerShell version] first.<br />
<br />
{{note}} Depending on your Internet connection and computer speed, this one-time setup will take 30 minutes or more - so grab a cup of tea or coffee.<br />
<br />
[[File:Start-of-installation.gif|frame|none|Sometimes the output will get stuck and not progress - just press Enter to make it continue. This is a well-known [https://serverfault.com/questions/204150/sometimes-powershell-stops-sending-output-until-i-press-enter-why Powershell bug.]]]<br />
<br />
During the installation, you'll see the Qt installer window pop-up - this is normal:<br />
<br />
[[File:Qt-installer.gif|thumb|none]]<br />
<br />
The Qt installer might ask you about your data collection preferences - answer as you wish and the automated install will continue:<br />
<br />
[[File:Qt-installer-data-collection.png|thumb|none]]<br />
<br />
The installer's final step will be compiling all of the source code, which looks like this:<br />
<br />
[[File:Compiling-step.gif|thumb|none]]<br />
<br />
After it's all done, a Mudlet version ending in "-dev" will launch automatically:<br />
<br />
[[File:Mudlet-launching.gif|frame|none]]<br />
<br />
If something didn't work right, you can check out the verbose log that is available at <code>C:\src\verbose_output.log</code>.<br />
<br />
=== Coding on Mudlet ===<br />
<br />
Open <code>C:\<path to repository>\src\mudlet.pro</code> in Qt Creator, which resides here: <code>C:\Qt\Tools\QtCreator\bin\qtcreator.exe</code>. Then enable Debug and Release builds and hit ''Configure Project'':<br />
<br />
[[File:Selection_173.png|frame|none]]<br />
<br />
Press <code>Ctrl+5</code> and update project settings. Check how many logical processors are available in your system with the Task Manager:<br />
<br />
[[File:Task-manager.png|thumb|none|2 processors are available in this example]]<br />
<br />
And set this amount in Qt Creator:<br />
<br />
[[File:Change Qt Creator to use many cores.gif|frame|none]]<br />
<br />
Hit run:<br />
<br />
[[File:Selection 176.png|frame|none]]<br />
<br />
Click on '''Compile Output''' to see progress on compiling:<br />
<br />
[[File:Selection 177.png|frame|none]]<br />
<br />
When it's all ready, the new Mudlet with your changes will launch. '''You're all done'''!<br />
<br />
=== Contributing changes ===<br />
<br />
Once you're all done with your changes, contribute them to Mudlet using a [https://help.github.com/desktop/guides/contributing-to-projects/creating-a-pull-request/#platform-windows pull request]. Thanks for improving open-source!<br />
<br />
=== Uninstalling ===<br />
To get rid of everything, uninstall Qt using the <code>C:\Qt\MaintenanceTool.exe</code> and remove the following folders:<br />
<br />
C:\Libraries<br />
C:\LuaRocks<br />
C:\MinGW<br />
C:\Python27<br />
C:\Qt<br />
C:\src<br />
<br />
== Compiling on Github Codespaces ==<br />
<br />
Github Codespaces allow you to code and run Mudlet all from the browser - makes it a lot easier to get started. It also allows you to code Mudlet itself from any computer in the world! As for this time Github Codespaces is in a private beta, so make sure to [https://github.com/features/codespaces/signup apply here]. <br />
<br />
'''1. Create a new codespace'''<br />
<br />
Create a new Codespace by going to https://github.com/Mudlet/Mudlet using Google Chrome or Microsoft Edge (Firefox at the time of the writing doesn't have working copy/paste). There, click the green "Code" button, select the "Codespaces" tab and click "New codespace".<br />
<br />
[[File:New codespace.png|alt=New codespace screenshot|frameless]]<br />
<br />
'''2. Wait for it to load'''<br />
<br />
This will take a while (~5min) so grab a tea:<br />
<br />
[[File:Building Visual Studio Codespace.png|frameless]]<br />
<br />
'''3. Connect to the environment'''<br />
<br />
Go to the <code>Ports</code> section at the bottom and change the Port Privacy of the Open Mudlet port to Public:<br />
<br />
[[File:Port privacy in Github Codespaces.png|900x900px]]<br />
<br />
<br />
Then connect to your online Linux desktop with <code>mudlet</code> as the password by clicking on the web icon. <br />
<br />
[[File:Connect to remote machine.png|frameless]]<br />
<br />
<br />
In case it can't connect, make sure the port privacy is set to <code>Public</code>. If it still can't connect, try 4-5 more times - eventually it'll work.<br />
<br />
<br />
<br />
We chose a retro 90's look here to fit with the whole hacking theme, so if you see this you're good 😉<br />
<br />
[[File:Github_codespaces_desktop.png|alt=|frameless|400x400px]]<br />
<br />
'''4. Build Mudlet'''<br />
<br />
In Codespaces, hit <code>F7</code> and select <code>Let CMake guess...</code><br />
<br />
[[File:CMake configuration.png|none]]<br />
<br />
It will then start building Mudlet automatically. Using the [https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/about-billing-for-codespaces Basic instance] (only kind available in beta) the first-time build will take ~25min, so take a break here - you've made excellent progress. All follow-up compiles after this will be quicker, by the way.<br />
<br />
[[File:Building Mudlet in codespaces.png|none]]<br />
<br />
'''5. Run Mudlet'''<br />
<br />
[[File:Launch Mudlet.png|none]]<br />
<br />
Hit the little play button at the bottom of the screen, and Mudlet will now launch in the remote connection tab. Not working? [https://discord.gg/kuYvMQ9 We can help]. Otherwise, enjoy!<br />
<br />
[[File:Mudlet running remotely.png |500px]]<br />
<br />
Note: When the codespace is unused for a while, it will disconnect. It'll never disconnect while you're actively using it. See [https://github.com/microsoft/vscode-dev-containers/issues/588 Github issue] for details.<br />
<br />
== Developing with Docker ==<br />
<br />
Docker is a system designed for more reproducible and isolated builds. A docker setup exists and has been tested using Pop OS! 20.04 (which is derived from Ubuntu 20.04). First, follow the instructions to install both [https://docs.docker.com/get-docker/ docker] and [https://docs.docker.com/compose/install/ docker-compose].<br />
<br />
Clone the development branch<br />
<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
cd Mudlet/docker<br />
<br />
Make a local copy of the .env.template file:<br />
<br />
cp .env.template .env<br />
<br />
If you wish to customize things like the number of cores to use for building mudlet, feel free to change the corresponding values in the .env file.<br />
<br />
To run Qt-Creator and develop Mudlet, simply run `docker-compose up dev`.<br />
To run Mudlet, simply run `docker-compose up mudlet`. Note: At the moment, the mudlet build will not persist settings past container rebuilds.<br />
<br />
== Compiling on Windows 7+ (MSYS2 Alternative)==<br />
<br />
''INCOMPLETE, IN PROGRESS''<br />
<br />
Go to http://www.msys2.org/ to download the 64 bit MSYS2 installer (as of 2020/05/24 32 bit hosts - for '''compiling''' software, but ''not'' for using code built with it have been deprecated, the last installer for that 32-bit systems is held at: http://repo.msys2.org/distrib/i686/msys2-i686-20200517.exe) and follow the installation instructions (Steps 1 to 8 on that page), these instructions assume that "C:\msys64" or "C:\msys32" is used depending on the bitness of the system it is being installed on.<br />
<br />
Install the following packages (using "pacman -S ''packageName''"), the ones with a '''-i686-''' in the middle are the ones for 32-bit (i686) targets and '''-x86_64-''' are the ones for 64-bit targets - it is possible to install both for building Mudlet for target PCs of both bitnesses on a 64-bit host, it is not clear whether the reverse is true with a 32-bit host. These will pull in a number of other required packages as well (the ''--needed'' option prevents the re-installation of packages that have already been installed by MSYS2/Mingw-w64's own setup/installation process) - as some of the packages, e.g. ''base-devel'' are actually ''groups'' you will be requested to select which members of that group are actually required, it is easiest to just go with the default which is to install ALL of the packages in that group!<br />
<br />
: For 32-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ pacman -S --needed base-devel git mercurial cvs wget ruby zip p7zip python mingw-w64-i686-toolchain mingw-w64-i686-qt-creator mingw-w64-i686-qt5-multimedia mingw-w64-i686-libzip mingw-w64-i686-pugixml mingw-w64-i686-lua51 mingw-w64-i686-lua51-lpeg mingw-w64-i686-lua51-lsqlite3 mingw-w64-i686-hunspell mingw-w64-i686-boost mingw-w64-i686-yajl mingw-w64-i686-clang mingw-w64-i686-cmake mingw-w64-i686-SDL unzip<br />
</syntaxhighlight><br />
<br />
: For 64-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ pacman -S --needed base-devel git mercurial cvs wget ruby zip p7zip python mingw-w64-x86_64-toolchain mingw-w64-x86_64-qt-creator mingw-w64-x86_64-qt5-multimedia mingw-w64-x86_64-libzip mingw-w64-x86_64-pugixml mingw-w64-x86_64-lua51 mingw-w64-x86_64-lua51-lpeg mingw-w64-x86_64-lua51-lsqlite3 mingw-w64-x86_64-hunspell mingw-w64-x86_64-boost mingw-w64-x86_64-yajl mingw-w64-x86_64-clang mingw-w64-x86_64-cmake mingw-w64-x86_64-SDL unzip<br />
</syntaxhighlight><br />
<br />
::The ''*-zziplib'' libraries are used by the ''luazip'' luarock {from the Kepler project} but Mudlet will work perfectly well with the alternative ''lua-zip'' {from the brimworks GitHub repository - which also provides the ''lua-yajl'' rock} which does not require this library - although it is possible that it might still be pulled into the system as a dependency of another MSYS2 package.<br />
<br />
:Note that this will install the MSYS2 builds of the Qt Libraries and Creator IDE - ''THE ON/OFF-LINE INSTALLER OF THE QT LIBRARIES AND CREATOR VIA DOWNLOADS FROM QT ARE NOT USEFUL IN THIS SETUP!''<br />
<br />
:{| class="wikitable"<br />
|-<br />
|'''Attention - Luarocks packages problem'''<br />
|-<br />
| Recently the Luarocks project attempted to adopt the MSYS2/Mingw-w64 platform as one it would supported natively and the MSYS2/Mingw-w64 project went and upgraded its luarocks packages to make use of the changes and also on-board other improvements (and the version number increased from ''2.4.4-2'' to ''3.5.0-1'') unfortunately this completely broke them and although the issue has been reported ([https://github.com/msys2/MINGW-packages/issues/9037 MSYS2 Issue 9037]) a fix has not yet materialised. The only way to work around this in the meantime is to download the older package (with '''wget''') and install it manually (with '''pacman -U):<br />
|-<br />
|For 32-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ wget https://repo.msys2.org/mingw/mingw32/mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
--2021-07-07 22:19:09-- https://repo.msys2.org/mingw/mingw32/mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
Resolving repo.msys2.org (repo.msys2.org)... 178.63.98.68<br />
Connecting to repo.msys2.org (repo.msys2.org)|178.63.98.68|:443... connected.<br />
HTTP request sent, awaiting response... 200 OK<br />
Length: 97905 (96K) [application/octet-stream]<br />
Saving to: ‘mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’<br />
<br />
mingw-w64-i686-lua51-luarocks-2.4.4-2- 100%[===========================================================================>] 95.61K --.-KB/s in 0.07s<br />
<br />
2021-07-07 22:19:10 (1.43 MB/s) - ‘mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’ saved [97905/97905]<br />
<br />
<br />
MSYS user@computer ~<br />
$ pacman -U mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
loading packages...<br />
resolving dependencies...<br />
looking for conflicting packages...<br />
<br />
Packages (1) mingw-w64-i686-lua51-luarocks-2.4.4-2<br />
<br />
Total Installed Size: 0.46 MiB<br />
<br />
:: Proceed with installation? [Y/n] y<br />
(1/1) checking keys in keyring [#####################################################] 100%<br />
(1/1) checking package integrity [#####################################################] 100%<br />
(1/1) loading package files [#####################################################] 100%<br />
(1/1) checking for file conflicts [#####################################################] 100%<br />
(1/1) checking available disk space [#####################################################] 100%<br />
:: Processing package changes...<br />
(1/1) installing mingw-w64-i686-lua51-luarocks [#####################################################] 100%<br />
<br />
MSYS user@computer ~<br />
</syntaxhighlight><br />
|-<br />
|For 64-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ wget https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
--2021-07-07 22:17:32-- https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
Resolving repo.msys2.org (repo.msys2.org)... 178.63.98.68<br />
Connecting to repo.msys2.org (repo.msys2.org)|178.63.98.68|:443... connected.<br />
HTTP request sent, awaiting response... 200 OK<br />
Length: 97935 (96K) [application/octet-stream]<br />
Saving to: ‘mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’<br />
<br />
mingw-w64-x86_64-lua51-luarocks-2.4.4- 100%[===========================================================================>] 95.64K --.-KB/s in 0.07s<br />
<br />
2021-07-07 22:17:32 (1.28 MB/s) - ‘mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’ saved [97935/97935]<br />
<br />
<br />
MSYS user@computer ~<br />
$ pacman -U mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
loading packages...<br />
resolving dependencies...<br />
looking for conflicting packages...<br />
<br />
Packages (1) mingw-w64-x86_64-lua51-luarocks-2.4.4-2<br />
<br />
Total Installed Size: 0.46 MiB<br />
<br />
:: Proceed with installation? [Y/n] y<br />
(1/1) checking keys in keyring [#####################################################] 100%<br />
(1/1) checking package integrity [#####################################################] 100%<br />
(1/1) loading package files [#####################################################] 100%<br />
(1/1) checking for file conflicts [#####################################################] 100%<br />
(1/1) checking available disk space [#####################################################] 100%<br />
:: Processing package changes...<br />
(1/1) installing mingw-w64-x86_64-lua51-luarocks [#####################################################] 100%<br />
<br />
MSYS user@computer ~<br />
</syntaxhighlight><br />
|}<br />
<br />
::{| class="wikitable"<br />
|-<br />
|'''Warning for those planning to build ''both'' 32 and 64 bit versions'''<br />
|-<br />
|If one is planning to build ''both'' bitness binaries an additional step is necessary as, by default, the MSYS2/Mingw-w64 ''luarocks'' setup seems to place any ''.lua'' or ''.dll'' modules it builds/installs on a per user (the so-called ''local'' basis) into the same directories with the same names. This is no good for two reasons:<br />
* It is difficult to work out which bitness a particular module is for and whilst 32-bit modules ''might'' work in a 64-bit environment the reverse is definitely not the case<br />
* It confuses the Luarocks package management systems (as effectively there will be two different luarocks systems operated side-by-side)<br />
<br />
This can be worked around by:<br />
* Editing the '''.\etc\luarocks\config-5.1.lua''' for each bitness so that the ''rocks_trees'' table entry for the ''user'' key is changed from this in '''both''' files:<br />
:<syntaxhighlight lang="lua"> { name = [[user]], root = home..[[/.luarocks]] },</syntaxhighlight><br />
to something different for each of them, say, for example, for the the 64-bit one:<br />
:<syntaxhighlight lang="lua"> { name = [[user]], root = home..[[/.luarocks-x64]] },</syntaxhighlight><br />
* Then by specifying the ''rocktree'' name ('''user''') on the command line when '''installing''' or '''building''' a luarock with the ''--tree user'' argument - note that for some inexplicable reason the ''--local'' argument that '''''should''''' do the same thing does not seem to work for these two actions, it is not clear whether this is a MSYS2/Mingw-w64 specific issue or it goes further upstream to Luarocks in general. Thus, in the next step it will be necessary to change from using:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install --local rockname<br />
</syntaxhighlight><br />
to, for the example given:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install --tree user rockname<br />
</syntaxhighlight><br />
where ''user'' is the literal string "user" to match the Lua table key in the rock_trees and not, in this case, a representation of the user-name/account of the person performing the action.<br />
|}<br />
<br />
From the Windows ''Start menu'' start a shell appropriate for the target with the bitness to be built for i.e. '''"MSYS2 Mingw 32-Bit"''' or '''"MSYS2 Mingw 64-Bit"'''. This will likely position the current directory to the root directory of the MSYS2 environment, the text about the prompt line (the one with the "$") will contain three different bits of colored text '''username@computername'''; one of '''MSYS2'''/'''MINGW32'''/'''MINGW''' depending on the type of shell you currently in use and '''/''' representing the root directory (which will actually be the directory MSYS2 was installed to, for example on the author's system this is "C:/msys64"). Change to the home directory in MYSY by entering "cd" on its own with no argument (it will show up as '''~''' and it would work out to be, for '''user''' to be '''c:/msys64/home/user''' or '''c:/msys32/home/user''' (if both bitnessess are to be built it will be necessary to repeat the following step twice, one for each and also observe the steps in the above warning) install the following luarocks:<br />
<br />
:{| class="wikitable sortable"<br />
|-<br />
! rockname<br />
|-<br />
| lrexlib-pcre<br />
|-<br />
| lua-yajl<br />
|-<br />
| luafilesystem<br />
|-<br />
| luasql-sqlite3<br />
|-<br />
| luautf8<br />
|-<br />
| luazip or lua-zip<br />
|}<br />
by using:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install [--local] rockname<br />
</syntaxhighlight><br />
The ''--local'' argument is an optional one that causes the luarock and the lua module to be installed on a per-user basis rather than on a system wide one, this may be important if the PC is used by multiple users and more than one of them uses Lua in any form.<br />
<br />
Now create somewhere to work on the Mudlet source, assuming that other software coding with other pieces of software will be done, create a sub-directory in the home directory, and then make one just for Mudlet under that:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ mkdir ./src<br />
<br />
MINGW64 user@computer ~<br />
$ mkdir ./src/mudlet<br />
</syntaxhighlight><br />
<br />
Change to that directory and get the source code:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ cd ./src/mudlet<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git clone git://github.com/Mudlet/Mudlet.git .<br />
</syntaxhighlight><br />
<br />
If you are planning to contribute to the Mudlet code you will want to visit Github and create your own GitHub repository, you can then push commits (changes to the code) to there and raise a Pull Request for a Mudlet Maker to drag the changes over to the above repository. You will want to add your repository and perhaps those of some other contributors so you can track what they are doing and see/try/experiment with their PRs before they get merged. Therefore you will want to add some other repositories into the mix. The names you use to identify those other repositories will show up in any utility that works with the repository you have just created in the above "clone" operation and can be anything you like but it makes sense to have clear names. So to add "myName", and those of the leading active contributors to the Mudlet codebase you will use:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Mine https://github.com/myName/Mudlet.git<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Vadim https://github.com/vadi2/Mudlet.git <br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add SlySven https://github.com/SlySven/Mudlet.git<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Kebap https://github.com/Kebap/Mudlet.git<br />
</syntaxhighlight><br />
<br />
Now obtain ''all'' the versions of the code with:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ git fetch --all<br />
</syntaxhighlight><br />
<br />
This will produce a lot of lines of output the first time and it might take a little while on a slow connection...<br />
<br />
{Section missing - it turns out that the default GUI git tools that the author of this section would normally use: "gitk" and "git gui" have some problems in the versions currently supplied from the MSYS2 system - and it was necessary to import them from the set that the Git4Win have patched - see https://github.com/git-for-windows/git/wiki/Install-inside-MSYS2-proper }<br />
<br />
Some modifications to the qmake/cmake project files are needed and these are now supported in the main ''development'' branch in the upstream {the Mudlet organisation's own GitHub repository} which requires that there is an environmental variable '''WITH_MAIN_BUILD_SYSTEM''' and it is set to the (case-insensitive) value '''NO''':<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ export WITH_MAIN_BUILD_SYSTEM=NO<br />
</syntaxhighlight><br />
<br />
Also the '''MINGW_BASE_DIR''' environmental variable will need to be set to the root directory for the MINGW-W64 installation for the appropriate bitness of the target to be made. For building on a 64-Bit Host {the PC that is ''compiling'' the code} to make a 64-Bit application this will likely be '''C:/msys64/mingw64''' and for a 32-Bit application it will probably be '''C:/msys64/ming32'''.<br />
: E.g. <syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ export MINGW_BASE_DIR=C:/msys64/mingw64 # To build a 64-Bit Application with a 64-Bit system<br />
</syntaxhighlight><br />
<br />
: Or: <syntaxhighlight lang="shell"><br />
MINGW32 user@computer ~/src/mudlet<br />
$ export MINGW_BASE_DIR=C:/msys64/mingw32 # To build a 32-Bit Application with a 64-Bit system<br />
</syntaxhighlight><br />
<br />
Now checkout a branch {ideally, if working on solving a new issue, or adding a feature or resolving a bug, one should create a new branch that is a copy of the current, upstream ''development'' branch} and then work on it with Qt Creator:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ qtcreator &<br />
</syntaxhighlight><br />
<br />
Load in the '''mudlet.pro''' ''qmake'' project file in the '''src''' subdirectory (e.g. for this example: '''c:/msys64/home/user/src/mudlet/src/mudlet.pro''') and get hacking...<br />
<br />
= Setting up IDEs =<br />
== CLion ==<br />
=== Qt not detected ===<br />
If you'd like to use CLion and it is giving the following error:<br />
<br />
<nowiki><br />
By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has<br />
asked CMake to find a package configuration file provided by "Qt5Core", but<br />
CMake did not find one.<br />
<br />
...<br />
</nowiki><br />
<br />
You can fix this by setting <code>-DCMAKE_PREFIX_PATH=<your Qt + version + compiler location></code>. For example: <code>-DCMAKE_PREFIX_PATH=/media/vadi/SSDer/Programs/Qt/5.15.2/gcc_64/</code> [[File:CLion CMake settings - finidng Qt.png|700px|none]]<br />
<br />
=== CLion setup on Windows ===<br />
After running <code>setup-windows-sdk.ps1</code> make sure to set Cmake options to:<br />
-DCMAKE_PREFIX_PATH=C:\Qt\Tools\mingw730_32;C:\Qt\5.14.2\mingw73_32 -DBoost_INCLUDE_DIR=C:\Libraries\boost_1_71_0<br />
''Directories might vary slightly, when different Qt, Boost or MinGW version will be used.''<br />
<br />
[[File:Clion Settings - Cmake.png|frameless|700x700px]]<br />
<br />
<br />
<br />
You will need 32 bit version of MinGW. Set it in the <code>Toolset</code> field to:<br />
C:\Qt\Tools\mingw730_32<br />
<br />
''Directory may be slightly different if MinGW version used will change.''<br />
[[File:Toolchain.png|frameless|700x700px]]<br />
<br />
=== Clang Tidy ===<br />
Ensure that CLion is set to run the project's [https://www.jetbrains.com/help/clion/clang-tidy-checks-support.html#paticularcheck .clang-tidy checks] with the <code>Prefer .clang-tidy files over IDE settings</code> option:<br />
<br />
[[File:Clang Tidy CLIon.png|700px|none]]<br />
<br />
This helps us catch any issues just a bit earlier.<br />
<br />
=== Clang Format ===<br />
Ensure that [https://www.jetbrains.com/help/clion/clangformat-as-alternative-formatter.html#clion-support CLion is set to use] the <code>.clang-format</code> formatting style:<br />
<br />
[[File:Clang-format CLion.png]]<br />
<br />
This helps keep the look'n'feel of the source code in a consistent manner, even with many people contributing to Mudlet.<br />
<br />
== Visual Studio Code ==<br />
<br />
To set the path in Visual Studio Code, open settings, search for <code>cmake environment</code> and set the <code>CMAKE_PREFIX_PATH</code> to your path, such as <code>/media/vadi/SSDer/Programs/Qt/5.14.1/gcc_64/</code>:<br />
<br />
[[File:CMake path in Visual Studio Code.png|none]]<br />
<br />
===Clang Tidy===<br />
clang-tidy catches common programming issues, run it by selecting 'Analysis' from the command palette (Ctrl+Shift+P by default):<br />
<br />
[[File:Clang-tidy in vscode.png|none]]<br />
<br />
It is also possible [https://devblogs.microsoft.com/cppblog/visual-studio-code-c-december-2021-update-clang-tidy/ check status of analysis and cancel if needed].<br />
<br />
===Checking memory leaks & other issues (sanitizers)===<br />
Besides clang-tidy, it's also possible to enable clang sanitizers to double-check for issues:<br />
<br />
* [https://clang.llvm.org/docs/LeakSanitizer.html LeakSanitizer] for detecting memory leaks<br />
* [https://clang.llvm.org/docs/AddressSanitizer.html AddressSanitizer] for detecting most issues dealing with memory, such as out of bounds accesses to heap, stack, global and more<br />
* [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html UndefinedBehaviourSanitizer] for detecting the use of various features of C/C++ that are explicitly listed as resulting in undefined behaviour (such as using misaligned or null pointer, conversion to, from, or between floating-point types which would overflow the destination, division by zero, etc)<br />
* [https://clang.llvm.org/docs/MemorySanitizer.html MemorySanitizer] for detecting reading uninitialised memory<br />
* [https://clang.llvm.org/docs/ThreadSanitizer.html ThreadSanitizer] for detecting threading issues<br />
<br />
To use the sanitisers, set the <code>USE_SANITIZER</code> CMake variable to one or several variables (separate by comma): <code>Address</code>, <code>Memory</code>, <code>MemoryWithOrigins</code>, <code>Undefined</code>, <code>Thread</code>, or <code>Leak</code><br />
<br />
To use them in VSCode, set the <code>cmake.configureSettings</code> variable:<br />
<br />
[[File:Cmake.configureSettings option in vscode.png|frameless|890x890px]]<br />
<br />
[[File:Choosing which sanitizers in vscode to use.png|frameless|891x891px]]<br />
<br />
Not all sanitisers can be used with each other - in that case the cmake configuration won't allow you to continue.<br />
<br />
== Qt Creator==<br />
===Clang Tidy and Clazy===<br />
<br />
Configure Mudlet-specific checks for [https://clang.llvm.org/extra/clang-tidy/ clang-tidy] and [https://github.com/KDE/clazy clazy] tools help catch any issues early on. See [https://doc.qt.io/qtcreator/creator-clang-tools.html Qt Creator's instructions] for setting this up - clang-tidy can use the <code>.clang-tidy</code> file that's available at the root of the repository, and for clazy enable <code>level0</code> and <code>level1</code> checks.<br />
<br />
[[File:Clang tidy configuration.png|frame|none]]<br />
[[File:Clazy configuration.png|frame|none]]<br />
<br />
===Checking memory leaks & other issues (sanitizers)===<br />
Besides clang-tidy, it's also possible to enable clang sanitizers to double-check for issues:<br />
<br />
* [https://clang.llvm.org/docs/LeakSanitizer.html LeakSanitizer] for detecting memory leaks<br />
* [https://clang.llvm.org/docs/AddressSanitizer.html AddressSanitizer] for detecting most issues dealing with memory, such as out of bounds accesses to heap, stack, global and more<br />
* [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html UndefinedBehaviourSanitizer] for detecting the use of various features of C/C++ that are explicitly listed as resulting in undefined behaviour (such as using misaligned or null pointer, conversion to, from, or between floating-point types which would overflow the destination, division by zero, etc)<br />
* [https://clang.llvm.org/docs/MemorySanitizer.html MemorySanitizer] for detecting reading uninitialised memory<br />
* [https://clang.llvm.org/docs/ThreadSanitizer.html ThreadSanitizer] for detecting threading issues<br />
<br />
To use the sanitisers, set the <code>USE_SANITIZER</code> CMake variable to one or several variables (separate by comma): <code>Address</code>, <code>Memory</code>, <code>MemoryWithOrigins</code>, <code>Undefined</code>, <code>Thread</code>, or <code>Leak</code><br />
<br />
To use them in Qt creator, head to <code>Projects</code> - <code>Build</code>: <br />
<br />
[[File:Sanitisers in qt creator.png|frameless|890x890px]]<br />
<br />
Not all sanitisers can be used with each other - in that case the cmake configuration won't allow you to continue.<br />
<br />
==Clang Format==<br />
Ensure that Qt Creator is set to use the <code>.clang-format</code> formatting style in the C++ settings. Turn on <code>Format instead of indenting</code> for <code>Ctrl+I</code> to format code, and ensure <code>Override Clang Format configuration file</code> is disabled:<br />
<br />
[[File:Qt Creator clang format.png]]<br />
<br />
This helps keep the look'n'feel of the source code in a consistent manner, even with many people contributing to Mudlet.<br />
<br />
<br />
=Building with multiple versions of Lua=<br />
Mudlet uses Lua 5.1 only, so if you are compiling on a system that also has later versions installed, you might get the following error: <code>‘LUA_GLOBALSINDEX’ was not declared in this scope</code>.<br />
<br />
To fix this, pass the path to Lua headers explicitly. For CMake: <code>-DLUA_INCLUDE_DIR=/usr/include/lua5.1</code> (adjust as needed).</div>Dargothhttps://wiki.mudlet.org/index.php?title=Compiling_Mudlet&diff=19772Compiling Mudlet2022-01-19T23:11:58Z<p>Dargoth: /* Setup on Windows */</p>
<hr />
<div>{{TOC right}}<br />
<br />
If you just want to use Mudlet, you can skip these steps, and use one of the already ready (pre-compiled) installers [https://www.mudlet.org/download ready for download].<br />
<br />
Otherwise, hop in for new adventure! <br />
<br />
[[File:Easy Mudlet code understanding.png|frame|none]]<br />
<br />
= Key contributing information =<br />
<br />
Clang format is used to automatically format code submissions using the [https://github.com/Mudlet/Mudlet/blob/development/src/.clang-format src/.clang-format] style. [http://doc.qt.io/qtcreator/creator-beautifier.html See here] how to enable clang-format with Qt Creator - and make sure to specify the 'File' option for the configuration style.<br />
<br />
Branches:<br />
<br />
'''development''' is the development branch where new features can go.<br />
<br />
Workflow:<br />
<br />
Fork and submit a PR with your changes ([https://guides.github.com/activities/forking/ Github tutorial]).<br />
<br />
Here is a list of package versions delivered with different Linux distros. You may want to upgrade these: <br />
https://repology.org/project/mudlet/versions<br />
<br />
= Compiling =<br />
<br />
== Compiling on Ubuntu ==<br />
<br />
These instructions will get you setup compiling on Ubuntu. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
===Ubuntu 21.10===<br />
Following instructions will work on Ubuntu 21.10 as well as all it's flavours and derivatives (such as KDE Neon, for example)<br />
Important thing is to have ''Universe'' repository enabled in your package manager. (on Ubuntu you will have all the repositories that you need already enabled by default.)<br />
<br />
'''1. necessary dependencies'''<br />
<br />
Majority of required dependencies can be obtained from repositories, and can be installed with following command:<br />
<br />
sudo apt install ubuntu-restricted-extras qtcreator build-essential git zlib1g-dev libhunspell-dev \<br />
libpcre3-dev libzip-dev libboost-dev libboost-all-dev libyajl-dev libpulse-dev libpugixml-dev \<br />
liblua5.1-0-dev lua-filesystem lua-zip lua-sql-sqlite3 luarocks ccache lua-rex-pcre lua5.1 \<br />
libglu1-mesa-dev mesa-common-dev libglib2.0-dev libgstreamer1.0-dev libqt5opengl5-dev \<br />
qtmultimedia5-dev qttools5-dev qt5keychain-dev libsecret-1-dev \<br />
libqt5texttospeech5-dev qtspeech5-flite-plugin qtspeech5-speechd-plugin \<br />
qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtmultimedia5-dev<br />
<br />
Few of required Lua modules are not available in official repositories, so they have to be installed using ''luarocks''<br />
sudo luarocks install lcf<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''2. obtaining the source code'''<br />
<br />
If you're compiling Mudlet from source for everyday use with few more features that are not present in official AppImage, it is strongly advised that you obtain and compile the source code latest ''stable'' release of Mudlet. At the moment of writing this article, current stable version is 4.10.1, you'll need to adjust version number if new release comes out at later date.<br />
mkdir build && cd build<br />
wget https://www.mudlet.org/wp-content/files/Mudlet-4.10.1.tar.xz<br />
tar xvf Mudlet-4.10.1.tar.xz<br />
cd src<br />
<br />
However, if you're feeling adventurous and wish to play with the latest development code, you can obtain it directly from Mudlet's Git repository:<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
mkdir Mudlet/build<br />
cd Mudlet/build<br />
<br />
'''3. compiling the code'''<br />
<br />
There below are two ways to build with qmake, the first is for general use, the second is for developers:<br />
qmake ../src/mudlet.pro<br />
'''*OR*'''<br />
qmake CONFIG+=debug ../src/mudlet.pro<br />
<br />
'''Now finish compiling:'''<br />
make -j `nproc`<br />
<br />
4. '''installing compiled code'''<br />
<br />
After successful code compilation, next few commands will install resulting binaries, desktop file for menus and appropriate icon.<br />
sudo make install<br />
sudo cp ../mudlet.png /usr/share/pixmaps<br />
sudo cp ../mudlet.desktop /usr/share/applications<br />
<br />
5. '''optional additional software'''<br />
<br />
One of the major reasons for compiling Mudlet from source is the ability to unlock more features that are not enabled in official AppImage.<br />
Manual compilation will resolve the issues with sound by using system provided libraries, as well as enable more detailed theming of Mudlet application itself.<br />
However, do take note that Mudlet is a Qt based program, and that theming will not 'just work' in GTK based desktop environments (Gnome, XFCE, MATE, Budgie).<br />
sudo apt install qt5ct<br />
will install a tool for configuration of look and feel of Qt programs inside those desktop environments.<br />
Users of Qt based Desktop environments (KDE Plasma, LXQT) can simply use settings provided by environment itself.<br />
<br />
Many of Qt widget styles and color schemes are available in official repositories, and will make Mudlet better.<br />
<br />
6. '''Mudlet on Wayland'''<br />
<br />
Mudlet compiled like this will run and work on Wayland, however, there are a few quirks with Keybidings (Numpad may not work as expected).<br />
Until that is resolved you may wish to start mudlet with:<br />
QT_QPA_PLATFORM=xcb mudlet<br />
(enter in terminal or simply change the Exec= line in /usr/share/applications/mudlet.desktop)<br />
<br />
7. '''uninstallation'''<br />
<br />
You can reverse the process described in this guide with following command:<br />
<br />
sudo rm -fr /usr/bin/mudlet /usr/share/mudlet /usr/share/applications/mudlet.desktop /usr/share/pixmaps/mudlet.png<br />
<br />
===Ubuntu 20.10===<br />
Following instructions will work on Ubuntu 20.10 as well as all it's flavours and derivatives (such as KDE Neon, for example)<br />
Important thing is to have ''Universe'' repository enabled in your package manager.<br />
<br />
1. '''necessary dependencies'''<br />
<br />
Majority of required dependencies can be obtained from repositories, and can be installed with following command:<br />
<br />
sudo apt install qtcreator build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev libzip-dev libboost-dev libboost-all-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev lua5.1 libqt5opengl5-dev libglu1-mesa-dev mesa-common-dev libglib2.0-dev libgstreamer1.0-dev qt5keychain-dev libsecret-1-dev libqt5texttospeech5-dev qtspeech5-flite-plugin qtspeech5-speechd-plugin<br />
<br />
Few of required Lua modules are not available in official repositories, so they have to be installed using ''luarocks'' <br />
sudo luarocks install lcf<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
2. '''obtaining the source code'''<br />
<br />
If you're compiling Mudlet from source for everyday use with few more features that are not present in official AppImage, it is strongly advised that you obtain and compile the source code latest ''stable'' release of Mudlet. At the moment of writing this article, current stable version is 4.10.1, you'll need to adjust version number if new release comes out at later date.<br />
mkdir build && cd build<br />
wget https://www.mudlet.org/wp-content/files/Mudlet-4.10.1.tar.xz<br />
tar xvf Mudlet-4.10.1.tar.xz<br />
cd src<br />
<br />
However, if you're feeling adventurous and wish to play with the latest development code, you can obtain it directly from Mudlet's Git repository:<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
cd Mudlet/src/<br />
<br />
3. '''compiling the code'''<br />
<br />
Following commands will configure the code to install Mudlet on a system level and compile it.<br />
If you wish to install it somewhere else, you may adjust both paths in following command to point to desired destination before compiling it with make. (Rest of this guide will assume you're installing on a system level)<br />
WITH_FONTS=NO WITH_OWN_QTKEYCHAIN=NO WITH_UPDATER=NO WITH_VARIABLE_SPLASH_SCREEN=NO XDG_DATA_DIRS=/usr/share qmake PREFIX=/usr<br />
make -j `nproc`<br />
<br />
4. '''compiling on Ubuntu for Raspberry Pi'''<br />
<br />
Ubuntu for Raspberry Pi is essentially the same as Ubuntu for regular PC, however, due to sketchy state of OpenGL drivers on RPi 4, you'll likely need to disable Mudlet's 3D Mapper or code will just not compile. Adjusted commands are:<br />
WITH_3DMAPPER=NO WITH_FONTS=NO WITH_OWN_QTKEYCHAIN=NO WITH_UPDATER=NO WITH_VARIABLE_SPLASH_SCREEN=NO XDG_DATA_DIRS=/usr/share qmake PREFIX=/usr<br />
make<br />
<br />
5. '''installing compiled code'''<br />
<br />
After successful code compilation, next few commands will install resulting binaries, desktop file for menus and appropriate icon.<br />
sudo make install<br />
sudo cp ../mudlet.png /usr/share/pixmaps<br />
sudo cp ../mudlet.desktop /usr/share/applications<br />
<br />
6. '''optional additional software'''<br />
<br />
One of the major reasons for compiling Mudlet from source is the ability to unlock more features that are not enabled in official AppImage.<br />
Manual compilation will resolve the issues with sound by using system provided libraries, as well as enable more detailed theming of Mudlet application itself.<br />
However, do take note that Mudlet is a Qt based program, and that theming will not 'just work' in GTK based desktop environments (Gnome, XFCE, MATE, Budgie).<br />
sudo apt install qt5ct<br />
will install a tool for configuration of look and feel of Qt programs inside those desktop environments.<br />
Users of Qt based Desktop environments (KDE Plasma, LXQT) can simply use settings provided by environment itself.<br />
<br />
Many of Qt widget styles and color schemes are available in official repositories, and will make Mudlet better.<br />
<br />
7. '''Mudlet on Wayland'''<br />
<br />
Mudlet compiled like this will run and work on Wayland, however, there are a few quirks with Keybidings (Numpad may not work as expected). <br />
Until that is resolved you may wish to start mudlet with:<br />
QT_QPA_PLATFORM=xcb mudlet<br />
(enter in terminal or simply change the Exec= line in /usr/share/applications/mudlet.desktop)<br />
<br />
8. '''uninstallation'''<br />
<br />
You can reverse the process described in this guide with following command:<br />
<br />
sudo rm -fr /usr/bin/mudlet /usr/share/mudlet /usr/share/applications/mudlet.desktop /usr/share/pixmaps/mudlet.png<br />
<br />
===Ubuntu 18.04 setup===<br />
<br />
For Ubuntu 18.04 see the instructions for [[#Compiling_on_Debian_9_.27Stretch.27|Compiling on Debian 9 'Stretch']] (tested working perfectly).<br />
<br />
<br />
'''1. Ubuntu 18.04 setup'''<br />
<br />
If you're on Ubuntu 18.04 (Bionic Beaver), install the following. If you're on a newer Ubuntu, skip this step and go to ''2. Install dependencies''.<br />
<br />
sudo add-apt-repository ppa:beineri/opt-qt-5.12.3-bionic<br />
sudo apt update<br />
sudo apt install qt512-meta-full qt512creator<br />
source /opt/qt512/bin/qt512-env.sh<br />
<br />
'''2. Install dependencies'''<br />
<br />
sudo apt install git build-essential qt5-default qtmultimedia5-dev qttools5-dev \<br />
lua5.1 liblua5.1-0-dev libpcre3-dev libboost-dev zlib1g-dev cmake \<br />
libhunspell-dev lua-rex-pcre lua-sql-sqlite3 lua-filesystem lua-zip libyajl-dev \<br />
libzip-dev libgstreamer0.10-0 libglu1-mesa-dev ccache libpugixml-dev \<br />
mesa-common-dev qtcreator libpulse-dev libglib2.0-dev luarocks libboost-all-dev \<br />
libsecret-1-dev<br />
sudo apt install gstreamer0.10-fluendo-mp3 # may not work on newer Ubuntu<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''3. Get Mudlet source'''<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''4. Create a build directory'''<br />
<br />
cd mudlet<br />
mkdir build<br />
cd build<br />
<br />
'''5. Run the following commands, depending on which build system you want to use '''<br />
<br />
'''EITHER:'''<br />
<br />
cmake ..<br />
<br />
'''OR:'''<br />
<br />
qmake CONFIG+=debug ../src/mudlet.pro<br />
<br />
'''THEN:'''<br />
<br />
make -j `nproc`<br />
<br />
'''5. Start the application you have just compiled - enjoy'''<br />
<br />
cd src<br />
./mudlet<br />
<br />
== Compiling on Chrome OS ==<br />
<br />
These instructions will get you setup compiling on Chrome OS. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
'''1. Install dependencies'''<br />
<br />
sudo apt install git build-essential qt5-default qtmultimedia5-dev qttools5-dev \<br />
lua5.1 liblua5.1-0-dev libpcre3-dev libboost-dev zlib1g-dev cmake \<br />
libhunspell-dev lua-rex-pcre lua-sql-sqlite3 lua-filesystem lua-zip libyajl-dev \<br />
libzip-dev libglu1-mesa-dev ccache libpugixml-dev mesa-common-dev qtcreator \<br />
libpulse-dev libglib2.0-dev luarocks libboost-all-dev libsecret-1-dev \<br />
ninja-build libsecret-1-dev<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''3. Get Mudlet source'''<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''4. Create a build directory'''<br />
<br />
cd mudlet<br />
mkdir build && cd build<br />
<br />
'''5. Run the following command '''<br />
<br />
cmake .. -G Ninja<br />
<br />
'''then:'''<br />
<br />
ninja<br />
<br />
'''5. Start the application you have just compiled - enjoy'''<br />
<br />
src/mudlet<br />
{{Note}}Did <code>ninja</code> fail with <code>c++: fatal error: Killed signal terminated program cclplus</code>? Try again with <code>ninja -j 2</code><br />
<br />
== Compiling on macOS ==<br />
<br />
These instructions will get you setup compiling on macOS. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord server] or [http://forums.mudlet.org/viewforum.php?f=7 forums] otherwise.<br />
<br />
<br />
'''1. Install prerequisites'''<br />
<br />
Install [https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12 XCode], command line tools for XCode, and [http://brew.sh HomeBrew].<br />
<br />
Once everything is installed, do:<br />
<br />
brew doctor<br />
brew update<br />
brew install git<br />
<br />
'''2. Get Mudlet source'''<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git <br />
<br />
'''3. Go to the parent of the mudlet "src" folder and create (if necessary) a build subdirectory (this is so that we can build out of source which keeps the source code clean)'''<br />
cd Mudlet && mkdir build<br />
<br />
'''3. Setup your environment'''<br />
./CI/travis.osx.before_install.sh<br />
./CI/travis.osx.install.sh<br />
<br />
luarocks config lua_version 5.1<br />
eval `luarocks path --lua-version=5.1`<br />
For the following, one may have to add <code>''_DIR="/opt/homebrew/"''</code> such as <code>PCRE_DIR="/opt/homebrew/"</code> or <code>ZIP_DIR="/opt/homebrew/"</code> if the installation could not find header files.<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lrexlib-pcre<br />
brew install sqlite<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luasql-sqlite3 SQLITE_DIR=`brew --prefix sqlite` <br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luautf8<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lua-yajl<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luafilesystem<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lua-zip<br />
<br />
brew install p7zip<br />
export BOOST_ROOT="$(pwd)/../Mudlet/3rdparty/boost"<br />
export BOOST_URL="https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2/download"<br />
mkdir -p $BOOST_ROOT<br />
curl --progress-bar --location --output $BOOST_ROOT/download.tar.bz2 $BOOST_URL<br />
7z -o$BOOST_ROOT x $BOOST_ROOT/download.tar.bz2 -y -bd<br />
7z -o$BOOST_ROOT x $BOOST_ROOT/download.tar -y -bd<br />
cd $BOOST_ROOT && cp -r boost_*/* .<br />
rm -rf boost_*/* download.tar.bz2 download.tar<br />
OK to answer yes to delete files if prompted for the <code>rm</code> command above.<br />
<br />
'''4. Run the following commands'''<br />
<br />
cd ../../build<br />
cmake ../../Mudlet -DCMAKE_PREFIX_PATH=`brew --prefix qt5`<br />
make -j `sysctl -n hw.ncpu`<br />
<br />
<br />
'''5. Enjoy'''<br />
<br />
The mudlet.app is now available in <code>src/</code> for launching:<br />
<br />
open src/Mudlet.app<br />
<br />
== Compiling on Debian 'Sid' ==<br />
<br />
'''1. Install required packages from main repo.'''<br />
<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev<br />
<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''2. Grab latest Mudlet source.'''<br />
<br />
mkdir ~/projects && cd ~/projects && git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''3. Build Mudlet.'''<br />
<br />
cd ~/projects/mudlet/src<br />
<br />
qmake<br />
<br />
make<br />
<br />
sudo make install<br />
<br />
== Compiling on Debian 11 'Bullseye' ==<br />
<br />
'''1. Install required packages.'''<br />
<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtmultimedia5-dev \<br />
qttools5-dev luarocks ccache libpugixml-dev libqt5texttospeech5-dev qtspeech5-flite-plugin \<br />
qtspeech5-speechd-plugin libqt5opengl5-dev<br />
<br />
sudo luarocks install luautf8 <br />
sudo luarocks install lua-yajl<br />
<br />
'''2. Get Mudlet source.'''<br />
<br />
mkdir ~/source && cd ~/source<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git<br />
<br />
Note: the line above will check out `development` branch source code, and this might not always be stable. You can check out the latest release source code using this command:<br />
<br />
git clone --recursive --branch main https://github.com/Mudlet/Mudlet.git<br />
<br />
'''3. Build Mudlet.'''<br />
<br />
mkdir ~/source/Mudlet/build && cd ~/source/Mudlet/build<br />
<br />
qmake ../src/mudlet.pro<br />
<br />
make -j `nproc`<br />
<br />
sudo make install<br />
<br />
After these steps you can run Mudlet by typing:<br />
<br />
mudlet<br />
<br />
== Compiling on Raspberry Pi OS ==<br />
<br />
These instructions will get you compiling and running Mudlet on Raspberry Pi OS (Buster). Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
''' 1.a Install apt dependencies '''<br />
<br />
sudo apt-get update<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-graph-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev cmake<br />
<br />
<br />
[[File:Apt-get-install-y-n.png|center|thumb|installing apt dependencies]]<br />
<br />
''' 1.b Install luarocks dependencies '''<br />
<br />
sudo luarocks install luautf8 <br />
sudo luarocks install lua-yajl YAJL_LIBDIR=/usr/lib/arm-linux-gnueabihf/ YAJL_INCDIR=/usr/include<br />
<br />
<br />
[[File:After-luarocks-dependencies.png|center|thumb|after luarocks dependencies]]<br />
<br />
''' 2. Get Mudlet source '''<br />
<br />
mkdir ~/source && cd ~/source <br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
<br />
[[File:After-get-mudlet-source.png|center|thumb|After cloning]]<br />
<br />
''' 3. Create a build directory '''<br />
<br />
cd Mudlet && mkdir build && cd build<br />
<br />
''' 4. Run the following commands to build '''<br />
<br />
WITH_UPDATER=NO WITH_3DMAPPER=NO qmake ../src/mudlet.pro<br />
<br />
:If you get a response along the lines of:<br />
<br />
qmake: could not find a Qt installation of ''<br />
<br />
:then you likely have ''qtchooser'' present in your system that allows for both Qt4 and Qt5 (or more than one Qt5 version) and it modifiers qmake and some other Qt development programs to take an additional argument to specify which version to use. In that case you should use:<br />
<br />
WITH_UPDATER=NO WITH_3DMAPPER=NO qmake -qt=qt5 ../src/mudlet.pro<br />
<br />
[[File:After-qmake.png|center|thumb|After qmake]]<br />
<br />
''' THEN: '''<br />
:For the fastest compile time, 15-20min on a RPi4 with 4GB of ram<br />
make -j `nproc`<br />
<br />
''' OR: '''<br />
<br />
:If you want to use your Pi while it builds or have an older Raspberry Pi, be prepared for it to take a while (over an hour) - ''it is not recommended to try to more than one compilation task at a time on the older systems with the '''-j''' option as they will only have a system memory with enough space for one of some of those tasks'':<br />
make<br />
<br />
[[File:Success.png|center|thumb|Success!]]<br />
<br />
''' 4. Install the application you have just compiled '''<br />
<br />
sudo make install<br />
<br />
[[File:Installed.png|center|thumb|Installed now]]<br />
<br />
''' 5. Enjoy! '''<br />
<br />
# mudlet is in the path, can just run it<br />
mudlet<br />
<br />
== Compiling on ArchLinux ==<br />
<br />
Mudlet is available in the [https://aur.archlinux.org Arch User Repository]. <br />
<br />
To install it use your favourite AUR helper (helper tool will automatically resove dependancies); example using ''yay'' :<br />
yay -S mudlet<br />
<br />
For more info on this process, visit [https://wiki.archlinux.org/index.php/Arch_User_Repository Arch User Repository - ArchWiki].<br />
<br />
''Note: For the most recent development version of Mudlet, replace 'mudlet' with 'mudlet-git' in the above commands and proceed as described.''<br />
<br />
''Built in fonts have been disabled, but are available in packages listed as optional dependancies.''<br />
<br />
''Discord support in Mudlet depends on an extrenal library provided by discord-rpc-api, which is also available in AUR, choose whichever variant suits you best.''<br />
<br />
== Compiling on Gentoo ==<br />
An [https://github.com/toaster/gentoo-overlay overlay containing Mudlet is available] for compiling Mudlet on Gentoo.<br />
<br />
== Compiling on Windows ==<br />
<br />
These instructions will get you setup compiling on Windows. <br />
<br />
Need a hand? Join us on the Mudlet [https://discord.gg/BwgJpMj Discord server] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
'''1. Download Mudlet source code'''<br />
<br />
# Install [https://desktop.github.com/ Github Desktop].<br />
# Clone ([https://help.github.com/desktop/guides/contributing-to-projects/cloning-a-repository-from-github-to-github-desktop/#platform-windows instructions]) Mudlet's [https://github.com/mudlet/mudlet repository] to your local drive.<br />
{{note}} You must use a location on <code>C:\</code> without any spaces in folder names! <br />
<br />
'''2. Perform a one-time setup'''<br />
<br />
Right-click on <code>setup-windows-sdk.ps1</code> and select <code>Run with PowerShell</code>. This will automatically download all of the requires tools (including Python 2) and libraries, set them up for you, build Mudlet, and launch it! If this script exits immediately, please [https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-7.1#upgrading-existing-windows-powershell upgrade your PowerShell version] first.<br />
<br />
{{note}} Depending on your Internet connection and computer speed, this one-time setup will take 30 minutes or more - so grab a cup of tea or coffee.<br />
<br />
[[File:Start-of-installation.gif|frame|none|Sometimes the output will get stuck and not progress - just press Enter to make it continue. This is a well-known [https://serverfault.com/questions/204150/sometimes-powershell-stops-sending-output-until-i-press-enter-why Powershell bug.]]]<br />
<br />
During the installation, you'll see the Qt installer window pop-up - this is normal:<br />
<br />
[[File:Qt-installer.gif|thumb|none]]<br />
<br />
The Qt installer might ask you about your data collection preferences - answer as you wish and the automated install will continue:<br />
<br />
[[File:Qt-installer-data-collection.png|thumb|none]]<br />
<br />
The installer's final step will be compiling all of the source code, which looks like this:<br />
<br />
[[File:Compiling-step.gif|thumb|none]]<br />
<br />
After it's all done, a Mudlet version ending in "-dev" will launch automatically:<br />
<br />
[[File:Mudlet-launching.gif|frame|none]]<br />
<br />
If something didn't work right, you can check out the verbose log that is available at <code>C:\src\verbose_output.log</code>.<br />
<br />
=== Coding on Mudlet ===<br />
<br />
Open <code>C:\<path to repository>\src\mudlet.pro</code> in Qt Creator, which resides here: <code>C:\Qt\Tools\QtCreator\bin\qtcreator.exe</code>. Then enable Debug and Release builds and hit ''Configure Project'':<br />
<br />
[[File:Selection_173.png|frame|none]]<br />
<br />
Press <code>Ctrl+5</code> and update project settings. Check how many logical processors are available in your system with the Task Manager:<br />
<br />
[[File:Task-manager.png|thumb|none|2 processors are available in this example]]<br />
<br />
And set this amount in Qt Creator:<br />
<br />
[[File:Change Qt Creator to use many cores.gif|frame|none]]<br />
<br />
Hit run:<br />
<br />
[[File:Selection 176.png|frame|none]]<br />
<br />
Click on '''Compile Output''' to see progress on compiling:<br />
<br />
[[File:Selection 177.png|frame|none]]<br />
<br />
When it's all ready, the new Mudlet with your changes will launch. '''You're all done'''!<br />
<br />
=== Contributing changes ===<br />
<br />
Once you're all done with your changes, contribute them to Mudlet using a [https://help.github.com/desktop/guides/contributing-to-projects/creating-a-pull-request/#platform-windows pull request]. Thanks for improving open-source!<br />
<br />
=== Uninstalling ===<br />
To get rid of everything, uninstall Qt using the <code>C:\Qt\MaintenanceTool.exe</code> and remove the following folders:<br />
<br />
C:\Libraries<br />
C:\LuaRocks<br />
C:\MinGW<br />
C:\Python27<br />
C:\Qt<br />
C:\src<br />
<br />
== Compiling on Github Codespaces ==<br />
<br />
Github Codespaces allow you to code and run Mudlet all from the browser - makes it a lot easier to get started. It also allows you to code Mudlet itself from any computer in the world! As for this time Github Codespaces is in a private beta, so make sure to [https://github.com/features/codespaces/signup apply here]. <br />
<br />
'''1. Create a new codespace'''<br />
<br />
Create a new Codespace by going to https://github.com/Mudlet/Mudlet using Google Chrome or Microsoft Edge (Firefox at the time of the writing doesn't have working copy/paste). There, click the green "Code" button, select the "Codespaces" tab and click "New codespace".<br />
<br />
[[File:New codespace.png|alt=New codespace screenshot|frameless]]<br />
<br />
'''2. Wait for it to load'''<br />
<br />
This will take a while (~5min) so grab a tea:<br />
<br />
[[File:Building Visual Studio Codespace.png|frameless]]<br />
<br />
'''3. Connect to the environment'''<br />
<br />
Go to the <code>Ports</code> section at the bottom and change the Port Privacy of the Open Mudlet port to Public:<br />
<br />
[[File:Port privacy in Github Codespaces.png|900x900px]]<br />
<br />
<br />
Then connect to your online Linux desktop with <code>mudlet</code> as the password by clicking on the web icon. <br />
<br />
[[File:Connect to remote machine.png|frameless]]<br />
<br />
<br />
In case it can't connect, make sure the port privacy is set to <code>Public</code>. If it still can't connect, try 4-5 more times - eventually it'll work.<br />
<br />
<br />
<br />
We chose a retro 90's look here to fit with the whole hacking theme, so if you see this you're good 😉<br />
<br />
[[File:Github_codespaces_desktop.png|alt=|frameless|400x400px]]<br />
<br />
'''4. Build Mudlet'''<br />
<br />
In Codespaces, hit <code>F7</code> and select <code>Let CMake guess...</code><br />
<br />
[[File:CMake configuration.png|none]]<br />
<br />
It will then start building Mudlet automatically. Using the [https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/about-billing-for-codespaces Basic instance] (only kind available in beta) the first-time build will take ~25min, so take a break here - you've made excellent progress. All follow-up compiles after this will be quicker, by the way.<br />
<br />
[[File:Building Mudlet in codespaces.png|none]]<br />
<br />
'''5. Run Mudlet'''<br />
<br />
[[File:Launch Mudlet.png|none]]<br />
<br />
Hit the little play button at the bottom of the screen, and Mudlet will now launch in the remote connection tab. Not working? [https://discord.gg/kuYvMQ9 We can help]. Otherwise, enjoy!<br />
<br />
[[File:Mudlet running remotely.png |500px]]<br />
<br />
Note: When the codespace is unused for a while, it will disconnect. It'll never disconnect while you're actively using it. See [https://github.com/microsoft/vscode-dev-containers/issues/588 Github issue] for details.<br />
<br />
== Developing with Docker ==<br />
<br />
Docker is a system designed for more reproducible and isolated builds. A docker setup exists and has been tested using Pop OS! 20.04 (which is derived from Ubuntu 20.04). First, follow the instructions to install both [https://docs.docker.com/get-docker/ docker] and [https://docs.docker.com/compose/install/ docker-compose].<br />
<br />
Clone the development branch<br />
<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
cd Mudlet/docker<br />
<br />
Make a local copy of the .env.template file:<br />
<br />
cp .env.template .env<br />
<br />
If you wish to customize things like the number of cores to use for building mudlet, feel free to change the corresponding values in the .env file.<br />
<br />
To run Qt-Creator and develop Mudlet, simply run `docker-compose up dev`.<br />
To run Mudlet, simply run `docker-compose up mudlet`. Note: At the moment, the mudlet build will not persist settings past container rebuilds.<br />
<br />
== Compiling on Windows 7+ (MSYS2 Alternative)==<br />
<br />
''INCOMPLETE, IN PROGRESS''<br />
<br />
Go to http://www.msys2.org/ to download the 64 bit MSYS2 installer (as of 2020/05/24 32 bit hosts - for '''compiling''' software, but ''not'' for using code built with it have been deprecated, the last installer for that 32-bit systems is held at: http://repo.msys2.org/distrib/i686/msys2-i686-20200517.exe) and follow the installation instructions (Steps 1 to 8 on that page), these instructions assume that "C:\msys64" or "C:\msys32" is used depending on the bitness of the system it is being installed on.<br />
<br />
Install the following packages (using "pacman -S ''packageName''"), the ones with a '''-i686-''' in the middle are the ones for 32-bit (i686) targets and '''-x86_64-''' are the ones for 64-bit targets - it is possible to install both for building Mudlet for target PCs of both bitnesses on a 64-bit host, it is not clear whether the reverse is true with a 32-bit host. These will pull in a number of other required packages as well (the ''--needed'' option prevents the re-installation of packages that have already been installed by MSYS2/Mingw-w64's own setup/installation process) - as some of the packages, e.g. ''base-devel'' are actually ''groups'' you will be requested to select which members of that group are actually required, it is easiest to just go with the default which is to install ALL of the packages in that group!<br />
<br />
: For 32-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ pacman -S --needed base-devel git mercurial cvs wget ruby zip p7zip python mingw-w64-i686-toolchain mingw-w64-i686-qt-creator mingw-w64-i686-qt5-multimedia mingw-w64-i686-libzip mingw-w64-i686-pugixml mingw-w64-i686-lua51 mingw-w64-i686-lua51-lpeg mingw-w64-i686-lua51-lsqlite3 mingw-w64-i686-hunspell mingw-w64-i686-boost mingw-w64-i686-yajl mingw-w64-i686-clang mingw-w64-i686-cmake mingw-w64-i686-SDL unzip<br />
</syntaxhighlight><br />
<br />
: For 64-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ pacman -S --needed base-devel git mercurial cvs wget ruby zip p7zip python mingw-w64-x86_64-toolchain mingw-w64-x86_64-qt-creator mingw-w64-x86_64-qt5-multimedia mingw-w64-x86_64-libzip mingw-w64-x86_64-pugixml mingw-w64-x86_64-lua51 mingw-w64-x86_64-lua51-lpeg mingw-w64-x86_64-lua51-lsqlite3 mingw-w64-x86_64-hunspell mingw-w64-x86_64-boost mingw-w64-x86_64-yajl mingw-w64-x86_64-clang mingw-w64-x86_64-cmake mingw-w64-x86_64-SDL unzip<br />
</syntaxhighlight><br />
<br />
::The ''*-zziplib'' libraries are used by the ''luazip'' luarock {from the Kepler project} but Mudlet will work perfectly well with the alternative ''lua-zip'' {from the brimworks GitHub repository - which also provides the ''lua-yajl'' rock} which does not require this library - although it is possible that it might still be pulled into the system as a dependency of another MSYS2 package.<br />
<br />
:Note that this will install the MSYS2 builds of the Qt Libraries and Creator IDE - ''THE ON/OFF-LINE INSTALLER OF THE QT LIBRARIES AND CREATOR VIA DOWNLOADS FROM QT ARE NOT USEFUL IN THIS SETUP!''<br />
<br />
:{| class="wikitable"<br />
|-<br />
|'''Attention - Luarocks packages problem'''<br />
|-<br />
| Recently the Luarocks project attempted to adopt the MSYS2/Mingw-w64 platform as one it would supported natively and the MSYS2/Mingw-w64 project went and upgraded its luarocks packages to make use of the changes and also on-board other improvements (and the version number increased from ''2.4.4-2'' to ''3.5.0-1'') unfortunately this completely broke them and although the issue has been reported ([https://github.com/msys2/MINGW-packages/issues/9037 MSYS2 Issue 9037]) a fix has not yet materialised. The only way to work around this in the meantime is to download the older package (with '''wget''') and install it manually (with '''pacman -U):<br />
|-<br />
|For 32-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ wget https://repo.msys2.org/mingw/mingw32/mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
--2021-07-07 22:19:09-- https://repo.msys2.org/mingw/mingw32/mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
Resolving repo.msys2.org (repo.msys2.org)... 178.63.98.68<br />
Connecting to repo.msys2.org (repo.msys2.org)|178.63.98.68|:443... connected.<br />
HTTP request sent, awaiting response... 200 OK<br />
Length: 97905 (96K) [application/octet-stream]<br />
Saving to: ‘mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’<br />
<br />
mingw-w64-i686-lua51-luarocks-2.4.4-2- 100%[===========================================================================>] 95.61K --.-KB/s in 0.07s<br />
<br />
2021-07-07 22:19:10 (1.43 MB/s) - ‘mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’ saved [97905/97905]<br />
<br />
<br />
MSYS user@computer ~<br />
$ pacman -U mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
loading packages...<br />
resolving dependencies...<br />
looking for conflicting packages...<br />
<br />
Packages (1) mingw-w64-i686-lua51-luarocks-2.4.4-2<br />
<br />
Total Installed Size: 0.46 MiB<br />
<br />
:: Proceed with installation? [Y/n] y<br />
(1/1) checking keys in keyring [#####################################################] 100%<br />
(1/1) checking package integrity [#####################################################] 100%<br />
(1/1) loading package files [#####################################################] 100%<br />
(1/1) checking for file conflicts [#####################################################] 100%<br />
(1/1) checking available disk space [#####################################################] 100%<br />
:: Processing package changes...<br />
(1/1) installing mingw-w64-i686-lua51-luarocks [#####################################################] 100%<br />
<br />
MSYS user@computer ~<br />
</syntaxhighlight><br />
|-<br />
|For 64-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ wget https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
--2021-07-07 22:17:32-- https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
Resolving repo.msys2.org (repo.msys2.org)... 178.63.98.68<br />
Connecting to repo.msys2.org (repo.msys2.org)|178.63.98.68|:443... connected.<br />
HTTP request sent, awaiting response... 200 OK<br />
Length: 97935 (96K) [application/octet-stream]<br />
Saving to: ‘mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’<br />
<br />
mingw-w64-x86_64-lua51-luarocks-2.4.4- 100%[===========================================================================>] 95.64K --.-KB/s in 0.07s<br />
<br />
2021-07-07 22:17:32 (1.28 MB/s) - ‘mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’ saved [97935/97935]<br />
<br />
<br />
MSYS user@computer ~<br />
$ pacman -U mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
loading packages...<br />
resolving dependencies...<br />
looking for conflicting packages...<br />
<br />
Packages (1) mingw-w64-x86_64-lua51-luarocks-2.4.4-2<br />
<br />
Total Installed Size: 0.46 MiB<br />
<br />
:: Proceed with installation? [Y/n] y<br />
(1/1) checking keys in keyring [#####################################################] 100%<br />
(1/1) checking package integrity [#####################################################] 100%<br />
(1/1) loading package files [#####################################################] 100%<br />
(1/1) checking for file conflicts [#####################################################] 100%<br />
(1/1) checking available disk space [#####################################################] 100%<br />
:: Processing package changes...<br />
(1/1) installing mingw-w64-x86_64-lua51-luarocks [#####################################################] 100%<br />
<br />
MSYS user@computer ~<br />
</syntaxhighlight><br />
|}<br />
<br />
::{| class="wikitable"<br />
|-<br />
|'''Warning for those planning to build ''both'' 32 and 64 bit versions'''<br />
|-<br />
|If one is planning to build ''both'' bitness binaries an additional step is necessary as, by default, the MSYS2/Mingw-w64 ''luarocks'' setup seems to place any ''.lua'' or ''.dll'' modules it builds/installs on a per user (the so-called ''local'' basis) into the same directories with the same names. This is no good for two reasons:<br />
* It is difficult to work out which bitness a particular module is for and whilst 32-bit modules ''might'' work in a 64-bit environment the reverse is definitely not the case<br />
* It confuses the Luarocks package management systems (as effectively there will be two different luarocks systems operated side-by-side)<br />
<br />
This can be worked around by:<br />
* Editing the '''.\etc\luarocks\config-5.1.lua''' for each bitness so that the ''rocks_trees'' table entry for the ''user'' key is changed from this in '''both''' files:<br />
:<syntaxhighlight lang="lua"> { name = [[user]], root = home..[[/.luarocks]] },</syntaxhighlight><br />
to something different for each of them, say, for example, for the the 64-bit one:<br />
:<syntaxhighlight lang="lua"> { name = [[user]], root = home..[[/.luarocks-x64]] },</syntaxhighlight><br />
* Then by specifying the ''rocktree'' name ('''user''') on the command line when '''installing''' or '''building''' a luarock with the ''--tree user'' argument - note that for some inexplicable reason the ''--local'' argument that '''''should''''' do the same thing does not seem to work for these two actions, it is not clear whether this is a MSYS2/Mingw-w64 specific issue or it goes further upstream to Luarocks in general. Thus, in the next step it will be necessary to change from using:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install --local rockname<br />
</syntaxhighlight><br />
to, for the example given:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install --tree user rockname<br />
</syntaxhighlight><br />
where ''user'' is the literal string "user" to match the Lua table key in the rock_trees and not, in this case, a representation of the user-name/account of the person performing the action.<br />
|}<br />
<br />
From the Windows ''Start menu'' start a shell appropriate for the target with the bitness to be built for i.e. '''"MSYS2 Mingw 32-Bit"''' or '''"MSYS2 Mingw 64-Bit"'''. This will likely position the current directory to the root directory of the MSYS2 environment, the text about the prompt line (the one with the "$") will contain three different bits of colored text '''username@computername'''; one of '''MSYS2'''/'''MINGW32'''/'''MINGW''' depending on the type of shell you currently in use and '''/''' representing the root directory (which will actually be the directory MSYS2 was installed to, for example on the author's system this is "C:/msys64"). Change to the home directory in MYSY by entering "cd" on its own with no argument (it will show up as '''~''' and it would work out to be, for '''user''' to be '''c:/msys64/home/user''' or '''c:/msys32/home/user''' (if both bitnessess are to be built it will be necessary to repeat the following step twice, one for each and also observe the steps in the above warning) install the following luarocks:<br />
<br />
:{| class="wikitable sortable"<br />
|-<br />
! rockname<br />
|-<br />
| lrexlib-pcre<br />
|-<br />
| lua-yajl<br />
|-<br />
| luafilesystem<br />
|-<br />
| luasql-sqlite3<br />
|-<br />
| luautf8<br />
|-<br />
| luazip or lua-zip<br />
|}<br />
by using:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install [--local] rockname<br />
</syntaxhighlight><br />
The ''--local'' argument is an optional one that causes the luarock and the lua module to be installed on a per-user basis rather than on a system wide one, this may be important if the PC is used by multiple users and more than one of them uses Lua in any form.<br />
<br />
Now create somewhere to work on the Mudlet source, assuming that other software coding with other pieces of software will be done, create a sub-directory in the home directory, and then make one just for Mudlet under that:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ mkdir ./src<br />
<br />
MINGW64 user@computer ~<br />
$ mkdir ./src/mudlet<br />
</syntaxhighlight><br />
<br />
Change to that directory and get the source code:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ cd ./src/mudlet<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git clone git://github.com/Mudlet/Mudlet.git .<br />
</syntaxhighlight><br />
<br />
If you are planning to contribute to the Mudlet code you will want to visit Github and create your own GitHub repository, you can then push commits (changes to the code) to there and raise a Pull Request for a Mudlet Maker to drag the changes over to the above repository. You will want to add your repository and perhaps those of some other contributors so you can track what they are doing and see/try/experiment with their PRs before they get merged. Therefore you will want to add some other repositories into the mix. The names you use to identify those other repositories will show up in any utility that works with the repository you have just created in the above "clone" operation and can be anything you like but it makes sense to have clear names. So to add "myName", and those of the leading active contributors to the Mudlet codebase you will use:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Mine https://github.com/myName/Mudlet.git<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Vadim https://github.com/vadi2/Mudlet.git <br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add SlySven https://github.com/SlySven/Mudlet.git<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Kebap https://github.com/Kebap/Mudlet.git<br />
</syntaxhighlight><br />
<br />
Now obtain ''all'' the versions of the code with:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ git fetch --all<br />
</syntaxhighlight><br />
<br />
This will produce a lot of lines of output the first time and it might take a little while on a slow connection...<br />
<br />
{Section missing - it turns out that the default GUI git tools that the author of this section would normally use: "gitk" and "git gui" have some problems in the versions currently supplied from the MSYS2 system - and it was necessary to import them from the set that the Git4Win have patched - see https://github.com/git-for-windows/git/wiki/Install-inside-MSYS2-proper }<br />
<br />
Some modifications to the qmake/cmake project files are needed and these are now supported in the main ''development'' branch in the upstream {the Mudlet organisation's own GitHub repository} which requires that there is an environmental variable '''WITH_MAIN_BUILD_SYSTEM''' and it is set to the (case-insensitive) value '''NO''':<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ export WITH_MAIN_BUILD_SYSTEM=NO<br />
</syntaxhighlight><br />
<br />
Also the '''MINGW_BASE_DIR''' environmental variable will need to be set to the root directory for the MINGW-W64 installation for the appropriate bitness of the target to be made. For building on a 64-Bit Host {the PC that is ''compiling'' the code} to make a 64-Bit application this will likely be '''C:/msys64/mingw64''' and for a 32-Bit application it will probably be '''C:/msys64/ming32'''.<br />
: E.g. <syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ export MINGW_BASE_DIR=C:/msys64/mingw64 # To build a 64-Bit Application with a 64-Bit system<br />
</syntaxhighlight><br />
<br />
: Or: <syntaxhighlight lang="shell"><br />
MINGW32 user@computer ~/src/mudlet<br />
$ export MINGW_BASE_DIR=C:/msys64/mingw32 # To build a 32-Bit Application with a 64-Bit system<br />
</syntaxhighlight><br />
<br />
Now checkout a branch {ideally, if working on solving a new issue, or adding a feature or resolving a bug, one should create a new branch that is a copy of the current, upstream ''development'' branch} and then work on it with Qt Creator:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ qtcreator &<br />
</syntaxhighlight><br />
<br />
Load in the '''mudlet.pro''' ''qmake'' project file in the '''src''' subdirectory (e.g. for this example: '''c:/msys64/home/user/src/mudlet/src/mudlet.pro''') and get hacking...<br />
<br />
= Setting up IDEs =<br />
== CLion ==<br />
=== Qt not detected ===<br />
If you'd like to use CLion and it is giving the following error:<br />
<br />
<nowiki><br />
By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has<br />
asked CMake to find a package configuration file provided by "Qt5Core", but<br />
CMake did not find one.<br />
<br />
...<br />
</nowiki><br />
<br />
You can fix this by setting <code>-DCMAKE_PREFIX_PATH=<your Qt + version + compiler location></code>. For example: <code>-DCMAKE_PREFIX_PATH=/media/vadi/SSDer/Programs/Qt/5.15.2/gcc_64/</code> [[File:CLion CMake settings - finidng Qt.png|700px|none]]<br />
<br />
=== CLion setup on Windows ===<br />
After running <code>setup-windows-sdk.ps1</code> make sure to set Cmake options to:<br />
-DCMAKE_PREFIX_PATH=C:\Qt\Tools\mingw730_32;C:\Qt\5.14.2\mingw73_32 -DBoost_INCLUDE_DIR=C:\Libraries\boost_1_71_0<br />
[[File:Clion Settings - Cmake.png|frameless|700x700px]]<br />
<br />
<br />
You will need 32 bit version of MinGW. Set it in the <code>Toolset</code> field to:<br />
C:\Qt\Tools\mingw730_32<br />
<br />
<br />
[[File:Toolchain.png|frameless|700x700px]]<br />
<br />
=== Clang Tidy ===<br />
Ensure that CLion is set to run the project's [https://www.jetbrains.com/help/clion/clang-tidy-checks-support.html#paticularcheck .clang-tidy checks] with the <code>Prefer .clang-tidy files over IDE settings</code> option:<br />
<br />
[[File:Clang Tidy CLIon.png|700px|none]]<br />
<br />
This helps us catch any issues just a bit earlier.<br />
<br />
=== Clang Format ===<br />
Ensure that [https://www.jetbrains.com/help/clion/clangformat-as-alternative-formatter.html#clion-support CLion is set to use] the <code>.clang-format</code> formatting style:<br />
<br />
[[File:Clang-format CLion.png]]<br />
<br />
This helps keep the look'n'feel of the source code in a consistent manner, even with many people contributing to Mudlet.<br />
<br />
== Visual Studio Code ==<br />
<br />
To set the path in Visual Studio Code, open settings, search for <code>cmake environment</code> and set the <code>CMAKE_PREFIX_PATH</code> to your path, such as <code>/media/vadi/SSDer/Programs/Qt/5.14.1/gcc_64/</code>:<br />
<br />
[[File:CMake path in Visual Studio Code.png|none]]<br />
<br />
===Clang Tidy===<br />
clang-tidy catches common programming issues, run it by selecting 'Analysis' from the command palette (Ctrl+Shift+P by default):<br />
<br />
[[File:Clang-tidy in vscode.png|none]]<br />
<br />
It is also possible [https://devblogs.microsoft.com/cppblog/visual-studio-code-c-december-2021-update-clang-tidy/ check status of analysis and cancel if needed].<br />
<br />
===Checking memory leaks & other issues (sanitizers)===<br />
Besides clang-tidy, it's also possible to enable clang sanitizers to double-check for issues:<br />
<br />
* [https://clang.llvm.org/docs/LeakSanitizer.html LeakSanitizer] for detecting memory leaks<br />
* [https://clang.llvm.org/docs/AddressSanitizer.html AddressSanitizer] for detecting most issues dealing with memory, such as out of bounds accesses to heap, stack, global and more<br />
* [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html UndefinedBehaviourSanitizer] for detecting the use of various features of C/C++ that are explicitly listed as resulting in undefined behaviour (such as using misaligned or null pointer, conversion to, from, or between floating-point types which would overflow the destination, division by zero, etc)<br />
* [https://clang.llvm.org/docs/MemorySanitizer.html MemorySanitizer] for detecting reading uninitialised memory<br />
* [https://clang.llvm.org/docs/ThreadSanitizer.html ThreadSanitizer] for detecting threading issues<br />
<br />
To use the sanitisers, set the <code>USE_SANITIZER</code> CMake variable to one or several variables (separate by comma): <code>Address</code>, <code>Memory</code>, <code>MemoryWithOrigins</code>, <code>Undefined</code>, <code>Thread</code>, or <code>Leak</code><br />
<br />
To use them in VSCode, set the <code>cmake.configureSettings</code> variable:<br />
<br />
[[File:Cmake.configureSettings option in vscode.png|frameless|890x890px]]<br />
<br />
[[File:Choosing which sanitizers in vscode to use.png|frameless|891x891px]]<br />
<br />
Not all sanitisers can be used with each other - in that case the cmake configuration won't allow you to continue.<br />
<br />
== Qt Creator==<br />
===Clang Tidy and Clazy===<br />
<br />
Configure Mudlet-specific checks for [https://clang.llvm.org/extra/clang-tidy/ clang-tidy] and [https://github.com/KDE/clazy clazy] tools help catch any issues early on. See [https://doc.qt.io/qtcreator/creator-clang-tools.html Qt Creator's instructions] for setting this up - clang-tidy can use the <code>.clang-tidy</code> file that's available at the root of the repository, and for clazy enable <code>level0</code> and <code>level1</code> checks.<br />
<br />
[[File:Clang tidy configuration.png|frame|none]]<br />
[[File:Clazy configuration.png|frame|none]]<br />
<br />
===Checking memory leaks & other issues (sanitizers)===<br />
Besides clang-tidy, it's also possible to enable clang sanitizers to double-check for issues:<br />
<br />
* [https://clang.llvm.org/docs/LeakSanitizer.html LeakSanitizer] for detecting memory leaks<br />
* [https://clang.llvm.org/docs/AddressSanitizer.html AddressSanitizer] for detecting most issues dealing with memory, such as out of bounds accesses to heap, stack, global and more<br />
* [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html UndefinedBehaviourSanitizer] for detecting the use of various features of C/C++ that are explicitly listed as resulting in undefined behaviour (such as using misaligned or null pointer, conversion to, from, or between floating-point types which would overflow the destination, division by zero, etc)<br />
* [https://clang.llvm.org/docs/MemorySanitizer.html MemorySanitizer] for detecting reading uninitialised memory<br />
* [https://clang.llvm.org/docs/ThreadSanitizer.html ThreadSanitizer] for detecting threading issues<br />
<br />
To use the sanitisers, set the <code>USE_SANITIZER</code> CMake variable to one or several variables (separate by comma): <code>Address</code>, <code>Memory</code>, <code>MemoryWithOrigins</code>, <code>Undefined</code>, <code>Thread</code>, or <code>Leak</code><br />
<br />
To use them in Qt creator, head to <code>Projects</code> - <code>Build</code>: <br />
<br />
[[File:Sanitisers in qt creator.png|frameless|890x890px]]<br />
<br />
Not all sanitisers can be used with each other - in that case the cmake configuration won't allow you to continue.<br />
<br />
==Clang Format==<br />
Ensure that Qt Creator is set to use the <code>.clang-format</code> formatting style in the C++ settings. Turn on <code>Format instead of indenting</code> for <code>Ctrl+I</code> to format code, and ensure <code>Override Clang Format configuration file</code> is disabled:<br />
<br />
[[File:Qt Creator clang format.png]]<br />
<br />
This helps keep the look'n'feel of the source code in a consistent manner, even with many people contributing to Mudlet.<br />
<br />
<br />
=Building with multiple versions of Lua=<br />
Mudlet uses Lua 5.1 only, so if you are compiling on a system that also has later versions installed, you might get the following error: <code>‘LUA_GLOBALSINDEX’ was not declared in this scope</code>.<br />
<br />
To fix this, pass the path to Lua headers explicitly. For CMake: <code>-DLUA_INCLUDE_DIR=/usr/include/lua5.1</code> (adjust as needed).</div>Dargothhttps://wiki.mudlet.org/index.php?title=Compiling_Mudlet&diff=19771Compiling Mudlet2022-01-19T23:09:10Z<p>Dargoth: /* Setting up IDEs - CLion on Windows with CMake */</p>
<hr />
<div>{{TOC right}}<br />
<br />
If you just want to use Mudlet, you can skip these steps, and use one of the already ready (pre-compiled) installers [https://www.mudlet.org/download ready for download].<br />
<br />
Otherwise, hop in for new adventure! <br />
<br />
[[File:Easy Mudlet code understanding.png|frame|none]]<br />
<br />
= Key contributing information =<br />
<br />
Clang format is used to automatically format code submissions using the [https://github.com/Mudlet/Mudlet/blob/development/src/.clang-format src/.clang-format] style. [http://doc.qt.io/qtcreator/creator-beautifier.html See here] how to enable clang-format with Qt Creator - and make sure to specify the 'File' option for the configuration style.<br />
<br />
Branches:<br />
<br />
'''development''' is the development branch where new features can go.<br />
<br />
Workflow:<br />
<br />
Fork and submit a PR with your changes ([https://guides.github.com/activities/forking/ Github tutorial]).<br />
<br />
Here is a list of package versions delivered with different Linux distros. You may want to upgrade these: <br />
https://repology.org/project/mudlet/versions<br />
<br />
= Compiling =<br />
<br />
== Compiling on Ubuntu ==<br />
<br />
These instructions will get you setup compiling on Ubuntu. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
===Ubuntu 21.10===<br />
Following instructions will work on Ubuntu 21.10 as well as all it's flavours and derivatives (such as KDE Neon, for example)<br />
Important thing is to have ''Universe'' repository enabled in your package manager. (on Ubuntu you will have all the repositories that you need already enabled by default.)<br />
<br />
'''1. necessary dependencies'''<br />
<br />
Majority of required dependencies can be obtained from repositories, and can be installed with following command:<br />
<br />
sudo apt install ubuntu-restricted-extras qtcreator build-essential git zlib1g-dev libhunspell-dev \<br />
libpcre3-dev libzip-dev libboost-dev libboost-all-dev libyajl-dev libpulse-dev libpugixml-dev \<br />
liblua5.1-0-dev lua-filesystem lua-zip lua-sql-sqlite3 luarocks ccache lua-rex-pcre lua5.1 \<br />
libglu1-mesa-dev mesa-common-dev libglib2.0-dev libgstreamer1.0-dev libqt5opengl5-dev \<br />
qtmultimedia5-dev qttools5-dev qt5keychain-dev libsecret-1-dev \<br />
libqt5texttospeech5-dev qtspeech5-flite-plugin qtspeech5-speechd-plugin \<br />
qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtmultimedia5-dev<br />
<br />
Few of required Lua modules are not available in official repositories, so they have to be installed using ''luarocks''<br />
sudo luarocks install lcf<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''2. obtaining the source code'''<br />
<br />
If you're compiling Mudlet from source for everyday use with few more features that are not present in official AppImage, it is strongly advised that you obtain and compile the source code latest ''stable'' release of Mudlet. At the moment of writing this article, current stable version is 4.10.1, you'll need to adjust version number if new release comes out at later date.<br />
mkdir build && cd build<br />
wget https://www.mudlet.org/wp-content/files/Mudlet-4.10.1.tar.xz<br />
tar xvf Mudlet-4.10.1.tar.xz<br />
cd src<br />
<br />
However, if you're feeling adventurous and wish to play with the latest development code, you can obtain it directly from Mudlet's Git repository:<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
mkdir Mudlet/build<br />
cd Mudlet/build<br />
<br />
'''3. compiling the code'''<br />
<br />
There below are two ways to build with qmake, the first is for general use, the second is for developers:<br />
qmake ../src/mudlet.pro<br />
'''*OR*'''<br />
qmake CONFIG+=debug ../src/mudlet.pro<br />
<br />
'''Now finish compiling:'''<br />
make -j `nproc`<br />
<br />
4. '''installing compiled code'''<br />
<br />
After successful code compilation, next few commands will install resulting binaries, desktop file for menus and appropriate icon.<br />
sudo make install<br />
sudo cp ../mudlet.png /usr/share/pixmaps<br />
sudo cp ../mudlet.desktop /usr/share/applications<br />
<br />
5. '''optional additional software'''<br />
<br />
One of the major reasons for compiling Mudlet from source is the ability to unlock more features that are not enabled in official AppImage.<br />
Manual compilation will resolve the issues with sound by using system provided libraries, as well as enable more detailed theming of Mudlet application itself.<br />
However, do take note that Mudlet is a Qt based program, and that theming will not 'just work' in GTK based desktop environments (Gnome, XFCE, MATE, Budgie).<br />
sudo apt install qt5ct<br />
will install a tool for configuration of look and feel of Qt programs inside those desktop environments.<br />
Users of Qt based Desktop environments (KDE Plasma, LXQT) can simply use settings provided by environment itself.<br />
<br />
Many of Qt widget styles and color schemes are available in official repositories, and will make Mudlet better.<br />
<br />
6. '''Mudlet on Wayland'''<br />
<br />
Mudlet compiled like this will run and work on Wayland, however, there are a few quirks with Keybidings (Numpad may not work as expected).<br />
Until that is resolved you may wish to start mudlet with:<br />
QT_QPA_PLATFORM=xcb mudlet<br />
(enter in terminal or simply change the Exec= line in /usr/share/applications/mudlet.desktop)<br />
<br />
7. '''uninstallation'''<br />
<br />
You can reverse the process described in this guide with following command:<br />
<br />
sudo rm -fr /usr/bin/mudlet /usr/share/mudlet /usr/share/applications/mudlet.desktop /usr/share/pixmaps/mudlet.png<br />
<br />
===Ubuntu 20.10===<br />
Following instructions will work on Ubuntu 20.10 as well as all it's flavours and derivatives (such as KDE Neon, for example)<br />
Important thing is to have ''Universe'' repository enabled in your package manager.<br />
<br />
1. '''necessary dependencies'''<br />
<br />
Majority of required dependencies can be obtained from repositories, and can be installed with following command:<br />
<br />
sudo apt install qtcreator build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev libzip-dev libboost-dev libboost-all-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev lua5.1 libqt5opengl5-dev libglu1-mesa-dev mesa-common-dev libglib2.0-dev libgstreamer1.0-dev qt5keychain-dev libsecret-1-dev libqt5texttospeech5-dev qtspeech5-flite-plugin qtspeech5-speechd-plugin<br />
<br />
Few of required Lua modules are not available in official repositories, so they have to be installed using ''luarocks'' <br />
sudo luarocks install lcf<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
2. '''obtaining the source code'''<br />
<br />
If you're compiling Mudlet from source for everyday use with few more features that are not present in official AppImage, it is strongly advised that you obtain and compile the source code latest ''stable'' release of Mudlet. At the moment of writing this article, current stable version is 4.10.1, you'll need to adjust version number if new release comes out at later date.<br />
mkdir build && cd build<br />
wget https://www.mudlet.org/wp-content/files/Mudlet-4.10.1.tar.xz<br />
tar xvf Mudlet-4.10.1.tar.xz<br />
cd src<br />
<br />
However, if you're feeling adventurous and wish to play with the latest development code, you can obtain it directly from Mudlet's Git repository:<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
cd Mudlet/src/<br />
<br />
3. '''compiling the code'''<br />
<br />
Following commands will configure the code to install Mudlet on a system level and compile it.<br />
If you wish to install it somewhere else, you may adjust both paths in following command to point to desired destination before compiling it with make. (Rest of this guide will assume you're installing on a system level)<br />
WITH_FONTS=NO WITH_OWN_QTKEYCHAIN=NO WITH_UPDATER=NO WITH_VARIABLE_SPLASH_SCREEN=NO XDG_DATA_DIRS=/usr/share qmake PREFIX=/usr<br />
make -j `nproc`<br />
<br />
4. '''compiling on Ubuntu for Raspberry Pi'''<br />
<br />
Ubuntu for Raspberry Pi is essentially the same as Ubuntu for regular PC, however, due to sketchy state of OpenGL drivers on RPi 4, you'll likely need to disable Mudlet's 3D Mapper or code will just not compile. Adjusted commands are:<br />
WITH_3DMAPPER=NO WITH_FONTS=NO WITH_OWN_QTKEYCHAIN=NO WITH_UPDATER=NO WITH_VARIABLE_SPLASH_SCREEN=NO XDG_DATA_DIRS=/usr/share qmake PREFIX=/usr<br />
make<br />
<br />
5. '''installing compiled code'''<br />
<br />
After successful code compilation, next few commands will install resulting binaries, desktop file for menus and appropriate icon.<br />
sudo make install<br />
sudo cp ../mudlet.png /usr/share/pixmaps<br />
sudo cp ../mudlet.desktop /usr/share/applications<br />
<br />
6. '''optional additional software'''<br />
<br />
One of the major reasons for compiling Mudlet from source is the ability to unlock more features that are not enabled in official AppImage.<br />
Manual compilation will resolve the issues with sound by using system provided libraries, as well as enable more detailed theming of Mudlet application itself.<br />
However, do take note that Mudlet is a Qt based program, and that theming will not 'just work' in GTK based desktop environments (Gnome, XFCE, MATE, Budgie).<br />
sudo apt install qt5ct<br />
will install a tool for configuration of look and feel of Qt programs inside those desktop environments.<br />
Users of Qt based Desktop environments (KDE Plasma, LXQT) can simply use settings provided by environment itself.<br />
<br />
Many of Qt widget styles and color schemes are available in official repositories, and will make Mudlet better.<br />
<br />
7. '''Mudlet on Wayland'''<br />
<br />
Mudlet compiled like this will run and work on Wayland, however, there are a few quirks with Keybidings (Numpad may not work as expected). <br />
Until that is resolved you may wish to start mudlet with:<br />
QT_QPA_PLATFORM=xcb mudlet<br />
(enter in terminal or simply change the Exec= line in /usr/share/applications/mudlet.desktop)<br />
<br />
8. '''uninstallation'''<br />
<br />
You can reverse the process described in this guide with following command:<br />
<br />
sudo rm -fr /usr/bin/mudlet /usr/share/mudlet /usr/share/applications/mudlet.desktop /usr/share/pixmaps/mudlet.png<br />
<br />
===Ubuntu 18.04 setup===<br />
<br />
For Ubuntu 18.04 see the instructions for [[#Compiling_on_Debian_9_.27Stretch.27|Compiling on Debian 9 'Stretch']] (tested working perfectly).<br />
<br />
<br />
'''1. Ubuntu 18.04 setup'''<br />
<br />
If you're on Ubuntu 18.04 (Bionic Beaver), install the following. If you're on a newer Ubuntu, skip this step and go to ''2. Install dependencies''.<br />
<br />
sudo add-apt-repository ppa:beineri/opt-qt-5.12.3-bionic<br />
sudo apt update<br />
sudo apt install qt512-meta-full qt512creator<br />
source /opt/qt512/bin/qt512-env.sh<br />
<br />
'''2. Install dependencies'''<br />
<br />
sudo apt install git build-essential qt5-default qtmultimedia5-dev qttools5-dev \<br />
lua5.1 liblua5.1-0-dev libpcre3-dev libboost-dev zlib1g-dev cmake \<br />
libhunspell-dev lua-rex-pcre lua-sql-sqlite3 lua-filesystem lua-zip libyajl-dev \<br />
libzip-dev libgstreamer0.10-0 libglu1-mesa-dev ccache libpugixml-dev \<br />
mesa-common-dev qtcreator libpulse-dev libglib2.0-dev luarocks libboost-all-dev \<br />
libsecret-1-dev<br />
sudo apt install gstreamer0.10-fluendo-mp3 # may not work on newer Ubuntu<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''3. Get Mudlet source'''<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''4. Create a build directory'''<br />
<br />
cd mudlet<br />
mkdir build<br />
cd build<br />
<br />
'''5. Run the following commands, depending on which build system you want to use '''<br />
<br />
'''EITHER:'''<br />
<br />
cmake ..<br />
<br />
'''OR:'''<br />
<br />
qmake CONFIG+=debug ../src/mudlet.pro<br />
<br />
'''THEN:'''<br />
<br />
make -j `nproc`<br />
<br />
'''5. Start the application you have just compiled - enjoy'''<br />
<br />
cd src<br />
./mudlet<br />
<br />
== Compiling on Chrome OS ==<br />
<br />
These instructions will get you setup compiling on Chrome OS. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
'''1. Install dependencies'''<br />
<br />
sudo apt install git build-essential qt5-default qtmultimedia5-dev qttools5-dev \<br />
lua5.1 liblua5.1-0-dev libpcre3-dev libboost-dev zlib1g-dev cmake \<br />
libhunspell-dev lua-rex-pcre lua-sql-sqlite3 lua-filesystem lua-zip libyajl-dev \<br />
libzip-dev libglu1-mesa-dev ccache libpugixml-dev mesa-common-dev qtcreator \<br />
libpulse-dev libglib2.0-dev luarocks libboost-all-dev libsecret-1-dev \<br />
ninja-build libsecret-1-dev<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''3. Get Mudlet source'''<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''4. Create a build directory'''<br />
<br />
cd mudlet<br />
mkdir build && cd build<br />
<br />
'''5. Run the following command '''<br />
<br />
cmake .. -G Ninja<br />
<br />
'''then:'''<br />
<br />
ninja<br />
<br />
'''5. Start the application you have just compiled - enjoy'''<br />
<br />
src/mudlet<br />
{{Note}}Did <code>ninja</code> fail with <code>c++: fatal error: Killed signal terminated program cclplus</code>? Try again with <code>ninja -j 2</code><br />
<br />
== Compiling on macOS ==<br />
<br />
These instructions will get you setup compiling on macOS. Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord server] or [http://forums.mudlet.org/viewforum.php?f=7 forums] otherwise.<br />
<br />
<br />
'''1. Install prerequisites'''<br />
<br />
Install [https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12 XCode], command line tools for XCode, and [http://brew.sh HomeBrew].<br />
<br />
Once everything is installed, do:<br />
<br />
brew doctor<br />
brew update<br />
brew install git<br />
<br />
'''2. Get Mudlet source'''<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git <br />
<br />
'''3. Go to the parent of the mudlet "src" folder and create (if necessary) a build subdirectory (this is so that we can build out of source which keeps the source code clean)'''<br />
cd Mudlet && mkdir build<br />
<br />
'''3. Setup your environment'''<br />
./CI/travis.osx.before_install.sh<br />
./CI/travis.osx.install.sh<br />
<br />
luarocks config lua_version 5.1<br />
eval `luarocks path --lua-version=5.1`<br />
For the following, one may have to add <code>''_DIR="/opt/homebrew/"''</code> such as <code>PCRE_DIR="/opt/homebrew/"</code> or <code>ZIP_DIR="/opt/homebrew/"</code> if the installation could not find header files.<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lrexlib-pcre<br />
brew install sqlite<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luasql-sqlite3 SQLITE_DIR=`brew --prefix sqlite` <br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luautf8<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lua-yajl<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install luafilesystem<br />
luarocks --lua-version=5.1 --lua-dir=`brew --prefix lua@5.1` install lua-zip<br />
<br />
brew install p7zip<br />
export BOOST_ROOT="$(pwd)/../Mudlet/3rdparty/boost"<br />
export BOOST_URL="https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2/download"<br />
mkdir -p $BOOST_ROOT<br />
curl --progress-bar --location --output $BOOST_ROOT/download.tar.bz2 $BOOST_URL<br />
7z -o$BOOST_ROOT x $BOOST_ROOT/download.tar.bz2 -y -bd<br />
7z -o$BOOST_ROOT x $BOOST_ROOT/download.tar -y -bd<br />
cd $BOOST_ROOT && cp -r boost_*/* .<br />
rm -rf boost_*/* download.tar.bz2 download.tar<br />
OK to answer yes to delete files if prompted for the <code>rm</code> command above.<br />
<br />
'''4. Run the following commands'''<br />
<br />
cd ../../build<br />
cmake ../../Mudlet -DCMAKE_PREFIX_PATH=`brew --prefix qt5`<br />
make -j `sysctl -n hw.ncpu`<br />
<br />
<br />
'''5. Enjoy'''<br />
<br />
The mudlet.app is now available in <code>src/</code> for launching:<br />
<br />
open src/Mudlet.app<br />
<br />
== Compiling on Debian 'Sid' ==<br />
<br />
'''1. Install required packages from main repo.'''<br />
<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev<br />
<br />
sudo luarocks install luautf8<br />
sudo luarocks install lua-yajl<br />
<br />
'''2. Grab latest Mudlet source.'''<br />
<br />
mkdir ~/projects && cd ~/projects && git clone --recursive https://github.com/Mudlet/Mudlet.git mudlet<br />
<br />
'''3. Build Mudlet.'''<br />
<br />
cd ~/projects/mudlet/src<br />
<br />
qmake<br />
<br />
make<br />
<br />
sudo make install<br />
<br />
== Compiling on Debian 11 'Bullseye' ==<br />
<br />
'''1. Install required packages.'''<br />
<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools qtmultimedia5-dev \<br />
qttools5-dev luarocks ccache libpugixml-dev libqt5texttospeech5-dev qtspeech5-flite-plugin \<br />
qtspeech5-speechd-plugin libqt5opengl5-dev<br />
<br />
sudo luarocks install luautf8 <br />
sudo luarocks install lua-yajl<br />
<br />
'''2. Get Mudlet source.'''<br />
<br />
mkdir ~/source && cd ~/source<br />
<br />
git clone --recursive https://github.com/Mudlet/Mudlet.git<br />
<br />
Note: the line above will check out `development` branch source code, and this might not always be stable. You can check out the latest release source code using this command:<br />
<br />
git clone --recursive --branch main https://github.com/Mudlet/Mudlet.git<br />
<br />
'''3. Build Mudlet.'''<br />
<br />
mkdir ~/source/Mudlet/build && cd ~/source/Mudlet/build<br />
<br />
qmake ../src/mudlet.pro<br />
<br />
make -j `nproc`<br />
<br />
sudo make install<br />
<br />
After these steps you can run Mudlet by typing:<br />
<br />
mudlet<br />
<br />
== Compiling on Raspberry Pi OS ==<br />
<br />
These instructions will get you compiling and running Mudlet on Raspberry Pi OS (Buster). Need a hand? Join us on Mudlet's [https://discord.gg/BwgJpMj Discord] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
''' 1.a Install apt dependencies '''<br />
<br />
sudo apt-get update<br />
sudo apt-get install build-essential git liblua5.1-dev zlib1g-dev libhunspell-dev libpcre3-dev \<br />
libzip-dev libboost-graph-dev libyajl-dev libpulse-dev lua-rex-pcre lua-filesystem lua-zip \<br />
lua-sql-sqlite3 qt5-default qtmultimedia5-dev qttools5-dev luarocks ccache libpugixml-dev cmake<br />
<br />
<br />
[[File:Apt-get-install-y-n.png|center|thumb|installing apt dependencies]]<br />
<br />
''' 1.b Install luarocks dependencies '''<br />
<br />
sudo luarocks install luautf8 <br />
sudo luarocks install lua-yajl YAJL_LIBDIR=/usr/lib/arm-linux-gnueabihf/ YAJL_INCDIR=/usr/include<br />
<br />
<br />
[[File:After-luarocks-dependencies.png|center|thumb|after luarocks dependencies]]<br />
<br />
''' 2. Get Mudlet source '''<br />
<br />
mkdir ~/source && cd ~/source <br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
<br />
[[File:After-get-mudlet-source.png|center|thumb|After cloning]]<br />
<br />
''' 3. Create a build directory '''<br />
<br />
cd Mudlet && mkdir build && cd build<br />
<br />
''' 4. Run the following commands to build '''<br />
<br />
WITH_UPDATER=NO WITH_3DMAPPER=NO qmake ../src/mudlet.pro<br />
<br />
:If you get a response along the lines of:<br />
<br />
qmake: could not find a Qt installation of ''<br />
<br />
:then you likely have ''qtchooser'' present in your system that allows for both Qt4 and Qt5 (or more than one Qt5 version) and it modifiers qmake and some other Qt development programs to take an additional argument to specify which version to use. In that case you should use:<br />
<br />
WITH_UPDATER=NO WITH_3DMAPPER=NO qmake -qt=qt5 ../src/mudlet.pro<br />
<br />
[[File:After-qmake.png|center|thumb|After qmake]]<br />
<br />
''' THEN: '''<br />
:For the fastest compile time, 15-20min on a RPi4 with 4GB of ram<br />
make -j `nproc`<br />
<br />
''' OR: '''<br />
<br />
:If you want to use your Pi while it builds or have an older Raspberry Pi, be prepared for it to take a while (over an hour) - ''it is not recommended to try to more than one compilation task at a time on the older systems with the '''-j''' option as they will only have a system memory with enough space for one of some of those tasks'':<br />
make<br />
<br />
[[File:Success.png|center|thumb|Success!]]<br />
<br />
''' 4. Install the application you have just compiled '''<br />
<br />
sudo make install<br />
<br />
[[File:Installed.png|center|thumb|Installed now]]<br />
<br />
''' 5. Enjoy! '''<br />
<br />
# mudlet is in the path, can just run it<br />
mudlet<br />
<br />
== Compiling on ArchLinux ==<br />
<br />
Mudlet is available in the [https://aur.archlinux.org Arch User Repository]. <br />
<br />
To install it use your favourite AUR helper (helper tool will automatically resove dependancies); example using ''yay'' :<br />
yay -S mudlet<br />
<br />
For more info on this process, visit [https://wiki.archlinux.org/index.php/Arch_User_Repository Arch User Repository - ArchWiki].<br />
<br />
''Note: For the most recent development version of Mudlet, replace 'mudlet' with 'mudlet-git' in the above commands and proceed as described.''<br />
<br />
''Built in fonts have been disabled, but are available in packages listed as optional dependancies.''<br />
<br />
''Discord support in Mudlet depends on an extrenal library provided by discord-rpc-api, which is also available in AUR, choose whichever variant suits you best.''<br />
<br />
== Compiling on Gentoo ==<br />
An [https://github.com/toaster/gentoo-overlay overlay containing Mudlet is available] for compiling Mudlet on Gentoo.<br />
<br />
== Compiling on Windows ==<br />
<br />
These instructions will get you setup compiling on Windows. <br />
<br />
Need a hand? Join us on the Mudlet [https://discord.gg/BwgJpMj Discord server] or [http://forums.mudlet.org/viewforum.php?f=7 forums].<br />
<br />
'''1. Download Mudlet source code'''<br />
<br />
# Install [https://desktop.github.com/ Github Desktop].<br />
# Clone ([https://help.github.com/desktop/guides/contributing-to-projects/cloning-a-repository-from-github-to-github-desktop/#platform-windows instructions]) Mudlet's [https://github.com/mudlet/mudlet repository] to your local drive.<br />
{{note}} You must use a location on <code>C:\</code> without any spaces in folder names! <br />
<br />
'''2. Perform a one-time setup'''<br />
<br />
Right-click on <code>setup-windows-sdk.ps1</code> and select <code>Run with PowerShell</code>. This will automatically download all of the requires tools (including Python 2) and libraries, set them up for you, build Mudlet, and launch it! If this script exits immediately, please [https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/install/installing-windows-powershell?view=powershell-7.1#upgrading-existing-windows-powershell upgrade your PowerShell version] first.<br />
<br />
{{note}} Depending on your Internet connection and computer speed, this one-time setup will take 30 minutes or more - so grab a cup of tea or coffee.<br />
<br />
[[File:Start-of-installation.gif|frame|none|Sometimes the output will get stuck and not progress - just press Enter to make it continue. This is a well-known [https://serverfault.com/questions/204150/sometimes-powershell-stops-sending-output-until-i-press-enter-why Powershell bug.]]]<br />
<br />
During the installation, you'll see the Qt installer window pop-up - this is normal:<br />
<br />
[[File:Qt-installer.gif|thumb|none]]<br />
<br />
The Qt installer might ask you about your data collection preferences - answer as you wish and the automated install will continue:<br />
<br />
[[File:Qt-installer-data-collection.png|thumb|none]]<br />
<br />
The installer's final step will be compiling all of the source code, which looks like this:<br />
<br />
[[File:Compiling-step.gif|thumb|none]]<br />
<br />
After it's all done, a Mudlet version ending in "-dev" will launch automatically:<br />
<br />
[[File:Mudlet-launching.gif|frame|none]]<br />
<br />
If something didn't work right, you can check out the verbose log that is available at <code>C:\src\verbose_output.log</code>.<br />
<br />
=== Coding on Mudlet ===<br />
<br />
Open <code>C:\<path to repository>\src\mudlet.pro</code> in Qt Creator, which resides here: <code>C:\Qt\Tools\QtCreator\bin\qtcreator.exe</code>. Then enable Debug and Release builds and hit ''Configure Project'':<br />
<br />
[[File:Selection_173.png|frame|none]]<br />
<br />
Press <code>Ctrl+5</code> and update project settings. Check how many logical processors are available in your system with the Task Manager:<br />
<br />
[[File:Task-manager.png|thumb|none|2 processors are available in this example]]<br />
<br />
And set this amount in Qt Creator:<br />
<br />
[[File:Change Qt Creator to use many cores.gif|frame|none]]<br />
<br />
Hit run:<br />
<br />
[[File:Selection 176.png|frame|none]]<br />
<br />
Click on '''Compile Output''' to see progress on compiling:<br />
<br />
[[File:Selection 177.png|frame|none]]<br />
<br />
When it's all ready, the new Mudlet with your changes will launch. '''You're all done'''!<br />
<br />
=== Contributing changes ===<br />
<br />
Once you're all done with your changes, contribute them to Mudlet using a [https://help.github.com/desktop/guides/contributing-to-projects/creating-a-pull-request/#platform-windows pull request]. Thanks for improving open-source!<br />
<br />
=== Uninstalling ===<br />
To get rid of everything, uninstall Qt using the <code>C:\Qt\MaintenanceTool.exe</code> and remove the following folders:<br />
<br />
C:\Libraries<br />
C:\LuaRocks<br />
C:\MinGW<br />
C:\Python27<br />
C:\Qt<br />
C:\src<br />
<br />
== Compiling on Github Codespaces ==<br />
<br />
Github Codespaces allow you to code and run Mudlet all from the browser - makes it a lot easier to get started. It also allows you to code Mudlet itself from any computer in the world! As for this time Github Codespaces is in a private beta, so make sure to [https://github.com/features/codespaces/signup apply here]. <br />
<br />
'''1. Create a new codespace'''<br />
<br />
Create a new Codespace by going to https://github.com/Mudlet/Mudlet using Google Chrome or Microsoft Edge (Firefox at the time of the writing doesn't have working copy/paste). There, click the green "Code" button, select the "Codespaces" tab and click "New codespace".<br />
<br />
[[File:New codespace.png|alt=New codespace screenshot|frameless]]<br />
<br />
'''2. Wait for it to load'''<br />
<br />
This will take a while (~5min) so grab a tea:<br />
<br />
[[File:Building Visual Studio Codespace.png|frameless]]<br />
<br />
'''3. Connect to the environment'''<br />
<br />
Go to the <code>Ports</code> section at the bottom and change the Port Privacy of the Open Mudlet port to Public:<br />
<br />
[[File:Port privacy in Github Codespaces.png|900x900px]]<br />
<br />
<br />
Then connect to your online Linux desktop with <code>mudlet</code> as the password by clicking on the web icon. <br />
<br />
[[File:Connect to remote machine.png|frameless]]<br />
<br />
<br />
In case it can't connect, make sure the port privacy is set to <code>Public</code>. If it still can't connect, try 4-5 more times - eventually it'll work.<br />
<br />
<br />
<br />
We chose a retro 90's look here to fit with the whole hacking theme, so if you see this you're good 😉<br />
<br />
[[File:Github_codespaces_desktop.png|alt=|frameless|400x400px]]<br />
<br />
'''4. Build Mudlet'''<br />
<br />
In Codespaces, hit <code>F7</code> and select <code>Let CMake guess...</code><br />
<br />
[[File:CMake configuration.png|none]]<br />
<br />
It will then start building Mudlet automatically. Using the [https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/about-billing-for-codespaces Basic instance] (only kind available in beta) the first-time build will take ~25min, so take a break here - you've made excellent progress. All follow-up compiles after this will be quicker, by the way.<br />
<br />
[[File:Building Mudlet in codespaces.png|none]]<br />
<br />
'''5. Run Mudlet'''<br />
<br />
[[File:Launch Mudlet.png|none]]<br />
<br />
Hit the little play button at the bottom of the screen, and Mudlet will now launch in the remote connection tab. Not working? [https://discord.gg/kuYvMQ9 We can help]. Otherwise, enjoy!<br />
<br />
[[File:Mudlet running remotely.png |500px]]<br />
<br />
Note: When the codespace is unused for a while, it will disconnect. It'll never disconnect while you're actively using it. See [https://github.com/microsoft/vscode-dev-containers/issues/588 Github issue] for details.<br />
<br />
== Developing with Docker ==<br />
<br />
Docker is a system designed for more reproducible and isolated builds. A docker setup exists and has been tested using Pop OS! 20.04 (which is derived from Ubuntu 20.04). First, follow the instructions to install both [https://docs.docker.com/get-docker/ docker] and [https://docs.docker.com/compose/install/ docker-compose].<br />
<br />
Clone the development branch<br />
<br />
git clone --recursive -b development https://github.com/Mudlet/Mudlet.git<br />
cd Mudlet/docker<br />
<br />
Make a local copy of the .env.template file:<br />
<br />
cp .env.template .env<br />
<br />
If you wish to customize things like the number of cores to use for building mudlet, feel free to change the corresponding values in the .env file.<br />
<br />
To run Qt-Creator and develop Mudlet, simply run `docker-compose up dev`.<br />
To run Mudlet, simply run `docker-compose up mudlet`. Note: At the moment, the mudlet build will not persist settings past container rebuilds.<br />
<br />
== Compiling on Windows 7+ (MSYS2 Alternative)==<br />
<br />
''INCOMPLETE, IN PROGRESS''<br />
<br />
Go to http://www.msys2.org/ to download the 64 bit MSYS2 installer (as of 2020/05/24 32 bit hosts - for '''compiling''' software, but ''not'' for using code built with it have been deprecated, the last installer for that 32-bit systems is held at: http://repo.msys2.org/distrib/i686/msys2-i686-20200517.exe) and follow the installation instructions (Steps 1 to 8 on that page), these instructions assume that "C:\msys64" or "C:\msys32" is used depending on the bitness of the system it is being installed on.<br />
<br />
Install the following packages (using "pacman -S ''packageName''"), the ones with a '''-i686-''' in the middle are the ones for 32-bit (i686) targets and '''-x86_64-''' are the ones for 64-bit targets - it is possible to install both for building Mudlet for target PCs of both bitnesses on a 64-bit host, it is not clear whether the reverse is true with a 32-bit host. These will pull in a number of other required packages as well (the ''--needed'' option prevents the re-installation of packages that have already been installed by MSYS2/Mingw-w64's own setup/installation process) - as some of the packages, e.g. ''base-devel'' are actually ''groups'' you will be requested to select which members of that group are actually required, it is easiest to just go with the default which is to install ALL of the packages in that group!<br />
<br />
: For 32-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ pacman -S --needed base-devel git mercurial cvs wget ruby zip p7zip python mingw-w64-i686-toolchain mingw-w64-i686-qt-creator mingw-w64-i686-qt5-multimedia mingw-w64-i686-libzip mingw-w64-i686-pugixml mingw-w64-i686-lua51 mingw-w64-i686-lua51-lpeg mingw-w64-i686-lua51-lsqlite3 mingw-w64-i686-hunspell mingw-w64-i686-boost mingw-w64-i686-yajl mingw-w64-i686-clang mingw-w64-i686-cmake mingw-w64-i686-SDL unzip<br />
</syntaxhighlight><br />
<br />
: For 64-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ pacman -S --needed base-devel git mercurial cvs wget ruby zip p7zip python mingw-w64-x86_64-toolchain mingw-w64-x86_64-qt-creator mingw-w64-x86_64-qt5-multimedia mingw-w64-x86_64-libzip mingw-w64-x86_64-pugixml mingw-w64-x86_64-lua51 mingw-w64-x86_64-lua51-lpeg mingw-w64-x86_64-lua51-lsqlite3 mingw-w64-x86_64-hunspell mingw-w64-x86_64-boost mingw-w64-x86_64-yajl mingw-w64-x86_64-clang mingw-w64-x86_64-cmake mingw-w64-x86_64-SDL unzip<br />
</syntaxhighlight><br />
<br />
::The ''*-zziplib'' libraries are used by the ''luazip'' luarock {from the Kepler project} but Mudlet will work perfectly well with the alternative ''lua-zip'' {from the brimworks GitHub repository - which also provides the ''lua-yajl'' rock} which does not require this library - although it is possible that it might still be pulled into the system as a dependency of another MSYS2 package.<br />
<br />
:Note that this will install the MSYS2 builds of the Qt Libraries and Creator IDE - ''THE ON/OFF-LINE INSTALLER OF THE QT LIBRARIES AND CREATOR VIA DOWNLOADS FROM QT ARE NOT USEFUL IN THIS SETUP!''<br />
<br />
:{| class="wikitable"<br />
|-<br />
|'''Attention - Luarocks packages problem'''<br />
|-<br />
| Recently the Luarocks project attempted to adopt the MSYS2/Mingw-w64 platform as one it would supported natively and the MSYS2/Mingw-w64 project went and upgraded its luarocks packages to make use of the changes and also on-board other improvements (and the version number increased from ''2.4.4-2'' to ''3.5.0-1'') unfortunately this completely broke them and although the issue has been reported ([https://github.com/msys2/MINGW-packages/issues/9037 MSYS2 Issue 9037]) a fix has not yet materialised. The only way to work around this in the meantime is to download the older package (with '''wget''') and install it manually (with '''pacman -U):<br />
|-<br />
|For 32-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ wget https://repo.msys2.org/mingw/mingw32/mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
--2021-07-07 22:19:09-- https://repo.msys2.org/mingw/mingw32/mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
Resolving repo.msys2.org (repo.msys2.org)... 178.63.98.68<br />
Connecting to repo.msys2.org (repo.msys2.org)|178.63.98.68|:443... connected.<br />
HTTP request sent, awaiting response... 200 OK<br />
Length: 97905 (96K) [application/octet-stream]<br />
Saving to: ‘mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’<br />
<br />
mingw-w64-i686-lua51-luarocks-2.4.4-2- 100%[===========================================================================>] 95.61K --.-KB/s in 0.07s<br />
<br />
2021-07-07 22:19:10 (1.43 MB/s) - ‘mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’ saved [97905/97905]<br />
<br />
<br />
MSYS user@computer ~<br />
$ pacman -U mingw-w64-i686-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
loading packages...<br />
resolving dependencies...<br />
looking for conflicting packages...<br />
<br />
Packages (1) mingw-w64-i686-lua51-luarocks-2.4.4-2<br />
<br />
Total Installed Size: 0.46 MiB<br />
<br />
:: Proceed with installation? [Y/n] y<br />
(1/1) checking keys in keyring [#####################################################] 100%<br />
(1/1) checking package integrity [#####################################################] 100%<br />
(1/1) loading package files [#####################################################] 100%<br />
(1/1) checking for file conflicts [#####################################################] 100%<br />
(1/1) checking available disk space [#####################################################] 100%<br />
:: Processing package changes...<br />
(1/1) installing mingw-w64-i686-lua51-luarocks [#####################################################] 100%<br />
<br />
MSYS user@computer ~<br />
</syntaxhighlight><br />
|-<br />
|For 64-Bit Mudlet builds:<br />
:<syntaxhighlight lang="shell"><br />
MSYS user@computer ~<br />
$ wget https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
--2021-07-07 22:17:32-- https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
Resolving repo.msys2.org (repo.msys2.org)... 178.63.98.68<br />
Connecting to repo.msys2.org (repo.msys2.org)|178.63.98.68|:443... connected.<br />
HTTP request sent, awaiting response... 200 OK<br />
Length: 97935 (96K) [application/octet-stream]<br />
Saving to: ‘mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’<br />
<br />
mingw-w64-x86_64-lua51-luarocks-2.4.4- 100%[===========================================================================>] 95.64K --.-KB/s in 0.07s<br />
<br />
2021-07-07 22:17:32 (1.28 MB/s) - ‘mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst’ saved [97935/97935]<br />
<br />
<br />
MSYS user@computer ~<br />
$ pacman -U mingw-w64-x86_64-lua51-luarocks-2.4.4-2-any.pkg.tar.zst<br />
loading packages...<br />
resolving dependencies...<br />
looking for conflicting packages...<br />
<br />
Packages (1) mingw-w64-x86_64-lua51-luarocks-2.4.4-2<br />
<br />
Total Installed Size: 0.46 MiB<br />
<br />
:: Proceed with installation? [Y/n] y<br />
(1/1) checking keys in keyring [#####################################################] 100%<br />
(1/1) checking package integrity [#####################################################] 100%<br />
(1/1) loading package files [#####################################################] 100%<br />
(1/1) checking for file conflicts [#####################################################] 100%<br />
(1/1) checking available disk space [#####################################################] 100%<br />
:: Processing package changes...<br />
(1/1) installing mingw-w64-x86_64-lua51-luarocks [#####################################################] 100%<br />
<br />
MSYS user@computer ~<br />
</syntaxhighlight><br />
|}<br />
<br />
::{| class="wikitable"<br />
|-<br />
|'''Warning for those planning to build ''both'' 32 and 64 bit versions'''<br />
|-<br />
|If one is planning to build ''both'' bitness binaries an additional step is necessary as, by default, the MSYS2/Mingw-w64 ''luarocks'' setup seems to place any ''.lua'' or ''.dll'' modules it builds/installs on a per user (the so-called ''local'' basis) into the same directories with the same names. This is no good for two reasons:<br />
* It is difficult to work out which bitness a particular module is for and whilst 32-bit modules ''might'' work in a 64-bit environment the reverse is definitely not the case<br />
* It confuses the Luarocks package management systems (as effectively there will be two different luarocks systems operated side-by-side)<br />
<br />
This can be worked around by:<br />
* Editing the '''.\etc\luarocks\config-5.1.lua''' for each bitness so that the ''rocks_trees'' table entry for the ''user'' key is changed from this in '''both''' files:<br />
:<syntaxhighlight lang="lua"> { name = [[user]], root = home..[[/.luarocks]] },</syntaxhighlight><br />
to something different for each of them, say, for example, for the the 64-bit one:<br />
:<syntaxhighlight lang="lua"> { name = [[user]], root = home..[[/.luarocks-x64]] },</syntaxhighlight><br />
* Then by specifying the ''rocktree'' name ('''user''') on the command line when '''installing''' or '''building''' a luarock with the ''--tree user'' argument - note that for some inexplicable reason the ''--local'' argument that '''''should''''' do the same thing does not seem to work for these two actions, it is not clear whether this is a MSYS2/Mingw-w64 specific issue or it goes further upstream to Luarocks in general. Thus, in the next step it will be necessary to change from using:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install --local rockname<br />
</syntaxhighlight><br />
to, for the example given:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install --tree user rockname<br />
</syntaxhighlight><br />
where ''user'' is the literal string "user" to match the Lua table key in the rock_trees and not, in this case, a representation of the user-name/account of the person performing the action.<br />
|}<br />
<br />
From the Windows ''Start menu'' start a shell appropriate for the target with the bitness to be built for i.e. '''"MSYS2 Mingw 32-Bit"''' or '''"MSYS2 Mingw 64-Bit"'''. This will likely position the current directory to the root directory of the MSYS2 environment, the text about the prompt line (the one with the "$") will contain three different bits of colored text '''username@computername'''; one of '''MSYS2'''/'''MINGW32'''/'''MINGW''' depending on the type of shell you currently in use and '''/''' representing the root directory (which will actually be the directory MSYS2 was installed to, for example on the author's system this is "C:/msys64"). Change to the home directory in MYSY by entering "cd" on its own with no argument (it will show up as '''~''' and it would work out to be, for '''user''' to be '''c:/msys64/home/user''' or '''c:/msys32/home/user''' (if both bitnessess are to be built it will be necessary to repeat the following step twice, one for each and also observe the steps in the above warning) install the following luarocks:<br />
<br />
:{| class="wikitable sortable"<br />
|-<br />
! rockname<br />
|-<br />
| lrexlib-pcre<br />
|-<br />
| lua-yajl<br />
|-<br />
| luafilesystem<br />
|-<br />
| luasql-sqlite3<br />
|-<br />
| luautf8<br />
|-<br />
| luazip or lua-zip<br />
|}<br />
by using:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ luarocks install [--local] rockname<br />
</syntaxhighlight><br />
The ''--local'' argument is an optional one that causes the luarock and the lua module to be installed on a per-user basis rather than on a system wide one, this may be important if the PC is used by multiple users and more than one of them uses Lua in any form.<br />
<br />
Now create somewhere to work on the Mudlet source, assuming that other software coding with other pieces of software will be done, create a sub-directory in the home directory, and then make one just for Mudlet under that:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ mkdir ./src<br />
<br />
MINGW64 user@computer ~<br />
$ mkdir ./src/mudlet<br />
</syntaxhighlight><br />
<br />
Change to that directory and get the source code:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~<br />
$ cd ./src/mudlet<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git clone git://github.com/Mudlet/Mudlet.git .<br />
</syntaxhighlight><br />
<br />
If you are planning to contribute to the Mudlet code you will want to visit Github and create your own GitHub repository, you can then push commits (changes to the code) to there and raise a Pull Request for a Mudlet Maker to drag the changes over to the above repository. You will want to add your repository and perhaps those of some other contributors so you can track what they are doing and see/try/experiment with their PRs before they get merged. Therefore you will want to add some other repositories into the mix. The names you use to identify those other repositories will show up in any utility that works with the repository you have just created in the above "clone" operation and can be anything you like but it makes sense to have clear names. So to add "myName", and those of the leading active contributors to the Mudlet codebase you will use:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Mine https://github.com/myName/Mudlet.git<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Vadim https://github.com/vadi2/Mudlet.git <br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add SlySven https://github.com/SlySven/Mudlet.git<br />
<br />
MINGW64 user@computer ~/src/mudlet<br />
$ git remote add Kebap https://github.com/Kebap/Mudlet.git<br />
</syntaxhighlight><br />
<br />
Now obtain ''all'' the versions of the code with:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ git fetch --all<br />
</syntaxhighlight><br />
<br />
This will produce a lot of lines of output the first time and it might take a little while on a slow connection...<br />
<br />
{Section missing - it turns out that the default GUI git tools that the author of this section would normally use: "gitk" and "git gui" have some problems in the versions currently supplied from the MSYS2 system - and it was necessary to import them from the set that the Git4Win have patched - see https://github.com/git-for-windows/git/wiki/Install-inside-MSYS2-proper }<br />
<br />
Some modifications to the qmake/cmake project files are needed and these are now supported in the main ''development'' branch in the upstream {the Mudlet organisation's own GitHub repository} which requires that there is an environmental variable '''WITH_MAIN_BUILD_SYSTEM''' and it is set to the (case-insensitive) value '''NO''':<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ export WITH_MAIN_BUILD_SYSTEM=NO<br />
</syntaxhighlight><br />
<br />
Also the '''MINGW_BASE_DIR''' environmental variable will need to be set to the root directory for the MINGW-W64 installation for the appropriate bitness of the target to be made. For building on a 64-Bit Host {the PC that is ''compiling'' the code} to make a 64-Bit application this will likely be '''C:/msys64/mingw64''' and for a 32-Bit application it will probably be '''C:/msys64/ming32'''.<br />
: E.g. <syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ export MINGW_BASE_DIR=C:/msys64/mingw64 # To build a 64-Bit Application with a 64-Bit system<br />
</syntaxhighlight><br />
<br />
: Or: <syntaxhighlight lang="shell"><br />
MINGW32 user@computer ~/src/mudlet<br />
$ export MINGW_BASE_DIR=C:/msys64/mingw32 # To build a 32-Bit Application with a 64-Bit system<br />
</syntaxhighlight><br />
<br />
Now checkout a branch {ideally, if working on solving a new issue, or adding a feature or resolving a bug, one should create a new branch that is a copy of the current, upstream ''development'' branch} and then work on it with Qt Creator:<br />
:<syntaxhighlight lang="shell"><br />
MINGW64 user@computer ~/src/mudlet<br />
$ qtcreator &<br />
</syntaxhighlight><br />
<br />
Load in the '''mudlet.pro''' ''qmake'' project file in the '''src''' subdirectory (e.g. for this example: '''c:/msys64/home/user/src/mudlet/src/mudlet.pro''') and get hacking...<br />
<br />
= Setting up IDEs =<br />
== CLion ==<br />
=== Qt not detected ===<br />
If you'd like to use CLion and it is giving the following error:<br />
<br />
<nowiki><br />
By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has<br />
asked CMake to find a package configuration file provided by "Qt5Core", but<br />
CMake did not find one.<br />
<br />
...<br />
</nowiki><br />
<br />
You can fix this by setting <code>-DCMAKE_PREFIX_PATH=<your Qt + version + compiler location></code>. For example: <code>-DCMAKE_PREFIX_PATH=/media/vadi/SSDer/Programs/Qt/5.15.2/gcc_64/</code> [[File:CLion CMake settings - finidng Qt.png|700px|none]]<br />
<br />
=== Setup on Windows ===<br />
After running <code>setup-windows-sdk.ps1</code> make sure to set Cmake options to:<br />
-DCMAKE_PREFIX_PATH=C:\Qt\Tools\mingw730_32;C:\Qt\5.14.2\mingw73_32 -DBoost_INCLUDE_DIR=C:\Libraries\boost_1_71_0<br />
[[File:Clion Settings - Cmake.png|frameless|700x700px]]<br />
<br />
<br />
You will need 32 bit version of MinGW. Set it in the <code>Toolset</code> field to:<br />
C:\Qt\Tools\mingw730_32<br />
<br />
<br />
[[File:Toolchain.png|frameless|700x700px]]<br />
<br />
=== Clang Tidy ===<br />
Ensure that CLion is set to run the project's [https://www.jetbrains.com/help/clion/clang-tidy-checks-support.html#paticularcheck .clang-tidy checks] with the <code>Prefer .clang-tidy files over IDE settings</code> option:<br />
<br />
[[File:Clang Tidy CLIon.png|700px|none]]<br />
<br />
This helps us catch any issues just a bit earlier.<br />
<br />
=== Clang Format ===<br />
Ensure that [https://www.jetbrains.com/help/clion/clangformat-as-alternative-formatter.html#clion-support CLion is set to use] the <code>.clang-format</code> formatting style:<br />
<br />
[[File:Clang-format CLion.png]]<br />
<br />
This helps keep the look'n'feel of the source code in a consistent manner, even with many people contributing to Mudlet.<br />
<br />
== Visual Studio Code ==<br />
<br />
To set the path in Visual Studio Code, open settings, search for <code>cmake environment</code> and set the <code>CMAKE_PREFIX_PATH</code> to your path, such as <code>/media/vadi/SSDer/Programs/Qt/5.14.1/gcc_64/</code>:<br />
<br />
[[File:CMake path in Visual Studio Code.png|none]]<br />
<br />
===Clang Tidy===<br />
clang-tidy catches common programming issues, run it by selecting 'Analysis' from the command palette (Ctrl+Shift+P by default):<br />
<br />
[[File:Clang-tidy in vscode.png|none]]<br />
<br />
It is also possible [https://devblogs.microsoft.com/cppblog/visual-studio-code-c-december-2021-update-clang-tidy/ check status of analysis and cancel if needed].<br />
<br />
===Checking memory leaks & other issues (sanitizers)===<br />
Besides clang-tidy, it's also possible to enable clang sanitizers to double-check for issues:<br />
<br />
* [https://clang.llvm.org/docs/LeakSanitizer.html LeakSanitizer] for detecting memory leaks<br />
* [https://clang.llvm.org/docs/AddressSanitizer.html AddressSanitizer] for detecting most issues dealing with memory, such as out of bounds accesses to heap, stack, global and more<br />
* [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html UndefinedBehaviourSanitizer] for detecting the use of various features of C/C++ that are explicitly listed as resulting in undefined behaviour (such as using misaligned or null pointer, conversion to, from, or between floating-point types which would overflow the destination, division by zero, etc)<br />
* [https://clang.llvm.org/docs/MemorySanitizer.html MemorySanitizer] for detecting reading uninitialised memory<br />
* [https://clang.llvm.org/docs/ThreadSanitizer.html ThreadSanitizer] for detecting threading issues<br />
<br />
To use the sanitisers, set the <code>USE_SANITIZER</code> CMake variable to one or several variables (separate by comma): <code>Address</code>, <code>Memory</code>, <code>MemoryWithOrigins</code>, <code>Undefined</code>, <code>Thread</code>, or <code>Leak</code><br />
<br />
To use them in VSCode, set the <code>cmake.configureSettings</code> variable:<br />
<br />
[[File:Cmake.configureSettings option in vscode.png|frameless|890x890px]]<br />
<br />
[[File:Choosing which sanitizers in vscode to use.png|frameless|891x891px]]<br />
<br />
Not all sanitisers can be used with each other - in that case the cmake configuration won't allow you to continue.<br />
<br />
== Qt Creator==<br />
===Clang Tidy and Clazy===<br />
<br />
Configure Mudlet-specific checks for [https://clang.llvm.org/extra/clang-tidy/ clang-tidy] and [https://github.com/KDE/clazy clazy] tools help catch any issues early on. See [https://doc.qt.io/qtcreator/creator-clang-tools.html Qt Creator's instructions] for setting this up - clang-tidy can use the <code>.clang-tidy</code> file that's available at the root of the repository, and for clazy enable <code>level0</code> and <code>level1</code> checks.<br />
<br />
[[File:Clang tidy configuration.png|frame|none]]<br />
[[File:Clazy configuration.png|frame|none]]<br />
<br />
===Checking memory leaks & other issues (sanitizers)===<br />
Besides clang-tidy, it's also possible to enable clang sanitizers to double-check for issues:<br />
<br />
* [https://clang.llvm.org/docs/LeakSanitizer.html LeakSanitizer] for detecting memory leaks<br />
* [https://clang.llvm.org/docs/AddressSanitizer.html AddressSanitizer] for detecting most issues dealing with memory, such as out of bounds accesses to heap, stack, global and more<br />
* [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html UndefinedBehaviourSanitizer] for detecting the use of various features of C/C++ that are explicitly listed as resulting in undefined behaviour (such as using misaligned or null pointer, conversion to, from, or between floating-point types which would overflow the destination, division by zero, etc)<br />
* [https://clang.llvm.org/docs/MemorySanitizer.html MemorySanitizer] for detecting reading uninitialised memory<br />
* [https://clang.llvm.org/docs/ThreadSanitizer.html ThreadSanitizer] for detecting threading issues<br />
<br />
To use the sanitisers, set the <code>USE_SANITIZER</code> CMake variable to one or several variables (separate by comma): <code>Address</code>, <code>Memory</code>, <code>MemoryWithOrigins</code>, <code>Undefined</code>, <code>Thread</code>, or <code>Leak</code><br />
<br />
To use them in Qt creator, head to <code>Projects</code> - <code>Build</code>: <br />
<br />
[[File:Sanitisers in qt creator.png|frameless|890x890px]]<br />
<br />
Not all sanitisers can be used with each other - in that case the cmake configuration won't allow you to continue.<br />
<br />
==Clang Format==<br />
Ensure that Qt Creator is set to use the <code>.clang-format</code> formatting style in the C++ settings. Turn on <code>Format instead of indenting</code> for <code>Ctrl+I</code> to format code, and ensure <code>Override Clang Format configuration file</code> is disabled:<br />
<br />
[[File:Qt Creator clang format.png]]<br />
<br />
This helps keep the look'n'feel of the source code in a consistent manner, even with many people contributing to Mudlet.<br />
<br />
<br />
=Building with multiple versions of Lua=<br />
Mudlet uses Lua 5.1 only, so if you are compiling on a system that also has later versions installed, you might get the following error: <code>‘LUA_GLOBALSINDEX’ was not declared in this scope</code>.<br />
<br />
To fix this, pass the path to Lua headers explicitly. For CMake: <code>-DLUA_INCLUDE_DIR=/usr/include/lua5.1</code> (adjust as needed).</div>Dargothhttps://wiki.mudlet.org/index.php?title=File:Toolchain.png&diff=19770File:Toolchain.png2022-01-19T23:04:44Z<p>Dargoth: </p>
<hr />
<div>MinGW</div>Dargothhttps://wiki.mudlet.org/index.php?title=File:Clion_Settings_-_Cmake.png&diff=19769File:Clion Settings - Cmake.png2022-01-19T23:02:14Z<p>Dargoth: </p>
<hr />
<div>Where to set CMake settings</div>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=18620Manual:UI Functions2022-01-10T10:27:59Z<p>Dargoth: /* addCommandLineMenuEvent */</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window,] label, eventName)<br />
<br />
Adds item to right click menu associated with command line.<br />
<br />
{{MudletVersion|4.14}}<br />
<br />
;See also: [[Manual:Lua_Functions#removeCommandLineMenuEvent|removeCommandLineMenuEvent()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that command line belongs to. Optional, will default to "main" (main window console)<br />
* ''label:''<br />
: Label of item<br />
* ''eventName:''<br />
: Event name that will be fired when clicked.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addCommandLineMenuEvent("My very own special paste from clipboard", "pasteFromCliboardWithoutLineBreaks" )<br />
registerAnynomousEventListener("pasteFromCliboardWithoutLineBreaks", function()<br />
local text = string.gsub(getClipboardText(), "[\r|\n]", "")<br />
appendCmdLine(text)<br />
end)<br />
</syntaxhighlight><br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<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)</syntaxhighlight><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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code> and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() send("hi") end, "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 - [[Manual:Lua_Functions#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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of strings which will be shown on the popup and right-click menu. i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- # format also works<br />
hechoLink("#ca00040black!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
{{MudletVersion|4.1}}<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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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, as text or a function (since Mudlet 4.11).<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!", function() send("hi") end, "This is a tooltip", true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)<br />
</syntaxhighlight><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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight><br />
* ''{hints}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"}, true)<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)<br />
</syntaxhighlight><br />
<br />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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, as text or a function (since Mudlet 4.11).<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!", function() echo("you clicked me!\n") end, "Click me popup")<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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!", function() echo("you clicked me!\n") end, "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 to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==removeCommandLineMenuEvent==<br />
;removeCommandLineMenuEvent([window,] label)<br />
<br />
:Removes an existing command line menu event.<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that item is associated with. Optional, defaults to "main" (main window console).<br />
* ''label:''<br />
: Label under which element is registered<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<br />
<br />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><br />
<br />
==selectCaptureGroup==<br />
;selectCaptureGroup(groupNumber)<br />
: Selects the content of the capture group number in your Perl regular expression (from matches[]). Also works with named capture group. It does not work with multimatches.<br />
<br />
:See also: [[#selectCurrentLine| selectCurrentLine()]]<br />
<br />
;Parameters<br />
* ''groupNumberOrName:''<br />
: number of the capture group you want to select, or the name of the capture group as a string<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 />
<br />
-- Or perhaps instead if you were to use "you have (?<euro>\d+) Euro"<br />
selectCaptureGroup("euro")<br />
fg("green")<br />
</syntaxhighlight><br />
<br />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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, as text or Lua function.<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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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", {function() send("bye") end, function() echo("hi!") end}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<br />
-- alternatively, put command as text (in [[ and ]] to use quotation marks inside)<br />
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"send 'bye' to the MUD", "click to echo 'hi!'"})<br />
<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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=18412Manual:UI Functions2021-11-22T10:04:49Z<p>Dargoth: /* UI Functions */</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window,] label, eventName)<br />
<br />
Adds item to right click menu associated with command line.<br />
<br />
{{MudletVersion|4.14}}<br />
<br />
;See also: [[Manual:Lua_Functions#removeCommandLineMenuEvent|removeCommandLineMenuEvent()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that command line belongs to. Optional, will default to "main" (main window console)<br />
* ''label:''<br />
: Label of item<br />
* ''eventName:''<br />
: Event name that will be fired when clicked.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addCommandLineMenuEvent("My very own special paste from clipboard", "pasteFromCliboardWithoutLineBreaks" )<br />
registerAnynomousEventListener("pasteFromCliboardWithoutLineBreaks", function()<br />
local text = string.gsub(getClipboardText(), "[\r|\n]", "")<br />
appendCmdLine(text)<br />
end<br />
</syntaxhighlight><br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code> and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==removeCommandLineMenuEvent==<br />
;removeCommandLineMenuEvent([window,] label)<br />
<br />
:Removes an existing command line menu event.<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that item is associated with. Optional, defaults to "main" (main window console).<br />
* ''label:''<br />
: Label under which element is registered<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<br />
<br />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=18411Manual:UI Functions2021-11-22T10:02:00Z<p>Dargoth: /* addCommandLineMenuEvent */</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window,] label, eventName)<br />
<br />
Adds item to right click menu associated with command line.<br />
<br />
{{MudletVersion|4.14}}<br />
<br />
;See also: [[Manual:Lua_Functions#removeCommandLineMenuEvent|removeCommandLineMenuEvent()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that command line belongs to. Optional, will default to "main" (main window console)<br />
* ''label:''<br />
: Label of item<br />
* ''eventName:''<br />
: Event name that will be fired when clicked.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addCommandLineMenuEvent("My very own special paste from clipboard", "pasteFromCliboardWithoutLineBreaks" )<br />
registerAnynomousEventListener("pasteFromCliboardWithoutLineBreaks", function()<br />
local text = string.gsub(getClipboardText(), "[\r|\n]", "")<br />
appendCmdLine(text)<br />
end<br />
</syntaxhighlight><br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code> and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=18410Manual:UI Functions2021-11-22T10:00:16Z<p>Dargoth: /* addCommandLineMenuEvent */</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window,] label, eventName)<br />
<br />
Adds item to right click menu associated with command line.<br />
<br />
{{MudletVersion|4.14}}<br />
<br />
;See also: [[Manual:Lua_Functions#removeCommandLineMenuEvent|removeCommandLineMenuEvent()]]<br />
<br />
;Parameters<br />
* ''window:''<br />
: Window that command line belongs to. Optional, will default to "main" (main window console)<br />
* ''label:''<br />
: Label of item<br />
* ''eventName:''<br />
: Event name that will be fired when clicked.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code> and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=18409Manual:UI Functions2021-11-22T09:55:53Z<p>Dargoth: /* UI Functions */</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 />
==addCommandLineMenuEvent==<br />
;addCommandLineMenuEvent([window], label, eventName)<br />
<br />
TO FILL<br />
<br />
==addMouseEvent==<br />
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])<br />
<br />
:Registers a new context menu option when right-clicked on a console window. Will return ''true'' if the event was added successfully, otherwise ''nil''+''message'' will be returned. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier for the mouse event.<br />
* ''eventName:''<br />
: Name of the Mudlet event that will handle the data.<br />
* ''displayName:''<br />
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.<br />
* ''tooltipText:''<br />
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.<br />
<br />
;Returns <br />
* Returns ''true'' if the mouse event was added successfully.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- An example showing implementing a hecho-friendly copy option:<br />
<br />
addMouseEvent("hecho copy", "onMouseCopyExample")<br />
<br />
function rgbToHex(r,g,b)<br />
local rgb = (r * 0x10000) + (g * 0x100) + b<br />
return string.format("#%x", rgb)<br />
end<br />
<br />
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)<br />
-- Check whether there's an actual selection<br />
if startCol == endCol and startRow == endRow then return end<br />
local parsed = ""<br />
local lastColor = nil<br />
-- Loop through each symbol within the range<br />
for l = startRow, endRow do<br />
local cStart = l == startRow and startCol or 0<br />
moveCursor(window, cStart, l)<br />
local cEnd = l == endRow and endCol or #getCurrentLine() - 1<br />
for c = cStart, cEnd do<br />
selectSection(window, c, 1)<br />
local symbol = getSelection(window) or ""<br />
-- Convert the foreground color to a hex format, suitable for hecho<br />
local color = rgbToHex(getFgColor(window))<br />
-- Don't repeat the color if previous one was the same<br />
if color == lastColor then<br />
parsed = parsed .. symbol<br />
else<br />
lastColor = color<br />
parsed = parsed .. color .. symbol<br />
end<br />
end<br />
if l ~= endRow then parsed = parsed .. "\n" end<br />
end<br />
setClipboardText(parsed)<br />
end<br />
<br />
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")<br />
</syntaxhighlight><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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==closestColor==<br />
; closestColor(colorOrR[,G,B])<br />
<br />
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''colorOrR:''<br />
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB when followed by two next optional parameters<br />
* ''G:''<br />
: (optional) green component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
* ''B:''<br />
: (optional) blue component of RGB coordinates. Only needed if first parameter sent as the Red component only<br />
<br />
;Returns<br />
* The closest color name from the color_table to the one supplied on success<br />
* nil + error if it cannot parse the parameters into a color.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"<br />
local colorName = closestColor({127, 255, 127}) -- "ansi_120"<br />
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"<br />
local colorName = closestColor("#a020e6") -- "purple"<br />
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)<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 />
: See also: [[#decho|decho()]]<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 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 (fills from left to right), vertical (fills bottom to top), goofy (fills right to left), or batty (fills top to bottom).<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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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 />
:You can also include <code><nowiki><i>italics</i></nowiki></code>, <code><nowiki><b>bold</b></nowiki></code> and <code><nowiki><u>underline</u></nowiki></code> tags.<br />
<br />
: See also: [[#cecho|cecho()]], [[#hecho|hecho()]], [[#copy2decho|copy2decho()]]<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getMouseEvents==<br />
; events = getMouseEvents()<br />
<br />
:Returns a table of registered mouse events, including any of the additional arguments they may have.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]<br />
<br />
;Returns <br />
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.<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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==removeMouseEvent==<br />
; removeMouseEvent(uniqueName)<br />
<br />
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]<br />
<br />
;Parameters<br />
* ''uniqueName:''<br />
: A unique identifier that the mouse event was registered under.<br />
<br />
;Returns <br />
* Returns ''True'' If the mouse event was removed successfully.<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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
==selectCmdLineText==<br />
;selectCmdLineText([commandLine])<br />
: Selects the text in your command line. You can specify which one, if you got many.<br />
<br />
:See also: [[#createCommandLine| createCommandLine()]]<br />
<br />
{{MudletVersion|4.13}}<br />
<br />
;Parameters<br />
* ''commandLine:''<br />
: (optional) name of the command line you want to have selected<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- First, create an extra commandline with the following lua script:<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%"<br />
}, inputContainer)<br />
inputContainer:attachToBorder("bottom")<br />
<br />
-- Now you can send the following lua code with your main command line.<br />
-- It will give 2 seconds time to click around, unselect its text, etc. before selecting its text for you:<br />
lua tempTimer(2, function() selectCmdLineText() end)<br />
<br />
-- This will instead select the text in the command line named extraCmdLine:<br />
lua selectCmdLineText('extraCmdLine')<br />
<br />
-- Same as before, but using the Geyser.CommandLine function instead:<br />
lua extraCmdLine:selectText() <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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:Event_Engine&diff=18296Manual:Event Engine2021-10-22T08:57:10Z<p>Dargoth: /* sysGetHttpDone */</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Manual on events, which events exist, how to raise events, how to handle them.}}<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, [one shot])]]'' 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", false)<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 = #args<br />
local first = args[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 />
===AdjustableContainerReposition===<br />
Raised while a [[Manual:Geyser#Adjustable.Container|adjustable container]] is re-positioned. <br />
<br />
<syntaxhighlight lang="lua"><br />
function repositioningContainer(eventName, containerName, width, height, x, y, mouseAction)<br />
print(f"{containerName}: {x}x, {y}y, {width}x{height}, using mouse? {mouseAction}")<br />
end<br />
<br />
registerAnonymousEventHandler("AdjustableContainerReposition", "repositioningContainer")<br />
</syntaxhighlight><br />
<br />
===AdjustableContainerRepositionFinish===<br />
Raised when an [[Manual:Geyser#Adjustable.Container|adjustable container]] done being re-positioned.<br />
<br />
<syntaxhighlight lang="lua"><br />
function finishedRepositioning(eventName, containerName, width, height, x, y)<br />
print(f"{containerName}: {x}x, {y}y, {width}x{height}")<br />
end<br />
<br />
registerAnonymousEventHandler("AdjustableContainerRepositionFinish", "finishedRepositioning")<br />
</syntaxhighlight><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 />
===mapModeChangeEvent===<br />
<br />
Raised when the mapper is switchting between "view-only" and "editing" mode of the [[Manual:Mapper#Visual_Map_Editor|Visual Map Editor]]. A value of "editing" or "viewing" will be given as argument to indicate which mode was entered.<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 />
{{MudletVersion|3.19}}<br />
<br />
===sysConnectionEvent===<br />
<br />
Raised when the profile becomes connected to a MUD.<br />
<br />
===sysCustomHttpDone===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#customHTTP|customHTTP()]] 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) and HTTP method.<br />
<br />
See also [[#sysCustomHttpError|sysCustomHttpError]].<br />
<br />
===sysCustomHttpError===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#customHTTP|customHTTP()]] request fails. Arguments are the error message and the URL that the request was sent to and HTTP method.<br />
<br />
See also [[#sysCustomHttpDone|sysCustomHttpDone]].<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.<br />
<br />
If you'd like to automatically reconnect when you get disconnected, make a new <code>Script</code> and add this inside:<br />
<br />
<syntaxhighlight lang="lua"><br />
registerAnonymousEventHandler("sysDisconnectionEvent", "reconnect")<br />
</syntaxhighlight><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. 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 />
===sysDownloadFileProgress===<br />
<br />
Raised while file is being downloaded to indicate progess of download.<br />
<br />
The arguments passed areː: event name, url of download, bytes downloaded, total bytes (if available).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- will show progress bar while download file and hide it after file download is complete<br />
local progressBar = Geyser.Gauge:new({<br />
name="downloadProgressBar",<br />
x="25%", y="10%",<br />
width="50%", height="5%",<br />
})<br />
progressBar:setFontSize(13)<br />
progressBar:setAlignment("center")<br />
progressBar:hide()<br />
<br />
<br />
local fileUrl = "https://www.mudlet.org/download/Mudlet-4.10.1-linux-x64.AppImage.tar"<br />
local targetFile = getMudletHomeDir() .. "/Mudlet.tar"<br />
function handleProgress(_, url, bytesDownloaded, totalBytes)<br />
if url ~= fileUrl then<br />
return<br />
end<br />
<br />
progressBar:show()<br />
<br />
if not totalBytes then<br />
bytesDownloaded = 0<br />
totalBytes = 1<br />
end<br />
<br />
progressBar:setValue(bytesDownloaded, totalBytes, math.floor((bytesDownloaded / totalBytes) * 100) .. "%")<br />
end<br />
<br />
registerAnonymousEventHandler("sysDownloadFileProgress", "handleProgress")<br />
<br />
function hideProgressBar()<br />
tempTimer(3, function() progressBar:hide() end)<br />
end <br />
<br />
registerAnonymousEventHandler("sysDownloadDone", "hideProgressBar")<br />
registerAnonymousEventHandler("sysDownloadError", "hideProgressBar")<br />
<br />
downloadFile(targetFile, fileUrl)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11}}<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 />
{{MudletVersion|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 />
===sysDropUrlEvent===<br />
<br />
Raised when a url is dropped on the Mudlet main window or a userwindow.<br />
As an url at the moment Mudlet understands<br />
The arguments passed areː url, schema, xpos, ypos, and consolename - "main" for the main window and otherwise of the userwindow/miniconsole name.<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
<syntaxhighlight lang="lua"><br />
function onDragAndDropUrl(_, url, schema, xpos, ypos, consolename)<br />
print(string.format("Dropped new url into %s: %s (suffix: %s)", consolename, filepath, suffix))<br />
if schema == "http" or schema == "https" then<br />
print("\nOh boy... this might be a link to some website")<br />
end<br />
end<br />
registerAnonymousEventHandler("sysDropUrlEvent", "onDragAndDropUrl")<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|3.3}}<br />
<br />
-- Gamepad events do not actually seem to work --><br />
<br />
===sysGetHttpDone===<br />
<br />
Raised whenever a [[Manual:Networking Functions#getHTTP|getHTTP()]] 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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
<br />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|3.0}}<br />
<br />
===sysMapDownloadEvent===<br />
<br />
Raised whenever an [[Standards:MMP|MMP map]] is downloaded and loaded in.<br />
<br />
===sysPathChanged===<br />
<br />
Raised whenever file or directory added through [[Manual:Lua_Functions#addFileWatch|addFileWatch()]] is modified.<br />
<br />
For directories this event is emitted when the directory at a specified path is modified (e.g., when a file is added or deleted) or removed from disk. Note that if there are several changes during a short period of time, some of the changes might not emit this signal. However, the last change in the sequence of changes will always generate this signal.<br />
<br />
For files this event is emitted when the file at the specified path is modified, renamed or removed from disk.<br />
<br />
{{MudletVersion|4.12}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
herbs = {}<br />
local herbsPath = getMudletHomeDir() .. "/herbs.lua"<br />
function herbsChangedHandler(_, path)<br />
if path == herbsPath then<br />
table.load(herbsPath, herbs)<br />
removeFileWatch(herbsPath)<br />
end<br />
end<br />
<br />
addFileWatch(herbsPath)<br />
registerAnonymousEventHandler("sysPathChanged", "herbsChangedHandler")<br />
</syntaxhighlight><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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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. <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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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, or when one of the borders 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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:String_Functions&diff=17691Manual:String Functions2021-09-13T13:02:29Z<p>Dargoth: /* f */</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Mudlet API documentation for functions used to manipulate strings.}}<br />
= String Functions =<br />
A collection of functions used to manipulate strings.<br />
==addWordToDictionary==<br />
;addWordToDictionary(word)<br />
:Adds the given word to the custom profile or shared dictionary (whichever is selected in preferences).<br />
<br />
: Returns true on success (the word was actually ''added'' to the dictionary by this call) and nil+msg on error - including if the word was already there - this is so that if you have other scripts that you wish to run when a word was added you can make their execution conditional on success here.<br />
<br />
:See also: [[#removeWordFromDictionary|removeWordFromDictionary()]]<br />
<br />
;Parameters<br />
* ''word:'' custom word to add to the dictionary.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addWordToDictionary("Darkwind")<br />
addWordToDictionary("黑暗的风")<br />
addWordToDictionary("норм")<br />
</syntaxhighlight><br />
<br />
;Example - function making use of return value:<br />
<syntaxhighlight lang="lua"><br />
function rememberPlayerName(name)<br />
if addWordToDictionary(n) then<br />
echo("Added '" .. n .. "' to dictionary...\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==f==<br />
; formattedString = f(str)<br />
: Allows you to combine variables and functions into text (string interpolation) using <code>{}</code>.<br />
<br />
; Parameters<br />
* ''str:''<br />
: The string to perform interpolation against.<br />
<br />
{{MudletVersion|4.11}}<br />
; Example:<br />
<br />
<syntaxhighlight lang=lua><br />
-- old way:<br />
cecho("\nHello, "..matches[2]..", how is it going?")<br />
<br />
-- new way:<br />
cecho(f("\nHello {matches[2]}, how is it going?")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang=lua><br />
testResult = "successful"<br />
-- old way:<br />
echo("The test was "..testResult.."\n")<br />
-- with f:<br />
echo(f("The test was {testResult}\n"))<br />
-- echoes "The test was successful\n"<br />
<br />
local testResult = "a failure"<br />
echo(f("The test was {testResult}\n"))<br />
-- echoes "The test was a failure\n" as it sees the local scope over global.<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang=lua><br />
-- You can also execute simple expressions<br />
echo(f("2 + 2 = {2 + 2}\n"))<br />
-- echoes "2 + 2 = 4\n"<br />
<br />
-- Or more complicated ones<br />
local function testFunc(item)<br />
return item:title()<br />
end<br />
<br />
echo(f("You should properly capitalize names, such as {testFunc('marilyn')}\n"))<br />
-- echoes "You should properly capitalize names, such as Marilyn\n"<br />
<br />
echo(f("You should properly capitalize names, such as {string.title('robert')}\n")<br />
-- same thing, but uses string.title directly and Robert instead of Marilyn<br />
</syntaxhighlight><br />
<br />
<br />
'''Caution!'''<br />
When using within closures, might not resolve variables correctly if they go out of a scope when closure is called.<br />
<syntaxhighlight lang=lua><br />
function formatter2000()<br />
local upvalue = "2000"<br />
local formatter = function() <br />
echo(f("Let's evaluate: {upvalue}\n"))<br />
end<br />
formatter() -- here evaulation inside f function will work<br />
return formatter<br />
end<br />
<br />
formatter2000()() -- here evaluation inside f function will return nil<br />
<br />
-- result<br />
-- Let's evaluate: 2000<br />
-- Let's evaulate: nil<br />
</syntaxhighlight><br />
<br />
==getDictionaryWordList==<br />
;getDictionaryWordList()<br />
:Returns the profile or shared custom dictionary word list (whichever is selected in preferences) - that is, words added via right-click "add word to dictionary" or [[#addWordToDictionary|addWordToDictionary()]].<br />
<br />
: Returns an indexed table of words.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getDictionaryWordList())<br />
</syntaxhighlight><br />
<br />
==removeWordFromDictionary==<br />
;removeWordFromDictionary(word)<br />
:Removed the given word to the custom profile or shared dictionary (whichever is selected in preferences).<br />
<br />
: Returns true on success (if the word was present and removed by this call) and nil+msg on error.<br />
<br />
:See also: [[#addWordToDictionary|addWordToDictionary()]]<br />
<br />
;Parameters<br />
* ''word:'' custom word to remove from the dictionary.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
removeWordFromDictionary("Darkwind")<br />
removeWordFromDictionary("黑暗的风")<br />
removeWordFromDictionary("норм")<br />
</syntaxhighlight><br />
<br />
==spellCheckWord==<br />
;spellCheckWord(word, [customDictionary])<br />
:Spellchecks the given word against the custom or the system dictionary.<br />
<br />
: Returns true if the word is spelled correctly or false if it's not, and nil+msg on error.<br />
<br />
:See also: [[#addWordToDictionary|addWordToDictionary()]], [[#removeWordFromDictionary|removeWordFromDictionary()]], [[#spellSuggestWord|spellSuggestWord()]]<br />
<br />
;Parameters<br />
* ''word'': word to spellcheck.<br />
* ''customDictionary'' (optional): dictionary to use. If true, the profile or shared dictionary will be used (depending on your settings). If omitted or false, the system dictionary (the language you have selected in settings) will be used.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- spellcheck against the language dictionary<br />
if spellCheckWord("run") then<br />
echo("'run' is spelled ok!\n")<br />
end<br />
<br />
-- spellcheck against the custom 'add word to dictionary'<br />
if spellCheckWord("Darkwind", true) then<br />
echo("'Darkwind' is spelled OK!\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==spellSuggestWord==<br />
;spellSuggestWord(word, [customDictionary])<br />
:Suggests similar words for the given word.<br />
<br />
: Returns a table of suggestions or nil+msg on error.<br />
<br />
:See also: [[#spellCheckWord|spellCheckWord()]]<br />
<br />
;Parameters<br />
* ''word'': word to give suggestions on.<br />
* ''customDictionary'' (optional): dictionary to use. If true, the profile or shared dictionary will be used (depending on your settings). If omitted or false, the system dictionary (the language you have selected in settings) will be used.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(spellSuggestWord("Darkwind"))<br />
</syntaxhighlight><br />
<br />
==string.byte, utf8.byte==<br />
;string.byte(string [, i [, j]]) or utf8.byte(string [, i [, j]])<br />
;<nowiki>mystring:byte([, i [, j]])</nowiki><br />
: Returns the internal numerical codes of the characters <code>s[i], s[i+1], ···, s[j]</code>. The default value for <code>i</code> is <code>1</code>; the default value for <code>j</code> is <code>i</code>.<br />
: Note that numerical codes are not necessarily portable across platforms.<br />
: string.byte() works with English text only, use utf8.byte() for the international version.<br />
: See also: [[#string.char.2C_utf8.char|string.char]], [[#string.char.2C_utf8.char|utf8.char]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the following call will return the ASCII values of "A", "B" and "C"<br />
a, b, c = string.byte("ABC", 1, 3)<br />
echo(a .. " - " .. b .. " - " .. c) -- shows "65 - 66 - 67"<br />
<br />
-- same for the international version but with the Unicode values<br />
a, b, c = utf8.byte("дом", 1, 3)<br />
echo(a .. " - " .. b .. " - " .. c) -- shows "1076 - 1086 - 1084"<br />
</syntaxhighlight><br />
<br />
==string.char, utf8.char==<br />
;string.char(···) or utf8.char(···)<br />
: Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument.<br />
: Note that numerical codes are not necessarily portable across platforms.<br />
: string.char() works with English text only, use utf8.char() for the international version.<br />
: See also: [[#string.byte.2C_utf8.byte|string.byte]], [[#string.byte.2C_utf8.byte|utf8.byte]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the following call will return the string "ABC" corresponding to the ASCII values 65, 66, 67<br />
mystring = string.char(65, 66, 67)<br />
<br />
-- same for the infernational version which will return text "дом" for the Unicode values 1076, 1086, 1084<br />
mystring = utf8.char(1076,1086,1084)<br />
print(mystring)<br />
</syntaxhighlight><br />
<br />
==string.cut==<br />
;string.cut(string, maxLen)<br />
: Cuts string to the specified maximum length.<br />
: Returns the modified string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The text you wish to cut. Passed as a string.<br />
* ''maxLen:''<br />
: The maximum length you wish the string to be. Passed as an integer number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--The following call will return 'abc' and store it in myString<br />
myString = string.cut("abcde", 3)<br />
--You can easily pad string to certain length. Example below will print 'abcde ' e.g. pad/cut string to 10 characters.<br />
local s = "abcde"<br />
s = string.cut(s .. " ", 10) -- append 10 spaces<br />
echo("'" .. s .. "'")<br />
</syntaxhighlight><br />
<br />
==string.dump==<br />
;string.dump()<br />
Converts a function into a binary string. You can use the loadstring() function later to get the function back.<br />
: string.dump() works with both English and non-English text fine.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
string = string.dump(echo("this is a string"))<br />
--The following should then echo "this is a string"<br />
loadstring(string)()<br />
</syntaxhighlight><br />
<br />
==string.enclose==<br />
;string.enclose(string)<br />
: Wraps a string with [[ ]]<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
:The string to enclose. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will echo '[[Oh noes!]]' to the main window<br />
echo("'" .. string.enclose("Oh noes!") .. "'")<br />
</syntaxhighlight><br />
<br />
==string.ends==<br />
;string.ends(String, Suffix)<br />
: Test if string is ending with specified suffix.<br />
: Returns true or false.<br />
: See also: [[#string.starts|string.starts]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string.<br />
* ''Suffix:''<br />
: The suffix to test for. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will test if the incoming line ends with "in bed" and if not will add it to the end.<br />
if not string.ends(line, "in bed") then<br />
echo("in bed\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==string.find, utf8.find==<br />
;string.find(text, pattern [, init [, plain]]) or utf8.find<br />
: Looks for the first match of pattern in the string text. If it finds a match, then find returns the indices of text where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in pattern being considered "magic". Note that if plain is given, then init must be given as well.<br />
If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.<br />
: string.find() works with English text only, use utf8.find() for the international version.<br />
;Example<br />
<syntaxhighlight lang=lua><br />
-- check if the word appears in a variable<br />
if string.find(matches[2], "rabbit") then<br />
echo("Found a rabbit!\n")<br />
end<br />
<br />
-- the following example will print: "3, 4"<br />
local start, stop = string.find("This is a test.", "is")<br />
if start then<br />
print(start .. ", " .. stop)<br />
end<br />
-- note that here "is" is being found at the end of the word "This", rather than the expected second word<br />
<br />
-- to make it match the word on its own, prefix %f[%a] and suffix %f[%A]<br />
if string.find("This is a test", "%f[%a]is%f[%A]") then<br />
echo("This 'is' is the actual stand-alone word\n")<br />
end<br />
</syntaxhighlight><br />
* Return value:<br />
: nil or start and stop position of the first matched text, followed by any captured text.<br />
<br />
==string.findPattern==<br />
; string.findPattern(text, pattern)<br />
: Return first matching substring or nil.<br />
<br />
; Parameters<br />
* ''text:''<br />
: The text you are searching the pattern for.<br />
* ''pattern:''<br />
: The pattern you are trying to find in the text.<br />
<br />
; Example:<br />
Following example will print: "I did find: Troll" string.<br />
<syntaxhighlight lang="lua"><br />
local match = string.findPattern("Troll is here!", "Troll")<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</syntaxhighlight><br />
:This example will find substring regardless of case.<br />
<syntaxhighlight lang="lua">local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</syntaxhighlight><br />
* Return value:<br />
: nil or first matching substring<br />
See also: [[#string.genNocasePattern|string.genNocasePattern()]]<br />
<br />
==string.format==<br />
;string.format(formatstring,...)<br />
: Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). The format string follows the same rules as the printf family of standard C functions. The only differences are that the options/modifiers *, l, L, n, p, and h are not supported and that there is an extra option, q. The q option formats a string in a form suitable to be safely read back by the Lua interpreter: the string is written between double quotes, and all double quotes, newlines, embedded zeros, and backslashes in the string are correctly escaped when written. For instance, the call<br />
<syntaxhighlight lang=lua><br />
string.format('%q', 'a string with "quotes" and \n new line')<br />
</syntaxhighlight><br />
will produce the string:<br />
<syntaxhighlight lang=lua><br />
"a string with \"quotes\" and \<br />
new line"<br />
</syntaxhighlight><br />
The options c, d, E, e, f, g, G, i, o, u, X, and x all expect a number as argument, whereas q and s expect a string.<br />
<br />
This function does not accept string values containing embedded zeros, except as arguments to the q option.<br />
<br />
string.format() works fine with both English and non-English text.<br />
<br />
;Example<br />
<syntaxhighlight lang=lua><br />
some_data = "MudletUser1"<br />
<br />
-- pad data 20 characters wide to the left<br />
display(string.format("%20s", some_data))<br />
-- result: " MudletUser1"<br />
<br />
-- pad same data but instead to the the right<br />
display(string.format("%-20s", some_data))<br />
-- result: "MudletUser1 "<br />
<br />
-- pad but first truncate data to 6 characters<br />
display(string.format("%20s", string.sub(some_data, 1, 6)))<br />
-- result: " Mudlet"<br />
</syntaxhighlight><br />
<br />
==string.genNocasePattern==<br />
; string.genNocasePattern(template)<br />
: Generate case insensitive search pattern from string.<br />
<br />
; Parameters<br />
* template: The original string to be used as the base.<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
echo(string.genNocasePattern("123abc"))<br />
-- result: "123[aA][bB][cC]"<br />
</syntaxhighlight><br />
<br />
==string.gfind==<br />
;string.gfind()<br />
: This is an old version of what is now string.gmatch. Use string.gmatch instead.<br />
;Example<br />
''Need example''<br />
<br />
==string.gmatch, utf8.gmatch==<br />
;string.gmatch(text, pattern) or utf8.gmatch<br />
: Returns an iterator function that, each time it is called, returns the next captures from pattern over string text. If pattern specifies no captures, then the whole match is produced in each call.<br />
As an example, the following loop<br />
<syntaxhighlight lang=lua><br />
s = "hello world from Lua"<br />
for w in string.gmatch(s, "%a+") do<br />
print(w)<br />
end</syntaxhighlight><br />
will iterate over all the words from string s, printing one per line. The next example collects all pairs key=value from the given string into a table:<br />
<syntaxhighlight lang=lua><br />
t = {}<br />
s = "from=world, to=Lua"<br />
for k, v in string.gmatch(s, "(%w+)=(%w+)") do<br />
t[k] = v<br />
end</syntaxhighlight><br />
For this function, a '^' at the start of a pattern does not work as an anchor, as this would prevent the iteration.<br />
: string.gmatch() works with English text only, use utf8.gmatch() for the international version.<br />
;Example<br />
''Need example''<br />
<br />
==string.gsub, utf8.gsub==<br />
;string.gsub(text, pattern, repl [, n]) or utf8.gsub<br />
: Returns a copy of text in which all (or the first n, if given) occurrences of the pattern have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred.<br />
<br />
:If repl is a string, then its value is used for replacement. The character % works as an escape character: any sequence in repl of the form %n, with n between 1 and 9, stands for the value of the n-th captured substring (see below). The sequence %0 stands for the whole match. The sequence %% stands for a single %.<br />
<br />
:If repl is a table, then the table is queried for every match, using the first capture as the key; if the pattern specifies no captures, then the whole match is used as the key.<br />
<br />
:If repl is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order; if the pattern specifies no captures, then the whole match is passed as a sole argument.<br />
<br />
:If the value returned by the table query or by the function call is a string or a number, then it is used as the replacement string; otherwise, if it is false or nil, then there is no replacement (that is, the original match is kept in the string).<br />
<br />
: string.gsub() works with English text only, use utf8.gsub() for the international version.<br />
;Example<br />
<syntaxhighlight lang=lua><br />
x = string.gsub("hello world", "(%w+)", "%1 %1")<br />
--> x="hello hello world world"<br />
<br />
x = string.gsub("hello world", "%w+", "%0 %0", 1)<br />
--> x="hello hello world"<br />
<br />
x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1")<br />
--> x="world hello Lua from"<br />
<br />
x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv)<br />
--> x="home = /home/roberto, user = roberto"<br />
<br />
x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s)<br />
return loadstring(s)()<br />
end)<br />
--> x="4+5 = 9"<br />
<br />
local t = {name="lua", version="5.1"}<br />
x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)<br />
--> x="lua-5.1.tar.gz"</syntaxhighlight><br />
<br />
==string.len, utf8.len==<br />
;string.len(string) or utf8.len(string)<br />
;<nowiki>mystring:len()</nowiki><br />
:Receives a string and returns its length. The empty string "" has length 0. Embedded zeros are counted, so "a\000bc\000" has length 5.<br />
: string.len() works with English text only, use utf8.len() for the international version.<br />
<br />
;Parameters:<br />
* ''string:''<br />
:The string (text) you want to find the length of.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- prints 5 for the 5 letters in our word<br />
print(string.len("hello"))<br />
<br />
-- international version<br />
print(utf8.len("слово"))<br />
</syntaxhighlight><br />
<br />
==string.lower, utf8.lower==<br />
;string.lower(string) or utf8.lower(string)<br />
;<nowiki>mystring:lower()</nowiki><br />
:Receives a string and returns a copy of this string with all uppercase letters changed to lowercase. All other characters are left unchanged. The definition of what an uppercase letter is depends on the current locale.<br />
: string.lower() works with English text only, use utf8.lower() for the international version.<br />
: See also: [[#string.upper.2C_utf8.upper|string.upper]], [[#string.upper.2C_utf8.upper|utf8.upper]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- prints an all-lowercase version<br />
print(string.lower("No way! This is AWESOME!"))<br />
<br />
-- international version<br />
print(utf8.lower("Класс! Ето ОТЛИЧНО!"))<br />
</syntaxhighlight><br />
<br />
==string.match, utf8.match==<br />
;string.match(text, pattern [, init]) or utf8.match()<br />
: Looks for the first match of pattern in the string text. If it finds one, then match returns the captures from the pattern; otherwise it returns nil. If pattern specifies no captures, then the whole match is returned. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative.<br />
: string.match() works with English text only, use utf8.match() for the international version.<br />
;Example<br />
''Need example''<br />
<br />
==string.rep==<br />
;string.rep(String, n)<br />
;<nowiki>mystring:rep(n)</nowiki><br />
: Returns a string that is the concatenation of <code>n</code> copies of the string <code>String</code>.<br />
: string.rep() works with both English and non-English text fine.<br />
<br />
;Example<br />
<syntaxhighlight lang=lua><br />
-- repeat * 10 times<br />
display(string.rep("*", 10))<br />
-- results in:<br />
**********<br />
<br />
-- do the same thing, but this time calling from a variable<br />
s = "*"<br />
display(s:rep(10))<br />
-- results in:<br />
**********<br />
</syntaxhighlight><br />
<br />
==string.reverse, utf8.reverse==<br />
;string.reverse(string) or utf8.reverse(string)<br />
;<nowiki>mystring:reverse()</nowiki><br />
<br />
: Returns a string that is the string <code>string</code> reversed.<br />
: string.reverse() works with English text only, use utf8.reverse() for the international version.<br />
<br />
;Parameters:<br />
* ''string:''<br />
:The string to reverse. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
mystring = "Hello from Lua"<br />
echo(mystring:reverse()) -- displays 'auL morf olleH'<br />
<br />
-- international version.<br />
mystring = "Привет от Луа!"<br />
echo(utf8.reverse(mystring)) -- displays '!ауЛ то тевирП', which probably looks the same to you<br />
</syntaxhighlight><br />
<br />
==string.split==<br />
;string.split(string, delimiter)<br />
;<nowiki>myString:split(delimiter)</nowiki><br />
: Splits a string into a table by the given delimiter. Can be called against a string (or variable holding a string) using the second form above.<br />
: Returns a table containing the split sections of the string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to split. Parameter is not needed if using second form of the syntax above. Passed as a string.<br />
* ''delimiter:''<br />
: The delimiter to use when splitting the string. Passed as a string, and allows for [http://www.lua.org/pil/20.2.html Lua pattern types]. Use % to escape here (and %% to escape a stand-alone %).<br />
{{ Note }} as of Mudlet 4.7+, delimiter will default to " " if not provided.<br />
<br />
{{ Note }} as of Mudlet 4.7+, using "" (empty string) for the delimiter will return the string as a table of characters. IE string.split("This","") will return as {"T", "h", "i", "s"}. Prior to 4.7 using empty string as the delimiter would error after hanging temporarily.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This will split the string by ", " delimiter and print the resulting table to the main window.<br />
names = "Alice, Bob, Peter"<br />
name_table = string.split(names, ", ")<br />
display(name_table)<br />
<br />
--The alternate method<br />
names = "Alice, Bob, Peter"<br />
name_table = names:split(", ")<br />
display(name_table)<br />
</syntaxhighlight><br />
<br />
:Either method above will print out:<br />
: table {<br />
:: 1: 'Alice'<br />
:: 2: 'Bob'<br />
:: 3: 'Peter'<br />
: }<br />
<br />
==string.starts==<br />
;string.starts(string, prefix)<br />
: Test if string is starting with specified prefix.<br />
: Returns true or false<br />
: See also: [[#string.ends|string.ends]]<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to test. Passed as a string.<br />
* ''prefix:''<br />
: The prefix to test for. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--The following will see if the line begins with "You" and if so will print a statement at the end of the line<br />
if string.starts(line, "You") then<br />
echo("====oh you====\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==string.sub, utf8.sub==<br />
;string.sub(text, i [, j]) or utf8.sub()<br />
: Returns the substring of text that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(text,1,j) returns a prefix of text with length j, and string.sub(text, -i) returns a suffix of text with length i.<br />
: string.sub() works with English text only, use utf8.sub() for the international version.<br />
;Example<br />
''Need example''<br />
<br />
==string.title==<br />
;string.title(string)<br />
;<nowiki>mystring:title()</nowiki><br />
: Capitalizes the first character in a string.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to modify. Not needed if you use the second form of the syntax above.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Variable testname is now Anna.<br />
testname = string.title("anna")<br />
--Example will set test to "Bob".<br />
test = "bob"<br />
test = test:title()<br />
</syntaxhighlight><br />
<br />
==string.trim==<br />
;string.trim(string)<br />
: Trims string, removing all 'extra' white space at the beginning and end of the text.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to trim. Passed as a string.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This will print 'Troll is here!', without the extra spaces.<br />
local str = string.trim(" Troll is here! ")<br />
echo("'" .. str .. "'")<br />
</syntaxhighlight><br />
<br />
==string.upper, utf8.upper==<br />
;string.upper(string) or utf8.upper(string)<br />
;<nowiki>mystring:upper()</nowiki><br />
: Receives a string and returns a copy of this string with all lowercase letters changed to uppercase. All other characters are left unchanged. The definition of what a lowercase letter is depends on the current locale.<br />
: string.upper() works with English text only, use utf8.upper() for the international version.<br />
<br />
: See also: [[#string.lower.2C_utf8.lower|string.lower]], [[#string.lower.2C_utf8.lower|utf8.lower]]<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string you want to change to uppercase<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- displays 'RUN BOB RUN'<br />
print(string.upper("run bob run"))<br />
<br />
-- displays 'ДАВАЙ ДАВАЙ!'<br />
print(utf8.upper("давай давай!"))<br />
</syntaxhighlight><br />
<br />
==utf8.charpos==<br />
;utf8.charpos(string[[, charpos], offset])<br />
: Converts UTF-8 position to byte offset, returns the character position and code point. If only offset is given, returns byte offset of this UTF-8 char index. If charpos and offset is given, a new charpos will be calculated by adding/subtracting UTF-8 char offset to current charpos. In all cases, it return a new char position, and code point (a number) at this position.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''charpos:''<br />
: (optional) character position to work on.<br />
* ''offset:''<br />
: (optional) offset (as a number) to work on.<br />
<br />
==utf8.escape==<br />
;utf8.escape(string)<br />
: Escape a string to UTF-8 format string. It support several escape formats:<br />
<br />
%ddd - which ddd is a decimal number at any length:<br />
change Unicode code point to UTF-8 format.<br />
%{ddd} - same as %nnn but has bracket around.<br />
%uddd - same as %ddd, u stands Unicode<br />
%u{ddd} - same as %{ddd}<br />
%xhhh - hexadigit version of %ddd<br />
%x{hhh} same as %xhhh.<br />
%? - '?' stands for any other character: escape this character.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string you want to escape<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local u = utf8.escape<br />
print(u"%123%u123%{123}%u{123}%xABC%x{ABC}")<br />
print(u"%%123%?%d%%u")<br />
</syntaxhighlight><br />
<br />
==utf8.fold==<br />
;utf8.fold(string)<br />
: Returns the lowercase version of the string for use in case-insensitive comparisons. If string is a number, it's treated as a code point and the converted code point is returned (as a number).<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string to lowercase.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(utf8.fold("ПРИВЕТ")) -- 'привет'<br />
print(utf8.fold("Привет")) -- 'привет'<br />
</syntaxhighlight><br />
<br />
==utf8.insert==<br />
;utf8.insert(string[, idx], substring)<br />
: Inserts the substring into the given string. If idx is given, inserts substring before the character at this index, otherwise the substring will append onto the end of string. idx can be negative.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''idx:''<br />
: (optional) character position to insert the string at.<br />
* ''substring:''<br />
: text to insert into the substring.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- inserts letter я before the 2nd letter and prints 'мясо'<br />
print(utf8.insert("мсо", 2, "я"))<br />
</syntaxhighlight><br />
<br />
==utf8.ncasecmp==<br />
;utf8.ncasecmp(a, b)<br />
: Compares ''a'' and ''b'' without case. Return -1 means a < b, 0 means a == b and 1 means a > b.<br />
<br />
;Parameters<br />
* ''a:''<br />
: String to compare.<br />
* ''b:''<br />
: String to compare against.<br />
<br />
==utf8.next==<br />
;utf8.next(string[, charpos[, offset]])<br />
: Iterates though the UTF-8 string.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''charpos:''<br />
: (optional) character position to work on.<br />
* ''offset:''<br />
: (optional) offset (as a number) to work on.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- prints location and code point of every letter<br />
for pos, code in utf8.next, "тут есть текст" do<br />
print(pos, code)<br />
end<br />
</syntaxhighlight><br />
<br />
==utf8.remove==<br />
;utf8.remove(string[, start[, stop]])<br />
: Removed characters from the given string. Deletes characters from the given ''start'' to the end of the string. If ''stop'' is given, deletes characters from ''start'' to ''stop'' (including start and stop). ''start'' and ''stop'' can be negative.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''start:''<br />
: position to start deleting characters from.<br />
* ''stop:''<br />
: (optional) posititon to stop deleting characters at.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete everything from the 3rd character including the character itself<br />
print(utf8.remove("мясо", 3)) -- 'мя'<br />
<br />
-- delete the last character, use negative to count backwards<br />
print(utf8.remove("мясо", -1)) -- 'мяс'<br />
<br />
-- delete everything from the 2nd to the 4th character<br />
print(utf8.remove("вкусное", 2,4)) -- 'вное'<br />
</syntaxhighlight><br />
<br />
==utf8.title==<br />
;utf8.title(string)<br />
: Returns the uppercase version of the string for use in case-insensitive comparisons. If string is a number, it's treated as a code point and the converted code point is returned (as a number).<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string to uppercase.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(utf8.title("привет")) -- 'ПРИВЕТ'<br />
print(utf8.title("Привет")) -- 'ПРИВЕТ'<br />
</syntaxhighlight><br />
<br />
==utf8.width==<br />
;utf8.width(string[, ambi_is_double[, default_width]])<br />
: Calculate the widths of the given string. If the string is a code point, return the width of this code point.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''ambi_is_double:''<br />
: (optional) if provided, the ambiguous width character's width is 2, otherwise it's 1.<br />
* ''default_width:''<br />
: (optional) if provided, this will be the width of unprintable character, used display a non-character mark for these characters.<br />
<br />
==utf8.widthindex==<br />
;utf8.widthindex(string, location[, ambi_is_double[, default_width]])<br />
: Returns the character index at the location in the given string as well as the offset and the width. This is a reverse operation of utf8.width().<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''location:''<br />
: location to get the width of.<br />
* ''ambi_is_double:''<br />
: (optional) if provided, the ambiguous width character's width is 2, otherwise it's 1.<br />
* ''default_width:''<br />
: (optional) if provided, this will be the width of unprintable character, used display a non-character mark for these characters.<br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:String_Functions&diff=17690Manual:String Functions2021-09-13T13:00:25Z<p>Dargoth: /* f */ example of closures fail</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Mudlet API documentation for functions used to manipulate strings.}}<br />
= String Functions =<br />
A collection of functions used to manipulate strings.<br />
==addWordToDictionary==<br />
;addWordToDictionary(word)<br />
:Adds the given word to the custom profile or shared dictionary (whichever is selected in preferences).<br />
<br />
: Returns true on success (the word was actually ''added'' to the dictionary by this call) and nil+msg on error - including if the word was already there - this is so that if you have other scripts that you wish to run when a word was added you can make their execution conditional on success here.<br />
<br />
:See also: [[#removeWordFromDictionary|removeWordFromDictionary()]]<br />
<br />
;Parameters<br />
* ''word:'' custom word to add to the dictionary.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addWordToDictionary("Darkwind")<br />
addWordToDictionary("黑暗的风")<br />
addWordToDictionary("норм")<br />
</syntaxhighlight><br />
<br />
;Example - function making use of return value:<br />
<syntaxhighlight lang="lua"><br />
function rememberPlayerName(name)<br />
if addWordToDictionary(n) then<br />
echo("Added '" .. n .. "' to dictionary...\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==f==<br />
; formattedString = f(str)<br />
: Allows you to combine variables and functions into text (string interpolation) using <code>{}</code>.<br />
<br />
; Parameters<br />
* ''str:''<br />
: The string to perform interpolation against.<br />
<br />
{{MudletVersion|4.11}}<br />
; Example:<br />
<br />
<syntaxhighlight lang=lua><br />
-- old way:<br />
cecho("\nHello, "..matches[2]..", how is it going?")<br />
<br />
-- new way:<br />
cecho(f("\nHello {matches[2]}, how is it going?")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang=lua><br />
testResult = "successful"<br />
-- old way:<br />
echo("The test was "..testResult.."\n")<br />
-- with f:<br />
echo(f("The test was {testResult}\n"))<br />
-- echoes "The test was successful\n"<br />
<br />
local testResult = "a failure"<br />
echo(f("The test was {testResult}\n"))<br />
-- echoes "The test was a failure\n" as it sees the local scope over global.<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang=lua><br />
-- You can also execute simple expressions<br />
echo(f("2 + 2 = {2 + 2}\n"))<br />
-- echoes "2 + 2 = 4\n"<br />
<br />
-- Or more complicated ones<br />
local function testFunc(item)<br />
return item:title()<br />
end<br />
<br />
echo(f("You should properly capitalize names, such as {testFunc('marilyn')}\n"))<br />
-- echoes "You should properly capitalize names, such as Marilyn\n"<br />
<br />
echo(f("You should properly capitalize names, such as {string.title('robert')}\n")<br />
-- same thing, but uses string.title directly and Robert instead of Marilyn<br />
</syntaxhighlight><br />
<br />
<br />
'''Caution!'''<br />
When using within closures, might not resolve variables correctly if they go out of a scope when closure is called.<br />
<syntaxhighlight lang=lua><br />
function formatter2000()<br />
local upvalue = "2000"<br />
local formatter = function() <br />
echo(f("Let's evaluate: {upvalue}\n"))<br />
end<br />
formatter() -- here evaulation inside f function will work<br />
return formatter<br />
end<br />
<br />
formatter2000()() -- here evaluation inside f function will return nil<br />
<br />
-- result<br />
-- Let's evaluate: 2000<br />
-- Let's evaulate: nil<br />
<syntaxhighlight><br />
<br />
==getDictionaryWordList==<br />
;getDictionaryWordList()<br />
:Returns the profile or shared custom dictionary word list (whichever is selected in preferences) - that is, words added via right-click "add word to dictionary" or [[#addWordToDictionary|addWordToDictionary()]].<br />
<br />
: Returns an indexed table of words.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getDictionaryWordList())<br />
</syntaxhighlight><br />
<br />
==removeWordFromDictionary==<br />
;removeWordFromDictionary(word)<br />
:Removed the given word to the custom profile or shared dictionary (whichever is selected in preferences).<br />
<br />
: Returns true on success (if the word was present and removed by this call) and nil+msg on error.<br />
<br />
:See also: [[#addWordToDictionary|addWordToDictionary()]]<br />
<br />
;Parameters<br />
* ''word:'' custom word to remove from the dictionary.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
removeWordFromDictionary("Darkwind")<br />
removeWordFromDictionary("黑暗的风")<br />
removeWordFromDictionary("норм")<br />
</syntaxhighlight><br />
<br />
==spellCheckWord==<br />
;spellCheckWord(word, [customDictionary])<br />
:Spellchecks the given word against the custom or the system dictionary.<br />
<br />
: Returns true if the word is spelled correctly or false if it's not, and nil+msg on error.<br />
<br />
:See also: [[#addWordToDictionary|addWordToDictionary()]], [[#removeWordFromDictionary|removeWordFromDictionary()]], [[#spellSuggestWord|spellSuggestWord()]]<br />
<br />
;Parameters<br />
* ''word'': word to spellcheck.<br />
* ''customDictionary'' (optional): dictionary to use. If true, the profile or shared dictionary will be used (depending on your settings). If omitted or false, the system dictionary (the language you have selected in settings) will be used.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- spellcheck against the language dictionary<br />
if spellCheckWord("run") then<br />
echo("'run' is spelled ok!\n")<br />
end<br />
<br />
-- spellcheck against the custom 'add word to dictionary'<br />
if spellCheckWord("Darkwind", true) then<br />
echo("'Darkwind' is spelled OK!\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==spellSuggestWord==<br />
;spellSuggestWord(word, [customDictionary])<br />
:Suggests similar words for the given word.<br />
<br />
: Returns a table of suggestions or nil+msg on error.<br />
<br />
:See also: [[#spellCheckWord|spellCheckWord()]]<br />
<br />
;Parameters<br />
* ''word'': word to give suggestions on.<br />
* ''customDictionary'' (optional): dictionary to use. If true, the profile or shared dictionary will be used (depending on your settings). If omitted or false, the system dictionary (the language you have selected in settings) will be used.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(spellSuggestWord("Darkwind"))<br />
</syntaxhighlight><br />
<br />
==string.byte, utf8.byte==<br />
;string.byte(string [, i [, j]]) or utf8.byte(string [, i [, j]])<br />
;<nowiki>mystring:byte([, i [, j]])</nowiki><br />
: Returns the internal numerical codes of the characters <code>s[i], s[i+1], ···, s[j]</code>. The default value for <code>i</code> is <code>1</code>; the default value for <code>j</code> is <code>i</code>.<br />
: Note that numerical codes are not necessarily portable across platforms.<br />
: string.byte() works with English text only, use utf8.byte() for the international version.<br />
: See also: [[#string.char.2C_utf8.char|string.char]], [[#string.char.2C_utf8.char|utf8.char]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the following call will return the ASCII values of "A", "B" and "C"<br />
a, b, c = string.byte("ABC", 1, 3)<br />
echo(a .. " - " .. b .. " - " .. c) -- shows "65 - 66 - 67"<br />
<br />
-- same for the international version but with the Unicode values<br />
a, b, c = utf8.byte("дом", 1, 3)<br />
echo(a .. " - " .. b .. " - " .. c) -- shows "1076 - 1086 - 1084"<br />
</syntaxhighlight><br />
<br />
==string.char, utf8.char==<br />
;string.char(···) or utf8.char(···)<br />
: Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument.<br />
: Note that numerical codes are not necessarily portable across platforms.<br />
: string.char() works with English text only, use utf8.char() for the international version.<br />
: See also: [[#string.byte.2C_utf8.byte|string.byte]], [[#string.byte.2C_utf8.byte|utf8.byte]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the following call will return the string "ABC" corresponding to the ASCII values 65, 66, 67<br />
mystring = string.char(65, 66, 67)<br />
<br />
-- same for the infernational version which will return text "дом" for the Unicode values 1076, 1086, 1084<br />
mystring = utf8.char(1076,1086,1084)<br />
print(mystring)<br />
</syntaxhighlight><br />
<br />
==string.cut==<br />
;string.cut(string, maxLen)<br />
: Cuts string to the specified maximum length.<br />
: Returns the modified string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The text you wish to cut. Passed as a string.<br />
* ''maxLen:''<br />
: The maximum length you wish the string to be. Passed as an integer number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--The following call will return 'abc' and store it in myString<br />
myString = string.cut("abcde", 3)<br />
--You can easily pad string to certain length. Example below will print 'abcde ' e.g. pad/cut string to 10 characters.<br />
local s = "abcde"<br />
s = string.cut(s .. " ", 10) -- append 10 spaces<br />
echo("'" .. s .. "'")<br />
</syntaxhighlight><br />
<br />
==string.dump==<br />
;string.dump()<br />
Converts a function into a binary string. You can use the loadstring() function later to get the function back.<br />
: string.dump() works with both English and non-English text fine.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
string = string.dump(echo("this is a string"))<br />
--The following should then echo "this is a string"<br />
loadstring(string)()<br />
</syntaxhighlight><br />
<br />
==string.enclose==<br />
;string.enclose(string)<br />
: Wraps a string with [[ ]]<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
:The string to enclose. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will echo '[[Oh noes!]]' to the main window<br />
echo("'" .. string.enclose("Oh noes!") .. "'")<br />
</syntaxhighlight><br />
<br />
==string.ends==<br />
;string.ends(String, Suffix)<br />
: Test if string is ending with specified suffix.<br />
: Returns true or false.<br />
: See also: [[#string.starts|string.starts]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string.<br />
* ''Suffix:''<br />
: The suffix to test for. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will test if the incoming line ends with "in bed" and if not will add it to the end.<br />
if not string.ends(line, "in bed") then<br />
echo("in bed\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==string.find, utf8.find==<br />
;string.find(text, pattern [, init [, plain]]) or utf8.find<br />
: Looks for the first match of pattern in the string text. If it finds a match, then find returns the indices of text where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in pattern being considered "magic". Note that if plain is given, then init must be given as well.<br />
If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.<br />
: string.find() works with English text only, use utf8.find() for the international version.<br />
;Example<br />
<syntaxhighlight lang=lua><br />
-- check if the word appears in a variable<br />
if string.find(matches[2], "rabbit") then<br />
echo("Found a rabbit!\n")<br />
end<br />
<br />
-- the following example will print: "3, 4"<br />
local start, stop = string.find("This is a test.", "is")<br />
if start then<br />
print(start .. ", " .. stop)<br />
end<br />
-- note that here "is" is being found at the end of the word "This", rather than the expected second word<br />
<br />
-- to make it match the word on its own, prefix %f[%a] and suffix %f[%A]<br />
if string.find("This is a test", "%f[%a]is%f[%A]") then<br />
echo("This 'is' is the actual stand-alone word\n")<br />
end<br />
</syntaxhighlight><br />
* Return value:<br />
: nil or start and stop position of the first matched text, followed by any captured text.<br />
<br />
==string.findPattern==<br />
; string.findPattern(text, pattern)<br />
: Return first matching substring or nil.<br />
<br />
; Parameters<br />
* ''text:''<br />
: The text you are searching the pattern for.<br />
* ''pattern:''<br />
: The pattern you are trying to find in the text.<br />
<br />
; Example:<br />
Following example will print: "I did find: Troll" string.<br />
<syntaxhighlight lang="lua"><br />
local match = string.findPattern("Troll is here!", "Troll")<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</syntaxhighlight><br />
:This example will find substring regardless of case.<br />
<syntaxhighlight lang="lua">local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</syntaxhighlight><br />
* Return value:<br />
: nil or first matching substring<br />
See also: [[#string.genNocasePattern|string.genNocasePattern()]]<br />
<br />
==string.format==<br />
;string.format(formatstring,...)<br />
: Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). The format string follows the same rules as the printf family of standard C functions. The only differences are that the options/modifiers *, l, L, n, p, and h are not supported and that there is an extra option, q. The q option formats a string in a form suitable to be safely read back by the Lua interpreter: the string is written between double quotes, and all double quotes, newlines, embedded zeros, and backslashes in the string are correctly escaped when written. For instance, the call<br />
<syntaxhighlight lang=lua><br />
string.format('%q', 'a string with "quotes" and \n new line')<br />
</syntaxhighlight><br />
will produce the string:<br />
<syntaxhighlight lang=lua><br />
"a string with \"quotes\" and \<br />
new line"<br />
</syntaxhighlight><br />
The options c, d, E, e, f, g, G, i, o, u, X, and x all expect a number as argument, whereas q and s expect a string.<br />
<br />
This function does not accept string values containing embedded zeros, except as arguments to the q option.<br />
<br />
string.format() works fine with both English and non-English text.<br />
<br />
;Example<br />
<syntaxhighlight lang=lua><br />
some_data = "MudletUser1"<br />
<br />
-- pad data 20 characters wide to the left<br />
display(string.format("%20s", some_data))<br />
-- result: " MudletUser1"<br />
<br />
-- pad same data but instead to the the right<br />
display(string.format("%-20s", some_data))<br />
-- result: "MudletUser1 "<br />
<br />
-- pad but first truncate data to 6 characters<br />
display(string.format("%20s", string.sub(some_data, 1, 6)))<br />
-- result: " Mudlet"<br />
</syntaxhighlight><br />
<br />
==string.genNocasePattern==<br />
; string.genNocasePattern(template)<br />
: Generate case insensitive search pattern from string.<br />
<br />
; Parameters<br />
* template: The original string to be used as the base.<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
echo(string.genNocasePattern("123abc"))<br />
-- result: "123[aA][bB][cC]"<br />
</syntaxhighlight><br />
<br />
==string.gfind==<br />
;string.gfind()<br />
: This is an old version of what is now string.gmatch. Use string.gmatch instead.<br />
;Example<br />
''Need example''<br />
<br />
==string.gmatch, utf8.gmatch==<br />
;string.gmatch(text, pattern) or utf8.gmatch<br />
: Returns an iterator function that, each time it is called, returns the next captures from pattern over string text. If pattern specifies no captures, then the whole match is produced in each call.<br />
As an example, the following loop<br />
<syntaxhighlight lang=lua><br />
s = "hello world from Lua"<br />
for w in string.gmatch(s, "%a+") do<br />
print(w)<br />
end</syntaxhighlight><br />
will iterate over all the words from string s, printing one per line. The next example collects all pairs key=value from the given string into a table:<br />
<syntaxhighlight lang=lua><br />
t = {}<br />
s = "from=world, to=Lua"<br />
for k, v in string.gmatch(s, "(%w+)=(%w+)") do<br />
t[k] = v<br />
end</syntaxhighlight><br />
For this function, a '^' at the start of a pattern does not work as an anchor, as this would prevent the iteration.<br />
: string.gmatch() works with English text only, use utf8.gmatch() for the international version.<br />
;Example<br />
''Need example''<br />
<br />
==string.gsub, utf8.gsub==<br />
;string.gsub(text, pattern, repl [, n]) or utf8.gsub<br />
: Returns a copy of text in which all (or the first n, if given) occurrences of the pattern have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred.<br />
<br />
:If repl is a string, then its value is used for replacement. The character % works as an escape character: any sequence in repl of the form %n, with n between 1 and 9, stands for the value of the n-th captured substring (see below). The sequence %0 stands for the whole match. The sequence %% stands for a single %.<br />
<br />
:If repl is a table, then the table is queried for every match, using the first capture as the key; if the pattern specifies no captures, then the whole match is used as the key.<br />
<br />
:If repl is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order; if the pattern specifies no captures, then the whole match is passed as a sole argument.<br />
<br />
:If the value returned by the table query or by the function call is a string or a number, then it is used as the replacement string; otherwise, if it is false or nil, then there is no replacement (that is, the original match is kept in the string).<br />
<br />
: string.gsub() works with English text only, use utf8.gsub() for the international version.<br />
;Example<br />
<syntaxhighlight lang=lua><br />
x = string.gsub("hello world", "(%w+)", "%1 %1")<br />
--> x="hello hello world world"<br />
<br />
x = string.gsub("hello world", "%w+", "%0 %0", 1)<br />
--> x="hello hello world"<br />
<br />
x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1")<br />
--> x="world hello Lua from"<br />
<br />
x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv)<br />
--> x="home = /home/roberto, user = roberto"<br />
<br />
x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s)<br />
return loadstring(s)()<br />
end)<br />
--> x="4+5 = 9"<br />
<br />
local t = {name="lua", version="5.1"}<br />
x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)<br />
--> x="lua-5.1.tar.gz"</syntaxhighlight><br />
<br />
==string.len, utf8.len==<br />
;string.len(string) or utf8.len(string)<br />
;<nowiki>mystring:len()</nowiki><br />
:Receives a string and returns its length. The empty string "" has length 0. Embedded zeros are counted, so "a\000bc\000" has length 5.<br />
: string.len() works with English text only, use utf8.len() for the international version.<br />
<br />
;Parameters:<br />
* ''string:''<br />
:The string (text) you want to find the length of.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- prints 5 for the 5 letters in our word<br />
print(string.len("hello"))<br />
<br />
-- international version<br />
print(utf8.len("слово"))<br />
</syntaxhighlight><br />
<br />
==string.lower, utf8.lower==<br />
;string.lower(string) or utf8.lower(string)<br />
;<nowiki>mystring:lower()</nowiki><br />
:Receives a string and returns a copy of this string with all uppercase letters changed to lowercase. All other characters are left unchanged. The definition of what an uppercase letter is depends on the current locale.<br />
: string.lower() works with English text only, use utf8.lower() for the international version.<br />
: See also: [[#string.upper.2C_utf8.upper|string.upper]], [[#string.upper.2C_utf8.upper|utf8.upper]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- prints an all-lowercase version<br />
print(string.lower("No way! This is AWESOME!"))<br />
<br />
-- international version<br />
print(utf8.lower("Класс! Ето ОТЛИЧНО!"))<br />
</syntaxhighlight><br />
<br />
==string.match, utf8.match==<br />
;string.match(text, pattern [, init]) or utf8.match()<br />
: Looks for the first match of pattern in the string text. If it finds one, then match returns the captures from the pattern; otherwise it returns nil. If pattern specifies no captures, then the whole match is returned. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative.<br />
: string.match() works with English text only, use utf8.match() for the international version.<br />
;Example<br />
''Need example''<br />
<br />
==string.rep==<br />
;string.rep(String, n)<br />
;<nowiki>mystring:rep(n)</nowiki><br />
: Returns a string that is the concatenation of <code>n</code> copies of the string <code>String</code>.<br />
: string.rep() works with both English and non-English text fine.<br />
<br />
;Example<br />
<syntaxhighlight lang=lua><br />
-- repeat * 10 times<br />
display(string.rep("*", 10))<br />
-- results in:<br />
**********<br />
<br />
-- do the same thing, but this time calling from a variable<br />
s = "*"<br />
display(s:rep(10))<br />
-- results in:<br />
**********<br />
</syntaxhighlight><br />
<br />
==string.reverse, utf8.reverse==<br />
;string.reverse(string) or utf8.reverse(string)<br />
;<nowiki>mystring:reverse()</nowiki><br />
<br />
: Returns a string that is the string <code>string</code> reversed.<br />
: string.reverse() works with English text only, use utf8.reverse() for the international version.<br />
<br />
;Parameters:<br />
* ''string:''<br />
:The string to reverse. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
mystring = "Hello from Lua"<br />
echo(mystring:reverse()) -- displays 'auL morf olleH'<br />
<br />
-- international version.<br />
mystring = "Привет от Луа!"<br />
echo(utf8.reverse(mystring)) -- displays '!ауЛ то тевирП', which probably looks the same to you<br />
</syntaxhighlight><br />
<br />
==string.split==<br />
;string.split(string, delimiter)<br />
;<nowiki>myString:split(delimiter)</nowiki><br />
: Splits a string into a table by the given delimiter. Can be called against a string (or variable holding a string) using the second form above.<br />
: Returns a table containing the split sections of the string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to split. Parameter is not needed if using second form of the syntax above. Passed as a string.<br />
* ''delimiter:''<br />
: The delimiter to use when splitting the string. Passed as a string, and allows for [http://www.lua.org/pil/20.2.html Lua pattern types]. Use % to escape here (and %% to escape a stand-alone %).<br />
{{ Note }} as of Mudlet 4.7+, delimiter will default to " " if not provided.<br />
<br />
{{ Note }} as of Mudlet 4.7+, using "" (empty string) for the delimiter will return the string as a table of characters. IE string.split("This","") will return as {"T", "h", "i", "s"}. Prior to 4.7 using empty string as the delimiter would error after hanging temporarily.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This will split the string by ", " delimiter and print the resulting table to the main window.<br />
names = "Alice, Bob, Peter"<br />
name_table = string.split(names, ", ")<br />
display(name_table)<br />
<br />
--The alternate method<br />
names = "Alice, Bob, Peter"<br />
name_table = names:split(", ")<br />
display(name_table)<br />
</syntaxhighlight><br />
<br />
:Either method above will print out:<br />
: table {<br />
:: 1: 'Alice'<br />
:: 2: 'Bob'<br />
:: 3: 'Peter'<br />
: }<br />
<br />
==string.starts==<br />
;string.starts(string, prefix)<br />
: Test if string is starting with specified prefix.<br />
: Returns true or false<br />
: See also: [[#string.ends|string.ends]]<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to test. Passed as a string.<br />
* ''prefix:''<br />
: The prefix to test for. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--The following will see if the line begins with "You" and if so will print a statement at the end of the line<br />
if string.starts(line, "You") then<br />
echo("====oh you====\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==string.sub, utf8.sub==<br />
;string.sub(text, i [, j]) or utf8.sub()<br />
: Returns the substring of text that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(text,1,j) returns a prefix of text with length j, and string.sub(text, -i) returns a suffix of text with length i.<br />
: string.sub() works with English text only, use utf8.sub() for the international version.<br />
;Example<br />
''Need example''<br />
<br />
==string.title==<br />
;string.title(string)<br />
;<nowiki>mystring:title()</nowiki><br />
: Capitalizes the first character in a string.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to modify. Not needed if you use the second form of the syntax above.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Variable testname is now Anna.<br />
testname = string.title("anna")<br />
--Example will set test to "Bob".<br />
test = "bob"<br />
test = test:title()<br />
</syntaxhighlight><br />
<br />
==string.trim==<br />
;string.trim(string)<br />
: Trims string, removing all 'extra' white space at the beginning and end of the text.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to trim. Passed as a string.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This will print 'Troll is here!', without the extra spaces.<br />
local str = string.trim(" Troll is here! ")<br />
echo("'" .. str .. "'")<br />
</syntaxhighlight><br />
<br />
==string.upper, utf8.upper==<br />
;string.upper(string) or utf8.upper(string)<br />
;<nowiki>mystring:upper()</nowiki><br />
: Receives a string and returns a copy of this string with all lowercase letters changed to uppercase. All other characters are left unchanged. The definition of what a lowercase letter is depends on the current locale.<br />
: string.upper() works with English text only, use utf8.upper() for the international version.<br />
<br />
: See also: [[#string.lower.2C_utf8.lower|string.lower]], [[#string.lower.2C_utf8.lower|utf8.lower]]<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string you want to change to uppercase<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- displays 'RUN BOB RUN'<br />
print(string.upper("run bob run"))<br />
<br />
-- displays 'ДАВАЙ ДАВАЙ!'<br />
print(utf8.upper("давай давай!"))<br />
</syntaxhighlight><br />
<br />
==utf8.charpos==<br />
;utf8.charpos(string[[, charpos], offset])<br />
: Converts UTF-8 position to byte offset, returns the character position and code point. If only offset is given, returns byte offset of this UTF-8 char index. If charpos and offset is given, a new charpos will be calculated by adding/subtracting UTF-8 char offset to current charpos. In all cases, it return a new char position, and code point (a number) at this position.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''charpos:''<br />
: (optional) character position to work on.<br />
* ''offset:''<br />
: (optional) offset (as a number) to work on.<br />
<br />
==utf8.escape==<br />
;utf8.escape(string)<br />
: Escape a string to UTF-8 format string. It support several escape formats:<br />
<br />
%ddd - which ddd is a decimal number at any length:<br />
change Unicode code point to UTF-8 format.<br />
%{ddd} - same as %nnn but has bracket around.<br />
%uddd - same as %ddd, u stands Unicode<br />
%u{ddd} - same as %{ddd}<br />
%xhhh - hexadigit version of %ddd<br />
%x{hhh} same as %xhhh.<br />
%? - '?' stands for any other character: escape this character.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string you want to escape<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local u = utf8.escape<br />
print(u"%123%u123%{123}%u{123}%xABC%x{ABC}")<br />
print(u"%%123%?%d%%u")<br />
</syntaxhighlight><br />
<br />
==utf8.fold==<br />
;utf8.fold(string)<br />
: Returns the lowercase version of the string for use in case-insensitive comparisons. If string is a number, it's treated as a code point and the converted code point is returned (as a number).<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string to lowercase.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(utf8.fold("ПРИВЕТ")) -- 'привет'<br />
print(utf8.fold("Привет")) -- 'привет'<br />
</syntaxhighlight><br />
<br />
==utf8.insert==<br />
;utf8.insert(string[, idx], substring)<br />
: Inserts the substring into the given string. If idx is given, inserts substring before the character at this index, otherwise the substring will append onto the end of string. idx can be negative.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''idx:''<br />
: (optional) character position to insert the string at.<br />
* ''substring:''<br />
: text to insert into the substring.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- inserts letter я before the 2nd letter and prints 'мясо'<br />
print(utf8.insert("мсо", 2, "я"))<br />
</syntaxhighlight><br />
<br />
==utf8.ncasecmp==<br />
;utf8.ncasecmp(a, b)<br />
: Compares ''a'' and ''b'' without case. Return -1 means a < b, 0 means a == b and 1 means a > b.<br />
<br />
;Parameters<br />
* ''a:''<br />
: String to compare.<br />
* ''b:''<br />
: String to compare against.<br />
<br />
==utf8.next==<br />
;utf8.next(string[, charpos[, offset]])<br />
: Iterates though the UTF-8 string.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''charpos:''<br />
: (optional) character position to work on.<br />
* ''offset:''<br />
: (optional) offset (as a number) to work on.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- prints location and code point of every letter<br />
for pos, code in utf8.next, "тут есть текст" do<br />
print(pos, code)<br />
end<br />
</syntaxhighlight><br />
<br />
==utf8.remove==<br />
;utf8.remove(string[, start[, stop]])<br />
: Removed characters from the given string. Deletes characters from the given ''start'' to the end of the string. If ''stop'' is given, deletes characters from ''start'' to ''stop'' (including start and stop). ''start'' and ''stop'' can be negative.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''start:''<br />
: position to start deleting characters from.<br />
* ''stop:''<br />
: (optional) posititon to stop deleting characters at.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete everything from the 3rd character including the character itself<br />
print(utf8.remove("мясо", 3)) -- 'мя'<br />
<br />
-- delete the last character, use negative to count backwards<br />
print(utf8.remove("мясо", -1)) -- 'мяс'<br />
<br />
-- delete everything from the 2nd to the 4th character<br />
print(utf8.remove("вкусное", 2,4)) -- 'вное'<br />
</syntaxhighlight><br />
<br />
==utf8.title==<br />
;utf8.title(string)<br />
: Returns the uppercase version of the string for use in case-insensitive comparisons. If string is a number, it's treated as a code point and the converted code point is returned (as a number).<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string to uppercase.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(utf8.title("привет")) -- 'ПРИВЕТ'<br />
print(utf8.title("Привет")) -- 'ПРИВЕТ'<br />
</syntaxhighlight><br />
<br />
==utf8.width==<br />
;utf8.width(string[, ambi_is_double[, default_width]])<br />
: Calculate the widths of the given string. If the string is a code point, return the width of this code point.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''ambi_is_double:''<br />
: (optional) if provided, the ambiguous width character's width is 2, otherwise it's 1.<br />
* ''default_width:''<br />
: (optional) if provided, this will be the width of unprintable character, used display a non-character mark for these characters.<br />
<br />
==utf8.widthindex==<br />
;utf8.widthindex(string, location[, ambi_is_double[, default_width]])<br />
: Returns the character index at the location in the given string as well as the offset and the width. This is a reverse operation of utf8.width().<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''location:''<br />
: location to get the width of.<br />
* ''ambi_is_double:''<br />
: (optional) if provided, the ambiguous width character's width is 2, otherwise it's 1.<br />
* ''default_width:''<br />
: (optional) if provided, this will be the width of unprintable character, used display a non-character mark for these characters.<br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:String_Functions&diff=17689Manual:String Functions2021-09-13T12:06:40Z<p>Dargoth: /* f */</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Mudlet API documentation for functions used to manipulate strings.}}<br />
= String Functions =<br />
A collection of functions used to manipulate strings.<br />
==addWordToDictionary==<br />
;addWordToDictionary(word)<br />
:Adds the given word to the custom profile or shared dictionary (whichever is selected in preferences).<br />
<br />
: Returns true on success (the word was actually ''added'' to the dictionary by this call) and nil+msg on error - including if the word was already there - this is so that if you have other scripts that you wish to run when a word was added you can make their execution conditional on success here.<br />
<br />
:See also: [[#removeWordFromDictionary|removeWordFromDictionary()]]<br />
<br />
;Parameters<br />
* ''word:'' custom word to add to the dictionary.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
addWordToDictionary("Darkwind")<br />
addWordToDictionary("黑暗的风")<br />
addWordToDictionary("норм")<br />
</syntaxhighlight><br />
<br />
;Example - function making use of return value:<br />
<syntaxhighlight lang="lua"><br />
function rememberPlayerName(name)<br />
if addWordToDictionary(n) then<br />
echo("Added '" .. n .. "' to dictionary...\n")<br />
end<br />
end<br />
</syntaxhighlight><br />
<br />
==f==<br />
; formattedString = f(str)<br />
: Allows you to combine variables and functions into text (string interpolation) using <code>{}</code>.<br />
<br />
; Parameters<br />
* ''str:''<br />
: The string to perform interpolation against.<br />
<br />
Caution!<br />
When using within closures, might not resolve variables correctly if they go out of a scope when closure is called.<br />
<br />
{{MudletVersion|4.11}}<br />
; Example:<br />
<br />
<syntaxhighlight lang=lua><br />
-- old way:<br />
cecho("\nHello, "..matches[2]..", how is it going?")<br />
<br />
-- new way:<br />
cecho(f("\nHello {matches[2]}, how is it going?")<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang=lua><br />
testResult = "successful"<br />
-- old way:<br />
echo("The test was "..testResult.."\n")<br />
-- with f:<br />
echo(f("The test was {testResult}\n"))<br />
-- echoes "The test was successful\n"<br />
<br />
local testResult = "a failure"<br />
echo(f("The test was {testResult}\n"))<br />
-- echoes "The test was a failure\n" as it sees the local scope over global.<br />
</syntaxhighlight><br />
<br />
<syntaxhighlight lang=lua><br />
-- You can also execute simple expressions<br />
echo(f("2 + 2 = {2 + 2}\n"))<br />
-- echoes "2 + 2 = 4\n"<br />
<br />
-- Or more complicated ones<br />
local function testFunc(item)<br />
return item:title()<br />
end<br />
<br />
echo(f("You should properly capitalize names, such as {testFunc('marilyn')}\n"))<br />
-- echoes "You should properly capitalize names, such as Marilyn\n"<br />
<br />
echo(f("You should properly capitalize names, such as {string.title('robert')}\n")<br />
-- same thing, but uses string.title directly and Robert instead of Marilyn<br />
</syntaxhighlight><br />
<br />
==getDictionaryWordList==<br />
;getDictionaryWordList()<br />
:Returns the profile or shared custom dictionary word list (whichever is selected in preferences) - that is, words added via right-click "add word to dictionary" or [[#addWordToDictionary|addWordToDictionary()]].<br />
<br />
: Returns an indexed table of words.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getDictionaryWordList())<br />
</syntaxhighlight><br />
<br />
==removeWordFromDictionary==<br />
;removeWordFromDictionary(word)<br />
:Removed the given word to the custom profile or shared dictionary (whichever is selected in preferences).<br />
<br />
: Returns true on success (if the word was present and removed by this call) and nil+msg on error.<br />
<br />
:See also: [[#addWordToDictionary|addWordToDictionary()]]<br />
<br />
;Parameters<br />
* ''word:'' custom word to remove from the dictionary.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
removeWordFromDictionary("Darkwind")<br />
removeWordFromDictionary("黑暗的风")<br />
removeWordFromDictionary("норм")<br />
</syntaxhighlight><br />
<br />
==spellCheckWord==<br />
;spellCheckWord(word, [customDictionary])<br />
:Spellchecks the given word against the custom or the system dictionary.<br />
<br />
: Returns true if the word is spelled correctly or false if it's not, and nil+msg on error.<br />
<br />
:See also: [[#addWordToDictionary|addWordToDictionary()]], [[#removeWordFromDictionary|removeWordFromDictionary()]], [[#spellSuggestWord|spellSuggestWord()]]<br />
<br />
;Parameters<br />
* ''word'': word to spellcheck.<br />
* ''customDictionary'' (optional): dictionary to use. If true, the profile or shared dictionary will be used (depending on your settings). If omitted or false, the system dictionary (the language you have selected in settings) will be used.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- spellcheck against the language dictionary<br />
if spellCheckWord("run") then<br />
echo("'run' is spelled ok!\n")<br />
end<br />
<br />
-- spellcheck against the custom 'add word to dictionary'<br />
if spellCheckWord("Darkwind", true) then<br />
echo("'Darkwind' is spelled OK!\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==spellSuggestWord==<br />
;spellSuggestWord(word, [customDictionary])<br />
:Suggests similar words for the given word.<br />
<br />
: Returns a table of suggestions or nil+msg on error.<br />
<br />
:See also: [[#spellCheckWord|spellCheckWord()]]<br />
<br />
;Parameters<br />
* ''word'': word to give suggestions on.<br />
* ''customDictionary'' (optional): dictionary to use. If true, the profile or shared dictionary will be used (depending on your settings). If omitted or false, the system dictionary (the language you have selected in settings) will be used.<br />
<br />
{{MudletVersion|3.18}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(spellSuggestWord("Darkwind"))<br />
</syntaxhighlight><br />
<br />
==string.byte, utf8.byte==<br />
;string.byte(string [, i [, j]]) or utf8.byte(string [, i [, j]])<br />
;<nowiki>mystring:byte([, i [, j]])</nowiki><br />
: Returns the internal numerical codes of the characters <code>s[i], s[i+1], ···, s[j]</code>. The default value for <code>i</code> is <code>1</code>; the default value for <code>j</code> is <code>i</code>.<br />
: Note that numerical codes are not necessarily portable across platforms.<br />
: string.byte() works with English text only, use utf8.byte() for the international version.<br />
: See also: [[#string.char.2C_utf8.char|string.char]], [[#string.char.2C_utf8.char|utf8.char]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the following call will return the ASCII values of "A", "B" and "C"<br />
a, b, c = string.byte("ABC", 1, 3)<br />
echo(a .. " - " .. b .. " - " .. c) -- shows "65 - 66 - 67"<br />
<br />
-- same for the international version but with the Unicode values<br />
a, b, c = utf8.byte("дом", 1, 3)<br />
echo(a .. " - " .. b .. " - " .. c) -- shows "1076 - 1086 - 1084"<br />
</syntaxhighlight><br />
<br />
==string.char, utf8.char==<br />
;string.char(···) or utf8.char(···)<br />
: Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument.<br />
: Note that numerical codes are not necessarily portable across platforms.<br />
: string.char() works with English text only, use utf8.char() for the international version.<br />
: See also: [[#string.byte.2C_utf8.byte|string.byte]], [[#string.byte.2C_utf8.byte|utf8.byte]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- the following call will return the string "ABC" corresponding to the ASCII values 65, 66, 67<br />
mystring = string.char(65, 66, 67)<br />
<br />
-- same for the infernational version which will return text "дом" for the Unicode values 1076, 1086, 1084<br />
mystring = utf8.char(1076,1086,1084)<br />
print(mystring)<br />
</syntaxhighlight><br />
<br />
==string.cut==<br />
;string.cut(string, maxLen)<br />
: Cuts string to the specified maximum length.<br />
: Returns the modified string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The text you wish to cut. Passed as a string.<br />
* ''maxLen:''<br />
: The maximum length you wish the string to be. Passed as an integer number.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--The following call will return 'abc' and store it in myString<br />
myString = string.cut("abcde", 3)<br />
--You can easily pad string to certain length. Example below will print 'abcde ' e.g. pad/cut string to 10 characters.<br />
local s = "abcde"<br />
s = string.cut(s .. " ", 10) -- append 10 spaces<br />
echo("'" .. s .. "'")<br />
</syntaxhighlight><br />
<br />
==string.dump==<br />
;string.dump()<br />
Converts a function into a binary string. You can use the loadstring() function later to get the function back.<br />
: string.dump() works with both English and non-English text fine.<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
string = string.dump(echo("this is a string"))<br />
--The following should then echo "this is a string"<br />
loadstring(string)()<br />
</syntaxhighlight><br />
<br />
==string.enclose==<br />
;string.enclose(string)<br />
: Wraps a string with [[ ]]<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
:The string to enclose. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will echo '[[Oh noes!]]' to the main window<br />
echo("'" .. string.enclose("Oh noes!") .. "'")<br />
</syntaxhighlight><br />
<br />
==string.ends==<br />
;string.ends(String, Suffix)<br />
: Test if string is ending with specified suffix.<br />
: Returns true or false.<br />
: See also: [[#string.starts|string.starts]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string.<br />
* ''Suffix:''<br />
: The suffix to test for. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--This will test if the incoming line ends with "in bed" and if not will add it to the end.<br />
if not string.ends(line, "in bed") then<br />
echo("in bed\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==string.find, utf8.find==<br />
;string.find(text, pattern [, init [, plain]]) or utf8.find<br />
: Looks for the first match of pattern in the string text. If it finds a match, then find returns the indices of text where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in pattern being considered "magic". Note that if plain is given, then init must be given as well.<br />
If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.<br />
: string.find() works with English text only, use utf8.find() for the international version.<br />
;Example<br />
<syntaxhighlight lang=lua><br />
-- check if the word appears in a variable<br />
if string.find(matches[2], "rabbit") then<br />
echo("Found a rabbit!\n")<br />
end<br />
<br />
-- the following example will print: "3, 4"<br />
local start, stop = string.find("This is a test.", "is")<br />
if start then<br />
print(start .. ", " .. stop)<br />
end<br />
-- note that here "is" is being found at the end of the word "This", rather than the expected second word<br />
<br />
-- to make it match the word on its own, prefix %f[%a] and suffix %f[%A]<br />
if string.find("This is a test", "%f[%a]is%f[%A]") then<br />
echo("This 'is' is the actual stand-alone word\n")<br />
end<br />
</syntaxhighlight><br />
* Return value:<br />
: nil or start and stop position of the first matched text, followed by any captured text.<br />
<br />
==string.findPattern==<br />
; string.findPattern(text, pattern)<br />
: Return first matching substring or nil.<br />
<br />
; Parameters<br />
* ''text:''<br />
: The text you are searching the pattern for.<br />
* ''pattern:''<br />
: The pattern you are trying to find in the text.<br />
<br />
; Example:<br />
Following example will print: "I did find: Troll" string.<br />
<syntaxhighlight lang="lua"><br />
local match = string.findPattern("Troll is here!", "Troll")<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</syntaxhighlight><br />
:This example will find substring regardless of case.<br />
<syntaxhighlight lang="lua">local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</syntaxhighlight><br />
* Return value:<br />
: nil or first matching substring<br />
See also: [[#string.genNocasePattern|string.genNocasePattern()]]<br />
<br />
==string.format==<br />
;string.format(formatstring,...)<br />
: Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). The format string follows the same rules as the printf family of standard C functions. The only differences are that the options/modifiers *, l, L, n, p, and h are not supported and that there is an extra option, q. The q option formats a string in a form suitable to be safely read back by the Lua interpreter: the string is written between double quotes, and all double quotes, newlines, embedded zeros, and backslashes in the string are correctly escaped when written. For instance, the call<br />
<syntaxhighlight lang=lua><br />
string.format('%q', 'a string with "quotes" and \n new line')<br />
</syntaxhighlight><br />
will produce the string:<br />
<syntaxhighlight lang=lua><br />
"a string with \"quotes\" and \<br />
new line"<br />
</syntaxhighlight><br />
The options c, d, E, e, f, g, G, i, o, u, X, and x all expect a number as argument, whereas q and s expect a string.<br />
<br />
This function does not accept string values containing embedded zeros, except as arguments to the q option.<br />
<br />
string.format() works fine with both English and non-English text.<br />
<br />
;Example<br />
<syntaxhighlight lang=lua><br />
some_data = "MudletUser1"<br />
<br />
-- pad data 20 characters wide to the left<br />
display(string.format("%20s", some_data))<br />
-- result: " MudletUser1"<br />
<br />
-- pad same data but instead to the the right<br />
display(string.format("%-20s", some_data))<br />
-- result: "MudletUser1 "<br />
<br />
-- pad but first truncate data to 6 characters<br />
display(string.format("%20s", string.sub(some_data, 1, 6)))<br />
-- result: " Mudlet"<br />
</syntaxhighlight><br />
<br />
==string.genNocasePattern==<br />
; string.genNocasePattern(template)<br />
: Generate case insensitive search pattern from string.<br />
<br />
; Parameters<br />
* template: The original string to be used as the base.<br />
<br />
; Example:<br />
<syntaxhighlight lang="lua"><br />
echo(string.genNocasePattern("123abc"))<br />
-- result: "123[aA][bB][cC]"<br />
</syntaxhighlight><br />
<br />
==string.gfind==<br />
;string.gfind()<br />
: This is an old version of what is now string.gmatch. Use string.gmatch instead.<br />
;Example<br />
''Need example''<br />
<br />
==string.gmatch, utf8.gmatch==<br />
;string.gmatch(text, pattern) or utf8.gmatch<br />
: Returns an iterator function that, each time it is called, returns the next captures from pattern over string text. If pattern specifies no captures, then the whole match is produced in each call.<br />
As an example, the following loop<br />
<syntaxhighlight lang=lua><br />
s = "hello world from Lua"<br />
for w in string.gmatch(s, "%a+") do<br />
print(w)<br />
end</syntaxhighlight><br />
will iterate over all the words from string s, printing one per line. The next example collects all pairs key=value from the given string into a table:<br />
<syntaxhighlight lang=lua><br />
t = {}<br />
s = "from=world, to=Lua"<br />
for k, v in string.gmatch(s, "(%w+)=(%w+)") do<br />
t[k] = v<br />
end</syntaxhighlight><br />
For this function, a '^' at the start of a pattern does not work as an anchor, as this would prevent the iteration.<br />
: string.gmatch() works with English text only, use utf8.gmatch() for the international version.<br />
;Example<br />
''Need example''<br />
<br />
==string.gsub, utf8.gsub==<br />
;string.gsub(text, pattern, repl [, n]) or utf8.gsub<br />
: Returns a copy of text in which all (or the first n, if given) occurrences of the pattern have been replaced by a replacement string specified by repl, which can be a string, a table, or a function. gsub also returns, as its second value, the total number of matches that occurred.<br />
<br />
:If repl is a string, then its value is used for replacement. The character % works as an escape character: any sequence in repl of the form %n, with n between 1 and 9, stands for the value of the n-th captured substring (see below). The sequence %0 stands for the whole match. The sequence %% stands for a single %.<br />
<br />
:If repl is a table, then the table is queried for every match, using the first capture as the key; if the pattern specifies no captures, then the whole match is used as the key.<br />
<br />
:If repl is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order; if the pattern specifies no captures, then the whole match is passed as a sole argument.<br />
<br />
:If the value returned by the table query or by the function call is a string or a number, then it is used as the replacement string; otherwise, if it is false or nil, then there is no replacement (that is, the original match is kept in the string).<br />
<br />
: string.gsub() works with English text only, use utf8.gsub() for the international version.<br />
;Example<br />
<syntaxhighlight lang=lua><br />
x = string.gsub("hello world", "(%w+)", "%1 %1")<br />
--> x="hello hello world world"<br />
<br />
x = string.gsub("hello world", "%w+", "%0 %0", 1)<br />
--> x="hello hello world"<br />
<br />
x = string.gsub("hello world from Lua", "(%w+)%s*(%w+)", "%2 %1")<br />
--> x="world hello Lua from"<br />
<br />
x = string.gsub("home = $HOME, user = $USER", "%$(%w+)", os.getenv)<br />
--> x="home = /home/roberto, user = roberto"<br />
<br />
x = string.gsub("4+5 = $return 4+5$", "%$(.-)%$", function (s)<br />
return loadstring(s)()<br />
end)<br />
--> x="4+5 = 9"<br />
<br />
local t = {name="lua", version="5.1"}<br />
x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)<br />
--> x="lua-5.1.tar.gz"</syntaxhighlight><br />
<br />
==string.len, utf8.len==<br />
;string.len(string) or utf8.len(string)<br />
;<nowiki>mystring:len()</nowiki><br />
:Receives a string and returns its length. The empty string "" has length 0. Embedded zeros are counted, so "a\000bc\000" has length 5.<br />
: string.len() works with English text only, use utf8.len() for the international version.<br />
<br />
;Parameters:<br />
* ''string:''<br />
:The string (text) you want to find the length of.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- prints 5 for the 5 letters in our word<br />
print(string.len("hello"))<br />
<br />
-- international version<br />
print(utf8.len("слово"))<br />
</syntaxhighlight><br />
<br />
==string.lower, utf8.lower==<br />
;string.lower(string) or utf8.lower(string)<br />
;<nowiki>mystring:lower()</nowiki><br />
:Receives a string and returns a copy of this string with all uppercase letters changed to lowercase. All other characters are left unchanged. The definition of what an uppercase letter is depends on the current locale.<br />
: string.lower() works with English text only, use utf8.lower() for the international version.<br />
: See also: [[#string.upper.2C_utf8.upper|string.upper]], [[#string.upper.2C_utf8.upper|utf8.upper]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- prints an all-lowercase version<br />
print(string.lower("No way! This is AWESOME!"))<br />
<br />
-- international version<br />
print(utf8.lower("Класс! Ето ОТЛИЧНО!"))<br />
</syntaxhighlight><br />
<br />
==string.match, utf8.match==<br />
;string.match(text, pattern [, init]) or utf8.match()<br />
: Looks for the first match of pattern in the string text. If it finds one, then match returns the captures from the pattern; otherwise it returns nil. If pattern specifies no captures, then the whole match is returned. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative.<br />
: string.match() works with English text only, use utf8.match() for the international version.<br />
;Example<br />
''Need example''<br />
<br />
==string.rep==<br />
;string.rep(String, n)<br />
;<nowiki>mystring:rep(n)</nowiki><br />
: Returns a string that is the concatenation of <code>n</code> copies of the string <code>String</code>.<br />
: string.rep() works with both English and non-English text fine.<br />
<br />
;Example<br />
<syntaxhighlight lang=lua><br />
-- repeat * 10 times<br />
display(string.rep("*", 10))<br />
-- results in:<br />
**********<br />
<br />
-- do the same thing, but this time calling from a variable<br />
s = "*"<br />
display(s:rep(10))<br />
-- results in:<br />
**********<br />
</syntaxhighlight><br />
<br />
==string.reverse, utf8.reverse==<br />
;string.reverse(string) or utf8.reverse(string)<br />
;<nowiki>mystring:reverse()</nowiki><br />
<br />
: Returns a string that is the string <code>string</code> reversed.<br />
: string.reverse() works with English text only, use utf8.reverse() for the international version.<br />
<br />
;Parameters:<br />
* ''string:''<br />
:The string to reverse. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
mystring = "Hello from Lua"<br />
echo(mystring:reverse()) -- displays 'auL morf olleH'<br />
<br />
-- international version.<br />
mystring = "Привет от Луа!"<br />
echo(utf8.reverse(mystring)) -- displays '!ауЛ то тевирП', which probably looks the same to you<br />
</syntaxhighlight><br />
<br />
==string.split==<br />
;string.split(string, delimiter)<br />
;<nowiki>myString:split(delimiter)</nowiki><br />
: Splits a string into a table by the given delimiter. Can be called against a string (or variable holding a string) using the second form above.<br />
: Returns a table containing the split sections of the string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to split. Parameter is not needed if using second form of the syntax above. Passed as a string.<br />
* ''delimiter:''<br />
: The delimiter to use when splitting the string. Passed as a string, and allows for [http://www.lua.org/pil/20.2.html Lua pattern types]. Use % to escape here (and %% to escape a stand-alone %).<br />
{{ Note }} as of Mudlet 4.7+, delimiter will default to " " if not provided.<br />
<br />
{{ Note }} as of Mudlet 4.7+, using "" (empty string) for the delimiter will return the string as a table of characters. IE string.split("This","") will return as {"T", "h", "i", "s"}. Prior to 4.7 using empty string as the delimiter would error after hanging temporarily.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- This will split the string by ", " delimiter and print the resulting table to the main window.<br />
names = "Alice, Bob, Peter"<br />
name_table = string.split(names, ", ")<br />
display(name_table)<br />
<br />
--The alternate method<br />
names = "Alice, Bob, Peter"<br />
name_table = names:split(", ")<br />
display(name_table)<br />
</syntaxhighlight><br />
<br />
:Either method above will print out:<br />
: table {<br />
:: 1: 'Alice'<br />
:: 2: 'Bob'<br />
:: 3: 'Peter'<br />
: }<br />
<br />
==string.starts==<br />
;string.starts(string, prefix)<br />
: Test if string is starting with specified prefix.<br />
: Returns true or false<br />
: See also: [[#string.ends|string.ends]]<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to test. Passed as a string.<br />
* ''prefix:''<br />
: The prefix to test for. Passed as a string.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--The following will see if the line begins with "You" and if so will print a statement at the end of the line<br />
if string.starts(line, "You") then<br />
echo("====oh you====\n")<br />
end<br />
</syntaxhighlight><br />
<br />
==string.sub, utf8.sub==<br />
;string.sub(text, i [, j]) or utf8.sub()<br />
: Returns the substring of text that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(text,1,j) returns a prefix of text with length j, and string.sub(text, -i) returns a suffix of text with length i.<br />
: string.sub() works with English text only, use utf8.sub() for the international version.<br />
;Example<br />
''Need example''<br />
<br />
==string.title==<br />
;string.title(string)<br />
;<nowiki>mystring:title()</nowiki><br />
: Capitalizes the first character in a string.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to modify. Not needed if you use the second form of the syntax above.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
--Variable testname is now Anna.<br />
testname = string.title("anna")<br />
--Example will set test to "Bob".<br />
test = "bob"<br />
test = test:title()<br />
</syntaxhighlight><br />
<br />
==string.trim==<br />
;string.trim(string)<br />
: Trims string, removing all 'extra' white space at the beginning and end of the text.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The string to trim. Passed as a string.<br />
<br />
;Example:<br />
<syntaxhighlight lang="lua"><br />
--This will print 'Troll is here!', without the extra spaces.<br />
local str = string.trim(" Troll is here! ")<br />
echo("'" .. str .. "'")<br />
</syntaxhighlight><br />
<br />
==string.upper, utf8.upper==<br />
;string.upper(string) or utf8.upper(string)<br />
;<nowiki>mystring:upper()</nowiki><br />
: Receives a string and returns a copy of this string with all lowercase letters changed to uppercase. All other characters are left unchanged. The definition of what a lowercase letter is depends on the current locale.<br />
: string.upper() works with English text only, use utf8.upper() for the international version.<br />
<br />
: See also: [[#string.lower.2C_utf8.lower|string.lower]], [[#string.lower.2C_utf8.lower|utf8.lower]]<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string you want to change to uppercase<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- displays 'RUN BOB RUN'<br />
print(string.upper("run bob run"))<br />
<br />
-- displays 'ДАВАЙ ДАВАЙ!'<br />
print(utf8.upper("давай давай!"))<br />
</syntaxhighlight><br />
<br />
==utf8.charpos==<br />
;utf8.charpos(string[[, charpos], offset])<br />
: Converts UTF-8 position to byte offset, returns the character position and code point. If only offset is given, returns byte offset of this UTF-8 char index. If charpos and offset is given, a new charpos will be calculated by adding/subtracting UTF-8 char offset to current charpos. In all cases, it return a new char position, and code point (a number) at this position.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''charpos:''<br />
: (optional) character position to work on.<br />
* ''offset:''<br />
: (optional) offset (as a number) to work on.<br />
<br />
==utf8.escape==<br />
;utf8.escape(string)<br />
: Escape a string to UTF-8 format string. It support several escape formats:<br />
<br />
%ddd - which ddd is a decimal number at any length:<br />
change Unicode code point to UTF-8 format.<br />
%{ddd} - same as %nnn but has bracket around.<br />
%uddd - same as %ddd, u stands Unicode<br />
%u{ddd} - same as %{ddd}<br />
%xhhh - hexadigit version of %ddd<br />
%x{hhh} same as %xhhh.<br />
%? - '?' stands for any other character: escape this character.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string you want to escape<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local u = utf8.escape<br />
print(u"%123%u123%{123}%u{123}%xABC%x{ABC}")<br />
print(u"%%123%?%d%%u")<br />
</syntaxhighlight><br />
<br />
==utf8.fold==<br />
;utf8.fold(string)<br />
: Returns the lowercase version of the string for use in case-insensitive comparisons. If string is a number, it's treated as a code point and the converted code point is returned (as a number).<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string to lowercase.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(utf8.fold("ПРИВЕТ")) -- 'привет'<br />
print(utf8.fold("Привет")) -- 'привет'<br />
</syntaxhighlight><br />
<br />
==utf8.insert==<br />
;utf8.insert(string[, idx], substring)<br />
: Inserts the substring into the given string. If idx is given, inserts substring before the character at this index, otherwise the substring will append onto the end of string. idx can be negative.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''idx:''<br />
: (optional) character position to insert the string at.<br />
* ''substring:''<br />
: text to insert into the substring.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- inserts letter я before the 2nd letter and prints 'мясо'<br />
print(utf8.insert("мсо", 2, "я"))<br />
</syntaxhighlight><br />
<br />
==utf8.ncasecmp==<br />
;utf8.ncasecmp(a, b)<br />
: Compares ''a'' and ''b'' without case. Return -1 means a < b, 0 means a == b and 1 means a > b.<br />
<br />
;Parameters<br />
* ''a:''<br />
: String to compare.<br />
* ''b:''<br />
: String to compare against.<br />
<br />
==utf8.next==<br />
;utf8.next(string[, charpos[, offset]])<br />
: Iterates though the UTF-8 string.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''charpos:''<br />
: (optional) character position to work on.<br />
* ''offset:''<br />
: (optional) offset (as a number) to work on.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- prints location and code point of every letter<br />
for pos, code in utf8.next, "тут есть текст" do<br />
print(pos, code)<br />
end<br />
</syntaxhighlight><br />
<br />
==utf8.remove==<br />
;utf8.remove(string[, start[, stop]])<br />
: Removed characters from the given string. Deletes characters from the given ''start'' to the end of the string. If ''stop'' is given, deletes characters from ''start'' to ''stop'' (including start and stop). ''start'' and ''stop'' can be negative.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''start:''<br />
: position to start deleting characters from.<br />
* ''stop:''<br />
: (optional) posititon to stop deleting characters at.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- delete everything from the 3rd character including the character itself<br />
print(utf8.remove("мясо", 3)) -- 'мя'<br />
<br />
-- delete the last character, use negative to count backwards<br />
print(utf8.remove("мясо", -1)) -- 'мяс'<br />
<br />
-- delete everything from the 2nd to the 4th character<br />
print(utf8.remove("вкусное", 2,4)) -- 'вное'<br />
</syntaxhighlight><br />
<br />
==utf8.title==<br />
;utf8.title(string)<br />
: Returns the uppercase version of the string for use in case-insensitive comparisons. If string is a number, it's treated as a code point and the converted code point is returned (as a number).<br />
<br />
;Parameters<br />
* ''string:''<br />
: The string to uppercase.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(utf8.title("привет")) -- 'ПРИВЕТ'<br />
print(utf8.title("Привет")) -- 'ПРИВЕТ'<br />
</syntaxhighlight><br />
<br />
==utf8.width==<br />
;utf8.width(string[, ambi_is_double[, default_width]])<br />
: Calculate the widths of the given string. If the string is a code point, return the width of this code point.<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''ambi_is_double:''<br />
: (optional) if provided, the ambiguous width character's width is 2, otherwise it's 1.<br />
* ''default_width:''<br />
: (optional) if provided, this will be the width of unprintable character, used display a non-character mark for these characters.<br />
<br />
==utf8.widthindex==<br />
;utf8.widthindex(string, location[, ambi_is_double[, default_width]])<br />
: Returns the character index at the location in the given string as well as the offset and the width. This is a reverse operation of utf8.width().<br />
<br />
;Parameters<br />
* ''string:''<br />
: The input string to work on.<br />
* ''location:''<br />
: location to get the width of.<br />
* ''ambi_is_double:''<br />
: (optional) if provided, the ambiguous width character's width is 2, otherwise it's 1.<br />
* ''default_width:''<br />
: (optional) if provided, this will be the width of unprintable character, used display a non-character mark for these characters.<br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17688Manual:UI Functions2021-09-12T22:47:10Z<p>Dargoth: /* dechoPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17687Manual:UI Functions2021-09-12T22:46:35Z<p>Dargoth: /* cinsertPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17686Manual:UI Functions2021-09-12T22:45:20Z<p>Dargoth: /* hechoPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17685Manual:UI Functions2021-09-12T22:44:22Z<p>Dargoth: /* echoPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17684Manual:UI Functions2021-09-12T22:43:44Z<p>Dargoth: /* insertPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17683Manual:UI Functions2021-09-12T22:41:42Z<p>Dargoth: /* dinsertPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17682Manual:UI Functions2021-09-12T22:40:14Z<p>Dargoth: /* cechoPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17681Manual:UI Functions2021-09-12T22:39:07Z<p>Dargoth: /* setPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{lua code}:''<br />
: a table of lua code strings to do or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17680Manual:UI Functions2021-09-12T22:36:44Z<p>Dargoth: /* insertLink */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17679Manual:UI Functions2021-09-12T22:35:01Z<p>Dargoth: /* hinsertPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 or a functions (since Mudlet 4.11). ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17678Manual:UI Functions2021-09-12T22:34:21Z<p>Dargoth: /* hinsertLink */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 or a function (since Mudlet 4.11).<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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17677Manual:UI Functions2021-09-12T22:33:14Z<p>Dargoth: /* dechoPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17676Manual:UI Functions2021-09-12T22:32:04Z<p>Dargoth: /* dinsertPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17675Manual:UI Functions2021-09-12T22:30:33Z<p>Dargoth: /* cinsertPopup */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 as string or a function (since Mudlet 4.11).<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 or functions. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 as string or a function (since Mudlet 4.11).<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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17674Manual:UI Functions2021-09-12T22:29:53Z<p>Dargoth: /* cinsertLink */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 as string or a function (since Mudlet 4.11).<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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 as string or a function (since Mudlet 4.11).<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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17673Manual:UI Functions2021-09-12T22:26:25Z<p>Dargoth: /* dinsertLink */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 as string or a function (since Mudlet 4.11).<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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17672Manual:UI Functions2021-09-12T22:24:47Z<p>Dargoth: /* dechoLink */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function (since Mudlet 4.11).<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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17671Manual:UI Functions2021-09-12T22:24:11Z<p>Dargoth: /* hechoLink */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function.<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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function (since Mudlet 4.11).<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17670Manual:UI Functions2021-09-12T22:23:42Z<p>Dargoth: /* echoLink */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function.<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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function (since Mudlet 4.11).<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function.<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:UI_Functions&diff=17669Manual:UI Functions2021-09-12T22:23:17Z<p>Dargoth: /* cechoLink */</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 />
{{MudletVersion|3.0}}<br />
{{note}} ANSI bold is available since Mudlet 3.7.1+.<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 />
==ansi2string==<br />
;ansi2string(text)<br />
: Strips ANSI colour sequences from a string (text)<br />
: See also: [[Manual:Lua_Functions#ansi2decho|ansi2decho()]]<br />
<br />
{{MudletVersion|4.10}}<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 />
;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 />
==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, as text or a function (since Mudlet 4.11).<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 />
<br />
<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 />
{{MudletVersion|4.1}}<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 />
==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 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:'' Name of userwindow label is created in. Optional, defaults to the main window if not provided.<br />
* ''name:'' 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:'' X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:'' Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:'' width of the label, in pixels. Passed as an integer number.<br />
* ''height:'' height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:'' 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:'' 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 ([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'' (optional):<br />
: the window to copy the text from. Defaults to "main". Only supported in Mudlet 4.12+<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, as text or a function.<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 />
==dreplaceLine==<br />
;dreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#dinsertText|dinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with RGB color values inside angle brackets <>, ie ''<128,0,0>''. If you'd like to use a background color, put it after a colon : - ''<:128,0,0>''. You can use the ''<r>'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">dreplaceLine("<255,0,255>[ALERT!]: <r>"..line)<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, as text or a function.<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 - [[Manual:Lua_Functions#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 />
{{MudletVersion|3.4}}<br />
{{note}} 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 />
;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 />
;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 />
==getProfileTabNumber==<br />
;getProfileTabNumber()<br />
: Returns the current tab number you're in. If you have just one profile loaded, it'll always return 1 - otherwise it'll be the nth tab that is currently open.<br />
<br />
; Parameters<br />
:None<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
print(f"Current playing in tab #{getProfileTabNumber()}.")<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, as text or a function.<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 />
==hideGauge==<br />
;hideGauge(gaugeName)<br />
: hides the given gauge.<br />
<br />
: See also: [[#showGauge|showGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my gauge")<br />
</syntaxhighlight><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 />
==hreplaceLine==<br />
;hreplaceLine ([window], text)<br />
: Replaces the output line from the game with a colour-tagged string.<br />
{{MudletVersion|4.12}}<br />
See Also: [[Manual:Lua_Functions#hecho|hecho()]], [[Manual:Lua_Functions#hinsertText|hinsertText()]]<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display, with hex color values , ie ''#ff00ff''. If you'd like to use a background color, put it after a comma , - ''#,ff99ff''. You can use the ''#r'' tag to reset to the default color. <br />
:<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">hreplaceLine("#ff00ff[ALERT!]: #r"..line)<br />
</syntaxhighlight><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 />
==loadWindowLayout==<br />
;loadWindowLayout()<br />
:Resets the layout of userwindows (floating miniconsoles) to the last saved state.<br />
<br />
:See also: [[#saveWindowLayout|saveWindowLayout()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadWindowLayout()<br />
</syntaxhighlight><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 />
: See also: [[#resetUserWindowTitle|resetUserWindowTitle()]], [[#setUserWindowTitle|setUserWindowTitle()]], [[#saveWindowLayout|saveWindowLayout()]], [[#loadWindowLayout|loadWindowLayout()]]<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 />
==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 />
==replaceLine==<br />
;replaceLine ([window], text)<br />
: Replaces the output line from the game with your own text.<br />
See Also: [[Manual:Lua_Functions#echo|echo()]], [[Manual:Lua_Functions#insertText|insertText()]]<br />
<br />
;Parameters<br />
* ''window'' (optional):<br />
: the window to copy the text from. Defaults to "main".<br />
* ''text:''<br />
*: The text to display<br />
<br />
;Example<br />
<syntaxhighlight lang="lua">replaceLine("[ALERT!]: "..line)<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 User Window consoles if they are floating.<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()]], [[#openUserWindow|openUserWindow()]]<br />
<br />
{{MudletVersion|3.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveWindowLayout()<br />
</syntaxhighlight><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 />
: (optional) amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque). Defaults to 255 if omitted.<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 />
: Lua function to call, or the function name, 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 />
createLabel("testLabel", 50, 50, 100, 100, 0)<br />
<br />
function onClickGoNorth(event)<br />
if event.button == "LeftButton" then<br />
send("walk north")<br />
elseif event.button == "RightButton" then<br />
send("swim north")<br />
elseif event.button == "MidButton" then<br />
send("gallop north")<br />
end<br />
end<br />
<br />
setLabelClickCallback("testLabel", "onClickGoNorth")<br />
<br />
-- you can also use them within tables:<br />
mynamespace =<br />
{<br />
onClickGoNorth =<br />
function()<br />
echo("the north button was clicked!")<br />
end,<br />
}<br />
setLabelClickCallback("testLabel", "mynamespace.onClickGoNorth")<br />
<br />
-- or by passing the function directly:<br />
setLabelClickCallback("testLabel", onClickGoNorth)<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 />
{{MudletVersion|3.0}}<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 />
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 />
-- example of selecting text in a miniconsole and turning it into a link:<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], {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 />
* ''{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 />
==showGauge==<br />
;showGauge(gaugeName)<br />
: shows the given gauge, in case it was hidden previously.<br />
<br />
: See also: [[#hideGauge|hideGauge()]], [[#createGauge|createGauge()]]<br />
<br />
;Parameters<br />
* ''gaugeName:''<br />
: name of the gauge to show.<br />
<br />
;Example:<br />
<br />
<syntaxhighlight lang="lua"><br />
hideGauge("my gauge")<br />
showGauge("my<br />
</syntaxhighlight><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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:Networking_Functions&diff=17668Manual:Networking Functions2021-09-12T21:57:09Z<p>Dargoth: correct code blocks for customHTTP and deleteHTTP</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Mudlet API documentation for functions for managing networking.}}<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, and (in Mudlet 4.12+) <code>true</code> or <code>false</code> indicating if you're currently connected to a game.<br />
:See also: [[Manual:Networking_Functions#connectToServer|connectToServer()]]<br />
<br />
{{MudletVersion|4.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local host, port, connected = getConnectionInfo()<br />
cecho(string.format("<light_grey>Playing on <forest_green>%s:%s<light_grey>, currently connected? <forest_green>%s\n", host, port, tostring(connected)))<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
==purgeMediaCache==<br />
;purgeMediaCache()<br />
: Purge all media file stored in the media cache within a given Mudlet profile (media used with MCMP and MSP protocols). As game developers update the media files on their games, this enables the media folder inside the profile to be cleared so that the media files could be refreshed to the latest update(s).<br />
<br />
;Guidance:<br />
<br />
* Instruct a player to type ''lua purgeMediaCache()'' on the command line, or<br />
* Distribute a trigger, button or other scriptable feature for the given profile to call ''purgeMediaCache()''<br />
<br />
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]], [[Manual:Scripting#MUD_Client_Media_Protocol|Scripting MCMP]]<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 />
{{MudletVersion|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 />
: When playing an IRE game, a call to <code>send(" ")</code> afterwards is necessary due to a bug in the game with compression (MCCP) is enabled.<br />
<br />
: See also: [[Manual:Scripting#GMCP|GMCP Scripting for Discord status]]<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 game (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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
: If you use a scripting language (ex. PHP) to handle this post, remember that the file is sent as raw data. Expecially no field name is provided, dispite it works in common html post.<br />
<br />
{{MudletVersion|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(nil, "https://httpbin.org/post", {}, "<fill in file location to upload here, maybe get from invokeDialog>")<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(response) 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 />
-- 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(response) 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 />
;HTTP Basic Authentication Example:<br />
If your HTTP endpoint requires authentication to post data, HTTP Basic Authentication is a common method for doing so. There are two ways to do so.<br />
<br />
OPTION 1: URL encoding:<br />
Many HTTP servers allow you to enter a HTTP Basic Authentication username and password at the beginning of the URL itself, in format:<br />
https://username:password@domain.com/path/to/endpoint<br />
<br />
OPTION 2: Authorization Header:<br />
Some HTTP servers may require you to put your Basic Authentication into the 'Authorization' HTTP header value.<br />
<br />
This requires encoding the username:password into base64.<br />
For example, if your username is 'user' and your password is '12345', you'd need to run the string "user:12345" through a base64 encoder, which would result in the string:<br />
dXNlcjoxMjM0NQ==<br />
<br />
Then, you'd need to set the HTTP header 'Authorization' field value to indicate it is using Basic auth and inserting the base64 string as:<br />
['Authorization'] = "Basic dXNlcjoxMjM0NQ=="<br />
<br />
As you're encoding your username and password, you probably want to do this encoding locally for security reasons. You also probably want to only use https:// and not http:// when sending usernames and passwords over the internet.<br />
<br />
In the HTTP Basic Authentication example below, there is an inline base64Encode() function included:<br />
<br />
<syntaxhighlight lang="lua"><br />
function base64Encode(data)<br />
-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de><br />
-- licensed under the terms of the LGPL2<br />
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'<br />
return ((data:gsub('.', function(x) <br />
local r,b='',x:byte()<br />
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end<br />
return r;<br />
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)<br />
if (#x < 6) then return '' end<br />
local c=0<br />
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end<br />
return b:sub(c+1,c+1)<br />
end)..({ '', '==', '=' })[#data%3+1])<br />
end<br />
-- Example: base64Encode("user:12345") -> dXNlcjoxMjM0NQ== <br />
<br />
function postJSON(url,dataTable,headerTable)<br />
-- This will create a JSON message body. Many modern REST APIs expect a JSON body. <br />
local data = dataTable or {text = "hello world"}<br />
local header = headerTable or {["Content-Type"] = "application/json"}<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 sL("HTTP response success"); echo(response) 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 sL("HTTP response error",3); echo(response) 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 />
-- 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 />
end<br />
<br />
data = {<br />
message = "I am the banana",<br />
user = "admin"<br />
}<br />
header = {<br />
["Content-Type"] = "application/json",<br />
["Authorization"] = "Basic " .. base64Encode("user:12345")<br />
}<br />
postJSON("http://postman-echo.com/post",data,header)<br />
</syntaxhighlight><br />
<br />
;URL Encoding vs JSON encoding<br />
Some HTTP endpoints may not support JSON encoding, and instead may require URL encoding. Here's an example function to convert your lua data table into a URL encoded string::<br />
<syntaxhighlight lang="lua"><br />
-- Example: URLEncodeTable({message="hello",person="world"}) -> "message=hello&person=world"<br />
<br />
function URLEncodeTable(Args)<br />
-- From: https://help.interfaceware.com/code/details/urlcode-lua<br />
----------------------------------------------------------------------------<br />
-- URL-encode the elements of a table creating a string to be used in a<br />
-- URL for passing data/parameters to another script<br />
-- @param args Table where to extract the pairs (name=value).<br />
-- @return String with the resulting encoding.<br />
----------------------------------------------------------------------------<br />
--<br />
local ipairs, next, pairs, tonumber, type = ipairs, next, pairs, tonumber, type<br />
local string = string<br />
local table = table<br />
<br />
--helper functions: <br />
----------------------------------------------------------------------------<br />
-- Decode an URL-encoded string (see RFC 2396)<br />
----------------------------------------------------------------------------<br />
local unescape = function (str)<br />
str = string.gsub (str, "+", " ")<br />
str = string.gsub (str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end)<br />
return str<br />
end<br />
<br />
----------------------------------------------------------------------------<br />
-- URL-encode a string (see RFC 2396)<br />
----------------------------------------------------------------------------<br />
local escape = function (str)<br />
str = string.gsub (str, "([^0-9a-zA-Z !'()*._~-])", -- locale independent<br />
function (c) return string.format ("%%%02X", string.byte(c)) end)<br />
str = string.gsub (str, " ", "+")<br />
return str<br />
end<br />
<br />
----------------------------------------------------------------------------<br />
-- Insert a (name=value) pair into table [[args]]<br />
-- @param args Table to receive the result.<br />
-- @param name Key for the table.<br />
-- @param value Value for the key.<br />
-- Multi-valued names will be represented as tables with numerical indexes<br />
-- (in the order they came).<br />
----------------------------------------------------------------------------<br />
local insertfield = function (args, name, value)<br />
if not args[name] then<br />
args[name] = value<br />
else<br />
local t = type (args[name])<br />
if t == "string" then<br />
args[name] = {args[name],value,}<br />
elseif t == "table" then<br />
table.insert (args[name], value)<br />
else<br />
error ("CGILua fatal error (invalid args table)!")<br />
end<br />
end<br />
end<br />
-- end helper functions <br />
<br />
if Args == nil or next(Args) == nil then -- no args or empty args?<br />
return ""<br />
end<br />
local strp = ""<br />
for key, vals in pairs(Args) do<br />
if type(vals) ~= "table" then<br />
vals = {vals}<br />
end<br />
for i,val in ipairs(vals) do<br />
strp = strp.."&"..key.."="..escape(val)<br />
end<br />
end<br />
-- remove first &<br />
return string.sub(strp,2)<br />
end<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 />
{{MudletVersion|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 />
{{MudletVersion|4.1}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><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 />
==customHTTP==<br />
;customHTTP(method, url, headersTable)<br />
: Sends an custom method request to the given URL. Raises [[Manual:Event_Engine#sysCustomHttpDone|sysCustomHttpDone]] on success or [[Manual:Event_Engine#sysCustomHttpError|sysCustomHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
;Parameters:<br />
* ''method:''<br />
: Http method to use (eg. PATCH, HEAD etc.)<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 />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
function onCustomHttpDone(_, url, body, method)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s<white>, method: <dark_green>%s", url, body, method))<br />
end<br />
<br />
registerAnonymousEventHandler("sysCustomHttpDone", sysCustomHttpDone)<br />
<br />
customHTTP("PATCH", "this us a request with custom headers", "https://httpbin.org/put", {["X-am-I-awesome"] = "yep I am"})<br />
customHTTP("PATCH", "https://httpbin.org/put", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:Event_Engine&diff=17667Manual:Event Engine2021-09-12T21:54:37Z<p>Dargoth: /* Mudlet-raised events */ sysCustomHttpDone & sysCustomHttpError</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Manual on events, which events exist, how to raise events, how to handle them.}}<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, [one shot])]]'' 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", false)<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 = #args<br />
local first = args[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 />
===AdjustableContainerReposition===<br />
Raised while a [[Manual:Geyser#Adjustable.Container|adjustable container]] is re-positioned. <br />
<br />
<syntaxhighlight lang="lua"><br />
function repositioningContainer(eventName, containerName, width, height, x, y, mouseAction)<br />
print(f"{containerName}: {x}x, {y}y, {width}x{height}, using mouse? {mouseAction}")<br />
end<br />
<br />
registerAnonymousEventHandler("AdjustableContainerReposition", "repositioningContainer")<br />
</syntaxhighlight><br />
<br />
===AdjustableContainerRepositionFinish===<br />
Raised when an [[Manual:Geyser#Adjustable.Container|adjustable container]] done being re-positioned.<br />
<br />
<syntaxhighlight lang="lua"><br />
function finishedRepositioning(eventName, containerName, width, height, x, y)<br />
print(f"{containerName}: {x}x, {y}y, {width}x{height}")<br />
end<br />
<br />
registerAnonymousEventHandler("AdjustableContainerRepositionFinish", "finishedRepositioning")<br />
</syntaxhighlight><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 />
{{MudletVersion|3.19}}<br />
<br />
===sysConnectionEvent===<br />
<br />
Raised when the profile becomes connected to a MUD.<br />
<br />
===sysCustomHttpDone===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#customHTTP|customHTTP()]] 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) and HTTP method.<br />
<br />
See also [[#sysCustomHttpError|sysCustomHttpError]].<br />
<br />
===sysCustomHttpError===<br />
<br />
Raised whenever a [[Manual:Networking_Functions#customHTTP|customHTTP()]] request fails. Arguments are the error message and the URL that the request was sent to and HTTP method.<br />
<br />
See also [[#sysCustomHttpDone|sysCustomHttpDone]].<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.<br />
<br />
If you'd like to automatically reconnect when you get disconnected, make a new <code>Script</code> and add this inside:<br />
<br />
<syntaxhighlight lang="lua"><br />
registerAnonymousEventHandler("sysDisconnectionEvent", "reconnect")<br />
</syntaxhighlight><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. 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 />
===sysDownloadFileProgress===<br />
<br />
Raised while file is being downloaded to indicate progess of download.<br />
<br />
The arguments passed areː: event name, url of download, bytes downloaded, total bytes (if available).<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- will show progress bar while download file and hide it after file download is complete<br />
local progressBar = Geyser.Gauge:new({<br />
name="downloadProgressBar",<br />
x="25%", y="10%",<br />
width="50%", height="5%",<br />
})<br />
progressBar:setFontSize(13)<br />
progressBar:setAlignment("center")<br />
progressBar:hide()<br />
<br />
<br />
local fileUrl = "https://www.mudlet.org/download/Mudlet-4.10.1-linux-x64.AppImage.tar"<br />
local targetFile = getMudletHomeDir() .. "/Mudlet.tar"<br />
function handleProgress(_, url, bytesDownloaded, totalBytes)<br />
if url ~= fileUrl then<br />
return<br />
end<br />
<br />
progressBar:show()<br />
<br />
if not totalBytes then<br />
bytesDownloaded = 0<br />
totalBytes = 1<br />
end<br />
<br />
progressBar:setValue(bytesDownloaded, totalBytes, math.floor((bytesDownloaded / totalBytes) * 100) .. "%")<br />
end<br />
<br />
registerAnonymousEventHandler("sysDownloadFileProgress", "handleProgress")<br />
<br />
function hideProgressBar()<br />
tempTimer(3, function() progressBar:hide() end)<br />
end <br />
<br />
registerAnonymousEventHandler("sysDownloadDone", "hideProgressBar")<br />
registerAnonymousEventHandler("sysDownloadError", "hideProgressBar")<br />
<br />
downloadFile(targetFile, fileUrl)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11}}<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 />
{{MudletVersion|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 />
===sysDropUrlEvent===<br />
<br />
Raised when a url is dropped on the Mudlet main window or a userwindow.<br />
As an url at the moment Mudlet understands<br />
The arguments passed areː url, schema, xpos, ypos, and consolename - "main" for the main window and otherwise of the userwindow/miniconsole name.<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
<syntaxhighlight lang="lua"><br />
function onDragAndDropUrl(_, url, schema, xpos, ypos, consolename)<br />
print(string.format("Dropped new url into %s: %s (suffix: %s)", consolename, filepath, suffix))<br />
if schema == "http" or schema == "https" then<br />
print("\nOh boy... this might be a link to some website")<br />
end<br />
end<br />
registerAnonymousEventHandler("sysDropUrlEvent", "onDragAndDropUrl")<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
<br />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|3.0}}<br />
<br />
===sysMapDownloadEvent===<br />
<br />
Raised whenever an [[Standards:MMP|MMP map]] is downloaded and loaded in.<br />
<br />
===sysPathChanged===<br />
<br />
Raised whenever file or directory added through [[Manual:Lua_Functions#addFileWatch|addFileWatch()]] is modified.<br />
<br />
For directories this event is emitted when the directory at a specified path is modified (e.g., when a file is added or deleted) or removed from disk. Note that if there are several changes during a short period of time, some of the changes might not emit this signal. However, the last change in the sequence of changes will always generate this signal.<br />
<br />
For files this event is emitted when the file at the specified path is modified, renamed or removed from disk.<br />
<br />
{{MudletVersion|4.12}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
herbs = {}<br />
local herbsPath = getMudletHomeDir() .. "/herbs.lua"<br />
function herbsChangedHandler(_, path)<br />
if path == herbsPath then<br />
table.load(herbsPath, herbs)<br />
removeFileWatch(herbsPath)<br />
end<br />
end<br />
<br />
addFileWatch(herbsPath)<br />
registerAnonymousEventHandler("sysPathChanged", "herbsChangedHandler")<br />
</syntaxhighlight><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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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. <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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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, or when one of the borders 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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:Networking_Functions&diff=17666Manual:Networking Functions2021-09-12T21:50:25Z<p>Dargoth: /* Networking Functions */ customHTTP</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Mudlet API documentation for functions for managing networking.}}<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, and (in Mudlet 4.12+) <code>true</code> or <code>false</code> indicating if you're currently connected to a game.<br />
:See also: [[Manual:Networking_Functions#connectToServer|connectToServer()]]<br />
<br />
{{MudletVersion|4.2}}<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
local host, port, connected = getConnectionInfo()<br />
cecho(string.format("<light_grey>Playing on <forest_green>%s:%s<light_grey>, currently connected? <forest_green>%s\n", host, port, tostring(connected)))<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
==purgeMediaCache==<br />
;purgeMediaCache()<br />
: Purge all media file stored in the media cache within a given Mudlet profile (media used with MCMP and MSP protocols). As game developers update the media files on their games, this enables the media folder inside the profile to be cleared so that the media files could be refreshed to the latest update(s).<br />
<br />
;Guidance:<br />
<br />
* Instruct a player to type ''lua purgeMediaCache()'' on the command line, or<br />
* Distribute a trigger, button or other scriptable feature for the given profile to call ''purgeMediaCache()''<br />
<br />
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]], [[Manual:Scripting#MUD_Client_Media_Protocol|Scripting MCMP]]<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 />
{{MudletVersion|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 />
: When playing an IRE game, a call to <code>send(" ")</code> afterwards is necessary due to a bug in the game with compression (MCCP) is enabled.<br />
<br />
: See also: [[Manual:Scripting#GMCP|GMCP Scripting for Discord status]]<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 game (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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
: If you use a scripting language (ex. PHP) to handle this post, remember that the file is sent as raw data. Expecially no field name is provided, dispite it works in common html post.<br />
<br />
{{MudletVersion|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(nil, "https://httpbin.org/post", {}, "<fill in file location to upload here, maybe get from invokeDialog>")<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(response) 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 />
-- 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(response) 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 />
;HTTP Basic Authentication Example:<br />
If your HTTP endpoint requires authentication to post data, HTTP Basic Authentication is a common method for doing so. There are two ways to do so.<br />
<br />
OPTION 1: URL encoding:<br />
Many HTTP servers allow you to enter a HTTP Basic Authentication username and password at the beginning of the URL itself, in format:<br />
https://username:password@domain.com/path/to/endpoint<br />
<br />
OPTION 2: Authorization Header:<br />
Some HTTP servers may require you to put your Basic Authentication into the 'Authorization' HTTP header value.<br />
<br />
This requires encoding the username:password into base64.<br />
For example, if your username is 'user' and your password is '12345', you'd need to run the string "user:12345" through a base64 encoder, which would result in the string:<br />
dXNlcjoxMjM0NQ==<br />
<br />
Then, you'd need to set the HTTP header 'Authorization' field value to indicate it is using Basic auth and inserting the base64 string as:<br />
['Authorization'] = "Basic dXNlcjoxMjM0NQ=="<br />
<br />
As you're encoding your username and password, you probably want to do this encoding locally for security reasons. You also probably want to only use https:// and not http:// when sending usernames and passwords over the internet.<br />
<br />
In the HTTP Basic Authentication example below, there is an inline base64Encode() function included:<br />
<br />
<syntaxhighlight lang="lua"><br />
function base64Encode(data)<br />
-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de><br />
-- licensed under the terms of the LGPL2<br />
local b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'<br />
return ((data:gsub('.', function(x) <br />
local r,b='',x:byte()<br />
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end<br />
return r;<br />
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)<br />
if (#x < 6) then return '' end<br />
local c=0<br />
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end<br />
return b:sub(c+1,c+1)<br />
end)..({ '', '==', '=' })[#data%3+1])<br />
end<br />
-- Example: base64Encode("user:12345") -> dXNlcjoxMjM0NQ== <br />
<br />
function postJSON(url,dataTable,headerTable)<br />
-- This will create a JSON message body. Many modern REST APIs expect a JSON body. <br />
local data = dataTable or {text = "hello world"}<br />
local header = headerTable or {["Content-Type"] = "application/json"}<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 sL("HTTP response success"); echo(response) 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 sL("HTTP response error",3); echo(response) 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 />
-- 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 />
end<br />
<br />
data = {<br />
message = "I am the banana",<br />
user = "admin"<br />
}<br />
header = {<br />
["Content-Type"] = "application/json",<br />
["Authorization"] = "Basic " .. base64Encode("user:12345")<br />
}<br />
postJSON("http://postman-echo.com/post",data,header)<br />
</syntaxhighlight><br />
<br />
;URL Encoding vs JSON encoding<br />
Some HTTP endpoints may not support JSON encoding, and instead may require URL encoding. Here's an example function to convert your lua data table into a URL encoded string::<br />
<syntaxhighlight lang="lua"><br />
-- Example: URLEncodeTable({message="hello",person="world"}) -> "message=hello&person=world"<br />
<br />
function URLEncodeTable(Args)<br />
-- From: https://help.interfaceware.com/code/details/urlcode-lua<br />
----------------------------------------------------------------------------<br />
-- URL-encode the elements of a table creating a string to be used in a<br />
-- URL for passing data/parameters to another script<br />
-- @param args Table where to extract the pairs (name=value).<br />
-- @return String with the resulting encoding.<br />
----------------------------------------------------------------------------<br />
--<br />
local ipairs, next, pairs, tonumber, type = ipairs, next, pairs, tonumber, type<br />
local string = string<br />
local table = table<br />
<br />
--helper functions: <br />
----------------------------------------------------------------------------<br />
-- Decode an URL-encoded string (see RFC 2396)<br />
----------------------------------------------------------------------------<br />
local unescape = function (str)<br />
str = string.gsub (str, "+", " ")<br />
str = string.gsub (str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end)<br />
return str<br />
end<br />
<br />
----------------------------------------------------------------------------<br />
-- URL-encode a string (see RFC 2396)<br />
----------------------------------------------------------------------------<br />
local escape = function (str)<br />
str = string.gsub (str, "([^0-9a-zA-Z !'()*._~-])", -- locale independent<br />
function (c) return string.format ("%%%02X", string.byte(c)) end)<br />
str = string.gsub (str, " ", "+")<br />
return str<br />
end<br />
<br />
----------------------------------------------------------------------------<br />
-- Insert a (name=value) pair into table [[args]]<br />
-- @param args Table to receive the result.<br />
-- @param name Key for the table.<br />
-- @param value Value for the key.<br />
-- Multi-valued names will be represented as tables with numerical indexes<br />
-- (in the order they came).<br />
----------------------------------------------------------------------------<br />
local insertfield = function (args, name, value)<br />
if not args[name] then<br />
args[name] = value<br />
else<br />
local t = type (args[name])<br />
if t == "string" then<br />
args[name] = {args[name],value,}<br />
elseif t == "table" then<br />
table.insert (args[name], value)<br />
else<br />
error ("CGILua fatal error (invalid args table)!")<br />
end<br />
end<br />
end<br />
-- end helper functions <br />
<br />
if Args == nil or next(Args) == nil then -- no args or empty args?<br />
return ""<br />
end<br />
local strp = ""<br />
for key, vals in pairs(Args) do<br />
if type(vals) ~= "table" then<br />
vals = {vals}<br />
end<br />
for i,val in ipairs(vals) do<br />
strp = strp.."&"..key.."="..escape(val)<br />
end<br />
end<br />
-- remove first &<br />
return string.sub(strp,2)<br />
end<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
==customHTTP==<br />
;customHTTP(method, url, headersTable)<br />
: Sends an custom method request to the given URL. Raises [[Manual:Event_Engine#sysCustomHttpDone|sysCustomHttpDone]] on success or [[Manual:Event_Engine#sysCustomHttpError|sysCustomHttpError]] on failure.<br />
:See also: [[#downloadFile|downloadFile()]], [[#getHTTP|getHTTP()]], [[#postHTTP|postHTTP()]], [[#putHTTP|putHTTP()]], [[#deleteHTTP|deleteHTTP()]].<br />
<br />
;Parameters:<br />
* ''method:''<br />
: Http method to use (eg. PATCH, HEAD etc.)<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 />
{{MudletVersion|4.11}}<br />
<br />
;Example<br />
function onCustomHttpDone(_, url, body, method)<br />
cecho(string.format("<white>url: <dark_green>%s<white>, body: <dark_green>%s<white>, method: <dark_green>%s", url, body, method))<br />
end<br />
<br />
registerAnonymousEventHandler("sysCustomHttpDone", sysCustomHttpDone)<br />
<br />
customHTTP("PATCH", "this us a request with custom headers", "https://httpbin.org/put", {["X-am-I-awesome"] = "yep I am"})<br />
customHTTP("PATCH", "https://httpbin.org/put", "<fill in file location to upload here>")<br />
</syntaxhighlight><br />
<br />
[[Category:Mudlet API]]<br />
[[Category:Mudlet Manual]]</div>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=17613Manual:Mapper Functions2021-08-07T08:32:32Z<p>Dargoth: /* unsetRoomCharColor */</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Mudlet API documentation for functions that manipulate the mapper and its related features.}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the game 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 />
{{MudletVersion|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 />
==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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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: [[#createMapLabel|createMapLabel]], [[#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}} ''name of userwindow'' available in Mudlet 4.6.1+<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 />
;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 />
==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, available in Mudlet 3.0+):<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 />
: 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, or:<br />
* ''areaName'' (available in Mudlet 3.0+):<br />
: Area name to delete.<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 />
==disableMapInfo==<br />
;disableMapInfo(label)<br />
<br />
Disable the particular map info - same as toggling off checkbox from select box under mapper.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info to be disabled was registered.<br />
<br />
: See also: [[#registerMapInfo|registerMapInfo()]], [[#enableMapInfo|enableMapInfo()]], [[#killMapInfo|killMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
==enableMapInfo==<br />
;enableMapInfo(label)<br />
<br />
Enable the particular map info - same as toggling on checkbox from select box under mapper.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info to be enabled was registered.<br />
<br />
: See also: [[#registerMapInfo|registerMapInfo()]], [[#disableMapInfo|disableMapInfo()]], [[#killMapInfo|killMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|3.0}}<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 />
==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 />
;See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<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 />
<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. <br />
{{Note}} 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. <br />
{{Note}} 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 />
;See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|3.3}}<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabel(areaID, labelID or labelText)<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 in 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, it will return an empty table.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]], [[#deleteMapLabel|deleteMapLabel()]]<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 />
==getMapMenus==<br />
;getMapMenus()<br />
<br />
:Returns a table with the available map menus as key-value in the format of <code>map menu - parent item</code>. If an item is positioned at the menu's top-level, the value will say <code>top-level</code>.<br />
:If you haven't opened a map yet, getMapMenus() will return nil+error message. If you don't have any map labels yet, an empty table <code>{}</code> is returned.<br />
<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- given the following menu structure:<br />
top-level<br />
menu1<br />
menu1.1<br />
action1.1.1<br />
menu1.2<br />
action1.2.1<br />
menu2<br />
<br />
getMapMenus() -- will return:<br />
{<br />
menu2 = "top-level",<br />
menu1.2 = "menu1",<br />
menu1.1 = "menu1",<br />
menu1 = "top-level"<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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(string.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 games 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 />
{{MudletVersion|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 games that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de]). ''-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 />
{{MudletVersion|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[, listAllExits])<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the special exits of.<br />
* ''listAllExits:''<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 />
See also: [[#lockSpecialExit|lockSpecialExit()]]<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 />
<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 />
==killMapInfo==<br />
;killMapInfo(label)<br />
<br />
Delete a map info contributor entirely - it will be not available anymore.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info to be removed was registered.<br />
<br />
: See also: [[#registerMapInfo|registerMapInfo()]], [[#enableMapInfo|enableMapInfo()]], [[#disableMapInfo|disableMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
==loadJsonMap==<br />
; loadJsonMap(pathFileName)<br />
<br />
; Parameters:<br />
<br />
* ''pathFileName'' a string that is an absolute path and file name to read the data from.<br />
<br />
Load the Mudlet map in text (JSON) format. It does take longer than loading usual map file (''.dat'' in binary) so it will show a progress dialog.<br />
<br />
: See also: [[#saveJsonMap|saveJsonMap()]]<br />
<br />
Returns:<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadJsonMap(getMudetHomeDir() .. "/map.json")<br />
<br />
true<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11.0}}<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 downloadable maps for their MUD games. <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 />
==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 />
{{MudletVersion|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 />
{{MudletVersion|4.7}}<br />
<br />
==registerMapInfo==<br />
;registerMapInfo(label, function)<br />
<br />
Adds an extra 'map info' to the mapper widget which can be used to display custom information.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info will be registered and visible in select box under mapper. You can use it later to kill map info, enable it, disable it or overwrite using [[#registerMapInfo|registerMapInfo()]] again.<br />
* ''function:''<br />
: Callback function that will be responsible for returning information how to draw map info fragment.<br />
<br />
Callback function is called with following arguments:<br />
* ''roomId'' - current roomId or currently selected room (when multiple selection is made this is center room)<br />
* ''selectionSize'' - how many rooms are selected<br />
* ''areaId'' - roomId's areaId<br />
* ''displayedAreaId'' - areaId that is currently displayed<br />
<br />
Callback needs to return following:<br />
* ''text'' - text that will be displayed (when empty, nothing will be displayed, if you want to "reserve" line or lines use not empty value " " or add line breaks "\n")<br />
* ''isBold'' (optional) - true/false - determines whether text will be bold <br />
* ''isItalic'' (optional) - true/false - determines whether text will be italic<br />
* ''color r'' (optional) - color of text red component (0-255)<br />
* ''color g'' (optional) - color of text green component (0-255)<br />
* ''color b'' (optional) - color of text blue component (0-255)<br />
<br />
{{note}}<br />
Map info is registered in disabled state, you need to enable it through script or by selecting checkbox under mapper.<br />
<br />
<syntaxhighlight lang="lua"><br />
registerMapInfo("My very own handler!", function(roomId, selectionSize, areaId, displayedArea) <br />
return string.format("RoomId: %d\nNumbers of room selected: %d\nAreaId: %d\nDisplaying area: %d", roomId, selectionSize, areaId, displayedArea),<br />
true, true, 0, 255, 0<br />
end)<br />
enableMapInfo("My very own handler!")<br />
</syntaxhighlight><br />
<br />
Example will display something like that:<br />
<br />
[[File:Map-info-example.png]]<br />
<br />
Using function arguments is completely optional and you can determine whether and how to display map info completely externally.<br />
<syntaxhighlight lang="lua"><br />
registerMapInfo("Alert", function() <br />
if character.hp < 20 then<br />
return "Look out! Your HP is getting low", true, false, unpack(color_table.red) -- will display red, bolded warning whne character.hp is below 20<br />
else<br />
return "" -- will not return anything<br />
end<br />
end)<br />
enableMapInfo("Alert")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
You can register multiple map infos - just give them unique names and toggle whichever ones you need.<br />
<br />
: See also: [[#killMapInfo|killMapInfo()]], [[#enableMapInfo|enableMapInfo()]], [[#disableMapInfo|disableMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<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 />
{{MudletVersion|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 />
==saveJsonMap==<br />
; saveJsonMap([pathFileName])<br />
Saves all the data that is normally held in the Mudlet map (''.dat'' as a binary format) in text (JSON) format. It does take longer to do this, so a progress dialog will be shown indicating the status. <br />
<br />
: See also: [[#loadJsonMap|loadJsonMap()]]<br />
{{MudletVersion|4.11.0}}<br />
<br />
; Parameters:<br />
* ''pathFileName'' (optional in Mudlet 4.12+): a string that is an absolute path and file name to save the data into.<br />
<br />
; Returns:<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveJsonMap(getMudetHomeDir() .. "/map.json")<br />
<br />
true<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 number | room name[, case-sensitive [, exact-match]])<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'', the optional second and third boolean parameters have been available since Mudlet 3.0;<br />
<br />
::If no rooms are found, then an empty table is returned.<br />
<br />
:If you pass it a '''number''' instead of a '''string''' as just one argument, it'll act like [[#getRoomName|getRoomName()]] and return the room name.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- show the behavior when given a room number:<br />
display(searchRoom(3088))<br />
"The North Road South of Taren Ferry"<br />
<br />
-- show the behavior when given a string:<br />
-- shows all rooms containing the text in any case:<br />
display(searchRoom("North road"))<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 />
-- or:<br />
-- display(searchRoom("North road",false))<br />
-- display(searchRoom("North road",false,false))<br />
-- would both also produce those results.<br />
<br />
-- shows all rooms containing the text in ONLY the letter-case provided:<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 that text in either letter-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 and exactly the given text:<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><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". <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". <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. 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 />
;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 />
{{MudletVersion|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}} parameter 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 />
{{MudletVersion|3.0}}<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(101, "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 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 />
;Game-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 game 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 />
==setRoomCharColor==<br />
;setRoomCharColor(roomId, r, g, b)<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set char color to.<br />
* ''r:''<br />
: Red component of room char color (0-255)<br />
* ''g:''<br />
: Green component of room char color (0-255)<br />
* ''b:''<br />
: Blue component of room char color (0-255)<br />
<br />
Sets color for room symbol.<br />
<br />
<syntaxhighlight lang="lua"><br />
setRoomCharColor(2402, 255, 0, 0)<br />
setRoomCharColor(2403, 0, 255, 0)<br />
setRoomCharColor(2404, 0, 0, 255)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11}}<br />
<br />
: See also: [[#unsetRoomCharColor|unsetRoomCharColor()]]<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 asa 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 />
==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 game 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 game 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 game 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 is available in Mudlet 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 />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==unsetRoomCharColor==<br />
;unsetRoomCharColor(roomId)<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to unset char color to.<br />
<br />
Removes char color setting from room, back to automatic determination based on room background lightness.<br />
<br />
<syntaxhighlight lang="lua"><br />
unsetRoomCharColor(2031)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11}}<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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=17612Manual:Mapper Functions2021-08-07T08:32:11Z<p>Dargoth: /* setRoomCharColor */</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Mudlet API documentation for functions that manipulate the mapper and its related features.}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the game 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 />
{{MudletVersion|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 />
==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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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: [[#createMapLabel|createMapLabel]], [[#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}} ''name of userwindow'' available in Mudlet 4.6.1+<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 />
;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 />
==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, available in Mudlet 3.0+):<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 />
: 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, or:<br />
* ''areaName'' (available in Mudlet 3.0+):<br />
: Area name to delete.<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 />
==disableMapInfo==<br />
;disableMapInfo(label)<br />
<br />
Disable the particular map info - same as toggling off checkbox from select box under mapper.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info to be disabled was registered.<br />
<br />
: See also: [[#registerMapInfo|registerMapInfo()]], [[#enableMapInfo|enableMapInfo()]], [[#killMapInfo|killMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
==enableMapInfo==<br />
;enableMapInfo(label)<br />
<br />
Enable the particular map info - same as toggling on checkbox from select box under mapper.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info to be enabled was registered.<br />
<br />
: See also: [[#registerMapInfo|registerMapInfo()]], [[#disableMapInfo|disableMapInfo()]], [[#killMapInfo|killMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|3.0}}<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 />
==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 />
;See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<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 />
<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. <br />
{{Note}} 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. <br />
{{Note}} 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 />
;See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|3.3}}<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabel(areaID, labelID or labelText)<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 in 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, it will return an empty table.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]], [[#deleteMapLabel|deleteMapLabel()]]<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 />
==getMapMenus==<br />
;getMapMenus()<br />
<br />
:Returns a table with the available map menus as key-value in the format of <code>map menu - parent item</code>. If an item is positioned at the menu's top-level, the value will say <code>top-level</code>.<br />
:If you haven't opened a map yet, getMapMenus() will return nil+error message. If you don't have any map labels yet, an empty table <code>{}</code> is returned.<br />
<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- given the following menu structure:<br />
top-level<br />
menu1<br />
menu1.1<br />
action1.1.1<br />
menu1.2<br />
action1.2.1<br />
menu2<br />
<br />
getMapMenus() -- will return:<br />
{<br />
menu2 = "top-level",<br />
menu1.2 = "menu1",<br />
menu1.1 = "menu1",<br />
menu1 = "top-level"<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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(string.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 games 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 />
{{MudletVersion|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 games that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de]). ''-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 />
{{MudletVersion|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[, listAllExits])<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the special exits of.<br />
* ''listAllExits:''<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 />
See also: [[#lockSpecialExit|lockSpecialExit()]]<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 />
<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 />
==killMapInfo==<br />
;killMapInfo(label)<br />
<br />
Delete a map info contributor entirely - it will be not available anymore.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info to be removed was registered.<br />
<br />
: See also: [[#registerMapInfo|registerMapInfo()]], [[#enableMapInfo|enableMapInfo()]], [[#disableMapInfo|disableMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
==loadJsonMap==<br />
; loadJsonMap(pathFileName)<br />
<br />
; Parameters:<br />
<br />
* ''pathFileName'' a string that is an absolute path and file name to read the data from.<br />
<br />
Load the Mudlet map in text (JSON) format. It does take longer than loading usual map file (''.dat'' in binary) so it will show a progress dialog.<br />
<br />
: See also: [[#saveJsonMap|saveJsonMap()]]<br />
<br />
Returns:<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadJsonMap(getMudetHomeDir() .. "/map.json")<br />
<br />
true<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11.0}}<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 downloadable maps for their MUD games. <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 />
==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 />
{{MudletVersion|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 />
{{MudletVersion|4.7}}<br />
<br />
==registerMapInfo==<br />
;registerMapInfo(label, function)<br />
<br />
Adds an extra 'map info' to the mapper widget which can be used to display custom information.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info will be registered and visible in select box under mapper. You can use it later to kill map info, enable it, disable it or overwrite using [[#registerMapInfo|registerMapInfo()]] again.<br />
* ''function:''<br />
: Callback function that will be responsible for returning information how to draw map info fragment.<br />
<br />
Callback function is called with following arguments:<br />
* ''roomId'' - current roomId or currently selected room (when multiple selection is made this is center room)<br />
* ''selectionSize'' - how many rooms are selected<br />
* ''areaId'' - roomId's areaId<br />
* ''displayedAreaId'' - areaId that is currently displayed<br />
<br />
Callback needs to return following:<br />
* ''text'' - text that will be displayed (when empty, nothing will be displayed, if you want to "reserve" line or lines use not empty value " " or add line breaks "\n")<br />
* ''isBold'' (optional) - true/false - determines whether text will be bold <br />
* ''isItalic'' (optional) - true/false - determines whether text will be italic<br />
* ''color r'' (optional) - color of text red component (0-255)<br />
* ''color g'' (optional) - color of text green component (0-255)<br />
* ''color b'' (optional) - color of text blue component (0-255)<br />
<br />
{{note}}<br />
Map info is registered in disabled state, you need to enable it through script or by selecting checkbox under mapper.<br />
<br />
<syntaxhighlight lang="lua"><br />
registerMapInfo("My very own handler!", function(roomId, selectionSize, areaId, displayedArea) <br />
return string.format("RoomId: %d\nNumbers of room selected: %d\nAreaId: %d\nDisplaying area: %d", roomId, selectionSize, areaId, displayedArea),<br />
true, true, 0, 255, 0<br />
end)<br />
enableMapInfo("My very own handler!")<br />
</syntaxhighlight><br />
<br />
Example will display something like that:<br />
<br />
[[File:Map-info-example.png]]<br />
<br />
Using function arguments is completely optional and you can determine whether and how to display map info completely externally.<br />
<syntaxhighlight lang="lua"><br />
registerMapInfo("Alert", function() <br />
if character.hp < 20 then<br />
return "Look out! Your HP is getting low", true, false, unpack(color_table.red) -- will display red, bolded warning whne character.hp is below 20<br />
else<br />
return "" -- will not return anything<br />
end<br />
end)<br />
enableMapInfo("Alert")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
You can register multiple map infos - just give them unique names and toggle whichever ones you need.<br />
<br />
: See also: [[#killMapInfo|killMapInfo()]], [[#enableMapInfo|enableMapInfo()]], [[#disableMapInfo|disableMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<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 />
{{MudletVersion|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 />
==saveJsonMap==<br />
; saveJsonMap([pathFileName])<br />
Saves all the data that is normally held in the Mudlet map (''.dat'' as a binary format) in text (JSON) format. It does take longer to do this, so a progress dialog will be shown indicating the status. <br />
<br />
: See also: [[#loadJsonMap|loadJsonMap()]]<br />
{{MudletVersion|4.11.0}}<br />
<br />
; Parameters:<br />
* ''pathFileName'' (optional in Mudlet 4.12+): a string that is an absolute path and file name to save the data into.<br />
<br />
; Returns:<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveJsonMap(getMudetHomeDir() .. "/map.json")<br />
<br />
true<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 number | room name[, case-sensitive [, exact-match]])<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'', the optional second and third boolean parameters have been available since Mudlet 3.0;<br />
<br />
::If no rooms are found, then an empty table is returned.<br />
<br />
:If you pass it a '''number''' instead of a '''string''' as just one argument, it'll act like [[#getRoomName|getRoomName()]] and return the room name.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- show the behavior when given a room number:<br />
display(searchRoom(3088))<br />
"The North Road South of Taren Ferry"<br />
<br />
-- show the behavior when given a string:<br />
-- shows all rooms containing the text in any case:<br />
display(searchRoom("North road"))<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 />
-- or:<br />
-- display(searchRoom("North road",false))<br />
-- display(searchRoom("North road",false,false))<br />
-- would both also produce those results.<br />
<br />
-- shows all rooms containing the text in ONLY the letter-case provided:<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 that text in either letter-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 and exactly the given text:<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><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". <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". <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. 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 />
;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 />
{{MudletVersion|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}} parameter 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 />
{{MudletVersion|3.0}}<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(101, "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 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 />
;Game-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 game 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 />
==setRoomCharColor==<br />
;setRoomCharColor(roomId, r, g, b)<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to to set char color to.<br />
* ''r:''<br />
: Red component of room char color (0-255)<br />
* ''g:''<br />
: Green component of room char color (0-255)<br />
* ''b:''<br />
: Blue component of room char color (0-255)<br />
<br />
Sets color for room symbol.<br />
<br />
<syntaxhighlight lang="lua"><br />
setRoomCharColor(2402, 255, 0, 0)<br />
setRoomCharColor(2403, 0, 255, 0)<br />
setRoomCharColor(2404, 0, 0, 255)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11}}<br />
<br />
: See also: [[#unsetRoomCharColor|unsetRoomCharColor()]]<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 asa 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 />
==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 game 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 game 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 game 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 is available in Mudlet 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 />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==unsetRoomCharColor==<br />
;unsetRoomCharColor(roomId)<br />
<br />
Removes char color setting from room, back to automatic determination based on room background lightness.<br />
<br />
<syntaxhighlight lang="lua"><br />
unsetRoomCharColor(2031)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11}}<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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:Mapper_Functions&diff=17611Manual:Mapper Functions2021-08-07T08:29:44Z<p>Dargoth: /* Mapper Functions */ add missing docs for setRoomCharColor and unsetRoomCharColor</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Mudlet API documentation for functions that manipulate the mapper and its related features.}}<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the game 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 />
{{MudletVersion|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 />
==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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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: [[#createMapLabel|createMapLabel]], [[#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}} ''name of userwindow'' available in Mudlet 4.6.1+<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 />
;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 />
==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, available in Mudlet 3.0+):<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 />
: 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, or:<br />
* ''areaName'' (available in Mudlet 3.0+):<br />
: Area name to delete.<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 />
==disableMapInfo==<br />
;disableMapInfo(label)<br />
<br />
Disable the particular map info - same as toggling off checkbox from select box under mapper.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info to be disabled was registered.<br />
<br />
: See also: [[#registerMapInfo|registerMapInfo()]], [[#enableMapInfo|enableMapInfo()]], [[#killMapInfo|killMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
==enableMapInfo==<br />
;enableMapInfo(label)<br />
<br />
Enable the particular map info - same as toggling on checkbox from select box under mapper.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info to be enabled was registered.<br />
<br />
: See also: [[#registerMapInfo|registerMapInfo()]], [[#disableMapInfo|disableMapInfo()]], [[#killMapInfo|killMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|3.0}}<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 />
==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 />
;See also: [[#setExit|setExit()]], [[#getRoomExits|getRoomExits()]]<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 />
<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. <br />
{{Note}} 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. <br />
{{Note}} 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 />
;See also: [[#clearAreaUserData|clearAreaUserData()]], [[#clearAreaUserDataItem|clearAreaUserDataItem()]], [[#getAllAreaUserData|getAllAreaUserData()]], [[#searchAreaUserData|searchAreaUserData()]], [[#setAreaUserData|setAreaUserData()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
display(getAreaUserData(34, "country"))<br />
-- might produce --<br />
"Andor"<br />
</syntaxhighlight><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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|3.3}}<br />
<br />
==getMapLabel==<br />
;labelinfo = getMapLabel(areaID, labelID or labelText)<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 in 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, it will return an empty table.<br />
<br />
: See also: [[#createMapLabel|createMapLabel()]], [[#getMapLabel|getMapLabel()]], [[#deleteMapLabel|deleteMapLabel()]]<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 />
==getMapMenus==<br />
;getMapMenus()<br />
<br />
:Returns a table with the available map menus as key-value in the format of <code>map menu - parent item</code>. If an item is positioned at the menu's top-level, the value will say <code>top-level</code>.<br />
:If you haven't opened a map yet, getMapMenus() will return nil+error message. If you don't have any map labels yet, an empty table <code>{}</code> is returned.<br />
<br />
: See also: [[#addMapMenu|addMapMenu()]], [[#addMapEvent|addMapEvent()]]<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
-- given the following menu structure:<br />
top-level<br />
menu1<br />
menu1.1<br />
action1.1.1<br />
menu1.2<br />
action1.2.1<br />
menu2<br />
<br />
getMapMenus() -- will return:<br />
{<br />
menu2 = "top-level",<br />
menu1.2 = "menu1",<br />
menu1.1 = "menu1",<br />
menu1 = "top-level"<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 />
{{MudletVersion|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 />
{{MudletVersion|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 />
{{MudletVersion|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(string.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 games 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 />
{{MudletVersion|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 games that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de]). ''-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 />
{{MudletVersion|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[, listAllExits])<br />
<br />
;Parameters<br />
* ''roomID:''<br />
: Room ID to return the special exits of.<br />
* ''listAllExits:''<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 />
See also: [[#lockSpecialExit|lockSpecialExit()]]<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 />
<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 />
==killMapInfo==<br />
;killMapInfo(label)<br />
<br />
Delete a map info contributor entirely - it will be not available anymore.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info to be removed was registered.<br />
<br />
: See also: [[#registerMapInfo|registerMapInfo()]], [[#enableMapInfo|enableMapInfo()]], [[#disableMapInfo|disableMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<br />
<br />
==loadJsonMap==<br />
; loadJsonMap(pathFileName)<br />
<br />
; Parameters:<br />
<br />
* ''pathFileName'' a string that is an absolute path and file name to read the data from.<br />
<br />
Load the Mudlet map in text (JSON) format. It does take longer than loading usual map file (''.dat'' in binary) so it will show a progress dialog.<br />
<br />
: See also: [[#saveJsonMap|saveJsonMap()]]<br />
<br />
Returns:<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
loadJsonMap(getMudetHomeDir() .. "/map.json")<br />
<br />
true<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11.0}}<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 downloadable maps for their MUD games. <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 />
==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 />
{{MudletVersion|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 />
{{MudletVersion|4.7}}<br />
<br />
==registerMapInfo==<br />
;registerMapInfo(label, function)<br />
<br />
Adds an extra 'map info' to the mapper widget which can be used to display custom information.<br />
<br />
;Parameters<br />
* ''label:''<br />
: Name under which map info will be registered and visible in select box under mapper. You can use it later to kill map info, enable it, disable it or overwrite using [[#registerMapInfo|registerMapInfo()]] again.<br />
* ''function:''<br />
: Callback function that will be responsible for returning information how to draw map info fragment.<br />
<br />
Callback function is called with following arguments:<br />
* ''roomId'' - current roomId or currently selected room (when multiple selection is made this is center room)<br />
* ''selectionSize'' - how many rooms are selected<br />
* ''areaId'' - roomId's areaId<br />
* ''displayedAreaId'' - areaId that is currently displayed<br />
<br />
Callback needs to return following:<br />
* ''text'' - text that will be displayed (when empty, nothing will be displayed, if you want to "reserve" line or lines use not empty value " " or add line breaks "\n")<br />
* ''isBold'' (optional) - true/false - determines whether text will be bold <br />
* ''isItalic'' (optional) - true/false - determines whether text will be italic<br />
* ''color r'' (optional) - color of text red component (0-255)<br />
* ''color g'' (optional) - color of text green component (0-255)<br />
* ''color b'' (optional) - color of text blue component (0-255)<br />
<br />
{{note}}<br />
Map info is registered in disabled state, you need to enable it through script or by selecting checkbox under mapper.<br />
<br />
<syntaxhighlight lang="lua"><br />
registerMapInfo("My very own handler!", function(roomId, selectionSize, areaId, displayedArea) <br />
return string.format("RoomId: %d\nNumbers of room selected: %d\nAreaId: %d\nDisplaying area: %d", roomId, selectionSize, areaId, displayedArea),<br />
true, true, 0, 255, 0<br />
end)<br />
enableMapInfo("My very own handler!")<br />
</syntaxhighlight><br />
<br />
Example will display something like that:<br />
<br />
[[File:Map-info-example.png]]<br />
<br />
Using function arguments is completely optional and you can determine whether and how to display map info completely externally.<br />
<syntaxhighlight lang="lua"><br />
registerMapInfo("Alert", function() <br />
if character.hp < 20 then<br />
return "Look out! Your HP is getting low", true, false, unpack(color_table.red) -- will display red, bolded warning whne character.hp is below 20<br />
else<br />
return "" -- will not return anything<br />
end<br />
end)<br />
enableMapInfo("Alert")<br />
</syntaxhighlight><br />
<br />
{{note}}<br />
You can register multiple map infos - just give them unique names and toggle whichever ones you need.<br />
<br />
: See also: [[#killMapInfo|killMapInfo()]], [[#enableMapInfo|enableMapInfo()]], [[#disableMapInfo|disableMapInfo()]]<br />
<br />
{{MudletVersion|4.11}}<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 />
{{MudletVersion|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 />
==saveJsonMap==<br />
; saveJsonMap([pathFileName])<br />
Saves all the data that is normally held in the Mudlet map (''.dat'' as a binary format) in text (JSON) format. It does take longer to do this, so a progress dialog will be shown indicating the status. <br />
<br />
: See also: [[#loadJsonMap|loadJsonMap()]]<br />
{{MudletVersion|4.11.0}}<br />
<br />
; Parameters:<br />
* ''pathFileName'' (optional in Mudlet 4.12+): a string that is an absolute path and file name to save the data into.<br />
<br />
; Returns:<br />
* ''true'' on success<br />
* ''nil'' and an error message on failure.<br />
<br />
;Example<br />
<syntaxhighlight lang="lua"><br />
saveJsonMap(getMudetHomeDir() .. "/map.json")<br />
<br />
true<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 number | room name[, case-sensitive [, exact-match]])<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'', the optional second and third boolean parameters have been available since Mudlet 3.0;<br />
<br />
::If no rooms are found, then an empty table is returned.<br />
<br />
:If you pass it a '''number''' instead of a '''string''' as just one argument, it'll act like [[#getRoomName|getRoomName()]] and return the room name.<br />
<br />
;Examples<br />
<syntaxhighlight lang="lua"><br />
-- show the behavior when given a room number:<br />
display(searchRoom(3088))<br />
"The North Road South of Taren Ferry"<br />
<br />
-- show the behavior when given a string:<br />
-- shows all rooms containing the text in any case:<br />
display(searchRoom("North road"))<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 />
-- or:<br />
-- display(searchRoom("North road",false))<br />
-- display(searchRoom("North road",false,false))<br />
-- would both also produce those results.<br />
<br />
-- shows all rooms containing the text in ONLY the letter-case provided:<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 that text in either letter-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 and exactly the given text:<br />
lua searchRoom("North road",true,true)<br />
{<br />
[3115] = "North road",<br />
[3117] = "North road"<br />
}<br />
</syntaxhighlight><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". <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". <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. 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 />
;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 />
{{MudletVersion|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}} parameter 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 />
{{MudletVersion|3.0}}<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(101, "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 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 />
;Game-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 game 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 />
==setRoomCharColor==<br />
;setRoomCharColor(roomId, r, g, b)<br />
<br />
Sets color for room symbol.<br />
<br />
<syntaxhighlight lang="lua"><br />
setRoomCharColor(2402, 255, 0, 0)<br />
setRoomCharColor(2403, 0, 255, 0)<br />
setRoomCharColor(2404, 0, 0, 255)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11}}<br />
<br />
: See also: [[#unsetRoomCharColor|unsetRoomCharColor()]]<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 asa 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 />
==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 game 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 game 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 game 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 is available in Mudlet 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 />
;Example<br />
<syntaxhighlight lang="lua"><br />
unHighlightRoom(4534)<br />
</syntaxhighlight><br />
<br />
==unsetRoomCharColor==<br />
;unsetRoomCharColor(roomId)<br />
<br />
Removes char color setting from room, back to automatic determination based on room background lightness.<br />
<br />
<syntaxhighlight lang="lua"><br />
unsetRoomCharColor(2031)<br />
</syntaxhighlight><br />
<br />
{{MudletVersion|4.11}}<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>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:Trigger_Engine&diff=16561Manual:Trigger Engine2021-07-23T16:56:41Z<p>Dargoth: /* Named patterns */</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Manual on triggering on game output, highlighting matches, literal text or regex patterns, combining triggers, etc.}}<br />
=Trigger Engine=<br />
<br />
Unlike alias that define patterns that match on user input, triggers define patterns that match on game output. In other words, triggers react to text that has been sent by the game, 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 game. 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 game 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 game 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 game any time it sees the word "pond" somewhere in the game 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 game. 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 game.<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 game 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 gameclients. 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 />
==Named capturing groups in Perl regex triggers and tempRegexTrigger==<br />
<br />
Since Mudlet 4.11+ you can use named capturing groups in , so you can access your matches not only by numeric index of your capturing group but also under certain name. It is especially useful when you have multiple patterns with different ordering of capture groups.<br />
<br />
Let's assume we want to capture name and class of character, but MUD outputs it two ways.<br />
# <code>My name is Dargoth. My class is a warrior.</code><br />
# <code>I am a wizard and my name is Delwing.</code><br />
<br />
Instead of creating two different triggers we can create only one containing alternative matching patterns:<br />
<br />
# <code>^My name is (?<name>\w+)\. My class is a (?<class>\w+)\.</code><br />
# <code>^I am a (?<class>\w+)\ and my name is (?<name>\w+)\.</code><br />
<br />
Notice that class and name come in different order, therefore in first case we will have name under matches[2] and in second case under matches[3]. With named capture groups in both cases we will have name available under matches.name and class under matches.class.<br />
<br />
Code example to handle named matches above:<br />
<syntaxhighlight lang="lua"><br />
echo("Name: " .. matches.name .. "\n")<br />
echo("Class: " .. matches.class .. "\n")<br />
</syntaxhighlight><br />
<br />
To verify whether named groups are available you can use flag <code>mudlet.supports.namedGroups</code>.<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 game, 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 />
<br />
== Testing triggers ==<br />
<br />
You can test your triggers with the '''`echo''' alias from the command line:<br />
<br />
<code><br />
`echo A test line.<br />
<br />
`echo One line.$Next line.$Third line.<br />
</code><br />
<br />
Alternatively, you can also record a replay and play it - triggers will be matched on it.<br />
<br />
== Named patterns ==<br />
You can use named patterns - that is, giving your captures names instead of [2], [3], [4] numbers - by adding '''?<variablename>''' to your capture Mudlet 4.11+:<br />
<br />
<syntaxhighlight lang="lua><br />
-- before: <br />
(\w+) = matches[2]<br />
<br />
-- now:<br />
(?<name>\w+) = matches.name or matches["name"]<br />
(?<weapon>\w+) = matches.weapon or matches["weapon"]<br />
</syntaxhighlight><br />
<br />
This can be particularly handy if you have several patterns in a trigger and the location of matches[n] moves around. Try this out in [https://forums.mudlet.org/viewtopic.php?f=6&t=23040 a demo package].<br />
<br />
Named capture groups still will be available under their respective number in <code>matches</code>.<br />
<br />
You can programatically check if your Mudlet supports this feature with <code>mudlet.supports.namedPatterns</code>.<br />
<br />
<br />
[[Category:Mudlet Manual]]</div>Dargothhttps://wiki.mudlet.org/index.php?title=Manual:Trigger_Engine&diff=16560Manual:Trigger Engine2021-07-23T16:56:08Z<p>Dargoth: /* Named patterns */</p>
<hr />
<div>{{TOC right}}<br />
{{#description2:Manual on triggering on game output, highlighting matches, literal text or regex patterns, combining triggers, etc.}}<br />
=Trigger Engine=<br />
<br />
Unlike alias that define patterns that match on user input, triggers define patterns that match on game output. In other words, triggers react to text that has been sent by the game, 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 game. 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 game 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 game 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 game any time it sees the word "pond" somewhere in the game 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 game. 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 game.<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 game 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 gameclients. 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 />
==Named capturing groups in Perl regex triggers and tempRegexTrigger==<br />
<br />
Since Mudlet 4.11+ you can use named capturing groups in , so you can access your matches not only by numeric index of your capturing group but also under certain name. It is especially useful when you have multiple patterns with different ordering of capture groups.<br />
<br />
Let's assume we want to capture name and class of character, but MUD outputs it two ways.<br />
# <code>My name is Dargoth. My class is a warrior.</code><br />
# <code>I am a wizard and my name is Delwing.</code><br />
<br />
Instead of creating two different triggers we can create only one containing alternative matching patterns:<br />
<br />
# <code>^My name is (?<name>\w+)\. My class is a (?<class>\w+)\.</code><br />
# <code>^I am a (?<class>\w+)\ and my name is (?<name>\w+)\.</code><br />
<br />
Notice that class and name come in different order, therefore in first case we will have name under matches[2] and in second case under matches[3]. With named capture groups in both cases we will have name available under matches.name and class under matches.class.<br />
<br />
Code example to handle named matches above:<br />
<syntaxhighlight lang="lua"><br />
echo("Name: " .. matches.name .. "\n")<br />
echo("Class: " .. matches.class .. "\n")<br />
</syntaxhighlight><br />
<br />
To verify whether named groups are available you can use flag <code>mudlet.supports.namedGroups</code>.<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 game, 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 />
<br />
== Testing triggers ==<br />
<br />
You can test your triggers with the '''`echo''' alias from the command line:<br />
<br />
<code><br />
`echo A test line.<br />
<br />
`echo One line.$Next line.$Third line.<br />
</code><br />
<br />
Alternatively, you can also record a replay and play it - triggers will be matched on it.<br />
<br />
== Named patterns ==<br />
You can use named patterns - that is, giving your captures names instead of [2], [3], [4] numbers - by adding '''?<variablename>''' to your capture Mudlet 4.11+:<br />
Named capture groups still we be available under their respective number in <code>matches</code><br />
<br />
<syntaxhighlight lang="lua><br />
-- before: <br />
(\w+) = matches[2]<br />
<br />
-- now:<br />
(?<name>\w+) = matches.name or matches["name"]<br />
(?<weapon>\w+) = matches.weapon or matches["weapon"]<br />
</syntaxhighlight><br />
<br />
This can be particularly handy if you have several patterns in a trigger and the location of matches[n] moves around. Try this out in [https://forums.mudlet.org/viewtopic.php?f=6&t=23040 a demo package].<br />
<br />
You can programatically check if your Mudlet supports this feature with <code>mudlet.supports.namedPatterns</code>.<br />
<br />
<br />
[[Category:Mudlet Manual]]</div>Dargoth