Difference between revisions of "Manual:UI Functions"

From Mudlet
Jump to navigation Jump to search
(Created page with "= UI Functions = ==appendBuffer== ;appendBuffer(name) : Pastes the previously copied rich text (including text formats like color etc.) into user window name. : See also: [[Man...")
 
Line 280: Line 280:
 
echo("sys","Hello world!")
 
echo("sys","Hello world!")
 
</lua>
 
</lua>
 +
 +
==decho==
 +
;decho (text[, foreground color] [, background color] [, true/false] [, name of console])
 +
: Color changes can be made using the format <FR,FG,FB:BR,BG,BB> where each field is a number from 0 to 255. The background portion can be omitted using <FR,FG,FB> or the foreground portion can be omitted using <:BR,BG,BB>. Arguments 2 and 3 set the default fore and background colors for the string using the same format as is used within the string, sans angle brackets, e.g. decho("test", "255,0,0", "0,255,0")
 +
 +
;Parameters
 +
* ''text:"
 +
: The text that you’d like to echo with embedded color tags. Tags take the RGB values only, see below for an explanation.
 +
* ''foreground color:''
 +
: Optional string containing value for foreground color as a named color.
 +
* ''background color:"
 +
: Optional string containing value for background color as a named color.
 +
* ''true/false''
 +
: Optional boolean that tells the function to use insertText() rather than echo().
 +
{{note}} If sending to miniConsole, this has to be false.
 +
* ''name of console''
 +
: Optional name of the console to echo to. Defaults to main.
 +
 +
;Example
 +
''Need example''
  
 
==deleteLine==
 
==deleteLine==

Revision as of 14:33, 15 January 2012

UI Functions

appendBuffer

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

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

bg

bg(colorName)
Changes the background color of the text. Useful for highlighting text.
See Also: fg, setBgColor
Parameters
  • colorName:
The name of the color to set the background to. Color Table
Example

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

calcFontSize

calcFontSize(fontSize)
Used to calculate the number of pixels wide and high a character would be on a mini console at fontSize.
Returns two numbers, width/height
See Also: setMiniConsoleFontSize, getMainWindowSize
Parameters
  • fontSize:
The font size you are wanting to calculate pixel sizes for. Passed as an integer number.
Example

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

cecho

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

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

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

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


clearUserWindow

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

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

clearWindow

clearWindow(name)
Clears the window or miniconsole with the name given as argument. If you don't give it a name, it will clear the main window (since 2.0-test3+)
See also: clearUserWindow
Parameters
  • name:
The name of the user window to clear. Passed as a string.
Examples

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

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

copy

copy()
Copies the current selection to the clipboard. This function operates on rich text, i. e. the selected text including all its format codes like colors, fonts etc. in the clipboard until it gets overwritten by another copy operation. example: This script copies the current line on the main screen to a user window (mini console) named chat and gags the output on the main screen.
See Also: selectString, selectCurrentLine
Parameters
None
Examples

<lua> selectString( line ) copy() appendBuffer("chat") replace("This line has been moved to the chat window!") </lua>

createBuffer

createBuffer(name)
Creates a named buffer for formatted text, much like a miniconsole, but the buffer cannot be shown on the screen. Intended for temporary use in the formatting of text.
Parameters
  • name:
The name of the buffer to create.

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

createConsole

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

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

createGauge

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

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


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

createLabel

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

Examples <lua> --This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle --of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent --and 255 non-transparent) the background text can still be read through. The message box will disappear after 2.3 seconds. local width, height = getMainWindowSize(); createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1); resizeWindow("messageBox",500,70); moveWindow("messageBox", (width/2)-300,(height/2)-100 ); setBackgroundColor("messageBox", 150,100,100,200);

echo("messageBox", [[

You are under attack!

]] );

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

createMiniConsole

createMiniConsole(name, posX, posY, width, height)
Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc.
Returns true or false.
See also: createLabel, hideWindow, showWindow, resizeWindow, setTextFormat, moveWindow, setMiniConsoleFontSize, handleWindowResizeEvent, setBorderTop, setWindowWrap, getMainWindowSize, calcFontSize
Parameters
  • name:
The name of the miniconsole. Must be unique, you can not have two or more miniconsoles with the same name. Passed as a string.
  • Xpos:
X position of the miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.
  • Ypos:
Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.
  • width:
The width of the miniconsole, in pixels. Passed as an integer number.
  • height:
The height of the miniconsole, in pixels. Passed as an integer number.

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


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

createMiniConsole("sys",WindowWidth-650,0,650,300) setBackgroundColor("sys",85,55,0,255) setMiniConsoleFontSize("sys", 8) -- wrap lines in window "sys" at 40 characters per line setWindowWrap("sys", 40) -- set default font colors and font style for window "sys" setTextFormat("sys",0,35,255,50,50,50,0,0,0)

echo("sys","Hello world!") </lua>

decho

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

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

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

Need example

deleteLine

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

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

deselect

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

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

echoLink

echoLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])
Echos a piece of text as a clickable link, at the end of the current selected line - similar to echo.
Parameters
  • text:
text to display in the echo. Same as a normal echo().
  • command:
lua code to do when the link is clicked.
  • hint:
text for the tooltip to be displayed when the mouse is over the link.
  • window:
if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.

echoUserWindow

echoUserWindow(windowName)
This function will print text to both mini console windows, dock windows and labels.
Depreciated - Use echo

echoPopup

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

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

fg

fg(colorName)
If used on a selection, sets the foreground color to colorName - otherwise, it will set the color of the next text-inserting calls (echo(), insertText, echoLink(), and others)
See Also: bg, setBgColor
Parameters
  • colorName:
The name of the color to set the foreground to - list of possible names: Color Table
Examples

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

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

getBgColor

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

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

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

end </lua>

getColumnNumber

getColumnNumber()
Gets the absolute column number of the current user cursor.
Parameters
None
Example

Need example

getCurrentLine

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

Need example

getFgColor

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

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

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

end </lua>

getLineCount

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

Need example

getLineNumber

getLines

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

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

getLineNumber

getLineNumber()
Gets the absolute line number of the current user cursor.
Parameters
None
Example

Need example

getMainConsoleWidth

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

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

hasFocus

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

<lua> if attacked and not hasFocus() then

 runaway()

else

 fight()

end </lua>

getMainWindowSize

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

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

getStopWatchTime

getStopWatchTimer(watchID)
Returns the time (milliseconds based) in form of 0.058 (= clock ran for 58 milliseconds before it was stopped)
See also: createStopWatch
Returns a number
Parameters
  • watchID
The ID number of the watch.
Example

Need example

handleWindowResizeEvent

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

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

Parameters
None
Example

<lua> function handleWindowResizeEvent()

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

end </lua>

hasFocus

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

Need example

hecho

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

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

hideToolBar

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

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

hideWindow

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

Need example

insertLink

insertLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])
Inserts a piece of text as a clickable link at the current cursor position - similar to insertText.
Parameters
  • text:
text to display in the echo. Same as a normal echo.
  • command:
lua code to do when the link is clicked.
  • hint:
text for the tooltip to be displayed when the mouse is over the link.
  • window:
if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.
Example

Need example

insertPopup

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

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

insertText

insertText(windowName, text)
Inserts text at cursor postion in window.
Parameters
  • window:
The window to insert the text to.
  • text:
The text you will insert into the current cursor position.
Example

Need example

isAnsiBgColor

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

<lua> 0 = default text color 1 = light black 2 = dark black 3 = light red 4 = dark red 5 = light green 6 = dark green 7 = light yellow 8 = dark yellow 9 = light blue 10 = dark blue 11 = light magenta 12 = dark magenta 13 = light cyan 14 = dark cyan 15 = light white 16 = dark white </lua>

Examples

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

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

else

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

end </lua>

Note
matches[1] holds the matched trigger pattern - even in substring, exact match, begin of line substring trigger patterns or even color triggers that do not know about the concept of capture groups. Consequently, you can always test if the text that has fired the trigger has a certain color and react accordingly. This function is faster than using getFgColor() and then handling the color comparison in Lua.

isAnsiFgColor

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

<lua> 0 = default text color 1 = light black 2 = dark black 3 = light red 4 = dark red 5 = light green 6 = dark green 7 = light yellow 8 = dark yellow 9 = light blue 10 = dark blue 11 = light magenta 12 = dark magenta 13 = light cyan 14 = dark cyan 15 = light white 16 = dark white </lua>

Examples

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

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

else

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

end </lua>

Note
matches[1] holds the matched trigger pattern - even in substring, exact match, begin of line substring trigger patterns or even color triggers that do not know about the concept of capture groups. Consequently, you can always test if the text that has fired the trigger has a certain color and react accordingly. This function is faster than using getFgColor() and then handling the color comparison in Lua.

moveCursor

moveCursor( windowName, x, y )
Moves the user cursor of the window windowName to the absolute point (x,y). This function returns false if such a move is impossible e.g. the coordinates don’t exist. To determine the correct coordinates use getLineNumber, getColumnNumber and getLastLineNumber. The trigger engine will always place the user cursor at the beginning of the current line before the script is run. If you omit the windowName argument, the main screen will be used.
Returns True or False
Parameters
  • windowName:
The window you are going to move the cursor in.
  • x:
The horizontal axis in the window
  • y:
The vertical axis in the window
Example

<lua> -- set up the small system message window in the top right corner

-- determine the size of your screen WindowWidth=0; WindowHeight=0; WindowWidth, WindowHeight = getMainWindowSize();

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

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

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

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

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

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

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

moveCursorEnd

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

Need example

replaceWildcard

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

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

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

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

resetFormat

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

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

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

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

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

end resetFormat() </lua>

selectCurrentLine

selectCurrentLine()
Selects the content of the current line that the cursor at. By default, the cursor is at the start of the current line that the triggers are processing, but you can move it with the moveCursor() function. Note Note: This selects the whole line, including the linebreak - so it has a subtle difference from the slightly slower selectString(line, 1) selection method.
See Also: selectString, getCurrentLine
Parameters
None
Examples

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

setBackgroundColor

setBackgroundColor(labelName, red, green, blue, transparency)
Sets rgb color values and the transparency for the given window. Colors are from 0 to 255 (0 being black), and transparency is from - to 255 (0 being completely transparent).

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

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

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

setBackgroundImage

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

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

setBorderBottom

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

<lua> setBorderLeft(100) </lua>

setBorderColor

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

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

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

setBorderLeft

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

<lua> setBorderLeft(100) </lua>

setBorderRight

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

<lua> setBorderRight(100) </lua>

setBorderTop

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

<lua> setBorderTop(100) </lua>

setLabelClickCallback

setLabelClickCallback(labelName, luaFunctionName, optional any amount of arguments)
Specifies a Lua function to be called if the user clicks on the label/image. This function can pass any number of string or integer number values as additional parameters. These parameters are then used in the callback - thus you can associate data with the label/button.
Parameters
  • labelName:
The name of the label to attach a callback function to.
  • luaFunctionName:
The Lua function name to call, as a string - it must be registered as a global function, and not inside any namespaces (tables).
  • optional any amount of arguments:
Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.

Examples <lua> function onClickGoNorth()

 echo("the north button was clicked!")

end

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

setLink

setLink(command, tooltip)
Turns the selected text into a clickable link - upon being clicked, the link will do the command code. Tooltip is a string which will be displayed when the mouse is over the selected text.
Parameters
  • command:
command to do when the text is clicked
  • tooltip:
tooltip to show when the mouse is over the text - explaining what would clicking do
Example

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

setLabelStyleSheet

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

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

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

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

setPopup

setPopup(name, {lua code}, {hints})
Turns the selected text into a left-clickable link, and a right-click menu for more options. The selected text, upon being left-clicked, will do the first command in the list. Upon being right-clicked, it'll display a menu with all possible commands. The menu will be populated with hints, one for each line.
Parameters
  • name:
the name of the console to operate on. If not using this in a miniConsole, use "main" as the name.
  • {lua code}:
a table of lua code strings to do. ie, <lua>{send("hello"), echo("hi!"}</lua>
  • {hints}:
a table of strings which will be shown on the popup and right-click menu. ie, <lua>{"send the hi command", "echo hi to yourself"}</lua>.
Example

<lua> -- In a `Raising your hand in greeting, you say "Hello!"` exact match trigger, -- the following code will make left-clicking on `Hello` show you an echo, while left-clicking -- will show some commands you can do.

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

showToolBar

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

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

startStopWatch

startStopWatch( watchID )
Need what it does here
Returns Need what is returns here
Parameters
  • watchID:
Information about it here
Example

Example needed

decho

decho(window, text)
Echoes text that can be easily formatted with colour tags in the hexadecimal format.
See Also: hecho, cecho
Parameters
  • window:
Optional - the window name to echo to - can either be none or "main" for the main window, or the miniconsoles name.
  • text:
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>. You can also reset the color to default withh the <r> tag.


Example

<lua> decho("Hi, this is <255,0,0>red text<r> and this is <0,0,255>blue text<r>." </lua>

wrapLine

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

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

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

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

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