Difference between revisions of "Manual:UI Functions"

From Mudlet
Jump to navigation Jump to search
(27 intermediate revisions by 4 users not shown)
Line 102: Line 102:
  
 
==calcFontSize==
 
==calcFontSize==
;calcFontSize(window_or_fontsize)
+
;calcFontSize(window_or_fontsize, [fontname])
: Used to calculate the number of pixels wide a 'W' character would be and the extreme top and bottom pixels that any character in the font would be for a given miniconsole and its font or a specific font size with the BitStream Vera Sans Mono font.
+
: 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.
 
: Returns two numbers, width/height
 
: Returns two numbers, width/height
: See Also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]
+
: See also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]]
  
 
;Parameters
 
;Parameters
 
* ''window_or_fontsize:''
 
* ''window_or_fontsize:''
 
: The miniconsole or font size you are wanting to calculate pixel sizes for.
 
: The miniconsole or font size you are wanting to calculate pixel sizes for.
 +
* ''fontname:''
 +
: Specific font name (along with the size as the first argument) to calculate for.
  
 
{{note}}
 
{{note}}
Window as an argument is supported since Mudlet 3.10.
+
Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.
  
 
;Example
 
;Example
Line 158: Line 160:
 
]])
 
]])
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
==cechoLink==
 
==cechoLink==
Line 163: Line 166:
 
: 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.
 
: 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.
  
: See also: [[#echoLink|cechoLink()]], [[#hechoLink|hechoLink()]]
+
: See also: [[#echoLink|echoLink()]], [[#dechoLink|dechoLink()]], [[#hechoLink|hechoLink()]]
  
 
;Parameters
 
;Parameters
Line 183: Line 186:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==cinsertText==
+
==cechoPopup==
;cinsertText([window], text)
+
;cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
: inserts text at the current cursor position, with the possibility for color tags.
+
: 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.
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]
 
  
;Parameters
+
; Parameters
* ''window:''
+
* ''windowName:''
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.
+
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.
 
* ''text:''
 
* ''text:''
: The text to display, with color names inside angle brackets <>, ie ''<red>''. If you'd like to use a background color, put it after a double colon : - ''<:red>''. You can use the ''<reset''> tag to reset to the default color. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]
+
: the text to display
 +
* ''{commands}:''
 +
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>
 +
* ''{hints}:''
 +
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>
 +
* ''useCurrentFormatElseDefault:''
 +
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")
+
-- Create some text as a clickable with a popup menu:
 +
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)
 +
</syntaxhighlight>
  
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")
+
{{note}} Available in Mudlet 4.1+
  
cinsertText("<blue:yellow>Blue on yellow text!")
+
==cinsertLink==
 +
;cinsertLink([windowName], text, command, hint, true)
 +
: 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.
  
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")
+
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]
</syntaxhighlight>
 
  
==clearUserWindow==
+
;Parameters
;clearUserWindow(name)
+
* ''windowName:''
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].
+
: optional parameter, allows selection between sending the link to a miniconsole or the main window.
 
+
* ''text:''
==clearWindow==
+
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#cecho|cecho()]].
;clearWindow([windowName])
+
* ''command:''
: Clears the label, mini console, or user window with the name given as argument (removes all text from it). If you don't give it a name, it will clear the main window (starting with Mudlet 2.0-test3+)
+
: lua code to do when the link is clicked.
 
+
* ''hint:''
;Parameters
+
: text for the tooltip to be displayed when the mouse is over the link.
* ''windowName:''
+
* ''true:''
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.
+
: requires argument for the colouring to work.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--This would clear a label, user window, or miniconsole with the name "Chat"
+
-- echo a link named 'press me!' that'll send the 'hi' command to the game
clearWindow("Chat")
+
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<syntaxhighlight lang="lua">
+
{{note}} Available in Mudlet 4.1+
-- this can clear your whole main window - needs Mudlet version >= 2.0
 
clearWindow()
 
</syntaxhighlight>
 
  
==copy==
+
==cinsertPopup==
; copy([windowName])
+
;cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
: Copies the current selection to the clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the clipboard until it gets overwritten by another copy operation.
+
: 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.
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]
 
  
 
; Parameters
 
; Parameters
* ''windowName'' (optional):
+
* ''windowName:''
: the window from which to copy text - use the main console if not specified.
+
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.
 +
* ''text:''
 +
: the text to display
 +
* ''{commands}:''
 +
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>
 +
* ''{hints}:''
 +
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>
 +
* ''useCurrentFormatElseDefault:''
 +
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- 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.
+
-- Create some text as a clickable with a popup menu:
selectString(line, 1)
+
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)
copy()
 
appendBuffer("chat")
 
replace("This line has been moved to the chat window!")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==createBuffer==
+
{{note}} Available in Mudlet 4.1+
;createBuffer(name)
 
: Creates a named buffer for formatted text, much like a miniconsole, but the buffer is not intended to be shown on the screen - use it for formatting text or storing formatted text.
 
  
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]
+
==cinsertText==
 +
;cinsertText([window], text)
 +
: inserts text at the current cursor position, with the possibility for color tags.
 +
: See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:UI Functions#creplaceLine|creplaceLine()]]
  
 
;Parameters
 
;Parameters
* ''name:''
+
* ''window:''
: The name of the buffer to create.
+
: Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.
 +
* ''text:''
 +
: The text to display, with color names inside angle brackets <>, ie ''<red>''. If you'd like to use a background color, put it after a double colon : - ''<:red>''. You can use the ''<reset''> tag to reset to the default color. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--This creates a named buffer called "scratchpad"
+
cinsertText("Hi! This text is <red>red, <blue>blue, <green> and green.")
createBuffer("scratchpad")
+
 
 +
cinsertText("<:green>Green background on normal foreground. Here we add an <ivory>ivory foreground.")
 +
 
 +
cinsertText("<blue:yellow>Blue on yellow text!")
 +
 
 +
cinsertText("myinfo", "<green>All of this text is green in the myinfo miniconsole.")
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==createButton==
+
==clearUserWindow==
A similar function to [[#createLabel|createLabel()]] that is old and outdated - use [[#createLabel|createLabel()]] instead.
+
;clearUserWindow(name)
 +
: This is (now) identical to [[Manual:Lua_Functions#clearWindow|clearWindow()]].
  
==createConsole==
+
==clearWindow==
;createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)
+
;clearWindow([windowName])
: 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.
+
: Clears the label, mini console, or user window with the name given as argument (removes all text from it). If you don't give it a name, it will clear the main window (starting with Mudlet 2.0-test3+)
  
 
;Parameters
 
;Parameters
* ''consoleName:''
+
* ''windowName:''
: The name of your new miniconsole. Passed as a string.
+
: (optional) The name of the label, mini console, or user window to clear. Passed as a string.
* ''fontSize:''
+
 
: The font size to use for the miniconsole. Passed as an integer number.
+
;Example
* ''charsPerLine:''
+
<syntaxhighlight lang="lua">
: How many characters wide to make the miniconsole. Passed as an integer number.
+
--This would clear a label, user window, or miniconsole with the name "Chat"
* ''numberOfLines:''
+
clearWindow("Chat")
: How many lines high to make the miniconsole. Passed as an integer number.
+
</syntaxhighlight>
* ''Xpos:''
 
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.
 
* ''Ypos:''
 
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.
 
  
;Example
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,
+
-- this can clear your whole main window - needs Mudlet version >= 2.0
-- 20 lines high, at coordinates 300x,400y
+
clearWindow()
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{note}}
+
==copy==
''(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.
+
; copy([windowName])
 +
: Copies the current selection to the clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the clipboard until it gets overwritten by another copy operation.
 +
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#paste|paste()]], [[#appendBuffer|appendBuffer()]], [[#replace|replace()]], [[#createMiniConsole|createMiniConsole()]], [[#openUserWindow|openUserWindow()]]
  
==createGauge==
+
; Parameters
;createGauge(name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)
+
* ''windowName'' (optional):
;createGauge(name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)
+
: the window from which to copy text - use the main console if not specified.
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.
 
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]
 
  
;Parameters
+
;Example
* ''name:''
+
<syntaxhighlight lang="lua">
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.
+
-- 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.
* ''width:''
+
selectString(line, 1)
: The width of the gauge, in pixels. Passed as an integer number.
+
copy()
* ''height:''
+
appendBuffer("chat")
: The height of the gauge, in pixels. Passed as an integer number.
+
replace("This line has been moved to the chat window!")
* ''Xpos:''
+
</syntaxhighlight>
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.
 
* ''Ypos:''
 
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.
 
* ''gaugeText:''
 
: Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil
 
* ''r:''
 
: The red component of the gauge color. Passed as an integer number from 0 to 255
 
* ''g:''
 
: The green component of the gauge color. Passed as an integer number from 0 to 255
 
* ''b:''
 
: The blue component of the gauge color. Passed as an integer number from 0 to 255
 
* ''colorName:''
 
: the name of color for the gauge. Passed as a string.
 
* ''orientation:''
 
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.
 
  
;Example
+
==createBuffer==
<syntaxhighlight lang="lua">
+
;createBuffer(name)
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.
+
: 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.
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().
 
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)
 
createGauge("healthBar", 300, 20, 30, 300, nil, "green")
 
  
 +
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]], [[#copy|copy()]], [[#paste|paste()]]
  
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:
+
;Parameters
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)
+
* ''name:''
-- or
+
: The name of the buffer to create.
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")
 
</syntaxhighlight>
 
  
{{note}}
+
;Example
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")
+
--This creates a named buffer called "scratchpad"
 +
createBuffer("scratchpad")
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==createLabel==
+
==createButton==
;createLabel(name, Xpos, Ypos, width, height, fillBackground)
+
A similar function to [[#createLabel|createLabel()]] that is old and outdated - use [[#createLabel|createLabel()]] instead.
: Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.
+
 
: Returns true or false.
+
==createConsole==
: 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()]]
+
;createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)
 +
: Makes a new miniconsole which can be sized based upon the width of a 'W' character and the extreme top and bottom positions any character of the font should use. The background will be black, and the text color white.
  
 
;Parameters
 
;Parameters
* ''name:''
+
* ''consoleName:''
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.
+
: The name of your new miniconsole. Passed as a string.
 +
* ''fontSize:''
 +
: The font size to use for the miniconsole. Passed as an integer number.
 +
* ''charsPerLine:''
 +
: How many characters wide to make the miniconsole. Passed as an integer number.
 +
* ''numberOfLines:''
 +
: How many lines high to make the miniconsole. Passed as an integer number.
 
* ''Xpos:''
 
* ''Xpos:''
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.
+
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.
 
* ''Ypos:''
 
* ''Ypos:''
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.
+
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.
* ''width:''
 
: The width of the label, in pixels. Passed as an integer number.
 
* ''height:''
 
: The height of the label, in pixels. Passed as an integer number.
 
* ''fillBackground:''
 
: Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.
 
  
 
;Example
 
;Example
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- a label situated at x=300 y-400 with dimensions 100x200
+
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide,
createLabel("a very basic label",300,400,100,200,1)
+
-- 20 lines high, at coordinates 300x,400y
 +
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<syntaxhighlight lang="lua">
+
{{note}}
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle
+
''(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.
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent
+
 
-- and 255 opaque) the background text can still be read through.
+
==createGauge==
local width, height = getMainWindowSize()
+
;createGauge(name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)
+
;createGauge(name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)
resizeWindow("messageBox",500,70)
+
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.
moveWindow("messageBox", (width/2)-300,(height/2)-100 )
+
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge()]], [[Manual:Lua_Functions#setGauge|setGauge()]], [[Manual:Lua_Functions#setGaugeText|setGaugeText()]], [[#setGaugeStyleSheet|setGaugeStyleSheet()]]
setBackgroundColor("messageBox", 255, 204, 0, 200)
 
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])
 
 
 
-- you can also make it react to clicks!
 
mynamespace = {
 
  messageBoxClicked = function()
 
    echo("hey you've clicked the box!\n")
 
  end
 
}
 
 
 
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")
 
  
 +
;Parameters
 +
* ''name:''
 +
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.
 +
* ''width:''
 +
: The width of the gauge, in pixels. Passed as an integer number.
 +
* ''height:''
 +
: The height of the gauge, in pixels. Passed as an integer number.
 +
* ''Xpos:''
 +
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.
 +
* ''Ypos:''
 +
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.
 +
* ''gaugeText:''
 +
: Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil
 +
* ''r:''
 +
: The red component of the gauge color. Passed as an integer number from 0 to 255
 +
* ''g:''
 +
: The green component of the gauge color. Passed as an integer number from 0 to 255
 +
* ''b:''
 +
: The blue component of the gauge color. Passed as an integer number from 0 to 255
 +
* ''colorName:''
 +
: the name of color for the gauge. Passed as a string.
 +
* ''orientation:''
 +
: the gauge orientation. Can be horizontal, vertical, goofy, or batty.
  
-- uncomment code below to make it also hide after a short while
+
;Example
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds
+
<syntaxhighlight lang="lua">
</syntaxhighlight>
+
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.
 +
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().
 +
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)
 +
createGauge("healthBar", 300, 20, 30, 300, nil, "green")
  
==createMiniConsole==
 
;createMiniConsole(name, x, y, width, height)
 
: Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc. Unlike labels, you cannot have transparency in them.
 
: You can use [[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#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]] functions.
 
  
 +
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:
 +
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)
 +
-- or
 +
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")
 +
</syntaxhighlight>
 +
 +
{{note}}
 +
If you want to put text on the back of the gauge when it's low, use an echo with the <gauge name>_back.
 +
<syntaxhighlight lang="lua">
 +
echo("healthBar_back", "This is a test of putting text on the back of the gauge!")
 +
</syntaxhighlight>
 +
 +
==createLabel==
 +
;createLabel(name, Xpos, Ypos, width, height, fillBackground)
 +
: Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.
 
: Returns true or false.
 
: Returns true or false.
 
+
: 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()]]
: 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#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap()]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize()]],  [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]],[[Manual:Lua_Functions#calcFontSize|calcFontSize()]]
 
  
 
;Parameters
 
;Parameters
 
 
* ''name:''
 
* ''name:''
: The name of the miniconsole. Must be unique. Passed as a string.
+
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.
* ''x'', ''y'', ''width'', ''height''
+
* ''Xpos:''
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createMiniConsole() will only set them once. Starting with 3.0, however, that is fine and calling createMiniConsole() will re-position your miniconsole appropriately.
+
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.
 +
* ''Ypos:''
 +
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.
 +
* ''width:''
 +
: The width of the label, in pixels. Passed as an integer number.
 +
* ''height:''
 +
: The height of the label, in pixels. Passed as an integer number.
 +
* ''fillBackground:''
 +
: Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.
  
 
;Example
 
;Example
==creplaceLine==
 
;creplaceLine (text)
 
: Replaces the output line from the MUD with a colour-tagged string.
 
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]
 
;Parameters
 
* ''text:''
 
*: The text to display, with color names inside angle brackets <>, ie ''<red>''. If you'd like to use a background color, put it after a colon : - ''<:red>''. You can use the ''<reset''> tag to reset to the default color. You can select any from this list: [[File:ShowColors.png|50px|frameless|Color Table]]
 
:
 
  
;Example
+
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)
+
-- a label situated at x=300 y-400 with dimensions 100x200
</syntaxhighlight>
+
createLabel("a very basic label",300,400,100,200,1)
 +
</syntaxhighlight>
 +
 
 +
<syntaxhighlight lang="lua">
 +
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle
 +
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent
 +
-- and 255 opaque) the background text can still be read through.
 +
local width, height = getMainWindowSize()
 +
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)
 +
resizeWindow("messageBox",500,70)
 +
moveWindow("messageBox", (width/2)-300,(height/2)-100 )
 +
setBackgroundColor("messageBox", 255, 204, 0, 200)
 +
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])
  
==decho==
+
-- you can also make it react to clicks!
;decho ([name of console,] text)
+
mynamespace = {
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB> where each field is a number from 0 to 255. The background portion can be omitted using <FR,FG,FB> or the foreground portion can be omitted using <:BR,BG,BB>. Arguments 2 and 3 set the default fore and background colors for the string using the same format as is used within the string, sans angle brackets, e.g. ''decho("<50,50,0:0,255,0>test")''.
+
  messageBoxClicked = function()
 +
    echo("hey you've clicked the box!\n")
 +
  end
 +
}
  
;Parameters
+
setLabelClickCallback("messageBox", "mynamespace.messageBoxClicked")
* ''name of console''
 
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.
 
* ''text:''
 
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.
 
  
;Example
 
<syntaxhighlight lang="lua">
 
decho("<50,50,0:0,255,0>test")
 
  
decho("miniconsolename", "<50,50,0:0,255,0>test")
+
-- uncomment code below to make it also hide after a short while
 +
-- tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==dechoLink==
+
==createMiniConsole==
;dechoLink([windowName], text, command, hint, true)
+
;createMiniConsole(name, x, y, width, height)
: 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.
+
: Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc. Unlike labels, you cannot have transparency in them.
 +
: You can use [[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.
 +
 
 +
: Returns true or false.
 +
 
 +
: 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()]]
  
 
;Parameters
 
;Parameters
* ''windowName:''
+
 
: (optional) allows selection between sending the link to a miniconsole or the "main" window.
+
* ''name:''
* ''text:''
+
: The name of the miniconsole. Must be unique. Passed as a string.
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].
+
* ''x'', ''y'', ''width'', ''height''
* ''command:''
+
: Parameters to set set the window size and location - in 2.1 and below it's best to set them via [[Manual:Lua_Functions#moveWindow|moveWindow()]] and [[Manual:Lua_Functions#resizeWindow|resizeWindow()]], as createMiniConsole() will only set them once. Starting with 3.0, however, that is fine and calling createMiniConsole() will re-position your miniconsole appropriately.
: lua code to do when the link is clicked.
 
* ''hint:''
 
: text for the tooltip to be displayed when the mouse is over the link.
 
* ''true:''
 
: requires argument for the colouring to work.
 
  
 
;Example
 
;Example
<syntaxhighlight lang="lua">
 
-- echo a link named 'press me!' that'll send the 'hi' command to the game
 
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)
 
</syntaxhighlight>
 
 
==deleteLine==
 
;deleteLine([windowName])
 
: Deletes the current line under the user cursor. This is a high speed gagging tool and is very good at this task, but is only meant to be use when a line should be omitted entirely in the output. If you echo() to that line it will not be shown, and lines deleted with deleteLine() are simply no longer rendered. This is purely visual - triggers will still fire on the line as expected.
 
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]
 
  
 +
==creplaceLine==
 +
;creplaceLine (text)
 +
: Replaces the output line from the MUD with a colour-tagged string.
 +
See Also: [[Manual:Lua_Functions#cecho|cecho()]], [[Manual:Lua_Functions#cinsertText|cinsertText()]]
 
;Parameters
 
;Parameters
* ''windowName:''
+
* ''text:''
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.
+
*: 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]]
 
+
:
{{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.
 
  
 
;Example
 
;Example
<syntaxhighlight lang="lua">
+
<syntaxhighlight lang="lua">creplaceLine("<magenta>[ALERT!]: <reset>"..line)
-- deletes the line - just put this command into the big script box. Keep the case the same -
+
</syntaxhighlight>
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else
 
deleteLine()
 
  
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.
+
==decho==
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window
+
;decho ([name of console,] text)
--Note: isPrompt() only works on servers which send a GA signal with their prompt.
+
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB> where each field is a number from 0 to 255. The background portion can be omitted using <FR,FG,FB> or the foreground portion can be omitted using <:BR,BG,BB>. Arguments 2 and 3 set the default fore and background colors for the string using the same format as is used within the string, sans angle brackets, e.g. ''decho("<50,50,0:0,255,0>test")''.
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])
 
 
 
-- example of deleting multiple lines:
 
deleteLine()                            -- delete the current line
 
moveCursor(0,getLineNumber()-1)        -- move the cursor back one line
 
deleteLine()                            -- delete the previous line now
 
</syntaxhighlight>
 
 
 
==deselect==
 
;deselect([window name])
 
: This is used to clear the current selection (to no longer have anything selected). Should be used after changing the formatting of text, to keep from accidentally changing the text again later with another formatting call.
 
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]
 
  
 
;Parameters
 
;Parameters
* ''window name:''
+
* ''name of console''
: (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.
+
: (Optional) Name of the console to echo to. If no name is given, this will defaults to the main window.
 +
* ''text:''
 +
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further
+
decho("<50,50,0:0,255,0>test")
--changes from effecting this line as well.
 
selectCurrentLine()
 
bg("red")
 
deselect()
 
</syntaxhighlight>
 
  
==disableClickthrough==
+
decho("miniconsolename", "<50,50,0:0,255,0>test")
; disableClickthrough(label)
+
</syntaxhighlight>
: 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.
 
: See also: [[#enableClickthrough|enableClickthrough()]]
 
  
;Parameters
+
==dechoLink==
* ''label:''
+
;dechoLink([windowName], text, command, hint, true)
: Name of the label to restore clickability on.
+
: 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.
 
 
{{note}}
 
Available since Mudlet 3.17
 
 
 
==disableScrollBar==
 
; disableScrollBar(windowName)
 
: Disables the scroll bar for the miniConsole named ''windowName''
 
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]
 
  
 
;Parameters
 
;Parameters
 
* ''windowName:''
 
* ''windowName:''
: The name of the window to disable the scroll bar in.
+
: (optional) allows selection between sending the link to a miniconsole or the "main" window.
 +
* ''text:''
 +
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].
 +
* ''command:''
 +
: lua code to do when the link is clicked.
 +
* ''hint:''
 +
: text for the tooltip to be displayed when the mouse is over the link.
 +
* ''true:''
 +
: requires argument for the colouring to work.
  
==echoLink==
+
;Example
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])
 
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].
 
 
 
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]
 
 
 
;Parameters
 
* ''windowName:''
 
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
 
* ''text:''
 
: Text to display in the echo. Same as a normal echo().
 
* ''command:''
 
: Lua code to do when the link is clicked.
 
* ''hint:''
 
: Text for the tooltip to be displayed when the mouse is over the link.
 
* ''useCurrentFormatElseDefault:''
 
: If true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.
 
 
 
;Example
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
-- echo a link named 'press me!' that'll send the 'hi' command to the game
 
-- echo a link named 'press me!' that'll send the 'hi' command to the game
echoLink("press me!", [[send("hi")]], "This is a tooltip")
+
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)
 
 
-- do the same, but send this link to a miniConsole
 
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==echoUserWindow==
+
==dechoPopup==
;echoUserWindow(windowName)
+
;dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.
+
: 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.
 
 
==echoPopup==
 
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
 
: Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like echo. The added text, upon being left-clicked, will do the first command in the list. Upon being right-clicked, it'll display a menu with all possible commands. The menu will be populated with hints, one for each line.
 
  
 
; Parameters
 
; Parameters
Line 581: Line 561:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
-- Create some text as a clickable with a popup menu:
 
-- Create some text as a clickable with a popup menu:
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})
+
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==enableClickthrough==
+
{{note}} Available in Mudlet 4.1+
; enableClickthrough(label)
 
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.
 
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.
 
: See also: [[#disableClickthrough|disableClickthrough()]]
 
 
 
;Parameters
 
* ''label:''
 
: The name of the label to enable clickthrough on.
 
  
{{note}}
+
==dinsertLink==
Available since Mudlet 3.17
+
;dinsertLink([windowName], text, command, hint, true)
 +
: 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.
  
==enableScrollBar==
+
: See also: [[#insertLink|insertLink()]], [[#hinsertLink|hinsertLink()]]
; enableScrollBar(windowName)
 
: Enables the scrollbar for the miniConsole named ''windowName''.
 
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]
 
  
 
;Parameters
 
;Parameters
 
* ''windowName:''
 
* ''windowName:''
: The name of the window to enable the scroll bar in.
+
: optional parameter, allows selection between sending the link to a miniconsole or the main window.
 +
* ''text:''
 +
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#decho|decho()]].
 +
* ''command:''
 +
: lua code to do when the link is clicked.
 +
* ''hint:''
 +
: text for the tooltip to be displayed when the mouse is over the link.
 +
* ''true:''
 +
: requires argument for the colouring to work.
  
==fg==
+
;Example
; fg([window], colorName)
+
<syntaxhighlight lang="lua">
: 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)
+
-- echo a link named 'press me!' that'll send the 'hi' command to the game
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]
+
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)
 +
</syntaxhighlight>
 +
 
 +
{{note}} Available in Mudlet 4.1+
 +
 
 +
==dinsertPopup==
 +
;dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
 +
: 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.
  
;Parameters
+
; Parameters
* ''window:''
+
* ''windowName:''
: (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).
+
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.
* ''colorName:''
+
* ''text:''
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]
+
: the text to display
 +
* ''{commands}:''
 +
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>
 +
* ''{hints}:''
 +
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>
 +
* ''useCurrentFormatElseDefault:''
 +
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--This would change the color of the text on the current line to green
+
-- Create some text as a clickable with a popup menu:
selectCurrentLine()
+
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)
fg("green")
+
</syntaxhighlight>
resetFormat()
+
 
 +
{{note}} Available in Mudlet 4.1+
  
--This will echo red, green, blue in their respective colors
+
==deleteLine==
fg("red")
+
;deleteLine([windowName])
echo("red ")
+
: 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.
fg("green")
+
: See also: [[Manual:Lua_Functions#replace|replace()]], [[Manual:Lua_Functions#wrapLine|wrapLine()]]
echo("green ")
 
fg("blue")
 
echo("blue ")
 
resetFormat()
 
  
-- example of working on a miniconsole
+
;Parameters
fg("my console", "red")
+
* ''windowName:''
echo("my console", "red text")
+
: (optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.
</syntaxhighlight>
 
  
==getAvailableFonts==
+
{{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.
; fonts = getAvailableFonts()
 
: 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.
 
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.
 
 
 
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]
 
 
 
{{note}}
 
Available since Mudlet 3.10
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- check if Ubuntu Mono is a font we can use
+
-- deletes the line - just put this command into the big script box. Keep the case the same -
if getAvailableFonts()["Ubuntu Mono"] then
+
-- it has to be deleteLine(), not Deleteline(), deleteline() or anything else
  -- make the miniconsole use the font at size 16
+
deleteLine()
  setFont("my miniconsole", "Ubuntu Mono")
+
 
  setFontSize("my miniconsole", 16)
+
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.
end
+
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window
 +
--Note: isPrompt() only works on servers which send a GA signal with their prompt.
 +
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])
 +
 
 +
-- example of deleting multiple lines:
 +
deleteLine()                            -- delete the current line
 +
moveCursor(0,getLineNumber()-1)         -- move the cursor back one line
 +
deleteLine()                           -- delete the previous line now
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getBgColor==
+
==deselect==
; r, g, b = getBgColor(windowName)
+
;deselect([window name])
: 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.
+
: 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.
 
+
: See also: [[#selectString|selectString()]], [[#selectCurrentLine|selectCurrentLine()]]
: See also: [[#setBgColor|setBgColor()]]
 
  
 
;Parameters
 
;Parameters
* ''windowName:''
+
* ''window name:''
: A window to operate on - either a miniconsole or the main window.
+
: (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.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
local r,g,b;
+
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further
selectString("troll",1)
+
--changes from effecting this line as well.
r,g,b = getBgColor()
+
selectCurrentLine()
if r == 255 and g == 0 and b == 0 then
+
bg("red")
    echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");
+
deselect()
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getColorWildcard==
+
==disableClickthrough==
; AnsiNumber = getColorWildcard(ansi color number)
+
; disableClickthrough(label)
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.
+
: 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.
 
+
: See also: [[#enableClickthrough|enableClickthrough()]]
: See also: [[#isAnsiFgColor|isAnsiFgColor()]],  [[#isAnsiBgColor|isAnsiBgColor()]]
 
  
 
;Parameters
 
;Parameters
* ''ansi color number:''
+
* ''label:''
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.
+
: Name of the label to restore clickability on.
  
;Example
+
{{note}}
<syntaxhighlight lang="lua">
+
Available since Mudlet 3.17
-- we can run this script on a line that has the players name coloured differently to easily capture it from
 
-- anywhere on the line
 
local match = getColorWildcard(14)
 
  
if match then
+
==disableScrollBar==
  echo("\nFound "..match.."!")
+
; disableScrollBar(windowName)
else
+
: Disables the scroll bar for the miniConsole named ''windowName''
  echo("\nDidn't find anyone.")
+
: See Also: [[Manual:Lua_Functions#enableScrollBar|enableScrollBar()]]
end
 
</syntaxhighlight>
 
  
==getColumnCount==
+
;Parameters
;columns = getColumnCount([windowName])
+
* ''windowName:''
: 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.
+
: The name of the window to disable the scroll bar in.
  
;Parameters:
+
==echoLink==
* ''windowName'':
+
;echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.
+
: Echos a piece of text as a clickable link, at the end of the current selected line - similar to [[Manual:Lua_Functions#echo|echo()]].
  
{{note}}
+
: See also: [[#cechoLink|cechoLink()]], [[#hechoLink|hechoLink()]]
Available since Mudlet 3.7.0
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
print("Maximum number of columns on the main window "..getColumnCount())
 
</syntaxhighlight>
 
 
 
==getColumnNumber==
 
;column = getColumnNumber([windowName])
 
: Gets the absolute column number of the current user cursor.
 
  
 
;Parameters
 
;Parameters
 
* ''windowName:''
 
* ''windowName:''
 
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
 
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
 
+
* ''text:''
{{note}} the argument is available since Mudlet 3.0.
+
: Text to display in the echo. Same as a normal echo().
 +
* ''command:''
 +
: Lua code to do when the link is clicked.
 +
* ''hint:''
 +
: Text for the tooltip to be displayed when the mouse is over the link.
 +
* ''useCurrentFormatElseDefault:''
 +
: If true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
HelloWorld = Geyser.MiniConsole:new({
+
-- echo a link named 'press me!' that'll send the 'hi' command to the game
  name="HelloWorld",
+
echoLink("press me!", [[send("hi")]], "This is a tooltip")
  x="70%", y="50%",
 
  width="30%", height="50%",
 
})
 
  
HelloWorld:echo("hello!\n")
+
-- do the same, but send this link to a miniConsole
HelloWorld:echo("hello!\n")
+
echoLink("my miniConsole", "press me!", [[send("hi")]], "This is a tooltip")
HelloWorld:echo("hello!\n")
+
</syntaxhighlight>
  
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))
+
==echoUserWindow==
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line
+
;echoUserWindow(windowName)
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))
+
:This function will print text to both mini console windows, dock windows and labels. It is outdated however - [[#echo|echo()]] instead.
  
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))
+
==echoPopup==
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line
+
;echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))
+
: 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.
</syntaxhighlight>
 
  
==getCurrentLine==
+
; Parameters
;content = getCurrentLine()
+
* ''windowName:''
: 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.
+
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.
 +
* ''text:''
 +
: the text to display
 +
* ''{commands}:''
 +
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>
 +
* ''{hints}:''
 +
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>
 +
* ''useCurrentFormatElseDefault:''
 +
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
print("Currently selected line: "..getCurrentLine())
+
-- Create some text as a clickable with a popup menu:
 +
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getFgColor==
+
==enableClickthrough==
; r, g, b = getFgColor(windowName)
+
; enableClickthrough(label)
: 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.
+
: Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.
 +
: This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.
 +
: See also: [[#disableClickthrough|disableClickthrough()]]
  
 
;Parameters
 
;Parameters
* ''windowName:''
+
* ''label:''
: A window to operate on - either a miniconsole or the main window.
+
: The name of the label to enable clickthrough on.
  
;Example
+
{{note}}
<syntaxhighlight lang="lua">
+
Available since Mudlet 3.17
selectString("troll",1)
 
local r,g,b = getFgColor()
 
if r == 255 and g == 0 and b == 0 then
 
  echo("HELP! troll is written in red letters, the monster is aggressive!\n");
 
end
 
</syntaxhighlight>
 
  
==getFont==
+
==enableScrollBar==
;font = getFont(windowName)
+
; enableScrollBar(windowName)
: 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.
+
: Enables the scrollbar for the miniConsole named ''windowName''.
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]
+
: See Also: [[Manual:Lua_Functions#disableScrollBar|disableScrollBar()]]
  
 
;Parameters
 
;Parameters
 
* ''windowName:''
 
* ''windowName:''
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.
+
: The name of the window to enable the scroll bar in.
  
{{note}}
+
==fg==
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].
+
; fg([window], colorName)
 +
: If used on a selection, sets the foreground color to ''colorName'' - otherwise, it will set the color of the next text-inserting calls (''echo(), insertText, echoLink()'', and others)
 +
: See Also: [[Manual:Lua_Functions#bg|bg()]], [[Manual:Lua_Functions#setBgColor|setBgColor()]]
  
;Example
+
;Parameters
 +
* ''window:''
 +
: (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).
 +
* ''colorName:''
 +
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]
 +
 
 +
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- The following will get the "main" console font size.
+
--This would change the color of the text on the current line to green
display("Font in the main window: "..getFont())
+
selectCurrentLine()
 +
fg("green")
 +
resetFormat()
  
display("Font in the main window: "..getFont("main"))
+
--This will echo red, green, blue in their respective colors
 +
fg("red")
 +
echo("red ")
 +
fg("green")
 +
echo("green ")
 +
fg("blue")
 +
echo("blue ")
 +
resetFormat()
  
-- This will get the font size of a user window named "user window awesome".
+
-- example of working on a miniconsole
display("Font size: " .. getFont("user window awesome"))
+
fg("my console", "red")
 +
echo("my console", "red text")
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getFontSize==
+
==getAvailableFonts==
;size = getFontSize(windowName)
+
; fonts = getAvailableFonts()
: 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.
+
: 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.
: See Also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]
+
: To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.
  
;Parameters
+
: See also: [[#getFont|getFont()]], [[#setFont|setFont()]]
* ''windowName:''
 
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.
 
  
 
{{note}}
 
{{note}}
Available in Mudlet 3.4+
+
Available since Mudlet 3.10
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- The following will get the "main" console font size.
+
-- check if Ubuntu Mono is a font we can use
local mainWindowFontSize = getFontSize()
+
if getAvailableFonts()["Ubuntu Mono"] then
if mainWindowFontSize then
+
  -- make the miniconsole use the font at size 16
    display("Font size: " .. mainWindowFontSize)
+
  setFont("my miniconsole", "Ubuntu Mono")
 +
  setFontSize("my miniconsole", 16)
 
end
 
end
 +
</syntaxhighlight>
  
local mainWindowFontSize = getFontSize("main")
+
==getBgColor==
if mainWindowFontSize then
+
; r, g, b = getBgColor(windowName)
    display("Font size: " .. fs2)
+
: 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.
end
 
  
-- This will get the font size of a user window named "user window awesome".
+
: See also: [[#setBgColor|setBgColor()]]
local awesomeWindowFontSize = getFontSize("user window awesome")
 
if awesomeWindowFontSize then
 
    display("Font size: " .. awesomeWindowFontSize)
 
end
 
</syntaxhighlight>
 
 
 
==getLastLineNumber==
 
;line = getLastLineNumber(windowName)
 
: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.
 
  
 
;Parameters
 
;Parameters
 
* ''windowName:''
 
* ''windowName:''
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.
+
: A window to operate on - either a miniconsole or the main window.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- get the latest line's # in the buffer
+
local r,g,b;
local latestline = getLastLineNumber("main")
+
selectString("troll",1)
 +
r,g,b = getBgColor()
 +
if r == 255 and g == 0 and b == 0 then
 +
    echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getLineCount==
+
==getBorderBottom==
;amount = getLineCount()
+
;getBorderBottom()
:Gets the absolute amount of lines in the current console buffer
+
: Returns the size of the bottom border of the main window in pixels.
 +
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]]
  
; Parameters
+
: {{note}} Available since Mudlet 4.0
:None
 
  
 
;Example
 
;Example
''Need example''
+
<syntaxhighlight lang="lua">
 +
setBorderBottom(150)
 +
getBorderBottom()
 +
-- returns: 150
 +
</syntaxhighlight>
  
==getLines==
+
==getBorderLeft==
;contents = getLines([windowName,] from_line_number, to_line_number)
+
;getBorderLeft()
: 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}''.
+
: Returns the size of the left border of the main window in pixels.  
 +
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]]
  
:Absolute line numbers are used.
+
: {{note}} Available since Mudlet 4.0
  
;Parameters
+
;Example
* ''windowName''
+
<syntaxhighlight lang="lua">
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)
+
setBorderLeft(5)
* ''from_line_number:''
+
getBorderLeft()
: First line number
+
-- returns: 5
* ''to_line_number:''
+
</syntaxhighlight>
: End line number
+
 
 +
==getBorderRight==
 +
;getBorderRight()
 +
: Returns the size of the right border of the main window in pixels.  
 +
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]
 +
 
 +
: {{note}} Available since Mudlet 4.0
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- retrieve & echo the last line:
+
setBorderRight(50)
echo(getLines(getLineNumber()-1, getLineNumber())[1])
+
getBorderRight()
 +
-- returns: 50
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
==getBorderSizes==
 +
;getBorderSizes()
 +
: Returns the a named table with the sizes of all borders of the main window in pixels.
 +
: 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()]]
 +
 +
: {{note}} Available since Mudlet 4.0
 +
 +
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- find out which server and port you are connected to (as per Mudlet settings dialog):
+
setBorderSizes(100, 50, 150, 0)
local t = getLines(0, getLineNumber())
+
getBorderSizes()
 +
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }
 +
getBorderSizes().right
 +
-- returns: 50
 +
</syntaxhighlight>
  
local server, port
+
==getBorderTop==
 +
;getBorderTop()
 +
: Returns the size of the top border of the main window in pixels.
 +
: See also: [[Manual:Lua_Functions#getBorderSizes|getBorderSizes()]], [[Manual:Lua_Functions#setBorderTop|setBorderTop()]]
  
for i = 1, #t do
+
: {{note}} Available since Mudlet 4.0
  local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")
 
  if s then server, port = s, p break end
 
end
 
  
display(server)
+
;Example
display(port)
+
<syntaxhighlight lang="lua">
 +
setBorderTop(100)
 +
getBorderTop()
 +
-- returns: 100
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getLineNumber==
+
==getColorWildcard==
;line = getLineNumber([windowName])
+
; AnsiNumber = getColorWildcard(ansi color number)
: 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()]].
+
: This function, given an ANSI color number ([[Manual:UI_Functions#isAnsiFgColor|list]]), will return all strings on the current line that match it.
 
+
 
 +
: See also: [[#isAnsiFgColor|isAnsiFgColor()]][[#isAnsiBgColor|isAnsiBgColor()]]
 +
 
 
;Parameters
 
;Parameters
* ''windowName:''
+
* ''ansi color number:''
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.
+
: A color number ([[Manual:UI_Functions#isAnsiFgColor|list]]) to match.
 
 
{{note}}
 
The argument is available since Mudlet 3.0.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word
+
-- we can run this script on a line that has the players name coloured differently to easily capture it from
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end
+
-- anywhere on the line
 +
local match = getColorWildcard(14)
  
-- check how many lines you've got in your miniconsole after echoing some text.
+
if match then
-- Note the use of moveCursorEnd() to update getLineNumber()'s output
+
  echo("\nFound "..match.."!")
HelloWorld = Geyser.MiniConsole:new({
+
else
  name="HelloWorld",
+
   echo("\nDidn't find anyone.")
   x="70%", y="50%",
+
end
  width="30%", height="50%",
+
</syntaxhighlight>
})
 
  
print(getLineNumber("HelloWorld"))
+
==getColumnCount==
 +
;columns = getColumnCount([windowName])
 +
: 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.
 +
 
 +
;Parameters:
 +
* ''windowName'':
 +
: (optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.
  
HelloWorld:echo("hello!\n")
+
{{note}}
HelloWorld:echo("hello!\n")
+
Available since Mudlet 3.7.0
HelloWorld:echo("hello!\n")
 
  
-- update the cursors position, as it seems to be necessary to do
+
;Example
moveCursorEnd("HelloWorld")
+
<syntaxhighlight lang="lua">
print(getLineNumber("HelloWorld"))
+
print("Maximum number of columns on the main window "..getColumnCount())
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getMainConsoleWidth==
+
==getColumnNumber==
;width = getMainConsoleWidth()
+
;column = getColumnNumber([windowName])
: Returns a single number; the width of the main console (MUD output) in pixels.
+
: Gets the absolute column number of the current user cursor.
 +
 
 +
;Parameters
 +
* ''windowName:''
 +
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
  
; Parameters
+
{{note}} the argument is available since Mudlet 3.0.
:None
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- Save width of the main console to a variable for future use.
+
HelloWorld = Geyser.MiniConsole:new({
consoleWidth = getMainConsoleWidth()
+
  name="HelloWorld",
</syntaxhighlight>
+
  x="70%", y="50%",
 +
  width="30%", height="50%",
 +
})
 +
 
 +
HelloWorld:echo("hello!\n")
 +
HelloWorld:echo("hello!\n")
 +
HelloWorld:echo("hello!\n")
  
==getMousePosition==
+
moveCursor("HelloWorld", 3, getLastLineNumber("HelloWorld"))
;x, y = getMousePosition()
+
-- should say 3, because we moved the cursor in the HellWorld window to the 3rd position in the line
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.
+
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))
  
; Parameters
+
moveCursor("HelloWorld", 1, getLastLineNumber("HelloWorld"))
:None
+
-- should say 3, because we moved the cursor in the HellWorld window to the 1st position in the line
 +
print("getColumnNumber: "..tostring(getColumnNumber("HelloWorld")))
 +
</syntaxhighlight>
  
{{note}} Available since Mudlet 3.1+
+
==getCurrentLine==
 +
;content = getCurrentLine()
 +
: Returns the content of the current line under the user cursor in the buffer. The Lua variable '''line''' holds the content of ''getCurrentLine()'' before any triggers have been run on this line. When triggers change the content of the buffer, the variable line will not be adjusted and thus hold an outdated string. ''line = getCurrentLine()'' will update line to the real content of the current buffer. This is important if you want to copy the current line after it has been changed by some triggers. ''selectString( line,1 )'' will return false and won't select anything because line no longer equals ''getCurrentLine()''. Consequently, ''selectString( getCurrentLine(), 1 )'' is what you need.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- Retrieve x and y position of the mouse to determine where to create a new label, then use that position to create a new label
+
print("Currently selected line: "..getCurrentLine())
local x, y = getMousePosition()
+
</syntaxhighlight>
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)
 
-- if the label already exists, just move it
 
moveWindow("clickGeneratedLabel", x, y)
 
-- and make it easier to notice
 
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)
 
</syntaxhighlight>
 
  
==getMainWindowSize==
+
==getFgColor==
;width, height = getMainWindowSize()
+
; r, g, b = getFgColor(windowName)
: 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.
+
: 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.
: See Also: [[Manual:Lua_Functions#setMainWindowSize|setMainWindowSize()]]
 
  
; Parameters
+
;Parameters
:None
+
* ''windowName:''
 +
: A window to operate on - either a miniconsole or the main window.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--this will get the size of your main mudlet window and save them
+
selectString("troll",1)
--into the variables mainHeight and mainWidth
+
local r,g,b = getFgColor()
mainWidth, mainHeight = getMainWindowSize()
+
if r == 255 and g == 0 and b == 0 then
 +
  echo("HELP! troll is written in red letters, the monster is aggressive!\n");
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getRowCount==
+
==getFont==
;rows = getRowCount([windowName])
+
;font = getFont(windowName)
: 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.
+
: 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.
 +
: See also: [[#setFont|setFont()]], [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]], [[#getAvailableFonts|getAvailableFonts()]]
  
;Parameters:
+
;Parameters
* ''windowName'':
+
* ''windowName:''
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.
+
: The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.
  
 
{{note}}
 
{{note}}
Available since Mudlet 3.7.0
+
Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using [[#setFont|setFont()]].
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
print("Maximum of rows on the main window "..getRowCount())
+
-- The following will get the "main" console font size.
 +
display("Font in the main window: "..getFont())
 +
 
 +
display("Font in the main window: "..getFont("main"))
 +
 
 +
-- This will get the font size of a user window named "user window awesome".
 +
display("Font size: " .. getFont("user window awesome"))
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getSelection==
+
==getFontSize==
;text, start, length = getSelection([windowName])
+
;size = getFontSize(windowName)
: 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.
+
: 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.
 +
: See Also: [[#setFontSize|setFontSize()]], [[#openUserWindow|openUserWindow()]]
  
;Parameters:
+
;Parameters
* ''windowName'':
+
* ''windowName:''
: (optional) name of the window to get the selection from. By default it operates on the main window.
+
: The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.
  
 
{{note}}
 
{{note}}
Available since Mudlet 3.16.0
+
Available in Mudlet 3.4+
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
selectCurrentLine()
+
-- The following will get the "main" console font size.
print("Current selection is: "..getSelection())
+
local mainWindowFontSize = getFontSize()
 +
if mainWindowFontSize then
 +
    display("Font size: " .. mainWindowFontSize)
 +
end
 +
 
 +
local mainWindowFontSize = getFontSize("main")
 +
if mainWindowFontSize then
 +
    display("Font size: " .. fs2)
 +
end
 +
 
 +
-- This will get the font size of a user window named "user window awesome".
 +
local awesomeWindowFontSize = getFontSize("user window awesome")
 +
if awesomeWindowFontSize then
 +
    display("Font size: " .. awesomeWindowFontSize)
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getStopWatchTime==
+
==getLastLineNumber==
;time = getStopWatchTime(watchID)
+
;line = getLastLineNumber(windowName)
: Returns the time (milliseconds based) in form of 0.058 (= clock ran for 58 milliseconds before it was stopped). Please note that after the stopwatch is stopped, retrieving the time will not work - it's only valid while it is running.
+
: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.
: See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]
 
 
 
:Returns a number
 
  
 
;Parameters
 
;Parameters
* ''watchID''
+
* ''windowName:''
: The ID number of the watch.
+
: name of the window to use. Either use ''main'' for the main window, or the name of the miniconsole.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- an example of showing the time left on the stopwatch
+
-- get the latest line's # in the buffer
teststopwatch = teststopwatch or createStopWatch()
+
local latestline = getLastLineNumber("main")
startStopWatch(teststopwatch)
 
echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))
 
tempTimer(1, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])
 
tempTimer(2, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])
 
stopStopWatch(teststopwatch)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getTextFormat==
+
==getLineCount==
;getTextFormat([windowName])
+
;amount = getLineCount()
: 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.
+
:Gets the absolute amount of lines in the current console buffer
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]
+
 
 +
; Parameters
 +
:None
 +
 
 +
;Example
 +
''Need example''
 +
 
 +
==getLines==
 +
;contents = getLines([windowName,] from_line_number, to_line_number)
 +
: Returns a section of the content of the screen text buffer. Returns a Lua table with the content of the lines on a per line basis. The form value is ''result = {relative_linenumber = line}''.
 +
 
 +
:Absolute line numbers are used.
  
 
;Parameters
 
;Parameters
 
* ''windowName''
 
* ''windowName''
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.
+
: (optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)
 +
* ''from_line_number:''
 +
: First line number
 +
* ''to_line_number:''
 +
: End line number
  
{{note}} Available since Mudlet 3.20.
+
;Example
 
 
;Example:
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- A suitable test for getTextFormat()
+
-- retrieve & echo the last line:
-- (copy it into an alias or a script)
+
echo(getLines(getLineNumber()-1, getLineNumber())[1])
 +
</syntaxhighlight>
  
clearWindow()
+
<syntaxhighlight lang="lua">
 +
-- find out which server and port you are connected to (as per Mudlet settings dialog):
 +
local t = getLines(0, getLineNumber())
  
echo("\n")
+
local server, port
  
local SGR = string.char(27)..'['
+
for i = 1, #t do
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")
+
  local s, p = t[i]:match("looking up the IP address of server:(.-):(%d+)")
 +
  if s then server, port = s, p break end
 +
end
  
moveCursor(1,1)
+
display(server)
selectSection(1,1)
+
display(port)
 +
</syntaxhighlight>
  
local results = getTextFormat()
+
==getLineNumber==
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))
+
;line = getLineNumber([windowName])
echo("\nItalic detected: " .. tostring(results["italic"]))
+
: 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()]].
echo("\nUnderline detected: " .. tostring(results["underline"]))
 
echo("\nReverse detected: " .. tostring(results["reverse"]))
 
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))
 
echo("\nOverline detected: " .. tostring(results["overline"]))
 
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")
 
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")
 
  
selectSection(21,1)
+
;Parameters
echo("\n\nFor individual parts of test text:")
+
* ''windowName:''
echo("\nBold detected (character 21): " .. tostring(results["bold"]))
+
: (optional) name of the miniconsole to operate on. If you'd like it to work on the main window, don't specify anything.
  
selectSection(28,1)
+
{{note}}
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))
+
The argument is available since Mudlet 3.0.
  
selectSection(37,1)
+
;Example
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))
+
<syntaxhighlight lang="lua">
 +
-- use getLines() in conjuction with getLineNumber() to check if the previous line has a certain word
 +
if getLines(getLineNumber()-1, getLineNumber())[1]:find("attacks") then echo("previous line had the word 'attacks' in it!\n") end
  
selectSection(67,1)
+
-- check how many lines you've got in your miniconsole after echoing some text.
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))
+
-- Note the use of moveCursorEnd() to update getLineNumber()'s output
 +
HelloWorld = Geyser.MiniConsole:new({
 +
  name="HelloWorld",
 +
  x="70%", y="50%",
 +
  width="30%", height="50%",
 +
})
  
selectSection(77,1)
+
print(getLineNumber("HelloWorld"))
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))
 
  
selectSection(89,1)
+
HelloWorld:echo("hello!\n")
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))
+
HelloWorld:echo("hello!\n")
echo("\n")
+
HelloWorld:echo("hello!\n")
 +
 
 +
-- update the cursors position, as it seems to be necessary to do
 +
moveCursorEnd("HelloWorld")
 +
print(getLineNumber("HelloWorld"))
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==handleWindowResizeEvent==
+
==getMainConsoleWidth==
;handleWindowResizeEvent()
+
;width = getMainConsoleWidth()
: (''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.
+
: Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.
  
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.
+
: See also: [[#getMainWindowSize|getMainWindowSize()]]
  
 
; Parameters
 
; Parameters
 
:None
 
:None
  
; Example
+
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
function handleWindowResizeEvent()
+
-- Save width of the main console to a variable for future use.
  -- determine the size of your screen
+
consoleWidth = getMainConsoleWidth()
  WindowWidth=0;
 
  WindowHeight=0;
 
  WindowWidth, WindowHeight = getMainWindowSize();
 
 
 
  -- move mini console "sys" to the far right side of the screen whenever the screen gets resized
 
  moveWindow("sys",WindowWidth-300,0)
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==hasFocus==
+
==getMousePosition==
;hasFocus()
+
;x, y = getMousePosition()
: 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.
+
: Returns the coordinates of the mouse's position, relative to the Mudlet window itself.
  
 
; Parameters
 
; Parameters
 
:None
 
:None
 +
 +
{{note}} Available since Mudlet 3.1+
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
if attacked and not hasFocus() then
+
-- 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
  runaway()
+
local x, y = getMousePosition()
else
+
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)
  fight()
+
-- if the label already exists, just move it
end
+
moveWindow("clickGeneratedLabel", x, y)
 +
-- and make it easier to notice
 +
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==hecho==
+
==getMainWindowSize==
;hecho([windowName], text)
+
;width, height = getMainWindowSize()
: Echoes text that can be easily formatted with colour tags in the hexadecimal format.
+
: 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.
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]
+
: See also: [[#setMainWindowSize|setMainWindowSize()]], [[#getMainConsoleWidth|getMainConsoleWidth()]]
  
;Parameters
+
; Parameters
* ''windowName:''
+
:None
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.
 
* ''text:''
 
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #cFRFGFB,BRBGBB where FR is the foreground red value, FG is the foreground green value, FB is the foreground blue value, BR is the background red value, etc., BRBGBB is optional. |r or #r can be used within the string to reset the colors to default.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
hecho("|ca00040black!")
+
--this will get the size of your main mudlet window and save them
-- same as above!
+
--into the variables mainHeight and mainWidth
hecho("#ca00040black!")
+
mainWidth, mainHeight = getMainWindowSize()
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==hechoLink==
+
==getRowCount==
;hechoLink([windowName], text, command, hint, true)
+
;rows = getRowCount([windowName])
: 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.
+
: 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.
  
: See also: [[#cechoLink|cechoLink()]], [[#echoLink|echoLink()]]
+
;Parameters:
 +
* ''windowName'':
 +
: (optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.
  
;Parameters
+
{{note}}
* ''windowName:''
+
Available since Mudlet 3.7.0
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.
 
* ''text:''
 
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].
 
* ''command:''
 
: lua code to do when the link is clicked.
 
* ''hint:''
 
: text for the tooltip to be displayed when the mouse is over the link.
 
* ''true:''
 
: requires argument for the colouring to work.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- echo a link named 'press me!' that'll send the 'hi' command to the game
+
print("Maximum of rows on the main window "..getRowCount())
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)
 
-- # format also works
 
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==hideToolBar==
+
==getSelection==
;hideToolBar(name)
+
;text, start, length = getSelection([windowName])
: 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.
+
: 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.
 +
 
 +
;Parameters:
 +
* ''windowName'':
 +
: (optional) name of the window to get the selection from. By default it operates on the main window.
  
;Parameters
+
{{note}}
* ''name:''
+
Available since Mudlet 3.16.0
: name of the button group to hide
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
hideToolBar("my offensive buttons")
+
selectCurrentLine()
 +
print("Current selection is: "..getSelection())
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==hideWindow==
+
==getTextFormat==
;hideWindow(name)
+
;getTextFormat([windowName])
: This function hides a mini console label. To show it again, use [[Manual:Lua_Functions#showWindow|showWindow()]].
+
: 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.
 +
: See Also: [[Manual:Lua_Functions#setTextFormat|setTextFormat()]]
  
: See also: [[Manual:Lua_Functions#createMiniConsole|createMiniConsole()]], [[Manual:Lua_Functions#createLabel|createLabel()]]
+
;Parameters
 +
* ''windowName''
 +
: (optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.
  
;Parameters
+
{{note}} Available since Mudlet 3.20.
* ''name''
 
: specifies the label you want to hide.
 
  
;Example
+
;Example:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
function miniconsoleTest()
+
-- A suitable test for getTextFormat()
  local windowWidth, windowHeight = getMainWindowSize()
+
-- (copy it into an alias or a script)
  
  -- create the miniconsole
+
clearWindow()
  createMiniConsole("sys", windowWidth-650,0,650,300)
 
  setBackgroundColor("sys",255,69,0,255)
 
  setMiniConsoleFontSize("sys", 8)
 
  -- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example
 
  setWindowWrap("sys", 40)
 
  
  print("created red window top-right")
+
echo("\n")
  
  tempTimer(1, function()
+
local SGR = string.char(27)..'['
    hideWindow("sys")
+
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")
    print("hid red window top-right")
 
  end)
 
  
  tempTimer(3, function()
+
moveCursor(1,1)
    showWindow("sys")
+
selectSection(1,1)
    print("showed red window top-right")
 
  end)
 
end
 
  
miniconsoleTest()
+
local results = getTextFormat()
</syntaxhighlight>
+
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))
 
+
echo("\nItalic detected: " .. tostring(results["italic"]))
==insertLink==
+
echo("\nUnderline detected: " .. tostring(results["underline"]))
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])
+
echo("\nReverse detected: " .. tostring(results["reverse"]))
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].
+
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))
 +
echo("\nOverline detected: " .. tostring(results["overline"]))
 +
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")
 +
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")
  
;Parameters
+
selectSection(21,1)
* ''windowName:''
+
echo("\n\nFor individual parts of test text:")
: (optional) the window to insert the link in - use either "main" or omit for the main window.
+
echo("\nBold detected (character 21): " .. tostring(results["bold"]))
* ''text:''
 
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].
 
* ''command:''
 
: lua code to do when the link is clicked.
 
* ''hint:''
 
: text for the tooltip to be displayed when the mouse is over the link.
 
* ''useCurrentLinkFormat:''
 
: (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.
 
  
;Example
+
selectSection(28,1)
<syntaxhighlight lang="lua">
+
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))
-- link with the default blue on white colors
 
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")
 
  
-- use current cursor colors by adding true at the end
+
selectSection(37,1)
fg("red")
+
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)
 
resetFormat()
 
</syntaxhighlight>
 
  
==insertPopup==
+
selectSection(67,1)
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])
+
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))
: 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.
 
  
; Parameters
+
selectSection(77,1)
* ''windowName:''
+
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.
 
* ''name:''
 
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.
 
* ''{lua code}:''
 
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.
 
* ''{hints}:''
 
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.
 
* ''useCurrentLinkFormat:''
 
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
 
  
;Example
+
selectSection(89,1)
<syntaxhighlight lang="lua">
+
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))
-- Create some text as a clickable with a popup menu:
+
echo("\n")
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==insertText==
+
==handleWindowResizeEvent==
;insertText([windowName], text)
+
;handleWindowResizeEvent()
: 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.
+
: (''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.
  
: insertHTML() also does the same thing as insertText, if you ever come across it.
+
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.
 
 
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]
 
  
 
; Parameters
 
; Parameters
* ''windowName:''
+
:None
: (optional) The window to insert the text to.
 
* ''text:''
 
: The text you will insert into the current cursor position.
 
  
;Example
+
; Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- move the cursor to the end of the previous line and insert some text
+
function handleWindowResizeEvent()
 +
  -- determine the size of your screen
 +
  WindowWidth=0;
 +
  WindowHeight=0;
 +
  WindowWidth, WindowHeight = getMainWindowSize();
  
-- move to the previous line
+
  -- move mini console "sys" to the far right side of the screen whenever the screen gets resized
moveCursor(0, getLineNumber()-1)
+
  moveWindow("sys",WindowWidth-300,0)
-- move the end the of the previous line
+
end
moveCursor(#getCurrentLine(), getLineNumber())
+
</syntaxhighlight>
  
fg("dark_slate_gray")
+
==hasFocus==
insertText(' <- that looks nice.')
+
;hasFocus()
 +
: Returns ''true'' or ''false'' depending if Mudlet's main window is currently in focus (ie, the user isn't focused on another window, like a browser). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.
 +
 
 +
; Parameters
 +
:None
  
deselect()
+
;Example
resetFormat()
+
<syntaxhighlight lang="lua">
moveCursorEnd()
+
if attacked and not hasFocus() then
 +
  runaway()
 +
else
 +
  fight()
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==ioprint==
+
==hecho==
;ioprint(text, some more text, ...)
+
;hecho([windowName], text)
: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).
+
: Echoes text that can be easily formatted with colour tags in the hexadecimal format.
 
+
: See Also: [[Manual:Lua_Functions#decho|decho()]], [[Manual:Lua_Functions#cecho|cecho()]]
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.
 
 
 
This function is useful in working out potential crashing problems with Mudlet due to your scripts - as you will still see whatever it printed when Mudlet crashes.
 
  
 
;Parameters
 
;Parameters
 +
* ''windowName:''
 +
: (optional) name of the window to echo to. Can either be omitted or "main" for the main window, else specify the miniconsoles name.
 
* ''text:''
 
* ''text:''
: The information you want to display.
+
: The text to display, with color changes made within the string using the format |cFRFGFB,BRBGBB or #cFRFGFB,BRBGBB where FR is the foreground red value, FG is the foreground green value, FB is the foreground blue value, BR is the background red value, etc., BRBGBB is optional. |r or #r can be used within the string to reset the colors to default.
;Example:
+
 
 +
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
ioprint("hi!")
+
hecho("|ca00040black!")
ioprint(1,2,3)
+
-- same as above!
ioprint(myvariable, someothervariable, yetanothervariable)
+
hecho("#ca00040black!")
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==isAnsiBgColor==
+
==hechoLink==
; isAnsiBgColor(ansiBgColorCode)
+
;hechoLink([windowName], text, command, hint, true)
: This function tests if the first character of '''the current selection''' has the background color specified by ansiBgColorCode.
+
: 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.
 +
 
 +
: See also: [[#cechoLink|cechoLink()]], [[#dechoLink|dechoLink()]]
  
 
;Parameters
 
;Parameters
* ''ansiBgColorCode:''
+
* ''windowName:''
: A color code to test for, possible codes are:
+
: (optional) - allows selection between sending the link to a miniconsole or the ''main'' window.
 +
* ''text:''
 +
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].
 +
* ''command:''
 +
: lua code to do when the link is clicked.
 +
* ''hint:''
 +
: text for the tooltip to be displayed when the mouse is over the link.
 +
* ''true:''
 +
: requires argument for the colouring to work.
  
 +
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
0 = default text color
+
-- echo a link named 'press me!' that'll send the 'hi' command to the game
1 = light black
+
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)
2 = dark black
+
-- # format also works
3 = light red
+
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)
4 = dark red
 
5 = light green
 
6 = dark green
 
7 = light yellow
 
8 = dark yellow
 
9 = light blue
 
10 = dark blue
 
11 = light magenta
 
12 = dark magenta
 
13 = light cyan
 
14 = dark cyan
 
15 = light white
 
16 = dark white
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
;Example
+
==hechoPopup==
<syntaxhighlight lang="lua">
+
;hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
selectString( matches[1], 1 )
+
: 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.
if isAnsiBgColor( 5 ) then
 
    bg("red");
 
    resetFormat();
 
    echo("yes, the background of the text is light green")
 
else
 
    echo( "no sorry, some other backgroundground color" )
 
end
 
</syntaxhighlight>
 
  
{{note}}
+
; Parameters
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.
+
* ''windowName:''
 +
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.
 +
* ''text:''
 +
: the text to display
 +
* ''{commands}:''
 +
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>
 +
* ''{hints}:''
 +
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>
 +
* ''useCurrentFormatElseDefault:''
 +
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
-- Create some text as a clickable with a popup menu:
 +
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)
 +
</syntaxhighlight>
 +
 
 +
{{note}} Available in Mudlet 4.1+
 +
 
 +
==hinsertLink==
 +
;hinsertLink([windowName], text, command, hint, true)
 +
: 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.
  
==isAnsiFgColor==
+
: See also: [[#insertLink|insertLink()]], [[#dinsertLink|dinsertLink()]]
; isAnsiFgColor(ansiFgColorCode)
 
: This function tests if the first character of '''the current selection''' has the foreground color specified by ansiFgColorCode.
 
  
 
;Parameters
 
;Parameters
* ''ansiFgColorCode:''
+
* ''windowName:''
: A color code to test for, possible codes are:
+
: optional parameter, allows selection between sending the link to a miniconsole or the main window.
 
+
* ''text:''
<syntaxhighlight lang="lua">
+
: text to display in the echo. Same as a normal [[Manual:Lua_Functions#hecho|hecho()]].
0 = default text color
+
* ''command:''
1 = light black
+
: lua code to do when the link is clicked.
2 = dark black
+
* ''hint:''
3 = light red
+
: text for the tooltip to be displayed when the mouse is over the link.
4 = dark red
+
* ''true:''
5 = light green
+
: requires argument for the colouring to work.
6 = dark green
 
7 = light yellow
 
8 = dark yellow
 
9 = light blue
 
10 = dark blue
 
11 = light magenta
 
12 = dark magenta
 
13 = light cyan
 
14 = dark cyan
 
15 = light white
 
16 = dark white
 
</syntaxhighlight>
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
selectString( matches[1], 1 )
+
-- echo a link named 'press me!' that'll send the 'hi' command to the game
if isAnsiFgColor( 5 ) then
+
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)
    bg("red");
+
</syntaxhighlight>
    resetFormat();
+
 
    echo("yes, the text is light green")
+
{{note}} Available in Mudlet 4.1+
else
+
 
    echo( "no sorry, some other foreground color" )
+
==hinsertPopup==
end
+
;hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
 +
: 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.
 +
 
 +
; Parameters
 +
* ''windowName:''
 +
: (optional) name of the window to echo to. Use either ''main'' or omit for the main window, or the miniconsoles name otherwise.
 +
* ''text:''
 +
: the text to display
 +
* ''{commands}:''
 +
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>
 +
* ''{hints}:''
 +
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>
 +
* ''useCurrentFormatElseDefault:''
 +
: (optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
-- Create some text as a clickable with a popup menu:
 +
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{note}}
+
{{note}} Available in Mudlet 4.1+
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.
 
  
==lowerWindow==
+
==hideToolBar==
;lowerWindow(labelName)
+
;hideToolBar(name)
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].
+
: Hides the toolbar with the given name name and makes it disappear. If all toolbars of a tool bar area (top, left, right) are hidden, the entire tool bar area disappears automatically.
  
 
;Parameters
 
;Parameters
* ''labelName:''
+
* ''name:''
: the name of the label/console you wish to move below the rest.
+
: name of the button group to hide
  
{{note}}
+
;Example
Available since Mudlet 3.1.0
 
 
 
; Example:
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
createLabel("blueLabel", 300, 300, 100, 100, 1)   --creates a blue label
+
hideToolBar("my offensive buttons")
setBackgroundColor("blueLabel", 50, 50, 250, 255)
 
 
 
createLabel("redLabel", 350, 350, 100, 100, 1)    --creates a red label which is placed on TOP of the blue label, as the last made label will sit at the top of the rest
 
setBackgroundColor("redLabel", 250, 50, 50, 255)
 
 
 
lowerWindow("redLabel")                          --lowers redLabel, causing blueLabel to be back on top
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==moveCursor==
+
==hideWindow==
;moveCursor([windowName], x, y)
+
;hideWindow(name)
: 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.
+
: 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()]].
  
: 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.
+
: See also: [[Manual:Lua_Functions#createMiniConsole|createMiniConsole()]], [[Manual:Lua_Functions#createLabel|createLabel()]]
  
 
;Parameters
 
;Parameters
* ''windowName:''
+
* ''name''
: (optional) The window you are going to move the cursor in.
+
: specifies the label or console you want to hide.
* ''x:''
 
: The horizontal axis in the window - that is, the letter position within the line.
 
* ''y:''
 
: The vertical axis in the window - that is, the line number.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- move cursor to the start of the previous line and insert -<(
+
function miniconsoleTest()
-- the first 0 means we want the cursor right at the start of the line,
+
  local windowWidth, windowHeight = getMainWindowSize()
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which
 
-- equals to the previous line
 
moveCursor(0, getLineNumber()-1)
 
insertText("-<(")
 
  
-- now we move the cursor at the end of the previous line. Because the
+
  -- create the miniconsole
-- cursor is on the previous line already, we can use #getCurrentLine()
+
  createMiniConsole("sys", windowWidth-650,0,650,300)
-- to see how long it is. We also just do getLineNumber() because getLineNumber()
+
  setBackgroundColor("sys",255,69,0,255)
-- returns the current line # the cursor is on
+
  setMiniConsoleFontSize("sys", 8)
moveCursor(#getCurrentLine(), getLineNumber())
+
  -- wrap lines in window "sys" at 40 characters per line - somewhere halfway, as an example
insertText(")>-")
+
  setWindowWrap("sys", 40)
  
-- finally, reset it to the end where it was after our shenaningans - other scripts
+
  print("created red window top-right")
-- could expect the cursor to be at the end
 
moveCursorEnd()
 
</syntaxhighlight>
 
  
<syntaxhighlight lang="lua">
+
  tempTimer(1, function()
-- a more complicated example showing how to work with Mudlet functions
+
    hideWindow("sys")
 +
    print("hid red window top-right")
 +
  end)
  
-- set up the small system message window in the top right corner
+
  tempTimer(3, function()
-- determine the size of your screen
+
    showWindow("sys")
local WindowWidth, WindowHeight = getMainWindowSize()
+
    print("showed red window top-right")
 +
  end)
 +
end
  
-- define a mini console named "sys" and set its background color
+
miniconsoleTest()
createMiniConsole("sys",WindowWidth-650,0,650,300)
+
</syntaxhighlight>
setBackgroundColor("sys",85,55,0,255)
 
  
-- you *must* set the font size, otherwise mini windows will not work properly
+
==insertLink==
setMiniConsoleFontSize("sys", 12)
+
;insertLink([windowName], text, command, hint, [useCurrentLinkFormat])
-- wrap lines in window "sys" at 65 characters per line
+
: Inserts a piece of text as a clickable link at the current cursor position - similar to [[Manual:Lua_Functions#insertText|insertText()]].
setWindowWrap("sys", 60)
 
-- set default font colors and font style for window "sys"
 
setTextFormat("sys",0,35,255,50,50,50,0,0,0)
 
-- clear the window
 
clearUserWindow("sys")
 
  
moveCursorEnd("sys")
+
;Parameters
setFgColor("sys", 10,10,0)
+
* ''windowName:''
setBgColor("sys", 0,0,255)
+
: (optional) the window to insert the link in - use either "main" or omit for the main window.
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")
+
* ''text:''
echo("sys", "test1---line2\n")
+
: text to display in the window. Same as a normal [[Manual:Lua_Functions#echo|echo()]].
echo("sys", "test1---line3\n")
+
* ''command:''
setTextFormat("sys",158,0,255,255,0,255,0,0,0);
+
: lua code to do when the link is clicked.
--setFgColor("sys",255,0,0);
+
* ''hint:''
echo("sys", "test1---line4\n")
+
: text for the tooltip to be displayed when the mouse is over the link.
echo("sys", "test1---line5\n")
+
* ''useCurrentLinkFormat:''
moveCursor("sys", 1,1)
+
: (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.
  
-- deleting lines 2+3
+
;Example
deleteLine("sys")
+
<syntaxhighlight lang="lua">
deleteLine("sys")
+
-- link with the default blue on white colors
 +
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")
  
-- inserting a line at pos 5,2
+
-- use current cursor colors by adding true at the end
moveCursor("sys", 5,2)
+
fg("red")
setFgColor("sys", 100,100,0)
+
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup", true)
setBgColor("sys", 255,100,0)
+
resetFormat()
insertText("sys","############## line inserted at pos 5/2 ##############")
+
</syntaxhighlight>
  
-- inserting a line at pos 0,0
+
==insertPopup==
moveCursor("sys", 0,0)
+
;insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])
selectCurrentLine("sys")
+
: 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.
setFgColor("sys", 255,155,255)
 
setBold( "sys", true );
 
setUnderline( "sys", true )
 
setItalics( "sys", true )
 
insertText("sys", "------- line inserted at: 0/0 -----\n")
 
  
setBold( "sys", true )
+
; Parameters
setUnderline( "sys", false )
 
setItalics( "sys", false )
 
setFgColor("sys", 255,100,0)
 
setBgColor("sys", 155,155,0)
 
echo("sys", "*** This is the end. ***\n")
 
</syntaxhighlight>
 
 
 
==moveCursorDown==
 
;moveCursorDown([windowName,] [lines,] [keepHorizontal])
 
: Moves the cursor in the given window down a specified number of lines.
 
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]
 
 
 
;Parameters
 
 
* ''windowName:''
 
* ''windowName:''
: (optional) name of the miniconsole/userwindow, or "main" for the main window.
+
: (optional) name of the window to echo to - use either ''main'' or omit for the main window, or the miniconsoles name otherwise.
 +
* ''name:''
 +
: the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.
 +
* ''{lua code}:''
 +
: a table of lua code strings to do. ie, <syntaxhighlight lang="lua" inline="">{[[send("hello")]], [[echo("hi!"]]}</syntaxhighlight>.
 +
* ''{hints}:''
 +
: a table of strings which will be shown on the popup and right-click menu. ie, <syntaxhighlight lang="lua" inline="">{"send the hi command", "echo hi to yourself"}</syntaxhighlight>.
 +
* ''useCurrentLinkFormat:''
 +
: (optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
  
* ''lines:''
+
;Example
: (optional) number of lines to move cursor down by, or 1 by default.
+
<syntaxhighlight lang="lua">
 +
-- Create some text as a clickable with a popup menu:
 +
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})
 +
</syntaxhighlight>
  
* ''keepHorizontal:''
+
==insertText==
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.
+
;insertText([windowName], text)
 +
: 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.
  
{{Note}}
+
: insertHTML() also does the same thing as insertText, if you ever come across it.
Available since Mudlet 3.17+
 
  
;Example
+
: See also: [[Manual:Lua_Functions#cinsertText|cinsertText()]]
'' Need example''
 
  
==moveCursorUp==
+
; Parameters
;moveCursorUp([windowName,] [lines,] [keepHorizontal])
+
* ''windowName:''
: Moves the cursor in the given window up a specified number of lines.
+
: (optional) The window to insert the text to.
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]
+
* ''text:''
 +
: The text you will insert into the current cursor position.
  
;Parameters
+
;Example
* ''windowName:''
+
<syntaxhighlight lang="lua">
: (optional) name of the miniconsole/userwindow, or "main" for the main window.
+
-- move the cursor to the end of the previous line and insert some text
 +
 
 +
-- move to the previous line
 +
moveCursor(0, getLineNumber()-1)
 +
-- move the end the of the previous line
 +
moveCursor(#getCurrentLine(), getLineNumber())
  
* ''lines:''
+
fg("dark_slate_gray")
: (optional) number of lines to move cursor up by, or 1 by default.
+
insertText(' <- that looks nice.')
  
* ''keepHorizontal:''
+
deselect()
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.
+
resetFormat()
 +
moveCursorEnd()
 +
</syntaxhighlight>
  
{{Note}}
+
==ioprint==
Available since Mudlet 3.17+
+
;ioprint(text, some more text, ...)
 +
: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).
  
;Example
+
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.
'' Need example''
 
  
==moveCursorEnd==
+
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.
;moveCursorEnd([windowName])
 
: Moves the cursor to the end of the buffer. "main" is the name of the main window, otherwise use the name of your user window.
 
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]
 
 
 
: Returns true or false
 
  
 
;Parameters
 
;Parameters
* ''windowName:''
+
* ''text:''
: (optional) name of the miniconsole/userwindow, or "main" for the main window.
+
: The information you want to display.
 +
;Example:
 +
<syntaxhighlight lang="lua">
 +
ioprint("hi!")
 +
ioprint(1,2,3)
 +
ioprint(myvariable, someothervariable, yetanothervariable)
 +
</syntaxhighlight>
  
;Example
+
==isAnsiBgColor==
'' Need example''
+
; isAnsiBgColor(ansiBgColorCode)
 +
: This function tests if the first character of '''the current selection''' has the background color specified by ansiBgColorCode.
  
==moveGauge==
+
;Parameters
;moveGauge(gaugeName, newX, newY)
+
* ''ansiBgColorCode:''
: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.
+
: A color code to test for, possible codes are:
  
;Parameters
+
<syntaxhighlight lang="lua">
* ''gaugeName:''
+
0 = default text color
: The name of your gauge
+
1 = light black
* ''newX:''
+
2 = dark black
: The horizontal pixel location
+
3 = light red
* ''newY:''
+
4 = dark red
: The vertical pixel location
+
5 = light green
 +
6 = dark green
 +
7 = light yellow
 +
8 = dark yellow
 +
9 = light blue
 +
10 = dark blue
 +
11 = light magenta
 +
12 = dark magenta
 +
13 = light cyan
 +
14 = dark cyan
 +
15 = light white
 +
16 = dark white
 +
</syntaxhighlight>
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- This would move the health bar gauge to the location 1200, 400
+
selectString( matches[1], 1 )
moveGauge("healthBar", 1200, 400)
+
if isAnsiBgColor( 5 ) then
 +
    bg("red");
 +
    resetFormat();
 +
    echo("yes, the background of the text is light green")
 +
else
 +
    echo( "no sorry, some other backgroundground color" )
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==moveWindow==
 
;moveWindow(name, x, y)
 
:This function moves window name to the given x/y coordinate. The main screen cannot be moved. Instead you’ll have to set appropriate border values → preferences to move the main screen e.g. to make room for chat or information mini consoles, or other GUI elements. In the future moveWindow() will set the border values automatically if the name parameter is omitted.
 
 
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderTop | setBorderTop()]], [[#openUserWindow | openUserWindow()]]
 
 
;Parameters
 
* ''name:''
 
: The name of your window
 
* ''newX:''
 
: The horizontal pixel location
 
* ''newY:''
 
: The vertical pixel location
 
  
 
{{note}}
 
{{note}}
Since Mudlet 3.7 this method can also be used on UserWindow consoles.
+
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.
  
==openUserWindow==
+
==isAnsiFgColor==
;openUserWindow(windowName, [restoreLayout])
+
; isAnsiFgColor(ansiFgColorCode)
: 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.
+
: This function tests if the first character of '''the current selection''' has the foreground color specified by ansiFgColorCode.
  
 
;Parameters
 
;Parameters
* ''windowName:''
+
* ''ansiFgColorCode:''
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).
+
: A color code to test for, possible codes are:
* ''restoreLayout:''
 
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.
 
  
{{note}}
 
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.
 
 
;Examples
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
openUserWindow("My floating window")
+
0 = default text color
cecho("My floating window", "<red>hello <blue>bob!")
+
1 = light black
 
+
2 = dark black
-- if you don't want Mudlet to remember its last position:
+
3 = light red
openUserWindow("My floating window", false)
+
4 = dark red
 +
5 = light green
 +
6 = dark green
 +
7 = light yellow
 +
8 = dark yellow
 +
9 = light blue
 +
10 = dark blue
 +
11 = light magenta
 +
12 = dark magenta
 +
13 = light cyan
 +
14 = dark cyan
 +
15 = light white
 +
16 = dark white
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==paste==
+
;Example
;paste(windowName)
+
<syntaxhighlight lang="lua">
: 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.
+
selectString( matches[1], 1 )
 
+
if isAnsiFgColor( 5 ) then
 +
    bg("red");
 +
    resetFormat();
 +
    echo("yes, the text is light green")
 +
else
 +
    echo( "no sorry, some other foreground color" )
 +
end
 +
</syntaxhighlight>
 +
 
 +
{{note}}
 +
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.
 +
 
 +
==lowerWindow==
 +
;lowerWindow(labelName)
 +
:Moves the referenced label/console below all other labels/consoles. For the opposite effect, see: [[#raiseWindow | raiseWindow()]].
 +
 
 
;Parameters
 
;Parameters
* ''windowName:''
+
* ''labelName:''
: The name of your window
+
: the name of the label/console you wish to move below the rest.
  
==prefix==
+
{{note}}
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])
+
Available since Mudlet 3.1.0
:Prefixes text at the beginning of the current line when used in a trigger.
 
  
;Parameters
+
; Example:
* ''text:''
 
: the information you want to prefix
 
* "writingFunction:"
 
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.
 
* "foregroundColor:"
 
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function
 
* "backgroundColor:"
 
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function
 
* "windowName:"
 
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed
 
;Example:
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that
+
createLabel("blueLabel", 300, 300, 100, 100, 1)  --creates a blue label
prefix(os.date("%H:%M:%S "))
+
setBackgroundColor("blueLabel", 50, 50, 250, 255)
-- Prefix the time in red into a miniconsole named "my_console"
+
 
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))
+
createLabel("redLabel", 350, 350, 100, 100, 1)   --creates a red label which is placed on TOP of the blue label, as the last made label will sit at the top of the rest
 +
setBackgroundColor("redLabel", 250, 50, 50, 255)
 +
 
 +
lowerWindow("redLabel")                         --lowers redLabel, causing blueLabel to be back on top
 
</syntaxhighlight>
 
</syntaxhighlight>
  
: See also: [[#suffix | suffix()]]
+
==moveCursor==
 +
;moveCursor([windowName], x, y)
 +
: Moves the user cursor of the window windowName, or the main window, to the absolute point (x,y). This function returns false if such a move is impossible e.g. the coordinates don’t exist. To determine the correct coordinates use [[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.
  
==print==
+
: 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.
;print(text, some more text, ...)
 
: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.
 
  
 
;Parameters
 
;Parameters
* ''text:''
+
* ''windowName:''
: The information you want to display.
+
: (optional) The window you are going to move the cursor in.
;Example:
+
* ''x:''
 +
: The horizontal axis in the window - that is, the letter position within the line.
 +
* ''y:''
 +
: The vertical axis in the window - that is, the line number.
 +
 
 +
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
print("hi!")
+
-- move cursor to the start of the previous line and insert -<(
print(1,2,3)
+
-- the first 0 means we want the cursor right at the start of the line,
print(myvariable, someothervariable, yetanothervariable)
+
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which
 +
-- equals to the previous line
 +
moveCursor(0, getLineNumber()-1)
 +
insertText("-<(")
 +
 
 +
-- now we move the cursor at the end of the previous line. Because the
 +
-- cursor is on the previous line already, we can use #getCurrentLine()
 +
-- to see how long it is. We also just do getLineNumber() because getLineNumber()
 +
-- returns the current line # the cursor is on
 +
moveCursor(#getCurrentLine(), getLineNumber())
 +
insertText(")>-")
 +
 
 +
-- finally, reset it to the end where it was after our shenaningans - other scripts
 +
-- could expect the cursor to be at the end
 +
moveCursorEnd()
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==raiseWindow==
+
<syntaxhighlight lang="lua">
;raiseWindow(labelName)
+
-- a more complicated example showing how to work with Mudlet functions
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].
 
  
;Parameters
+
-- set up the small system message window in the top right corner
* ''labelName:''
+
-- determine the size of your screen
: the name of the label/console you wish to bring to the top of the rest.
+
local WindowWidth, WindowHeight = getMainWindowSize()
  
{{note}}
+
-- define a mini console named "sys" and set its background color
Available since Mudlet 3.1.0
+
createMiniConsole("sys",WindowWidth-650,0,650,300)
 +
setBackgroundColor("sys",85,55,0,255)
  
; Example:
+
-- you *must* set the font size, otherwise mini windows will not work properly
<syntaxhighlight lang="lua">
+
setMiniConsoleFontSize("sys", 12)
createLabel("blueLabel", 300, 300, 100, 100, 1)   --creates a blue label
+
-- wrap lines in window "sys" at 65 characters per line
setBackgroundColor("blueLabel", 50, 50, 250, 255)
+
setWindowWrap("sys", 60)
 +
-- set default font colors and font style for window "sys"
 +
setTextFormat("sys",0,35,255,50,50,50,0,0,0)
 +
-- clear the window
 +
clearUserWindow("sys")
  
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
+
moveCursorEnd("sys")
setBackgroundColor("redLabel", 250, 50, 50, 255)
+
setFgColor("sys", 10,10,0)
 
+
setBgColor("sys", 0,0,255)
raiseWindow("blueLabel")                         --raises blueLabel back at the top, above redLabel
+
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")
</syntaxhighlight>
+
echo("sys", "test1---line2\n")
 +
echo("sys", "test1---line3\n")
 +
setTextFormat("sys",158,0,255,255,0,255,0,0,0);
 +
--setFgColor("sys",255,0,0);
 +
echo("sys", "test1---line4\n")
 +
echo("sys", "test1---line5\n")
 +
moveCursor("sys", 1,1)
  
==replace==
+
-- deleting lines 2+3
;replace([windowName], with, [keepcolor])
+
deleteLine("sys")
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.
+
deleteLine("sys")
  
{{note}}
+
-- inserting a line at pos 5,2
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.
+
moveCursor("sys", 5,2)
 +
setFgColor("sys", 100,100,0)
 +
setBgColor("sys", 255,100,0)
 +
insertText("sys","############## line inserted at pos 5/2 ##############")
  
{{note}}
+
-- inserting a line at pos 0,0
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.
+
moveCursor("sys", 0,0)
 +
selectCurrentLine("sys")
 +
setFgColor("sys", 255,155,255)
 +
setBold( "sys", true );
 +
setUnderline( "sys", true )
 +
setItalics( "sys", true )
 +
insertText("sys", "------- line inserted at: 0/0 -----\n")
  
;Parameters
+
setBold( "sys", true )
* ''windowName:''
+
setUnderline( "sys", false )
: (optional) name of window (a miniconsole)
+
setItalics( "sys", false )
* ''with:''
+
setFgColor("sys", 255,100,0)
: the new text to display.
+
setBgColor("sys", 155,155,0)
* ''keepcolor:''
+
echo("sys", "*** This is the end. ***\n")
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)
 
 
 
; Example:
 
<syntaxhighlight lang="lua">
 
-- replace word "troll" with "cute trolly"
 
selectString("troll",1)
 
replace("cute trolly")
 
 
 
-- replace the whole line
 
selectCurrentLine()
 
replace("Out with the old, in with the new!")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==replaceAll==
+
==moveCursorDown==
;replaceAll(what, with)
+
;moveCursorDown([windowName,] [lines,] [keepHorizontal])
: Replaces all occurrences of ''what'' in the current line with ''with''.
+
: Moves the cursor in the given window down a specified number of lines.
 +
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorUp|moveCursorUp()]], [[#moveCursorEnd|moveCursorEnd()]]
  
 
;Parameters
 
;Parameters
* ''what:''
+
* ''windowName:''
: the text to replace
+
: (optional) name of the miniconsole/userwindow, or "main" for the main window.
* ''with:''
 
: the new text to have in place
 
  
;Examples:
+
* ''lines:''
<syntaxhighlight lang="lua">
+
: (optional) number of lines to move cursor down by, or 1 by default.
-- replace all occurrences of the word "south" in the line with "north"
 
replaceAll("south", "north")
 
</syntaxhighlight>
 
  
<syntaxhighlight lang="lua">
+
* ''keepHorizontal:''
-- replace all occurrences of the text that the variable "target" has
+
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.
replaceAll(target, "The Bad Guy")
 
</syntaxhighlight>
 
  
==replaceWildcard==
+
{{Note}}
;replaceWildcard(which, replacement)
+
Available since Mudlet 3.17+
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:
 
  
<syntaxhighlight lang="lua">
+
;Example
selectString(matches[2], 1)
+
'' Need example''
replace("text")
 
</syntaxhighlight>
 
  
;Parameters
+
==moveCursorUp==
* ''which:''
+
;moveCursorUp([windowName,] [lines,] [keepHorizontal])
: Wildcard to replace.
+
: Moves the cursor in the given window up a specified number of lines.
* ''replacement:''
+
: See also: [[#moveCursor|moveCursor()]], [[#moveCursorDown|moveCursorDown()]], [[#moveCursorEnd|moveCursorEnd()]]
: Text to replace the wildcard with.
+
 
 +
;Parameters
 +
* ''windowName:''
 +
: (optional) name of the miniconsole/userwindow, or "main" for the main window.
  
;Example
+
* ''lines:''
<syntaxhighlight lang="lua">
+
: (optional) number of lines to move cursor up by, or 1 by default.
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello
 
</syntaxhighlight>
 
  
==resetFormat==
+
* ''keepHorizontal:''
;resetFormat()
+
: (optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.
: Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.
 
  
; Parameters
+
{{Note}}
:None
+
Available since Mudlet 3.17+
  
 
;Example
 
;Example
<syntaxhighlight lang="lua">
+
'' Need example''
-- select and set the 'Tommy' to red in the line
 
if selectString("Tommy", 1) ~= -1 then fg("red") end
 
  
-- now reset the formatting, so our echo isn't red
+
==moveCursorEnd==
resetFormat()
+
;moveCursorEnd([windowName])
echo(" Hi Tommy!")
+
: Moves the cursor to the end of the buffer. "main" is the name of the main window, otherwise use the name of your user window.
 +
: See Also: [[Manual:Lua_Functions#moveCursor|moveCursor()]]
  
-- another example: just highlighting some words
+
: Returns true or false
for _, word in ipairs{"he", "she", "her", "their"} do
 
  if selectString(word, 1) ~= -1 then
 
    bg("blue")
 
  end
 
end
 
resetFormat()
 
</syntaxhighlight>
 
 
 
==resizeWindow==
 
;resizeWindow(windowName, width, height)
 
: Resizes a mini console, label, or floating User Windows.
 
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderTop | setBorderTop()]], [[#openUserWindow | openUserWindow()]]
 
  
 
;Parameters
 
;Parameters
 
* ''windowName:''
 
* ''windowName:''
: The name of your window
+
: (optional) name of the miniconsole/userwindow, or "main" for the main window.
* ''width:''
 
: The new width you want
 
* ''height:''
 
: The new height you want
 
  
{{note}}
+
;Example
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.
+
'' Need example''
  
==selectCaptureGroup==
+
==moveGauge==
;selectCaptureGroup(groupNumber)
+
;moveGauge(gaugeName, newX, newY)
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.
+
: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.
 
 
:See also: [[#selectCurrentLine| selectCurrentLine()]]
 
  
 
;Parameters
 
;Parameters
* ''groupNumber:''
+
* ''gaugeName:''
: number of the capture group you want to select
+
: The name of your gauge
 +
* ''newX:''
 +
: The horizontal pixel location
 +
* ''newY:''
 +
: The vertical pixel location
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".
+
-- This would move the health bar gauge to the location 1200, 400
--If you want to color the amount of money you have green you do:
+
moveGauge("healthBar", 1200, 400)
 
 
selectCaptureGroup(1)
 
setFgColor(0,255,0)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==selectCurrentLine==
+
==moveWindow==
; selectCurrentLine([windowName])
+
;moveWindow(name, x, y)
: 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.
+
: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.
  
{{note}}
+
:See Also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.
 
: See also: [[Manual:Lua_Functions#selectString|selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]
 
  
; Parameters
+
;Parameters
 +
* ''name:''
 +
: The name of your window
 +
* ''newX:''
 +
: The horizontal pixel location
 +
* ''newY:''
 +
: The vertical pixel location
 +
 
 +
{{note}}
 +
Since Mudlet 3.7 this method can also be used on UserWindow consoles.
 +
 
 +
==openUserWindow==
 +
;openUserWindow(windowName, [restoreLayout])
 +
: 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.
 +
 
 +
;Parameters
 
* ''windowName:''
 
* ''windowName:''
: (optional) name of the window in which to select text.
+
: name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).
 +
* ''restoreLayout:''
 +
: (optional) - only relevant, if ''false'' is provided. Then the window won't be restored to its last known position.
 +
 
 +
{{note}}
 +
Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the ''restoreLayout'' argument is available as well.
  
;Example
+
;Examples
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- color the whole line green!
+
openUserWindow("My floating window")
selectCurrentLine()
+
cecho("My floating window", "<red>hello <blue>bob!")
fg("green")
 
deselect()
 
resetFormat()
 
  
-- to select the previous line, you can do this:
+
-- if you don't want Mudlet to remember its last position:
moveCursor(0, getLineNumber()-1)
+
openUserWindow("My floating window", false)
selectCurrentLine()
+
</syntaxhighlight>
  
-- to select two lines back, this:
+
==paste==
moveCursor(0, getLineNumber()-2)
+
;paste(windowName)
selectCurrentLine()
+
: 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.
  
</syntaxhighlight>
+
;Parameters
 +
* ''windowName:''
 +
: The name of your window
  
==selectSection==
+
==prefix==
;selectSection( [windowName], fromPosition, length )
+
;prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])
: 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.
+
:Prefixes text at the beginning of the current line when used in a trigger.
: 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.
 
 
 
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]
 
  
 
;Parameters
 
;Parameters
* "windowName:"
+
* ''text:''
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.
+
: the information you want to prefix
: Will not work if "main" is given as the windowName to try to select from the main window.
+
* "writingFunction:"
* ''fromPosition:''
+
: optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.
: number to specify at which position in the line to begin selecting
+
* "foregroundColor:"
* ''length:''
+
: optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function
: number to specify the amount of characters you want to select
+
* "backgroundColor:"
 
+
: optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function
;Example
+
* "windowName:"
 +
: optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed
 +
;Example:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- select and colour the first character in the line red
+
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that
if selectSection(0,1) then fg("red") end
+
prefix(os.date("%H:%M:%S "))
 +
-- Prefix the time in red into a miniconsole named "my_console"
 +
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))
 +
</syntaxhighlight>
  
-- select and colour the second character green (start selecting from the first character, and select 1 character)
+
: See also: [[#suffix | suffix()]]
if selectSection(1,1) then fg("green") end
 
  
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)
+
==print==
if selectSection(2,3) then fg("grey") end
+
;print(text, some more text, ...)
</syntaxhighlight>
+
: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.
  
==selectString==
+
;Parameters
;selectString( [windowName], text, number_of_match )
+
* ''text:''
: 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).
+
: The information you want to display.
 +
;Example:
 +
<syntaxhighlight lang="lua">
 +
print("hi!")
 +
print(1,2,3)
 +
print(myvariable, someothervariable, yetanothervariable)
 +
</syntaxhighlight>
  
{{note}}
+
==raiseWindow==
You can move the user cursor with [[#moveCursor | moveCursor()]]. When a new line arrives from the MUD, the user cursor is positioned at the beginning of the line. However, if one of your trigger scripts moves the cursor around you need to take care of the cursor position yourself and make sure that the cursor is in the correct line if you want to call one of the select functions. To deselect text, see [[#deselect | deselect()]].
+
;raiseWindow(labelName)
 +
:Raises the referenced label/console above all over labels/consoles. For the opposite effect, see: [[#lowerWindow | lowerWindow()]].
  
 
;Parameters
 
;Parameters
* ''windowName:''
+
* ''labelName:''
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.
+
: the name of the label/console you wish to bring to the top of the rest.
* ''text:''
 
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).
 
* ''number_of_match:''
 
: The occurrence of text on the line that you'd like to select. For example, if the line was "Bob and Bob", 1 would select the first Bob, and 2 would select the second Bob.
 
 
 
: Returns position in line or -1 on error (text not found in line)
 
  
 
{{note}}
 
{{note}}
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:
+
Available since Mudlet 3.1.0
  
;Example
+
; Example:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
if selectString( "big monster", 1 ) > -1 then fg("red") end
+
createLabel("blueLabel", 300, 300, 100, 100, 1)   --creates a blue label
 +
setBackgroundColor("blueLabel", 50, 50, 250, 255)
 +
 
 +
createLabel("redLabel", 350, 350, 100, 100, 1)    --creates a red label which is placed on TOP of the bluewindow, as the last made label will sit at the top of the rest
 +
setBackgroundColor("redLabel", 250, 50, 50, 255)
 +
 
 +
raiseWindow("blueLabel")                         --raises blueLabel back at the top, above redLabel
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==setAppStyleSheet==
+
==replace==
;setAppStyleSheet(stylesheet [, tag])
+
;replace([windowName], with, [keepcolor])
: Sets a stylesheet for the entire Mudlet application - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). 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.
+
:Replaces the currently selected text with the new text. To select text, use [[#selectString | selectString()]], [[#selectSection | selectSection()]] or a similar function.
 +
 
 +
{{note}}
 +
If you’d like to delete/gag the whole line, use [[#deleteLine | deleteLine()]] instead.
  
: The event has two arguments in addition to the standard first one (the event name), the first of the additional ones is the optional argument to the function which can be used to identify something about the source of the new application style (see below), if it is omitted an empty string will be passed as the parameter; the second additional parameter is the profile that loaded the new style sheet. In combination these two parameters may be utilised to inform any package or script that modifies the styling of any part of the user-interface how it might need to adjust the appearance of that styling.
+
{{note}}
 +
when used outside of a trigger context (for example, in a timer instead of a trigger), replace() won't trigger the screen to refresh. Instead, use ''replace("")'' and ''insertText("new text")'' as [[#insertText | insertText()]] does.
  
 
;Parameters
 
;Parameters
 +
* ''windowName:''
 +
: (optional) name of window (a miniconsole)
 +
* ''with:''
 +
: the new text to display.
 +
* ''keepcolor:''
 +
: (optional) argument, setting this to ''true'' will keep the existing colors (since Mudlet 3.0+)
  
* ''stylesheet:''
+
; Example:
: The entire stylesheet you'd like to use.
+
<syntaxhighlight lang="lua">
 +
-- replace word "troll" with "cute trolly"
 +
selectString("troll",1)
 +
replace("cute trolly")
  
* ''tag:'' (from Mudlet version '''3.19.0''')
+
-- replace the whole line
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.
+
selectCurrentLine()
 +
replace("Out with the old, in with the new!")
 +
</syntaxhighlight>
 +
 
 +
==replaceAll==
 +
;replaceAll(what, with)
 +
: Replaces all occurrences of ''what'' in the current line with ''with''.
  
;References
+
;Parameters
: 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.
+
* ''what:''
: 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].
+
: the text to replace
 +
{{note}}
 +
This accepts [https://www.lua.org/pil/20.2.html Lua patterns]
 +
* ''with:''
 +
: the new text to have in place
  
;Example
+
;Examples:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770
+
-- replace all occurrences of the word "south" in the line with "north"
local background_color = "#26192f"
+
replaceAll("south", "north")
local border_color = "#b8731b"
+
</syntaxhighlight>
  
setAppStyleSheet([[
+
<syntaxhighlight lang="lua">
  QMainWindow {
+
-- replace all occurrences of the text that the variable "target" has
    background: ]]..background_color..[[;
+
replaceAll(target, "The Bad Guy")
  }
+
</syntaxhighlight>
  QToolBar {
 
    background: ]]..background_color..[[;
 
  }
 
  QToolButton {
 
    background: ]]..background_color..[[;
 
    border-style: solid;
 
    border-width: 2px;
 
    border-color: ]]..border_color..[[;
 
    border-radius: 5px;
 
    font-family: BigNoodleTitling;
 
    color: white;
 
    margin: 2px;
 
    font-size: 12pt;
 
  }
 
  QToolButton:hover { background-color: grey;}
 
  QToolButton:focus { background-color: grey;}
 
  
  QTreeView {
+
==replaceWildcard==
    background: ]]..background_color..[[;
+
;replaceWildcard(which, replacement)
    color: white;
+
: Replaces the given wildcard (as a number) with the given text. Equivalent to doing:
  }
 
  
  QMenuBar{ background-color: ]]..background_color..[[;}
+
<syntaxhighlight lang="lua">
 +
selectString(matches[2], 1)
 +
replace("text")
 +
</syntaxhighlight>
  
  QMenuBar::item{ background-color: ]]..background_color..[[;}
+
;Parameters
 +
* ''which:''
 +
: Wildcard to replace.
 +
* ''replacement:''
 +
: Text to replace the wildcard with.
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello
 +
</syntaxhighlight>
 +
 
 +
==resetFormat==
 +
;resetFormat()
 +
: Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.
 +
 
 +
; Parameters
 +
:None
  
  QDockWidget::title {
+
;Example
    background: ]]..border_color..[[;
+
<syntaxhighlight lang="lua">
  }
+
-- select and set the 'Tommy' to red in the line
  QStatusBar {
+
if selectString("Tommy", 1) ~= -1 then fg("red") end
    background: ]]..border_color..[[;
+
 
  }
+
-- now reset the formatting, so our echo isn't red
  QScrollBar:vertical {
+
resetFormat()
    background: ]]..background_color..[[;
+
echo(" Hi Tommy!")
    width: 15px;
+
 
    margin: 22px 0 22px 0;
+
-- another example: just highlighting some words
  }
+
for _, word in ipairs{"he", "she", "her", "their"} do
  QScrollBar::handle:vertical {
+
   if selectString(word, 1) ~= -1 then
    background-color: ]]..background_color..[[;
+
    bg("blue")
    min-height: 20px;
+
   end
    border-width: 2px;
+
end
    border-style: solid;
+
resetFormat()
    border-color: ]]..border_color..[[;
+
</syntaxhighlight>
    border-radius: 7px;
 
  }
 
  QScrollBar::add-line:vertical {
 
  background-color: ]]..background_color..[[;
 
  border-width: 2px;
 
  border-style: solid;
 
  border-color: ]]..border_color..[[;
 
  border-bottom-left-radius: 7px;
 
  border-bottom-right-radius: 7px;
 
        height: 15px;
 
        subcontrol-position: bottom;
 
        subcontrol-origin: margin;
 
  }
 
  QScrollBar::sub-line:vertical {
 
  background-color: ]]..background_color..[[;
 
  border-width: 2px;
 
  border-style: solid;
 
  border-color: ]]..border_color..[[;
 
  border-top-left-radius: 7px;
 
  border-top-right-radius: 7px;
 
        height: 15px;
 
        subcontrol-position: top;
 
        subcontrol-origin: margin;
 
  }
 
   QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
 
    background: white;
 
    width: 4px;
 
    height: 3px;
 
  }
 
   QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
 
    background: none;
 
  }
 
]])
 
  
-- if you'd like to reset it, use:
+
==resizeWindow==
setAppStyleSheet("")
+
;resizeWindow(windowName, width, height)
</syntaxhighlight>
+
: Resizes a mini console, label, or floating User Windows.
 +
:See also: [[#createMiniConsole | createMiniConsole()]], [[#createLabel | createLabel()]], [[#handleWindowResizeEvent | handleWindowResizeEvent()]], [[#resizeWindow | resizeWindow()]], [[#setBorderSizes | setBorderSizes()]], [[#openUserWindow | openUserWindow()]]
  
Also available as a one-line install - copy/paste this into Mudlet:
+
;Parameters
 
+
* ''windowName:''
<code>
+
: The name of your window
lua function downloaded_package(a,b) if not b:find("dark",1,true) then return end installPackage(b) os.remove(b) end registerAnonymousEventHandler("sysDownloadDone","downloaded_package") downloadFile(getMudletHomeDir() .. "/dark.mpackage", "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip")
+
* ''width:''
</code>
+
: The new width you want
 +
* ''height:''
 +
: The new height you want
  
 
{{note}}
 
{{note}}
Available since Mudlet 3.0.
+
Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.
  
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''".
+
==selectCaptureGroup==
 +
;selectCaptureGroup(groupNumber)
 +
: Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.
  
==setBackgroundColor==
+
:See also: [[#selectCurrentLine| selectCurrentLine()]]
;setBackgroundColor([windowName], r, g, b, transparency)
 
: 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).
 
 
 
{{note}}
 
Transparency only works on labels, not miniconsoles for efficiency reasons.
 
  
 
;Parameters
 
;Parameters
 +
* ''groupNumber:''
 +
: number of the capture group you want to select
  
* ''windowName:''
+
;Example
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.
+
<syntaxhighlight lang="lua">
* ''r:''
+
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".
: Amount of red to use, from 0 (none) to 255 (full).
+
--If you want to color the amount of money you have green you do:
* ''g:''
 
: Amount of green to use, from 0 (none) to 255 (full).
 
* ''b:''
 
: Amount of red to use, from 0 (none) to 255 (full).
 
* ''transparency:''
 
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).
 
  
{{note}}
+
selectCaptureGroup(1)
The parameter windowName supports "main" since Mudlet 3.10.
+
setFgColor(0,255,0)
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- make a red label that's somewhat transparent
 
setBackgroundColor("some label",255,0,0,200)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==setBackgroundImage==
+
==selectCurrentLine==
;setBackgroundImage(labelName, imageLocation)
+
; selectCurrentLine([windowName])
: Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.
+
: Selects the content of the current line that the cursor at. By default, the cursor is at the start of the current line that the triggers are processing, but you can move it with the moveCursor() function.
  
 
{{note}}
 
{{note}}
You can only do this for labels, not miniconsoles.
+
This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower ''selectString(line, 1)'' selection method.
 +
: See also: [[Manual:Lua_Functions#selectString|selectString()]],  [[#selectCurrentLine| selectCurrentLine()]],  [[#getSelection| getSelection()]], [[Manual:Lua_Functions#getCurrentLine|getCurrentLine()]]
  
{{note}}
+
; Parameters
You can also load images via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].
+
* ''windowName:''
 +
: (optional) name of the window in which to select text.
  
;Parameters
+
;Example
 +
<syntaxhighlight lang="lua">
 +
-- color the whole line green!
 +
selectCurrentLine()
 +
fg("green")
 +
deselect()
 +
resetFormat()
 +
 
 +
-- to select the previous line, you can do this:
 +
moveCursor(0, getLineNumber()-1)
 +
selectCurrentLine()
  
* ''labelName:''
+
-- to select two lines back, this:
: The name of the label to change it's background color.
+
moveCursor(0, getLineNumber()-2)
* ''imageLocation:''
+
selectCurrentLine()
: The full path to the image location. It's best to use [[ ]] instead of "" for it - because for Windows paths, backslashes need to be escaped.
 
  
;Example
 
<syntaxhighlight lang="lua">
 
-- give the top border a nice look
 
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==setBgColor==
+
==selectSection==
;setBgColor([windowName], r, g, b)
+
;selectSection( [windowName], fromPosition, length )
: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.
+
: Selects the specified parts of the line starting ''from'' the left and extending to the right for however ''how long''. The line starts from 0.
 +
: Returns true if the selection was successful, and false if the line wasn't actually long enough or the selection couldn't be done in general.
  
See also: [[#cecho|cecho()]]
+
:See also:[[#selectString| selectString()]], [[#selectCurrentLine| selectCurrentLine()]], [[#getSelection| getSelection()]]
  
 
;Parameters
 
;Parameters
* ''windowName:''
+
* "windowName:"
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
+
: (optional) name of the window in which to select text. By default the main window, if no windowName is given.
* ''r:''
+
: Will not work if "main" is given as the windowName to try to select from the main window.
: The red component of the gauge color. Passed as an integer number from 0 to 255
+
* ''fromPosition:''
* ''g:''
+
: number to specify at which position in the line to begin selecting
: The green component of the gauge color. Passed as an integer number from 0 to 255
+
* ''length:''
* ''b:''
+
: number to specify the amount of characters you want to select
: The blue component of the gauge color. Passed as an integer number from 0 to 255
 
  
 
;Example
 
;Example
 +
<syntaxhighlight lang="lua">
 +
-- select and colour the first character in the line red
 +
if selectSection(0,1) then fg("red") end
 +
 +
-- select and colour the second character green (start selecting from the first character, and select 1 character)
 +
if selectSection(1,1) then fg("green") end
  
<syntaxhighlight lang="lua">
+
-- select and colour three character after the first two grey (start selecting from the 2nd character for 3 characters long)
--highlights the first occurrence of the string "Tom" in the current line with a red background color.
+
if selectSection(2,3) then fg("grey") end
selectString( "Tom", 1 )
 
setBgColor( 255,0,0 )
 
 
</syntaxhighlight>
 
</syntaxhighlight>
<syntaxhighlight lang="lua">
+
 
--prints "Hello" on red background and "You" on blue.
+
==selectString==
setBgColor(255,0,0)
+
;selectString( [windowName], text, number_of_match )
echo("Hello")
+
: 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).
setBgColor(0,0,255)
+
 
 +
{{note}}
 +
You can move the user cursor with [[#moveCursor | moveCursor()]]. When a new line arrives from the MUD, the user cursor is positioned at the beginning of the line. However, if one of your trigger scripts moves the cursor around you need to take care of the cursor position yourself and make sure that the cursor is in the correct line if you want to call one of the select functions. To deselect text, see [[#deselect | deselect()]].
 +
 
 +
;Parameters
 +
* ''windowName:''
 +
: (optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.
 +
* ''text:''
 +
: The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).
 +
* ''number_of_match:''
 +
: The occurrence of text on the line that you'd like to select. For example, if the line was "Bob and Bob", 1 would select the first Bob, and 2 would select the second Bob.
 +
 
 +
: Returns position in line or -1 on error (text not found in line)
 +
 
 +
{{note}}
 +
To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes:
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
if selectString( "big monster", 1 ) > -1 then fg("red") end
 +
</syntaxhighlight>
 +
 
 +
==setAppStyleSheet==
 +
;setAppStyleSheet(stylesheet [, tag])
 +
: Sets a stylesheet for the entire Mudlet application - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). 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.
 +
 
 +
: The event has two arguments in addition to the standard first one (the event name), the first of the additional ones is the optional argument to the function which can be used to identify something about the source of the new application style (see below), if it is omitted an empty string will be passed as the parameter; the second additional parameter is the profile that loaded the new style sheet. In combination these two parameters may be utilised to inform any package or script that modifies the styling of any part of the user-interface how it might need to adjust the appearance of that styling.
 +
 
 +
;Parameters
 +
 
 +
* ''stylesheet:''
 +
: The entire stylesheet you'd like to use.
 +
 
 +
* ''tag:'' (with Mudlet 3.19+)
 +
: An optional string tag or identifier that will be passed as a second argument in the ''sysAppStyleSheetChange'' event that is provided by that or later versions of Mudlet.
 +
 
 +
;References
 +
: 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.
 +
: 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].
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770
 +
local background_color = "#26192f"
 +
local border_color = "#b8731b"
 +
 
 +
setAppStyleSheet([[
 +
  QMainWindow {
 +
    background: ]]..background_color..[[;
 +
  }
 +
  QToolBar {
 +
    background: ]]..background_color..[[;
 +
  }
 +
  QToolButton {
 +
    background: ]]..background_color..[[;
 +
    border-style: solid;
 +
    border-width: 2px;
 +
    border-color: ]]..border_color..[[;
 +
    border-radius: 5px;
 +
    font-family: BigNoodleTitling;
 +
    color: white;
 +
    margin: 2px;
 +
    font-size: 12pt;
 +
  }
 +
  QToolButton:hover { background-color: grey;}
 +
  QToolButton:focus { background-color: grey;}
 +
 
 +
  QTreeView {
 +
    background: ]]..background_color..[[;
 +
    color: white;
 +
  }
 +
 
 +
  QMenuBar{ background-color: ]]..background_color..[[;}
 +
 
 +
  QMenuBar::item{ background-color: ]]..background_color..[[;}
 +
 
 +
  QDockWidget::title {
 +
    background: ]]..border_color..[[;
 +
  }
 +
  QStatusBar {
 +
    background: ]]..border_color..[[;
 +
  }
 +
  QScrollBar:vertical {
 +
    background: ]]..background_color..[[;
 +
    width: 15px;
 +
    margin: 22px 0 22px 0;
 +
  }
 +
  QScrollBar::handle:vertical {
 +
    background-color: ]]..background_color..[[;
 +
    min-height: 20px;
 +
    border-width: 2px;
 +
    border-style: solid;
 +
    border-color: ]]..border_color..[[;
 +
    border-radius: 7px;
 +
  }
 +
  QScrollBar::add-line:vertical {
 +
  background-color: ]]..background_color..[[;
 +
  border-width: 2px;
 +
  border-style: solid;
 +
  border-color: ]]..border_color..[[;
 +
  border-bottom-left-radius: 7px;
 +
  border-bottom-right-radius: 7px;
 +
        height: 15px;
 +
        subcontrol-position: bottom;
 +
        subcontrol-origin: margin;
 +
  }
 +
  QScrollBar::sub-line:vertical {
 +
  background-color: ]]..background_color..[[;
 +
  border-width: 2px;
 +
  border-style: solid;
 +
  border-color: ]]..border_color..[[;
 +
  border-top-left-radius: 7px;
 +
  border-top-right-radius: 7px;
 +
        height: 15px;
 +
        subcontrol-position: top;
 +
        subcontrol-origin: margin;
 +
  }
 +
  QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
 +
    background: white;
 +
    width: 4px;
 +
    height: 3px;
 +
  }
 +
  QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
 +
    background: none;
 +
  }
 +
]])
 +
 
 +
-- if you'd like to reset it, use:
 +
setAppStyleSheet("")
 +
 
 +
-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':
 +
setAppStyleSheet[[
 +
  TConsole QScrollBar:vertical {
 +
      border: 2px solid grey;
 +
      background: #32CC99;
 +
      width: 15px;
 +
      margin: 22px 0 22px 0;
 +
  }
 +
  TConsole QScrollBar::handle:vertical {
 +
      background: white;
 +
      min-height: 20px;
 +
  }
 +
  TConsole QScrollBar::add-line:vertical {
 +
      border: 2px solid grey;
 +
      background: #32CC99;
 +
      height: 20px;
 +
      subcontrol-position: bottom;
 +
      subcontrol-origin: margin;
 +
  }
 +
  TConsole QScrollBar::sub-line:vertical {
 +
      border: 2px solid grey;
 +
      background: #32CC99;
 +
      height: 20px;
 +
      subcontrol-position: top;
 +
      subcontrol-origin: margin;
 +
  }
 +
  TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
 +
      border: 2px solid grey;
 +
      width: 3px;
 +
      height: 3px;
 +
      background: white;
 +
  }
 +
  TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
 +
      background: none;
 +
  }
 +
]]
 +
</syntaxhighlight>
 +
 
 +
Also available as a one-line install - copy/paste this into Mudlet:
 +
 
 +
<code>
 +
lua function downloaded_package(a,b) if not b:find("dark",1,true) then return end installPackage(b) os.remove(b) end registerAnonymousEventHandler("sysDownloadDone","downloaded_package") downloadFile(getMudletHomeDir() .. "/dark.mpackage", "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip")
 +
</code>
 +
 
 +
{{note}}
 +
Available since Mudlet 3.0.
 +
 
 +
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''".
 +
 
 +
==setBackgroundColor==
 +
;setBackgroundColor([windowName], r, g, b, transparency)
 +
: 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).
 +
 
 +
{{note}}
 +
Transparency only works on labels, not miniconsoles for efficiency reasons.
 +
 
 +
;Parameters
 +
 
 +
* ''windowName:''
 +
: (optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.
 +
* ''r:''
 +
: Amount of red to use, from 0 (none) to 255 (full).
 +
* ''g:''
 +
: Amount of green to use, from 0 (none) to 255 (full).
 +
* ''b:''
 +
: Amount of red to use, from 0 (none) to 255 (full).
 +
* ''transparency:''
 +
: Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).
 +
 
 +
{{note}}
 +
The parameter windowName supports "main" since Mudlet 3.10.
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
-- make a red label that's somewhat transparent
 +
setBackgroundColor("some label",255,0,0,200)
 +
</syntaxhighlight>
 +
 
 +
==setBackgroundImage==
 +
;setBackgroundImage(labelName, imageLocation)
 +
: Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback()]] and such.
 +
 
 +
{{note}}
 +
You can only do this for labels, not miniconsoles.
 +
 
 +
{{note}}
 +
You can also load images via [[Manual:Lua_Functions#setLabelStyleSheet|setLabelStyleSheet()]].
 +
 
 +
;Parameters
 +
 
 +
* ''labelName:''
 +
: The name of the label to change it's background color.
 +
* ''imageLocation:''
 +
: The full path to the image location. It's best to use [[ ]] instead of "" for it - because for Windows paths, backslashes need to be escaped.
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
-- give the top border a nice look
 +
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])
 +
</syntaxhighlight>
 +
 
 +
==setBgColor==
 +
;setBgColor([windowName], r, g, b)
 +
:Sets the current text background color in the main window unless windowName parameter given. If you have selected text prior to this call, the selection will be highlighted otherwise the current text background color will be changed. If you set a foreground or background color, the color will be used until you call resetFormat() on all further print commands.
 +
 
 +
: ''See also:'' [[#cecho|cecho()]]
 +
 
 +
;Parameters
 +
* ''windowName:''
 +
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
 +
* ''r:''
 +
: The red component of the gauge color. Passed as an integer number from 0 to 255
 +
* ''g:''
 +
: The green component of the gauge color. Passed as an integer number from 0 to 255
 +
* ''b:''
 +
: The blue component of the gauge color. Passed as an integer number from 0 to 255
 +
 
 +
;Example
 +
 
 +
<syntaxhighlight lang="lua">
 +
--highlights the first occurrence of the string "Tom" in the current line with a red background color.
 +
selectString( "Tom", 1 )
 +
setBgColor( 255,0,0 )
 +
</syntaxhighlight>
 +
<syntaxhighlight lang="lua">
 +
--prints "Hello" on red background and "You" on blue.
 +
setBgColor(255,0,0)
 +
echo("Hello")
 +
setBgColor(0,0,255)
 
echo(" You!")
 
echo(" You!")
resetFormat()
+
resetFormat()
</syntaxhighlight>
+
</syntaxhighlight>
 
+
 
==setBold==
+
==setBold==
;setBold(windowName, boolean)
+
;setBold(windowName, boolean)
: Sets the current text font to bold (true) or non-bold (false) mode. If the windowName parameters omitted, the main screen will be used. If you've got text currently selected in the Mudlet buffer, then the selection will be bolded. Any text you add after with [[Manual:Lua_Functions#echo|echo()]] or [[Manual:Lua_Functions#insertText|insertText()]] will be bolded until you use [[Manual:Lua_Functions#resetFormat|resetFormat()]].
+
: 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()]].
 
+
 
* ''windowName:''
+
* ''windowName:''
: Optional parameter set the current text background color in windowname given.
+
: Optional parameter set the current text background color in windowname given.
 
+
 
* ''boolean:''
+
* ''boolean:''
: A <code>true</code> or <code>false</code> that enables or disables bolding of text
+
: A <code>true</code> or <code>false</code> that enables or disables bolding of text
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
-- enable bold formatting
 +
setBold(true)
 +
-- the following echo will be bolded
 +
echo("hi")
 +
-- turns off bolding, italics, underlines and colouring. It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.
 +
resetFormat()
 +
</syntaxhighlight>
 +
 
 +
==setBorderBottom==
 +
;setBorderBottom(size)
 +
: Sets the size of the bottom border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
 +
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderBottom|getBorderBottom()]]
 +
 
 +
;Parameters
 +
* ''size:''
 +
: Height of the border in pixels - with 0 indicating no border.
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
setBorderBottom(150)
 +
</syntaxhighlight>
 +
 
 +
==setBorderColor==
 +
;setBorderColor(red, green, blue)
 +
: Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.
 +
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]]
 +
 
 +
;Parameters
 +
* ''red:''
 +
: Amount of red color to use, from 0 to 255.
 +
* ''green:''
 +
: Amount of green color to use, from 0 to 255.
 +
* ''blue:''
 +
: Amount of blue color to use, from 0 to 255.
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
-- set the border to be completely blue
 +
setBorderColor(0, 0, 255)
 +
 
 +
-- or red, using a name
 +
setBorderColor( unpack(color_table.red) )
 +
</syntaxhighlight>
 +
 
 +
==setBorderLeft==
 +
;setBorderLeft(size)
 +
: Sets the size of the left border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
 +
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderLeft|getBorderLeft()]]
 +
 
 +
;Parameters
 +
* ''size:''
 +
: Width of the border in pixels - with 0 indicating no border.
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
setBorderLeft(5)
 +
</syntaxhighlight>
 +
 
 +
==setBorderRight==
 +
;setBorderRight(size)
 +
: Sets the size of the right border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
 +
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderRight|getBorderRight()]]
 +
 
 +
;Parameters
 +
* ''size:''
 +
: Width of the border in pixels - with 0 indicating no border.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- enable bold formatting
+
setBorderRight(50)
setBold(true)
 
-- the following echo will be bolded
 
echo("hi")
 
-- turns off bolding, italics, underlines and colouring. It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.
 
resetFormat()
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==setBorderBottom==
+
==setBorderSizes==
;setBorderBottom(size)
+
;setBorderSizes(top, right, bottom, left)
: Sets the size of the bottom border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
+
: Sets the size of all borders of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
: See Also: [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]
+
: The exact result of this function depends on how many numbers you give to it as arguments.
 +
: 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()]]
  
;Parameters
+
: {{note}} Available since Mudlet 4.0
* ''size:''
 
: Height of the border in pixels - with 0 indicating no border.
 
  
;Example
+
;Arguments
<syntaxhighlight lang="lua">
+
* '''setBorderSizes(top, right, bottom, left)'''
setBorderLeft(100)
+
: ''4 arguments:'' All borders will be set to their new given size.
</syntaxhighlight>
+
* '''setBorderSizes(top, width, bottom)'''
 
+
: ''3 arguments:'' Top and bottom borders will be set to their new given size, and right and left will gain the same width.  
==setBorderColor==
+
* '''setBorderSizes(height, width)'''
;setBorderColor(r, g, b)
+
: ''2 arguments:'' Top and bottom borders will gain the same height, and right and left borders gain the same width.  
: Sets the color of the main windows border that you can create either with setBorderTop(), setBorderBottom(), setBorderLeft(), setBorderRight(), or via the main window settings.
+
* '''setBorderSizes(size)'''
: See Also: [[Manual:Lua_Functions#setBorderTop|setBorderTop()]], [[Manual:Lua_Functions#setBorderBottom|setBorderBottom()]], [[Manual:Lua_Functions#setBorderLeft|setBorderLeft()]], [[Manual:Lua_Functions#setBorderRight|setBorderRight()]]
+
: ''1 argument:'' All borders will be set to the same size.
 
+
* '''setBorderSizes()'''
;Parameters
+
: ''0 arguments:'' All borders will be hidden or set to size of 0 = no border.
* ''r:''
 
: Amount of red to use, from 0 to 255.
 
* ''g:''
 
: Amount of green to use, from 0 to 255.
 
* ''b:''
 
: Amount of blue to use, from 0 to 255.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- set the border to be completely blue
+
setBorderSizes(100, 50, 150, 0)
setBorderColor(0, 0, 255)
+
-- big border at the top, bigger at the bottom, small at the right, none at the left
  
-- or red, using a name
+
setBorderSizes(100, 50, 150)
setBorderColor( unpack(color_table.red) )
+
-- big border at the top, bigger at the bottom, small at the right and the left
</syntaxhighlight>
 
  
==setBorderLeft==
+
setBorderSizes(100, 50)  
;setBorderLeft(size)
+
-- big border at the top and the bottom, small at the right and the left
: Sets the size of the left border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
 
: See Also: [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]
 
  
;Parameters
+
setBorderSizes(100)
* ''size:''
+
-- big borders at all four sides
: Width of the border in pixels - with 0 indicating no border.
 
  
;Example
+
setBorderSizes()  
<syntaxhighlight lang="lua">
+
-- no borders at all four sides
setBorderLeft(100)
 
</syntaxhighlight>
 
 
 
==setBorderRight==
 
;setBorderRight(size)
 
: Sets the size of the right border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
 
: See Also: [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]
 
 
 
;Parameters
 
* ''size:''
 
: Width of the border in pixels - with 0 indicating no border.
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
setBorderRight(100)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 2,202: Line 2,557:
 
;setBorderTop(size)
 
;setBorderTop(size)
 
: Sets the size of the top border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
 
: Sets the size of the top border of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
: See Also: [[Manual:Lua_Functions#setBorderColor|setBorderColor()]]
+
: See Also: [[Manual:Lua_Functions#setBorderSizes|setBorderSizes()]], [[Manual:Lua_Functions#setBorderColor|setBorderColor()]], [[Manual:Lua_Functions#getBorderTop|getBorderTop()]]
  
 
;Parameters
 
;Parameters
Line 2,214: Line 2,569:
  
 
==setFgColor==
 
==setFgColor==
;setFgColor([windowName],r, g, b)
+
;setFgColor([windowName], red, green, blue)
 
:Sets the current text foreground color in the main window unless windowName parameter given.
 
:Sets the current text foreground color in the main window unless windowName parameter given.
  
 
* ''windowName:''
 
* ''windowName:''
 
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
 
: (optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
* ''r:''
+
* ''red:''
 
: The red component of the gauge color. Passed as an integer number from 0 to 255
 
: The red component of the gauge color. Passed as an integer number from 0 to 255
* ''g:''
+
* ''green:''
 
: The green component of the gauge color. Passed as an integer number from 0 to 255
 
: The green component of the gauge color. Passed as an integer number from 0 to 255
* ''b:''
+
* ''blue:''
 
: The blue component of the gauge color. Passed as an integer number from 0 to 255
 
: The blue component of the gauge color. Passed as an integer number from 0 to 255
  
Line 2,232: Line 2,587:
 
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.
 
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.
 
selectString( "Tom", 1 )
 
selectString( "Tom", 1 )
setFgColor( 255,0,0 )
+
setFgColor( 255, 0, 0 )
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 14:14, 7 September 2019

UI Functions

All functions that help you customize Mudlet's interface and the game's text.

ansi2decho

ansi2decho(text, default_colour)
Converts ANSI colour sequences in text to colour tags that can be processed by the decho() function. Italics and underline not currently supported since decho doesn't support them.
See also: decho()

Note Note:

ANSI bold is available since Mudlet 3.7.1+.
Parameters
  • text:
String that contains ANSI colour sequences that should be replaced.
  • default_colour:
Optional - ANSI default colour code (used when handling orphan bold tags).
Return values
  • string text:
The decho-valid converted text.
  • string colour:
The ANSI code for the last used colour in the substitution (useful if you want to colour subsequent lines according to this colour).
Example
local replaced = ansi2decho('\27[0;1;36;40mYou say in a baritone voice, "Test."\27[0;37;40m')
-- 'replaced' should now contain <r><0,255,255:0,0,0>You say in a baritone voice, "Test."<r><192,192,192:0,0,0>
decho(replaced)

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:

decho(ansi2decho([[
                                                  �[38;5;95m▄�[48;5;95;38;5;130m▄▄▄�[38;5;95m█�[49m▀�[0m    �[0m
╭───────────────────────╮          �[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
│                       │         �[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
│  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
│                       ├────  �[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
╰───────────────────────╯      �[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
                                �[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
                                  �[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
                                 �[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
                                �[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
                               �[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
                              �[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
                           �[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
                                �[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
                                �[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
                                �[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
                              �[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
                            �[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
                                  �[38;5;95m▀▀▀▀▀▀▀▀▀�[0m                 �[0m
                                                                    ]]))

Squirrel-in-Mudlet.png

Note Note:

Available in Mudlet 3.0+

appendBuffer

appendBuffer(name)
Pastes the previously copied rich text (including text formats like color etc.) into user window name.
See also: selectCurrentLine(), copy(), paste()
Parameters
  • name:
The name of the user window to paste into. Passed as a string.
Example
--selects and copies an entire line to user window named "Chat"
selectCurrentLine()
copy()
appendBuffer("Chat")

bg

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

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

calcFontSize

calcFontSize(window_or_fontsize, [fontname])
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.
Returns two numbers, width/height
See also: setMiniConsoleFontSize(), getMainWindowSize()
Parameters
  • window_or_fontsize:
The miniconsole or font size you are wanting to calculate pixel sizes for.
  • fontname:
Specific font name (along with the size as the first argument) to calculate for.

Note Note: Window as an argument is available in Mudlet 3.10+, and font name in Mudlet 4.1+.

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

cecho

cecho([window], text)
Echoes text that can be easily formatted with colour tags. You can also include unicode art in it - try some examples from 1lineart.
See also: decho(), hecho(), creplaceLine()
Parameters
  • window:
Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.
  • text:
The text to display, with color names inside angle brackets <>, ie <red>. If you'd like to use a background color, put it after a colon : - <:red>. You can use the <reset> tag to reset to the default color. You can select any from this list: Color Table
Example
cecho("Hi! This text is <red>red, <blue>blue, <green> and green.")

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

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

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

cecho("<green>(╯°□°)<dark_green>╯︵ ┻━┻")

cecho("°º¤ø,¸¸,ø¤º°`°º¤ø,¸,ø¤°º¤ø,¸¸,ø¤º°`°º¤ø,¸")

cecho([[
 ██╗    ██╗     ██╗███╗   ██╗███████╗     █████╗ ██████╗ ████████╗
███║    ██║     ██║████╗  ██║██╔════╝    ██╔══██╗██╔══██╗╚══██╔══╝
╚██║    ██║     ██║██╔██╗ ██║█████╗      ███████║██████╔╝   ██║
 ██║    ██║     ██║██║╚██╗██║██╔══╝      ██╔══██║██╔══██╗   ██║
 ██║    ███████╗██║██║ ╚████║███████╗    ██║  ██║██║  ██║   ██║
 ╚═╝    ╚══════╝╚═╝╚═╝  ╚═══╝╚══════╝    ╚═╝  ╚═╝╚═╝  ╚═╝   ╚═╝
]])


cechoLink

cechoLink([windowName], text, command, hint, true)
Echos a piece of text as a clickable link, at the end of the current selected line - similar to cecho(). This version allows you to use colours within your link text.
See also: echoLink(), dechoLink(), hechoLink()
Parameters
  • windowName:
optional parameter, allows selection between sending the link to a miniconsole or the main window.
  • text:
text to display in the echo. Same as a normal cecho().
  • command:
lua code to do when the link is clicked.
  • hint:
text for the tooltip to be displayed when the mouse is over the link.
  • true:
requires argument for the colouring to work.
Example
-- echo a link named 'press me!' that'll send the 'hi' command to the game
cechoLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)

cechoPopup

cechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like 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.
Parameters
  • windowName:
(optional) name of the window to echo to. Use either main or omit for the main window, or the miniconsoles name otherwise.
  • text:
the text to display
  • {commands}:
a table of lua code strings to do. ie, {[[send("hello")]], [[echo("hi!"]]}
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, {"send the hi command", "echo hi to yourself"}
  • useCurrentFormatElseDefault:
(optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example
-- Create some text as a clickable with a popup menu:
cechoPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)

Note Note: Available in Mudlet 4.1+

cinsertLink

cinsertLink([windowName], text, command, hint, true)
Echos a piece of text as a clickable link, at the end of the current cursor position - similar to cinsertText(). This version allows you to use colours within your link text.
See also: insertLink(), hinsertLink()
Parameters
  • windowName:
optional parameter, allows selection between sending the link to a miniconsole or the main window.
  • text:
text to display in the echo. Same as a normal cecho().
  • command:
lua code to do when the link is clicked.
  • hint:
text for the tooltip to be displayed when the mouse is over the link.
  • true:
requires argument for the colouring to work.
Example
-- echo a link named 'press me!' that'll send the 'hi' command to the game
cinsertLink("<red>press <brown:white>me!", [[send("hi")]], "This is a tooltip", true)

Note Note: Available in Mudlet 4.1+

cinsertPopup

cinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
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(). The added text, upon being left-clicked, will do the first command in the list. Upon being right-clicked, it'll display a menu with all possible commands. The menu will be populated with hints, one for each line.
Parameters
  • windowName:
(optional) name of the window to echo to. Use either main or omit for the main window, or the miniconsoles name otherwise.
  • text:
the text to display
  • {commands}:
a table of lua code strings to do. ie, {[[send("hello")]], [[echo("hi!"]]}
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, {"send the hi command", "echo hi to yourself"}
  • useCurrentFormatElseDefault:
(optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example
-- Create some text as a clickable with a popup menu:
cinsertPopup("<red>activities<reset> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)

Note Note: Available in Mudlet 4.1+

cinsertText

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

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

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

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

clearUserWindow

clearUserWindow(name)
This is (now) identical to clearWindow().

clearWindow

clearWindow([windowName])
Clears the label, mini console, or user window with the name given as argument (removes all text from it). If you don't give it a name, it will clear the main window (starting with Mudlet 2.0-test3+)
Parameters
  • windowName:
(optional) The name of the label, mini console, or user window to clear. Passed as a string.
Example
--This would clear a label, user window, or miniconsole with the name "Chat"
clearWindow("Chat")
-- this can clear your whole main window - needs Mudlet version >= 2.0
clearWindow()

copy

copy([windowName])
Copies the current selection to the clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the clipboard until it gets overwritten by another copy operation.
See also: selectString(), selectCurrentLine(), paste(), appendBuffer(), replace(), createMiniConsole(), openUserWindow()
Parameters
  • windowName (optional):
the window from which to copy text - use the main console if not specified.
Example
-- 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.
selectString(line, 1)
copy()
appendBuffer("chat")
replace("This line has been moved to the chat window!")

createBuffer

createBuffer(name)
Creates a named buffer for formatted text, much like a miniconsole, but the buffer is not intended to be shown on the screen - use it for formatting text or storing formatted text.
See also: selectString(), selectCurrentLine(), copy(), paste()
Parameters
  • name:
The name of the buffer to create.
Example
--This creates a named buffer called "scratchpad"
createBuffer("scratchpad")

createButton

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

createConsole

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

Note Note:

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

createGauge

createGauge(name, width, height, Xpos, Ypos, gaugeText, r, g, b, orientation)
createGauge(name, width, height, Xpos, Ypos, gaugeText, colorName, orientation)
Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.
See also: moveGauge(), setGauge(), setGaugeText(), setGaugeStyleSheet()
Parameters
  • name:
The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.
  • width:
The width of the gauge, in pixels. Passed as an integer number.
  • height:
The height of the gauge, in pixels. Passed as an integer number.
  • Xpos:
X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.
  • Ypos:
Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.
  • gaugeText:
Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil
  • r:
The red component of the gauge color. Passed as an integer number from 0 to 255
  • g:
The green component of the gauge color. Passed as an integer number from 0 to 255
  • b:
The blue component of the gauge color. Passed as an integer number from 0 to 255
  • colorName:
the name of color for the gauge. Passed as a string.
  • orientation:
the gauge orientation. Can be horizontal, vertical, goofy, or batty.
Example
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)
createGauge("healthBar", 300, 20, 30, 300, nil, "green")


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

Note Note:

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

createLabel

createLabel(name, Xpos, Ypos, width, height, fillBackground)
Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.
Returns true or false.
See also: hideWindow(), showWindow(), resizeWindow(), setLabelClickCallback(), setTextFormat(), getTextFormat(), moveWindow(), setBackgroundColor(), getMainWindowSize(), calcFontSize()
Parameters
  • name:
The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.
  • Xpos:
X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.
  • Ypos:
Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.
  • width:
The width of the label, in pixels. Passed as an integer number.
  • height:
The height of the label, in pixels. Passed as an integer number.
  • fillBackground:
Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.
Example
-- a label situated at x=300 y-400 with dimensions 100x200
createLabel("a very basic label",300,400,100,200,1)
-- this example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle
-- of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent
-- and 255 opaque) the background text can still be read through.
local width, height = getMainWindowSize()
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1)
resizeWindow("messageBox",500,70)
moveWindow("messageBox", (width/2)-300,(height/2)-100 )
setBackgroundColor("messageBox", 255, 204, 0, 200)
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]])

-- you can also make it react to clicks!
mynamespace = {
  messageBoxClicked = function()
    echo("hey you've clicked the box!\n")
  end
}

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


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

createMiniConsole

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

creplaceLine

creplaceLine (text)
Replaces the output line from the MUD with a colour-tagged string.

See Also: cecho(), cinsertText()

Parameters
  • text:
    The text to display, with color names inside angle brackets <>, ie <red>. If you'd like to use a background color, put it after a colon : - <:red>. You can use the <reset> tag to reset to the default color. You can select any from this list: Color Table
Example
creplaceLine("<magenta>[ALERT!]: <reset>"..line)

decho

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

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

dechoLink

dechoLink([windowName], text, command, hint, true)
Echos a piece of text as a clickable link, at the end of the current selected line - similar to decho(). This version allows you to use colours within your link text.
Parameters
  • windowName:
(optional) allows selection between sending the link to a miniconsole or the "main" window.
  • text:
text to display in the echo. Same as a normal decho().
  • command:
lua code to do when the link is clicked.
  • hint:
text for the tooltip to be displayed when the mouse is over the link.
  • true:
requires argument for the colouring to work.
Example
-- echo a link named 'press me!' that'll send the 'hi' command to the game
dechoLink("<50,50,0:0,255,0>press me!", [[send("hi")]], "This is a tooltip", true)

dechoPopup

dechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like 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.
Parameters
  • windowName:
(optional) name of the window to echo to. Use either main or omit for the main window, or the miniconsoles name otherwise.
  • text:
the text to display
  • {commands}:
a table of lua code strings to do. ie, {[[send("hello")]], [[echo("hi!"]]}
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, {"send the hi command", "echo hi to yourself"}
  • useCurrentFormatElseDefault:
(optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example
-- Create some text as a clickable with a popup menu:
dechoPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)

Note Note: Available in Mudlet 4.1+

dinsertLink

dinsertLink([windowName], text, command, hint, true)
Echos a piece of text as a clickable link, at the end of the current cursor position - similar to dinsertText(). This version allows you to use colours within your link text.
See also: insertLink(), hinsertLink()
Parameters
  • windowName:
optional parameter, allows selection between sending the link to a miniconsole or the main window.
  • text:
text to display in the echo. Same as a normal decho().
  • command:
lua code to do when the link is clicked.
  • hint:
text for the tooltip to be displayed when the mouse is over the link.
  • true:
requires argument for the colouring to work.
Example
-- echo a link named 'press me!' that'll send the 'hi' command to the game
dinsertLink("<255,0,0>press <165,42,42:255,255,255>me!", [[send("hi")]], "This is a tooltip", true)

Note Note: Available in Mudlet 4.1+

dinsertPopup

dinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
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(). The added text, upon being left-clicked, will do the first command in the list. Upon being right-clicked, it'll display a menu with all possible commands. The menu will be populated with hints, one for each line.
Parameters
  • windowName:
(optional) name of the window to echo to. Use either main or omit for the main window, or the miniconsoles name otherwise.
  • text:
the text to display
  • {commands}:
a table of lua code strings to do. ie, {[[send("hello")]], [[echo("hi!"]]}
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, {"send the hi command", "echo hi to yourself"}
  • useCurrentFormatElseDefault:
(optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example
-- Create some text as a clickable with a popup menu:
dinsertPopup("<255,0,0>activities<r> to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)

Note Note: Available in Mudlet 4.1+

deleteLine

deleteLine([windowName])
Deletes the current line under the user cursor. This is a high speed gagging tool and is very good at this task, but is only meant to be use when a line should be omitted entirely in the output. If you echo() to that line it will not be shown, and lines deleted with deleteLine() are simply no longer rendered. This is purely visual - triggers will still fire on the line as expected.
See also: replace(), wrapLine()
Parameters
  • windowName:
(optional) name of the window to delete the line in. If no name is given, it just deletes the line it is used on.

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

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

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

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

deselect

deselect([window name])
This is used to clear the current selection (to no longer have anything selected). Should be used after changing the formatting of text, to keep from accidentally changing the text again later with another formatting call.
See also: selectString(), selectCurrentLine()
Parameters
  • window name:
(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.
Example
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further
--changes from effecting this line as well.
selectCurrentLine()
bg("red")
deselect()

disableClickthrough

disableClickthrough(label)
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.
See also: enableClickthrough()
Parameters
  • label:
Name of the label to restore clickability on.

Note Note: Available since Mudlet 3.17

disableScrollBar

disableScrollBar(windowName)
Disables the scroll bar for the miniConsole named windowName
See Also: enableScrollBar()
Parameters
  • windowName:
The name of the window to disable the scroll bar in.

echoLink

echoLink([windowName], text, command, hint, [useCurrentFormatElseDefault])
Echos a piece of text as a clickable link, at the end of the current selected line - similar to echo().
See also: cechoLink(), hechoLink()
Parameters
  • windowName:
(optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
  • text:
Text to display in the echo. Same as a normal echo().
  • command:
Lua code to do when the link is clicked.
  • hint:
Text for the tooltip to be displayed when the mouse is over the link.
  • useCurrentFormatElseDefault:
If true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.
Example
-- echo a link named 'press me!' that'll send the 'hi' command to the game
echoLink("press me!", [[send("hi")]], "This is a tooltip")

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

echoUserWindow

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

echoPopup

echoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like echo. The added text, upon being left-clicked, will do the first command in the list. Upon being right-clicked, it'll display a menu with all possible commands. The menu will be populated with hints, one for each line.
Parameters
  • windowName:
(optional) name of the window to echo to. Use either main or omit for the main window, or the miniconsoles name otherwise.
  • text:
the text to display
  • {commands}:
a table of lua code strings to do. ie, {[[send("hello")]], [[echo("hi!"]]}
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, {"send the hi command", "echo hi to yourself"}
  • useCurrentFormatElseDefault:
(optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example
-- Create some text as a clickable with a popup menu:
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})

enableClickthrough

enableClickthrough(label)
Make a label 'invisible' to clicks - so if you have another label underneath, it'll be clicked on instead of this one on top.
This affects clicks, double-clicks, right-clicks, as well as the onEnter/onLeave events.
See also: disableClickthrough()
Parameters
  • label:
The name of the label to enable clickthrough on.

Note Note: Available since Mudlet 3.17

enableScrollBar

enableScrollBar(windowName)
Enables the scrollbar for the miniConsole named windowName.
See Also: disableScrollBar()
Parameters
  • windowName:
The name of the window to enable the scroll bar in.

fg

fg([window], colorName)
If used on a selection, sets the foreground color to colorName - otherwise, it will set the color of the next text-inserting calls (echo(), insertText, echoLink(), and others)
See Also: bg(), setBgColor()
Parameters
  • window:
(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).
  • colorName:
The name of the color to set the foreground to - list of possible names: Color Table
Example
--This would change the color of the text on the current line to green
selectCurrentLine()
fg("green")
resetFormat()

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

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

getAvailableFonts

fonts = getAvailableFonts()
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.
To install a new font with your package, include the font file in your zip/mpackage and it'll be automatically installed for you.
See also: getFont(), setFont()

Note Note: Available since Mudlet 3.10

Example
-- check if Ubuntu Mono is a font we can use
if getAvailableFonts()["Ubuntu Mono"] then
  -- make the miniconsole use the font at size 16
  setFont("my miniconsole", "Ubuntu Mono")
  setFontSize("my miniconsole", 16)
end

getBgColor

r, g, b = getBgColor(windowName)
This function returns the rgb values of the background color of the first character of the current selection on mini console (window) windowName. If windowName is omitted Mudlet will use the main screen.
See also: setBgColor()
Parameters
  • windowName:
A window to operate on - either a miniconsole or the main window.
Example
local r,g,b;
selectString("troll",1)
r,g,b = getBgColor()
if r == 255 and g == 0 and b == 0 then
    echo("HELP! troll is highlighted in red letters, the monster is aggressive!\n");
end

getBorderBottom

getBorderBottom()
Returns the size of the bottom border of the main window in pixels.
See also: getBorderSizes(), setBorderBottom()
Note Note: Available since Mudlet 4.0
Example
setBorderBottom(150)
getBorderBottom()
-- returns: 150

getBorderLeft

getBorderLeft()
Returns the size of the left border of the main window in pixels.
See also: getBorderSizes(), setBorderLeft()
Note Note: Available since Mudlet 4.0
Example
setBorderLeft(5)
getBorderLeft()
-- returns: 5

getBorderRight

getBorderRight()
Returns the size of the right border of the main window in pixels.
See also: getBorderSizes(), setBorderRight()
Note Note: Available since Mudlet 4.0
Example
setBorderRight(50)
getBorderRight()
-- returns: 50

getBorderSizes

getBorderSizes()
Returns the a named table with the sizes of all borders of the main window in pixels.
See also: setBorderSizes(), getBorderTop(), getBorderRight(),getBorderBottom(), getBorderLeft()
Note Note: Available since Mudlet 4.0
Example
setBorderSizes(100, 50, 150, 0)
getBorderSizes()
-- returns: { top = 100, right = 50, bottom = 150, left = 0 }
getBorderSizes().right
-- returns: 50

getBorderTop

getBorderTop()
Returns the size of the top border of the main window in pixels.
See also: getBorderSizes(), setBorderTop()
Note Note: Available since Mudlet 4.0
Example
setBorderTop(100)
getBorderTop()
-- returns: 100

getColorWildcard

AnsiNumber = getColorWildcard(ansi color number)
This function, given an ANSI color number (list), will return all strings on the current line that match it.
See also: isAnsiFgColor(), isAnsiBgColor()
Parameters
  • ansi color number:
A color number (list) to match.
Example
-- we can run this script on a line that has the players name coloured differently to easily capture it from
-- anywhere on the line
local match = getColorWildcard(14)

if match then
  echo("\nFound "..match.."!")
else
  echo("\nDidn't find anyone.")
end

getColumnCount

columns = getColumnCount([windowName])
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.
Parameters
  • windowName:
(optional) name of the window whose number of columns we want to calculate. By default it operates on the main window.

Note Note: Available since Mudlet 3.7.0

Example
print("Maximum number of columns on the main window "..getColumnCount())

getColumnNumber

column = getColumnNumber([windowName])
Gets the absolute column number of the current user cursor.
Parameters
  • windowName:
(optional) either be none or "main" for the main console, or a miniconsole / userwindow name.

Note Note: the argument is available since Mudlet 3.0.

Example
HelloWorld = Geyser.MiniConsole:new({
  name="HelloWorld",
  x="70%", y="50%",
  width="30%", height="50%",
})

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

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

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

getCurrentLine

content = getCurrentLine()
Returns the content of the current line under the user cursor in the buffer. The Lua variable line holds the content of getCurrentLine() before any triggers have been run on this line. When triggers change the content of the buffer, the variable line will not be adjusted and thus hold an outdated string. line = getCurrentLine() will update line to the real content of the current buffer. This is important if you want to copy the current line after it has been changed by some triggers. selectString( line,1 ) will return false and won't select anything because line no longer equals getCurrentLine(). Consequently, selectString( getCurrentLine(), 1 ) is what you need.
Example
print("Currently selected line: "..getCurrentLine())

getFgColor

r, g, b = getFgColor(windowName)
This function returns the rgb values of the color of the first character of the current selection on mini console (window) windowName. If windowName is omitted Mudlet will use the main screen.
Parameters
  • windowName:
A window to operate on - either a miniconsole or the main window.
Example
selectString("troll",1)
local r,g,b = getFgColor()
if r == 255 and g == 0 and b == 0 then
  echo("HELP! troll is written in red letters, the monster is aggressive!\n");
end

getFont

font = getFont(windowName)
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.
See also: setFont(), setFontSize(), openUserWindow(), getAvailableFonts()
Parameters
  • windowName:
The window name to get font size of - can either be none or "main" for the main console, or a miniconsole/userwindow name.

Note Note: Available in Mudlet 3.4+. Since Mudlet 3.10, returns the actual font that was used in case you didn't have the required font when using setFont().

Example
-- The following will get the "main" console font size.
display("Font in the main window: "..getFont())

display("Font in the main window: "..getFont("main"))

-- This will get the font size of a user window named "user window awesome".
display("Font size: " .. getFont("user window awesome"))

getFontSize

size = getFontSize(windowName)
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.
See Also: setFontSize(), openUserWindow()
Parameters
  • windowName:
The window name to get font size of - can either be none or "main" for the main console, or a UserWindow name.

Note Note: Available in Mudlet 3.4+

Example
-- The following will get the "main" console font size.
local mainWindowFontSize = getFontSize()
if mainWindowFontSize then
    display("Font size: " .. mainWindowFontSize)
end

local mainWindowFontSize = getFontSize("main")
if mainWindowFontSize then
    display("Font size: " .. fs2)
end

-- This will get the font size of a user window named "user window awesome".
local awesomeWindowFontSize = getFontSize("user window awesome")
if awesomeWindowFontSize then
    display("Font size: " .. awesomeWindowFontSize)
end

getLastLineNumber

line = getLastLineNumber(windowName)
Returns the latest line's number in the main window or the miniconsole. This could be different from getLineNumber() if the cursor was moved around.
Parameters
  • windowName:
name of the window to use. Either use main for the main window, or the name of the miniconsole.
Example
-- get the latest line's # in the buffer
local latestline = getLastLineNumber("main")

getLineCount

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

Need example

getLines

contents = getLines([windowName,] from_line_number, to_line_number)
Returns a section of the content of the screen text buffer. Returns a Lua table with the content of the lines on a per line basis. The form value is result = {relative_linenumber = line}.
Absolute line numbers are used.
Parameters
  • windowName
(optional) name of the miniconsole/userwindow to get lines for, or "main" for the main window (Mudlet 3.17+)
  • from_line_number:
First line number
  • to_line_number:
End line number
Example
-- retrieve & echo the last line:
echo(getLines(getLineNumber()-1, getLineNumber())[1])
-- find out which server and port you are connected to (as per Mudlet settings dialog):
local t = getLines(0, getLineNumber())

local server, port

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

display(server)
display(port)

getLineNumber

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

Note Note: The argument is available since Mudlet 3.0.

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

-- check how many lines you've got in your miniconsole after echoing some text.
-- Note the use of moveCursorEnd() to update getLineNumber()'s output
HelloWorld = Geyser.MiniConsole:new({
  name="HelloWorld",
  x="70%", y="50%",
  width="30%", height="50%",
})

print(getLineNumber("HelloWorld"))

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

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

getMainConsoleWidth

width = getMainConsoleWidth()
Returns a single number; the width of the main console (game output) in pixels. This also accounts for any borders that have been set.
See also: getMainWindowSize()
Parameters
None
Example
-- Save width of the main console to a variable for future use.
consoleWidth = getMainConsoleWidth()

getMousePosition

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

Note Note: Available since Mudlet 3.1+

Example
-- Retrieve x and y position of the mouse to determine where to create a new label, then use that position to create a new label
local x, y = getMousePosition()
createLabel("clickGeneratedLabel", x, y, 100, 100, 1)
-- if the label already exists, just move it
moveWindow("clickGeneratedLabel", x, y)
-- and make it easier to notice
setBackgroundColor("clickGeneratedLabel", 255, 204, 0, 200)

getMainWindowSize

width, height = getMainWindowSize()
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.
See also: setMainWindowSize(), getMainConsoleWidth()
Parameters
None
Example
--this will get the size of your main mudlet window and save them
--into the variables mainHeight and mainWidth
mainWidth, mainHeight = getMainWindowSize()

getRowCount

rows = getRowCount([windowName])
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.
Parameters
  • windowName:
(optional) name of the window whose maximum number of rows we want to calculate. By default it operates on the main window.

Note Note: Available since Mudlet 3.7.0

Example
print("Maximum of rows on the main window "..getRowCount())

getSelection

text, start, length = getSelection([windowName])
Returns the text currently selected with selectString(), selectSection(), or selectCurrentLine(). Note that this isn't the text currently selected with the mouse.
Parameters
  • windowName:
(optional) name of the window to get the selection from. By default it operates on the main window.

Note Note: Available since Mudlet 3.16.0

Example
selectCurrentLine()
print("Current selection is: "..getSelection())

getTextFormat

getTextFormat([windowName])
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.
See Also: setTextFormat()
Parameters
  • windowName
(optional) Specify name of selected window. If no name or "main" is given, the format will be gathered from the main console.

Note Note: Available since Mudlet 3.20.

Example
-- A suitable test for getTextFormat()
-- (copy it into an alias or a script)

clearWindow()

echo("\n")

local SGR = string.char(27)..'['
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")

moveCursor(1,1)
selectSection(1,1)

local results = getTextFormat()
echo("For first character in test line:\nBold detected: " .. tostring(results["bold"]))
echo("\nItalic detected: " .. tostring(results["italic"]))
echo("\nUnderline detected: " .. tostring(results["underline"]))
echo("\nReverse detected: " .. tostring(results["reverse"]))
echo("\nStrikeout detected: " .. tostring(results["strikeout"]))
echo("\nOverline detected: " .. tostring(results["overline"]))
echo("\nForeground color: (" .. results["foreground"][1] .. ", " .. results["foreground"][2] .. ", " .. results["foreground"][3] .. ")")
echo("\nBackground color: (" .. results["background"][1] .. ", " .. results["background"][2] .. ", " .. results["background"][3] .. ")")

selectSection(21,1)
echo("\n\nFor individual parts of test text:")
echo("\nBold detected (character 21): " .. tostring(results["bold"]))

selectSection(28,1)
echo("\nItalic detected (character 28): " .. tostring(results["italic"]))

selectSection(37,1)
echo("\nUnderline detected (character 37): " .. tostring(results["underline"]))

selectSection(67,1)
echo("\nReverse detected (character 67): " .. tostring(results["reverse"]))

selectSection(77,1)
echo("\nStrikeout detected (character 77): " .. tostring(results["strikeout"]))

selectSection(89,1)
echo("\nOverline detected (character 89): " .. tostring(results["overline"]))
echo("\n")

handleWindowResizeEvent

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

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

Parameters
None
Example
function handleWindowResizeEvent()
   -- determine the size of your screen
   WindowWidth=0;
   WindowHeight=0;
   WindowWidth, WindowHeight = getMainWindowSize();

   -- move mini console "sys" to the far right side of the screen whenever the screen gets resized
   moveWindow("sys",WindowWidth-300,0)
end

hasFocus

hasFocus()
Returns true or false depending if Mudlet's main window is currently in focus (ie, the user isn't focused on another window, like a browser). If multiple profiles are loaded, this can also be used to check if a given profile is in focus.
Parameters
None
Example
if attacked and not hasFocus() then
  runaway()
else
  fight()
end

hecho

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

hechoLink

hechoLink([windowName], text, command, hint, true)
Echos a piece of text as a clickable link, at the end of the current selected line - similar to hecho(). This version allows you to use colours within your link text.
See also: cechoLink(), dechoLink()
Parameters
  • windowName:
(optional) - allows selection between sending the link to a miniconsole or the main window.
  • text:
text to display in the echo. Same as a normal hecho().
  • command:
lua code to do when the link is clicked.
  • hint:
text for the tooltip to be displayed when the mouse is over the link.
  • true:
requires argument for the colouring to work.
Example
-- echo a link named 'press me!' that'll send the 'hi' command to the game
hechoLink("|ca00040black!", [[send("hi")]], "This is a tooltip", true)
-- # format also works
hechoLink("#ca00040black!", [[send("hi")]], "This is a tooltip", true)

hechoPopup

hechoPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
Creates text with a left-clickable link, and a right-click menu for more options at the end of the current line, like 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.
Parameters
  • windowName:
(optional) name of the window to echo to. Use either main or omit for the main window, or the miniconsoles name otherwise.
  • text:
the text to display
  • {commands}:
a table of lua code strings to do. ie, {[[send("hello")]], [[echo("hi!"]]}
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, {"send the hi command", "echo hi to yourself"}
  • useCurrentFormatElseDefault:
(optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example
-- Create some text as a clickable with a popup menu:
hechoPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)

Note Note: Available in Mudlet 4.1+

hinsertLink

hinsertLink([windowName], text, command, hint, true)
Echos a piece of text as a clickable link, at the end of the current cursor position - similar to hinsertText(). This version allows you to use colours within your link text.
See also: insertLink(), dinsertLink()
Parameters
  • windowName:
optional parameter, allows selection between sending the link to a miniconsole or the main window.
  • text:
text to display in the echo. Same as a normal hecho().
  • command:
lua code to do when the link is clicked.
  • hint:
text for the tooltip to be displayed when the mouse is over the link.
  • true:
requires argument for the colouring to work.
Example
-- echo a link named 'press me!' that'll send the 'hi' command to the game
hinsertLink("#ff0000press #a52a2a,ffffffme!", [[send("hi")]], "This is a tooltip", true)

Note Note: Available in Mudlet 4.1+

hinsertPopup

hinsertPopup([windowName], text, {commands}, {hints}, [useCurrentFormatElseDefault])
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(). The added text, upon being left-clicked, will do the first command in the list. Upon being right-clicked, it'll display a menu with all possible commands. The menu will be populated with hints, one for each line.
Parameters
  • windowName:
(optional) name of the window to echo to. Use either main or omit for the main window, or the miniconsoles name otherwise.
  • text:
the text to display
  • {commands}:
a table of lua code strings to do. ie, {[[send("hello")]], [[echo("hi!"]]}
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, {"send the hi command", "echo hi to yourself"}
  • useCurrentFormatElseDefault:
(optional) a boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example
-- Create some text as a clickable with a popup menu:
hinsertPopup("#ff0000activities#r to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"}, true)

Note Note: Available in Mudlet 4.1+

hideToolBar

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

hideWindow

hideWindow(name)
This function hides a mini console, a user window or a label with the given name. To show it again, use showWindow().
See also: createMiniConsole(), createLabel()
Parameters
  • name
specifies the label or console you want to hide.
Example
function miniconsoleTest()
  local windowWidth, windowHeight = getMainWindowSize()

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

  print("created red window top-right")

  tempTimer(1, function()
    hideWindow("sys")
    print("hid red window top-right")
  end)

  tempTimer(3, function()
    showWindow("sys")
    print("showed red window top-right")
  end)
end

miniconsoleTest()

insertLink

insertLink([windowName], text, command, hint, [useCurrentLinkFormat])
Inserts a piece of text as a clickable link at the current cursor position - similar to insertText().
Parameters
  • windowName:
(optional) the window to insert the link in - use either "main" or omit for the main window.
  • text:
text to display in the window. Same as a normal echo().
  • command:
lua code to do when the link is clicked.
  • hint:
text for the tooltip to be displayed when the mouse is over the link.
  • useCurrentLinkFormat:
(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.
Example
-- link with the default blue on white colors
insertLink("hey, click me!", [[echo("you clicked me!\n")]], "Click me popup")

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

insertPopup

insertPopup([windowName], text, {commands}, {hints}, [useCurrentLinkFormat])
Creates text with a left-clickable link, and a right-click menu for more options exactly where the cursor position is, similar to insertText(). The inserted text, upon being left-clicked, will do the first command in the list. Upon being right-clicked, it'll display a menu with all possible commands. The menu will be populated with hints, one for each line.
Parameters
  • windowName:
(optional) name of the window to echo to - use either main or omit for the main window, or the miniconsoles name otherwise.
  • name:
the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.
  • {lua code}:
a table of lua code strings to do. ie, {[[send("hello")]], [[echo("hi!"]]}.
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, {"send the hi command", "echo hi to yourself"}.
  • useCurrentLinkFormat:
(optional) boolean value for using either the current formatting options (colour, underline, italic) or the link default (blue underline).
Example
-- Create some text as a clickable with a popup menu:
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})

insertText

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

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

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

deselect()
resetFormat()
moveCursorEnd()

ioprint

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

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

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

Parameters
  • text:
The information you want to display.
Example
ioprint("hi!")
ioprint(1,2,3)
ioprint(myvariable, someothervariable, yetanothervariable)

isAnsiBgColor

isAnsiBgColor(ansiBgColorCode)
This function tests if the first character of the current selection has the background color specified by ansiBgColorCode.
Parameters
  • ansiBgColorCode:
A color code to test for, possible codes are:
0 = default text color
1 = light black
2 = dark black
3 = light red
4 = dark red
5 = light green
6 = dark green
7 = light yellow
8 = dark yellow
9 = light blue
10 = dark blue
11 = light magenta
12 = dark magenta
13 = light cyan
14 = dark cyan
15 = light white
16 = dark white
Example
selectString( matches[1], 1 )
if isAnsiBgColor( 5 ) then
    bg("red");
    resetFormat();
    echo("yes, the background of the text is light green")
else
    echo( "no sorry, some other backgroundground color" )
end

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

isAnsiFgColor

isAnsiFgColor(ansiFgColorCode)
This function tests if the first character of the current selection has the foreground color specified by ansiFgColorCode.
Parameters
  • ansiFgColorCode:
A color code to test for, possible codes are:
0 = default text color
1 = light black
2 = dark black
3 = light red
4 = dark red
5 = light green
6 = dark green
7 = light yellow
8 = dark yellow
9 = light blue
10 = dark blue
11 = light magenta
12 = dark magenta
13 = light cyan
14 = dark cyan
15 = light white
16 = dark white
Example
selectString( matches[1], 1 )
if isAnsiFgColor( 5 ) then
    bg("red");
    resetFormat();
    echo("yes, the text is light green")
else
    echo( "no sorry, some other foreground color" )
end

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

lowerWindow

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

Note Note: Available since Mudlet 3.1.0

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

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

lowerWindow("redLabel")                          --lowers redLabel, causing blueLabel to be back on top

moveCursor

moveCursor([windowName], x, y)
Moves the user cursor of the window windowName, or the main window, to the absolute point (x,y). This function returns false if such a move is impossible e.g. the coordinates don’t exist. To determine the correct coordinates use getLineNumber(), getColumnNumber() and getLastLineNumber(). The trigger engine will always place the user cursor at the beginning of the current line before the script is run. If you omit the windowName argument, the main screen will be used.
Returns true or false depending on if the cursor was moved to a valid position. Check this before doing further cursor operations - because things like deleteLine() might invalidate this.
Parameters
  • windowName:
(optional) The window you are going to move the cursor in.
  • x:
The horizontal axis in the window - that is, the letter position within the line.
  • y:
The vertical axis in the window - that is, the line number.
Example
-- move cursor to the start of the previous line and insert -<(
-- the first 0 means we want the cursor right at the start of the line,
-- and getLineNumber()-1 means we want the cursor on the current line# - 1 which
-- equals to the previous line
moveCursor(0, getLineNumber()-1)
insertText("-<(")

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

-- finally, reset it to the end where it was after our shenaningans - other scripts
-- could expect the cursor to be at the end
moveCursorEnd()
-- a more complicated example showing how to work with Mudlet functions

-- set up the small system message window in the top right corner
-- determine the size of your screen
local WindowWidth, WindowHeight = getMainWindowSize()

-- define a mini console named "sys" and set its background color
createMiniConsole("sys",WindowWidth-650,0,650,300)
setBackgroundColor("sys",85,55,0,255)

-- you *must* set the font size, otherwise mini windows will not work properly
setMiniConsoleFontSize("sys", 12)
-- wrap lines in window "sys" at 65 characters per line
setWindowWrap("sys", 60)
-- set default font colors and font style for window "sys"
setTextFormat("sys",0,35,255,50,50,50,0,0,0)
-- clear the window
clearUserWindow("sys")

moveCursorEnd("sys")
setFgColor("sys", 10,10,0)
setBgColor("sys", 0,0,255)
echo("sys", "test1---line1\n<this line is to be deleted>\n<this line is to be deleted also>\n")
echo("sys", "test1---line2\n")
echo("sys", "test1---line3\n")
setTextFormat("sys",158,0,255,255,0,255,0,0,0);
--setFgColor("sys",255,0,0);
echo("sys", "test1---line4\n")
echo("sys", "test1---line5\n")
moveCursor("sys", 1,1)

-- deleting lines 2+3
deleteLine("sys")
deleteLine("sys")

-- inserting a line at pos 5,2
moveCursor("sys", 5,2)
setFgColor("sys", 100,100,0)
setBgColor("sys", 255,100,0)
insertText("sys","############## line inserted at pos 5/2 ##############")

-- inserting a line at pos 0,0
moveCursor("sys", 0,0)
selectCurrentLine("sys")
setFgColor("sys", 255,155,255)
setBold( "sys", true );
setUnderline( "sys", true )
setItalics( "sys", true )
insertText("sys", "------- line inserted at: 0/0 -----\n")

setBold( "sys", true )
setUnderline( "sys", false )
setItalics( "sys", false )
setFgColor("sys", 255,100,0)
setBgColor("sys", 155,155,0)
echo("sys", "*** This is the end. ***\n")

moveCursorDown

moveCursorDown([windowName,] [lines,] [keepHorizontal])
Moves the cursor in the given window down a specified number of lines.
See also: moveCursor(), moveCursorUp(), moveCursorEnd()
Parameters
  • windowName:
(optional) name of the miniconsole/userwindow, or "main" for the main window.
  • lines:
(optional) number of lines to move cursor down by, or 1 by default.
  • keepHorizontal:
(optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.

Note Note: Available since Mudlet 3.17+

Example

Need example

moveCursorUp

moveCursorUp([windowName,] [lines,] [keepHorizontal])
Moves the cursor in the given window up a specified number of lines.
See also: moveCursor(), moveCursorDown(), moveCursorEnd()
Parameters
  • windowName:
(optional) name of the miniconsole/userwindow, or "main" for the main window.
  • lines:
(optional) number of lines to move cursor up by, or 1 by default.
  • keepHorizontal:
(optional) true/false to specify if horizontal position should be retained, or reset to the start of the line otherwise.

Note Note: Available since Mudlet 3.17+

Example

Need example

moveCursorEnd

moveCursorEnd([windowName])
Moves the cursor to the end of the buffer. "main" is the name of the main window, otherwise use the name of your user window.
See Also: moveCursor()
Returns true or false
Parameters
  • windowName:
(optional) name of the miniconsole/userwindow, or "main" for the main window.
Example

Need example

moveGauge

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

moveWindow

moveWindow(name, x, y)
This function moves window name to the given x/y coordinate. The main screen cannot be moved. Instead you’ll have to set appropriate border values → preferences to move the main screen e.g. to make room for chat or information mini consoles, or other GUI elements. In the future moveWindow() will set the border values automatically if the name parameter is omitted.
See Also: createMiniConsole(), createLabel(), handleWindowResizeEvent(), resizeWindow(), setBorderSizes(), openUserWindow()
Parameters
  • name:
The name of your window
  • newX:
The horizontal pixel location
  • newY:
The vertical pixel location

Note Note: Since Mudlet 3.7 this method can also be used on UserWindow consoles.

openUserWindow

openUserWindow(windowName, [restoreLayout])
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.
Parameters
  • windowName:
name of your window, it must be unique across ALL profiles if more than one is open (for multi-playing).
  • restoreLayout:
(optional) - only relevant, if false is provided. Then the window won't be restored to its last known position.

Note Note: Since Mudlet version 3.2, Mudlet will automatically remember the windows last position and the restoreLayout argument is available as well.

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

-- if you don't want Mudlet to remember its last position:
openUserWindow("My floating window", false)

paste

paste(windowName)
Pastes the previously copied text including all format codes like color, font etc. at the current user cursor position. The copy() and paste() functions can be used to copy formated text from the main window to a user window without losing colors e. g. for chat windows, map windows etc.
Parameters
  • windowName:
The name of your window

prefix

prefix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])
Prefixes text at the beginning of the current line when used in a trigger.
Parameters
  • text:
the information you want to prefix
  • "writingFunction:"
optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.
  • "foregroundColor:"
optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function
  • "backgroundColor:"
optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function
  • "windowName:"
optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed
Example
-- Prefix the hours, minutes and seconds onto our prompt even though Mudlet has a button for that
prefix(os.date("%H:%M:%S "))
-- Prefix the time in red into a miniconsole named "my_console"
prefix(os.date("<red>%H:%M:%S<reset>", cecho, nil, nil, "my_console"))
See also: suffix()

print

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

raiseWindow

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

Note Note: Available since Mudlet 3.1.0

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

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

raiseWindow("blueLabel")                          --raises blueLabel back at the top, above redLabel

replace

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

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

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

Parameters
  • windowName:
(optional) name of window (a miniconsole)
  • with:
the new text to display.
  • keepcolor:
(optional) argument, setting this to true will keep the existing colors (since Mudlet 3.0+)
Example
-- replace word "troll" with "cute trolly"
selectString("troll",1)
replace("cute trolly")

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

replaceAll

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

Note Note: This accepts Lua patterns

  • with:
the new text to have in place
Examples
-- replace all occurrences of the word "south" in the line with "north"
replaceAll("south", "north")
-- replace all occurrences of the text that the variable "target" has
replaceAll(target, "The Bad Guy")

replaceWildcard

replaceWildcard(which, replacement)
Replaces the given wildcard (as a number) with the given text. Equivalent to doing:
selectString(matches[2], 1)
replace("text")
Parameters
  • which:
Wildcard to replace.
  • replacement:
Text to replace the wildcard with.
Example
replaceWildcard(2, "hello") -- on a perl regex trigger of ^You wave (goodbye)\.$, it will make it seem like you waved hello

resetFormat

resetFormat()
Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.
Parameters
None
Example
-- select and set the 'Tommy' to red in the line
if selectString("Tommy", 1) ~= -1 then fg("red") end

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

-- another example: just highlighting some words
for _, word in ipairs{"he", "she", "her", "their"} do
  if selectString(word, 1) ~= -1 then
    bg("blue")
  end
end
resetFormat()

resizeWindow

resizeWindow(windowName, width, height)
Resizes a mini console, label, or floating User Windows.
See also: createMiniConsole(), createLabel(), handleWindowResizeEvent(), resizeWindow(), setBorderSizes(), openUserWindow()
Parameters
  • windowName:
The name of your window
  • width:
The new width you want
  • height:
The new height you want

Note Note: Since Mudlet 3.7 this method can also be used on UserWindow consoles, only if they are floating.

selectCaptureGroup

selectCaptureGroup(groupNumber)
Selects the content of the capture group number in your Perl regular expression (from matches[]). It does not work with multimatches.
See also: selectCurrentLine()
Parameters
  • groupNumber:
number of the capture group you want to select
Example
--First, set a Perl Reqular expression e.g. "you have (\d+) Euro".
--If you want to color the amount of money you have green you do:

selectCaptureGroup(1)
setFgColor(0,255,0)

selectCurrentLine

selectCurrentLine([windowName])
Selects the content of the current line that the cursor at. By default, the cursor is at the start of the current line that the triggers are processing, but you can move it with the moveCursor() function.

Note Note: This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower selectString(line, 1) selection method.

See also: selectString(), selectCurrentLine(), getSelection(), getCurrentLine()
Parameters
  • windowName:
(optional) name of the window in which to select text.
Example
-- color the whole line green!
selectCurrentLine()
fg("green")
deselect()
resetFormat()

-- to select the previous line, you can do this:
moveCursor(0, getLineNumber()-1)
selectCurrentLine()

-- to select two lines back, this:
moveCursor(0, getLineNumber()-2)
selectCurrentLine()

selectSection

selectSection( [windowName], fromPosition, length )
Selects the specified parts of the line starting from the left and extending to the right for however how long. The line starts from 0.
Returns true if the selection was successful, and false if the line wasn't actually long enough or the selection couldn't be done in general.
See also: selectString(), selectCurrentLine(), getSelection()
Parameters
  • "windowName:"
(optional) name of the window in which to select text. By default the main window, if no windowName is given.
Will not work if "main" is given as the windowName to try to select from the main window.
  • fromPosition:
number to specify at which position in the line to begin selecting
  • length:
number to specify the amount of characters you want to select
Example
-- select and colour the first character in the line red
if selectSection(0,1) then fg("red") end

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

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

selectString

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

Note Note: You can move the user cursor with moveCursor(). When a new line arrives from the MUD, the user cursor is positioned at the beginning of the line. However, if one of your trigger scripts moves the cursor around you need to take care of the cursor position yourself and make sure that the cursor is in the correct line if you want to call one of the select functions. To deselect text, see deselect().

Parameters
  • windowName:
(optional) name of the window in which to select text. By default the main window, if no windowName or an empty string is given.
  • text:
The text to select. It is matched as a substring match (so the text anywhere within the line will get selected).
  • number_of_match:
The occurrence of text on the line that you'd like to select. For example, if the line was "Bob and Bob", 1 would select the first Bob, and 2 would select the second Bob.
Returns position in line or -1 on error (text not found in line)

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

Example
if selectString( "big monster", 1 ) > -1 then fg("red") end

setAppStyleSheet

setAppStyleSheet(stylesheet [, tag])
Sets a stylesheet for the entire Mudlet application - allowing you to customise content outside of the main window (the profile tabs, the scrollbar, and so on). 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.
The event has two arguments in addition to the standard first one (the event name), the first of the additional ones is the optional argument to the function which can be used to identify something about the source of the new application style (see below), if it is omitted an empty string will be passed as the parameter; the second additional parameter is the profile that loaded the new style sheet. In combination these two parameters may be utilised to inform any package or script that modifies the styling of any part of the user-interface how it might need to adjust the appearance of that styling.
Parameters
  • stylesheet:
The entire stylesheet you'd like to use.
  • tag: (with Mudlet 3.19+)
An optional string tag or identifier that will be passed as a second argument in the sysAppStyleSheetChange event that is provided by that or later versions of Mudlet.
References
See Qt Style Sheets Reference for the list of widgets you can style and CSS properties you can apply on them.
See also QDarkStyleSheet, a rather extensive stylesheet that shows you all the different configuration options you could apply, available as an mpackage here.
Example
-- credit to Akaya @ http://forums.mudlet.org/viewtopic.php?f=5&t=4610&start=10#p21770
local background_color = "#26192f"
local border_color = "#b8731b"

setAppStyleSheet([[
  QMainWindow {
     background: ]]..background_color..[[;
  }
  QToolBar {
     background: ]]..background_color..[[;
  }
  QToolButton {
     background: ]]..background_color..[[;
     border-style: solid;
     border-width: 2px;
     border-color: ]]..border_color..[[;
     border-radius: 5px;
     font-family: BigNoodleTitling;
     color: white;
     margin: 2px;
     font-size: 12pt;
  }
  QToolButton:hover { background-color: grey;}
  QToolButton:focus { background-color: grey;}

  QTreeView {
     background: ]]..background_color..[[;
     color: white;
  }

  QMenuBar{ background-color: ]]..background_color..[[;}

  QMenuBar::item{ background-color: ]]..background_color..[[;}

  QDockWidget::title {
     background: ]]..border_color..[[;
  }
  QStatusBar {
     background: ]]..border_color..[[;
  }
  QScrollBar:vertical {
     background: ]]..background_color..[[;
     width: 15px;
     margin: 22px 0 22px 0;
  }
  QScrollBar::handle:vertical {
     background-color: ]]..background_color..[[;
     min-height: 20px;
     border-width: 2px;
     border-style: solid;
     border-color: ]]..border_color..[[;
     border-radius: 7px;
  }
  QScrollBar::add-line:vertical {
   background-color: ]]..background_color..[[;
   border-width: 2px;
   border-style: solid;
   border-color: ]]..border_color..[[;
   border-bottom-left-radius: 7px;
   border-bottom-right-radius: 7px;
        height: 15px;
        subcontrol-position: bottom;
        subcontrol-origin: margin;
  }
  QScrollBar::sub-line:vertical {
   background-color: ]]..background_color..[[;
   border-width: 2px;
   border-style: solid;
   border-color: ]]..border_color..[[;
   border-top-left-radius: 7px;
   border-top-right-radius: 7px;
        height: 15px;
        subcontrol-position: top;
        subcontrol-origin: margin;
  }
  QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
     background: white;
     width: 4px;
     height: 3px;
  }
  QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
     background: none;
  }
]])

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

-- to only affect scrollbars within the main window and miniconsoles, prefix them with 'TConsole':
setAppStyleSheet[[
  TConsole QScrollBar:vertical {
      border: 2px solid grey;
      background: #32CC99;
      width: 15px;
      margin: 22px 0 22px 0;
  }
  TConsole QScrollBar::handle:vertical {
      background: white;
      min-height: 20px;
  }
  TConsole QScrollBar::add-line:vertical {
      border: 2px solid grey;
      background: #32CC99;
      height: 20px;
      subcontrol-position: bottom;
      subcontrol-origin: margin;
  }
  TConsole QScrollBar::sub-line:vertical {
      border: 2px solid grey;
      background: #32CC99;
      height: 20px;
      subcontrol-position: top;
      subcontrol-origin: margin;
  }
  TConsole QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
      border: 2px solid grey;
      width: 3px;
      height: 3px;
      background: white;
  }
  TConsole QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
      background: none;
  }
]]

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

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

Note Note: Available since Mudlet 3.0.

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

setBackgroundColor

setBackgroundColor([windowName], r, g, b, transparency)
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).

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

Parameters
  • windowName:
(optional) name of the label/miniconsole/userwindow to change the background color on, or "main" for the main window.
  • r:
Amount of red to use, from 0 (none) to 255 (full).
  • g:
Amount of green to use, from 0 (none) to 255 (full).
  • b:
Amount of red to use, from 0 (none) to 255 (full).
  • transparency:
Amount of transparency to use, from 0 (fully transparent) to 255 (fully opaque).

Note Note: The parameter windowName supports "main" since Mudlet 3.10.

Example
-- make a red label that's somewhat transparent
setBackgroundColor("some label",255,0,0,200)

setBackgroundImage

setBackgroundImage(labelName, imageLocation)
Loads an image file (png) as a background image for a label. This can be used to display clickable buttons in combination with setLabelClickCallback() and such.

Note Note: You can only do this for labels, not miniconsoles.

Note Note: You can also load images via setLabelStyleSheet().

Parameters
  • labelName:
The name of the label to change it's background color.
  • imageLocation:
The full path to the image location. It's best to use [[ ]] instead of "" for it - because for Windows paths, backslashes need to be escaped.
Example
-- give the top border a nice look
setBackgroundImage("top bar", [[/home/vadi/Games/Mudlet/games/top_bar.png]])

setBgColor

setBgColor([windowName], r, g, b)
Sets the current text background color in the main window unless windowName parameter given. If you have selected text prior to this call, the selection will be highlighted otherwise the current text background color will be changed. If you set a foreground or background color, the color will be used until you call resetFormat() on all further print commands.
See also: cecho()
Parameters
  • windowName:
(optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
  • r:
The red component of the gauge color. Passed as an integer number from 0 to 255
  • g:
The green component of the gauge color. Passed as an integer number from 0 to 255
  • b:
The blue component of the gauge color. Passed as an integer number from 0 to 255
Example
--highlights the first occurrence of the string "Tom" in the current line with a red background color.
selectString( "Tom", 1 )
setBgColor( 255,0,0 )
--prints "Hello" on red background and "You" on blue.
setBgColor(255,0,0)
echo("Hello")
setBgColor(0,0,255)
echo(" You!")
resetFormat()

setBold

setBold(windowName, boolean)
Sets the current text font to bold (true) or non-bold (false) mode. If the windowName parameters omitted, the main screen will be used. If you've got text currently selected in the Mudlet buffer, then the selection will be bolded. Any text you add after with echo() or insertText() will be bolded until you use resetFormat().
  • windowName:
Optional parameter set the current text background color in windowname given.
  • boolean:
A true or false that enables or disables bolding of text
Example
-- enable bold formatting
setBold(true)
-- the following echo will be bolded
echo("hi")
-- turns off bolding, italics, underlines and colouring. It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.
resetFormat()

setBorderBottom

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

setBorderColor

setBorderColor(red, green, blue)
Sets the color of the main windows border that you can create either with lua commands, or via the main window settings.
See Also: setBorderSizes()
Parameters
  • red:
Amount of red color to use, from 0 to 255.
  • green:
Amount of green color to use, from 0 to 255.
  • blue:
Amount of blue color to use, from 0 to 255.
Example
-- set the border to be completely blue
setBorderColor(0, 0, 255)

-- or red, using a name
setBorderColor( unpack(color_table.red) )

setBorderLeft

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

setBorderRight

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

setBorderSizes

setBorderSizes(top, right, bottom, left)
Sets the size of all borders of the main window in pixels. A border means that the MUD text won't go on it, so this gives you room to place your graphical elements there.
The exact result of this function depends on how many numbers you give to it as arguments.
See also: getBorderSizes(), setBorderTop(), setBorderRight(), setBorderBottom(), setBorderLeft(), setBorderColor()
Note Note: Available since Mudlet 4.0
Arguments
  • setBorderSizes(top, right, bottom, left)
4 arguments: All borders will be set to their new given size.
  • setBorderSizes(top, width, bottom)
3 arguments: Top and bottom borders will be set to their new given size, and right and left will gain the same width.
  • setBorderSizes(height, width)
2 arguments: Top and bottom borders will gain the same height, and right and left borders gain the same width.
  • setBorderSizes(size)
1 argument: All borders will be set to the same size.
  • setBorderSizes()
0 arguments: All borders will be hidden or set to size of 0 = no border.
Example
setBorderSizes(100, 50, 150, 0) 
-- big border at the top, bigger at the bottom, small at the right, none at the left

setBorderSizes(100, 50, 150) 
-- big border at the top, bigger at the bottom, small at the right and the left

setBorderSizes(100, 50) 
-- big border at the top and the bottom, small at the right and the left

setBorderSizes(100) 
-- big borders at all four sides

setBorderSizes() 
-- no borders at all four sides

setBorderTop

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

setFgColor

setFgColor([windowName], red, green, blue)
Sets the current text foreground color in the main window unless windowName parameter given.
  • windowName:
(optional) either be none or "main" for the main console, or a miniconsole / userwindow name.
  • red:
The red component of the gauge color. Passed as an integer number from 0 to 255
  • green:
The green component of the gauge color. Passed as an integer number from 0 to 255
  • blue:
The blue component of the gauge color. Passed as an integer number from 0 to 255
See also: setBgColor(), setHexFgColor(), setHexBgColor()
Example
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.
selectString( "Tom", 1 )
setFgColor( 255, 0, 0 )

setButtonStyleSheet

setButtonStyleSheet(button, markup)
Applies Qt style formatting to a button via a special markup language.
Parameters
  • button:
The name of the button to be formatted.
  • markup:
The string instructions, as specified by the Qt Style Sheet reference.
References
http://qt-project.org/doc/qt-5/stylesheet-reference.html
Example
setLabelStyleSheet("my test button", [[
  background-color: white;
  border: 10px solid green;
  font-size: 12px;
  ]])

setFont

setFont(name, font)
Sets the font on the given window or console name. Can be used to change font of the main console, miniconsoles, and userwindows. Use a monospaced font - non-monospace fonts are not supported in Mudlet. See here for more.
See also: getFont(), setFontSize(), getFontSize(), openUserWindow(), getAvailableFonts()
Parameters
  • name:
Optional - the window name to set font size of - can either be none or "main" for the main console, or a miniconsole / userwindow name.
  • font:
The font to use.

Note Note: Available in Mudlet 3.9+

Example
-- The following will set the "main" console window font to Ubuntu Mono, another font included in Mudlet.
setFont("Ubuntu Mono")
setFont("main", "Ubuntu Mono")

-- This will set the font size of a miniconsole named "combat" to Ubuntu Mono.
setFont("combat", "Ubuntu Mono")

setFontSize

setFontSize(name, size)
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.
See Also: getFontSize(), openUserWindow()
Parameters
  • name:
Optional - the window name to set font size of - can either be none or "main" for the main console, or a UserWindow name.
  • size:
The font size to apply to the window.

Note Note: Available in Mudlet 3.4+

Example
-- The following will set the "main" console window font to 12-point font.
setFontSize(12)
setFontSize("main", 12)

-- This will set the font size of a user window named "uw1" to 12-point font.
setFontSize("uw1", 12)

setGauge

setGauge(gaugeName, currentValue, maxValue, gaugeText)
Use this function when you want to change the gauges look according to your values. Typical usage would be in a prompt with your current health or whatever value, and throw in some variables instead of the numbers.
See also: moveGauge(), createGauge(), setGaugeText()
Example
-- create a gauge
createGauge("healthBar", 300, 20, 30, 300, nil, "green")

--Change the looks of the gauge named healthBar and make it
--fill to half of its capacity. The height is always remembered.
setGauge("healthBar", 200, 400)
--If you wish to change the text on your gauge, you’d do the following:
setGauge("healthBar", 200, 400, "some text")

setGaugeStyleSheet

setGaugeStyleSheet(gaugeName, css, cssback, csstext)
Sets the CSS stylesheets on a gauge - one on the front (the part that resizes accoding to the values on the gauge) and one in the back.
Example
setGaugeStyleSheet("hp_bar", [[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f04141, stop: 0.1 #ef2929, stop: 0.49 #cc0000, stop: 0.5 #a40000, stop: 1 #cc0000);
border-top: 1px black solid;
border-left: 1px black solid;
border-bottom: 1px black solid;
border-radius: 7;
padding: 3px;]],
[[background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #bd3333, stop: 0.1 #bd2020, stop: 0.49 #990000, stop: 0.5 #700000, stop: 1 #990000);
border-width: 1px;
border-color: black;
border-style: solid;
border-radius: 7;
padding: 3px;]])

setGaugeText

setGaugeText(gaugename, css, ccstext )
Set the formatting of the text used inside the inserted gaugename.
Example
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>]])
Useful resources
http://csstxt.com - Generate the text exactly how you like it before pasting it into the css slot.
https://www.w3schools.com/colors/colors_picker.asp - Can help you choose colors for your text!

setHexBgColor

setHexFgColor([windowName], hexColorString)
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.
  • windowName:
Optional parameter set the current text background color in windowname given.
  • hexColorString
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
See also: setBgColor(), setHexFgColor()
Example
--highlights the first occurrence of the string "Tom" in the current line with a red Background color.
selectString( "Tom", 1 )
setHexBgColor( "FF0000" )

setHexFgColor

setHexFgColor([windowName], hexColorString)
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.
  • windowName:
Optional parameter set the current text foreground color in windowname given.
  • hexColorString
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
See also: setFgColor(), setHexBgColor()
Example
--highlights the first occurrence of the string "Tom" in the current line with a red foreground color.
selectString( "Tom", 1 )
setHexFgColor( "FF0000" )

setItalics

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

setLabelClickCallback

setLabelClickCallback(labelName, luaFunctionName, [any arguments])
Specifies a Lua function to be called if the user clicks on the label/image. This function can pass any number of string or integer number values as additional parameters. These parameters are then used in the callback - thus you can associate data with the label/button. 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:
luaFuncName(optional number of arguments, event)

where event has the following structure:

event = {
  x = 100,
  y = 200,
  globalX = 300,
  globalY = 320,
  button = "LeftButton",
  buttons = {"RightButton", "MidButton"},
}
See also: setLabelDoubleClickCallback(), setLabelReleaseCallback(), setLabelMoveCallback(), setLabelWheelCallback(),setLabelOnEnter(), setLabelOnLeave()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string.
  • any arguments:
(optional) Any amount of arguments you'd like to pass to the calling function.

Note Note: Event argument only available in 3.6+

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

The following mouse button strings are defined:
"LeftButton"        "RightButton"        "MidButton"
"BackButton"        "ForwardButton"      "TaskButton"
"ExtraButton4"      "ExtraButton5"       "ExtraButton6"
"ExtraButton7"      "ExtraButton8"       "ExtraButton9"
"ExtraButton10"     "ExtraButton11"      "ExtraButton12"
"ExtraButton13"     "ExtraButton14"      "ExtraButton15"
"ExtraButton16"     "ExtraButton17"      "ExtraButton18"
"ExtraButton19"     "ExtraButton20"      "ExtraButton21"
"ExtraButton22"     "ExtraButton23"      "ExtraButton24"
Example
function onClickGoNorth(event)
  if event.button == "LeftButton" then
    send("walk north")
  else if event.button == "RightButton" then
    send("swim north")
  else if event.button == "MidButton" then
    send("gallop north")
  end
end

setLabelClickCallback( "compassNorthImage", "onClickGoNorth" )

-- you can also use them within tables now:
mynamespace = {
  onClickGoNorth = function()
    echo("the north button was clicked!")
  end
}

setLabelClickCallback( "compassNorthImage", "mynamespace.onClickGoNorth" )

setLabelDoubleClickCallback

setLabelDoubleClickCallback(labelName, luaFunctionName, [any arguments])
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 setLabelClickCallback()

Note Note: Available in Mudlet 3.6+

See also: setLabelClickCallback(), setLabelReleaseCallback(), setLabelMoveCallback(), setLabelWheelCallback(), setLabelOnEnter(), setLabelOnLeave()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string.
  • any arguments:
(optional) Any amount of arguments you'd like to pass to the calling function.

setLabelMoveCallback

setLabelMoveCallback(labelName, luaFunctionName, [any arguments])
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 setLabelClickCallback()
See Also: setLabelClickCallback(), setLabelDoubleClickCallback(), setLabelReleaseCallback(), setLabelWheelCallback(), setLabelOnEnter(), setLabelOnLeave()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string.
  • any arguments:
(optional) Any amount of arguments you'd like to pass to the calling function.

Note Note: Available since Mudlet 3.6

setLabelOnEnter

setLabelOnEnter(labelName, luaFunctionName, [any arguments])
Specifies a Lua function to be called when the mouse enters within the labels borders. This function can pass any number of string or integer number values as additional parameters. These parameters are then used in the callback - thus you can associate data with the label/button. Additionally, this function passes an event table as the final argument, similar to setLabelClickCallback(), but with slightly different information.
For this callback, the event argument has the following structure:
event = {
  x = 100,
  y = 200,
  globalX = 300,
  globalY = 320,
}
See Also: setLabelClickCallback(), setLabelDoubleClickCallback(), setLabelReleaseCallback(), setLabelMoveCallback(), setLabelWheelCallback(), setLabelOnLeave()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).
  • any arguments:
(optional) Any amount of arguments you'd like to pass to the calling function.
Example
function onMouseOver()
  echo("The mouse is hovering over the label!\n")
end

setLabelOnEnter( "compassNorthImage", "onMouseOver" )

setLabelOnLeave

setLabelClickCallback(labelName, luaFunctionName, [any arguments])
Specifies a Lua function to be called when the mouse leaves the labels borders. This function can pass any number of string or integer number values as additional parameters. These parameters are then used in the callback - thus you can associate data with the label/button.
See Also: setLabelClickCallback(), setLabelOnEnter()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).
  • any arguments:
(optional) Any amount of arguments you'd like to pass to the calling function.
Example
function onMouseLeft(argument)
  echo("The mouse quit hovering over the label the label! We also got this as data on the function: "..argument)
end

setLabelOnLeave( "compassNorthImage", "onMouseLeft", "argument to pass to function" )

setLabelReleaseCallback

setLabelReleaseCallback(labelName, luaFunctionName, [any arguments])
Specifies a Lua function to be called when a mouse click ends that originated on the specified label/console. This function is called even if you drag the mouse off of the label/console before releasing the click. This function can pass any number of string or integer number values as additional parameters. These parameters are then used in the callback - thus you can associate data with the label/button. Additionally, this function passes an event table as the final argument, as in setLabelClickCallback()
See Also: setLabelClickCallback(), setLabelDoubleClickCallback(), setLabelMoveCallback(), setLabelWheelCallback(), setLabelOnEnter(), setLabelOnLeave()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string.
  • any arguments:
(optional) Any amount of arguments you'd like to pass to the calling function.

Note Note: This command was added in version 3.0.0

Note Note: The event argument only available since Mudlet 3.6

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

setLabelReleaseCallback( "compassNorthImage", "onReleaseNorth" )

-- you can also use them within tables:
mynamespace = {
  onReleaseNorth = function()
    echo("the north button was released!")
  end
}

setLabelReleaseCallback( "compassNorthImage", "mynamespace.onReleaseNorth" )

setLabelStyleSheet

setLabelStyleSheet(label, markup)
Applies Qt style formatting to a label via a special markup language.
Parameters
  • label:
The name of the label to be formatted (passed when calling createLabel).
  • markup:
The string instructions, as specified by the Qt Style Sheet reference.
Note that when specifying a file path for styling purposes, forward slashes, / , must be used, even if your OS uses backslashes, \ , normally.
References
http://qt-project.org/doc/qt-5/stylesheet-reference.html
Example
-- This creates a label with a white background and a green border, with the text "test"
-- inside.
createLabel("test", 50, 50, 100, 100, 0)
setLabelStyleSheet("test", [[
  background-color: white;
  border: 10px solid green;
  font-size: 12px;
  ]])
echo("test", "test")

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

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

setLabelWheelCallback

setLabelWheelCallback(labelName, luaFunctionName, [any arguments])
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 setLabelClickCallback(), but with slightly different information.
For this callback, the event argument has the following structure:
event = {
  x = 100,
  y = 200,
  globalX = 300,
  globalY = 320,
  buttons = {"RightButton", "MidButton"},
  angleDeltaX = 0,
  angleDeltaY = 120
}
Keys angleDeltaX and angleDeltaY correspond with the horizontal and vertical scroll distance, respectively. For most mice, these values will be multiples of 120.
See Also: setLabelClickCallback(), setLabelDoubleClickCallback(), setLabelReleaseCallback(), setLabelMoveCallback(), setLabelOnEnter(), setLabelOnLeave()
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string.
  • any arguments:
(optional) Any amount of arguments you'd like to pass to the calling function.

Note Note: Available since Mudlet 3.6

Example
function onWheelNorth(event)
  if event.angleDeltaY > 0 then
    echo("the north button was wheeled forwards over!")
  else
    echo("the north button was wheeled backwards over!")
  end
end

setLabelWheelCallback( "compassNorthImage", "onWheelNorth" )

-- you can also use them within tables:
mynamespace = {
  onWheelNorth = function()
    echo("the north button was wheeled over!")
  end
}

setWheelReleaseCallback( "compassNorthImage", "mynamespace.onWheelNorth" )

setLink

setLink([windowName], command, tooltip)
Turns the selected() text into a clickable link - upon being clicked, the link will do the command code. Tooltip is a string which will be displayed when the mouse is over the selected text.
Parameters
  • windowName:
(optional) name of a miniconsole or a userwindow in which to select the text in.
  • command:
command to do when the text is clicked.
  • tooltip:
tooltip to show when the mouse is over the text - explaining what would clicking do.
Example
-- you can clickify a lot of things to save yourself some time - for example, you can change
--  the line where you receive a message to be clickable to read it!
-- prel regex trigger:
-- ^You just received message #(\w+) from \w+\.$
-- script:
selectString(matches[2], 1)
setUnderline(true) setLink([[send("msg read ]]..matches[2]..[[")]], "Read #"..matches[2])
resetFormat()

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

HelloWorld = Geyser.MiniConsole:new({
  name="HelloWorld",
  x="70%", y="50%",
  width="30%", height="50%",
})
HelloWorld:echo("hi")
selectString("HelloWorld", "hi", 1)
setLink("HelloWorld", "echo'you clicked hi!'", "click me!")

setMainWindowSize

setMainWindowSize(mainWidth, mainHeight)
Changes the size of your main Mudlet window to the values given.
See Also: getMainWindowSize()
Parameters
  • mainWidth:
The new width in pixels.
  • mainHeight:
The new height in pixels.
Example
--this will resize your main Mudlet window
setMainWindowSize(1024, 768)

setMiniConsoleFontSize

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

setOverline

setOverline([windowName], boolean)
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 echo() or insertText() will be overlined until you use resetFormat().
  • windowName:
(optional) name of the window to set the text to be overlined or not.
  • boolean:
A true or false that enables or disables overlining of text
Example
-- enable overlined text
setOverline(true)
-- the following echo will be have an overline
echo("hi")
-- 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.
resetFormat()

Note Note: Available since Mudlet 3.17+

setPopup

setPopup(windowName, {lua code}, {hints})
Turns the selected() text into a left-clickable link, and a right-click menu for more options. The selected text, upon being left-clicked, will do the first command in the list. Upon being right-clicked, it'll display a menu with all possible commands. The menu will be populated with hints, one for each line.
Parameters
  • windowName:
the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.
  • {lua code}:
a table of lua code strings to do. ie, {[[send("hello")]], [[echo("hi!"]]}
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, {"send the hi command", "echo hi to yourself"}.
Example
-- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger,
-- the following code will make left-clicking on `Hello` show you an echo, while right-clicking
-- will show some commands you can do.

selectString("Hello", 1)
setPopup("main", {[[send("bye")]], [[echo("hi!")]]}, {"left-click or right-click and do first item to send bye", "click to echo hi"})

setReverse

setReverse([windowName], boolean)
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 echo() or insertText() will have their foreground and background colors swapped until you use resetFormat().
  • windowName:
(optional) name of the window to set the text colors to be reversed or not.
  • boolean:
A true or false that enables or disables reversing of the fore- and back-ground colors of text
Example
-- enable fore/back-ground color reversal of text
setReverse(true)
-- the following echo will have the text colors reversed
echo("hi")
-- 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.
resetFormat()

Note Note: Available since Mudlet 3.17+

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

setStrikeOut

setStrikeOut([windowName], boolean)
Sets the current text font to be striken out (true) or not striken out (false) mode. If the windowName parameters omitted, the main screen will be used. If you've got text currently selected in the Mudlet buffer, then the selection will be bolded. Any text you add after with echo() or insertText() will be striken out until you use resetFormat().
  • windowName:
(optional) name of the window to set the text to be stricken out or not.
  • boolean:
A true or false that enables or disables striking out of text
Example
-- enable striken-out text
setStrikeOut(true)
-- the following echo will be have a strikethrough
echo("hi")
-- turns off bolding, italics, underlines, colouring, and strikethrough. It's good practice to clean up after you're done with the formatting, so other your formatting doesn't "bleed" into other echoes.
resetFormat()

setTextFormat

setTextFormat(windowName, r1, g1, b1, r2, g2, b2, bold, underline, italics, [strikeout], [overline], [reverse])
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( windowName, r,g,b ), setBold( windowName, true ), setItalics( windowName, true ), setUnderline( windowName, true ), setStrikeOut( windowName, true ).
See Also: getTextFormat()
Parameters
  • windowName
Specify name of selected window. If empty string "" or "main" format will be applied to the main console
  • r1,g1,b1
To color text background, give number values in RBG style
  • r2,g2,b2
To color text foreground, give number values in RBG style
  • bold
To format text bold, set to 1 or true, otherwise 0 or false
  • underline
To underline text, set to 1 or true, otherwise 0 or false
  • italics
To format text italic, set to 1 or true, otherwise 0 or false
  • strikeout
(optional) To strike text out, set to 1 or true, otherwise 0 or false or simply no argument
  • overline
(optional) To use overline, set to 1 or true, otherwise 0 or false or simply no argument
  • reverse
(optional) To swap foreground and background colors, set to 1 or true, otherwise 0 or false or simply no argument
Example
--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".
createMiniConsole( "con1", 0,0,300,100);
setTextFormat("con1",0,0,255,255,255,0,true,0,false,1);
echo("con1","This is a test")

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

setUnderline

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

setWindowWrap

setWindowWrap(windowName, wrapAt)
sets at what position in the line the will start word wrap.
Parameters
  • windowName:
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".
  • wrapAt:
Number of characters at which the wrap must happen at the latest. This means, it probably will be wrapped earlier than that.
Example
setWindowWrap("main", 10)
display("This is just a test")

-- The following output will result in the main window console:
"This is
just a
test"

showCaptureGroups

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

showMultimatches

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

showWindow

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

showColors

showColors([columns], [filterColor], [sort])
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}.
See Also: bg(), fg(), cecho()
Parameters
  • columns:
(optional) number of columns to print the color table in.
  • filterColor:
(optional) filter text. If given, the colors displayed will be limited to only show colors containing this text.
  • sort:
(optional) sort colors alphabetically.
Example
-- display as four columns:
showColors(4)

-- show only red colours:
showColors("red")

The output for this is:

showColors(4)

showToolBar

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

suffix

suffix(text, [writingFunction], [foregroundColor], [backgroundColor], [windowName])
Suffixes text at the end of the current line. This is similar to echo(), which also suffixes text at the end of the line, but different - echo() makes sure to do it on the last line in the buffer, while suffix does it on the line the cursor is currently on.
Parameters
  • text
the information you want to prefix
  • writingFunction
optional parameter, allows the selection of different functions to be used to write the text, valid options are: echo, cecho, decho, and hecho.
  • foregroundColor
optional parameter, allows a foreground color to be specified if using the echo function using a color name, as with the fg() function
  • backgroundColor
optional parameter, allows a background color to be specified if using the echo function using a color name, as with the bg() function
  • windowName
optional parameter, allows the selection a miniconsole or the main window for the line that will be prefixed
See also: prefix(), echo()

wrapLine

wrapLine(windowName, lineNumber)
wraps the line specified by lineNumber of mini console (window) windowName. This function will interpret \n characters, apply word wrap and display the new lines on the screen. This function may be necessary if you use deleteLine() and thus erase the entire current line in the buffer, but you want to do some further echo() calls after calling deleteLine(). You will then need to re-wrap the last line of the buffer to actually see what you have echoed and get your \n interpreted as newline characters properly. Using this function is no good programming practice and should be avoided. There are better ways of handling situations where you would call deleteLine() and echo afterwards e.g.:
selectString(line,1)
replace("")

This will effectively have the same result as a call to deleteLine() but the buffer line will not be entirely removed. Consequently, further calls to echo() etc. sort of functions are possible without using wrapLine() unnecessarily.

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