Difference between revisions of "User:Molideus"

From Mudlet
Jump to navigation Jump to search
 
Line 1: Line 1:
 
{{TOC right}}
 
{{TOC right}}
{{#description2:Mudlet API documentation for functions to manipulate Mudlet's scripting objects - triggers, aliases, and so forth.}}
 
= Mudlet Object Functions =
 
Collection of functions to manipulate Mudlet's scripting objects - triggers, aliases, and so forth.
 
  
==addCmdLineSuggestion==
+
This page is for the development of documentation for Lua API functions that are currently being worked on. Ideally the entries here can be created in the same format as will be eventually used in [[Manual:Lua_Functions|Lua Functions]] and its sub-sites.  
;addCmdLineSuggestion([name], suggestion)
 
: Add suggestion for tab completion for specified command line.
 
  
: For example, start typing ''he'' and hit ''TAB'' until ''help'' appears in command line.
+
Please use the [[Area_51/Template]] to add new entries in the sections below.
: Non-word characters are skipped (this is the reason why they can't be added at start of suggestion), therefore it's also possible to type: ''/he'' and hit ''TAB''.
 
  
: See also: [[Manual:Lua_Functions#clearCmdLineSuggestions|clearCmdLineSuggestions()]], [[Manual:Lua_Functions#removeCmdLineSuggestion|removeCmdLineSuggestion()]]
+
Links to other functions or parts in other sections (i.e. the main Wiki area) need to include the section details before the <nowiki>'#'</nowiki> character in the link identifier on the left side of the <nowiki>'|'</nowiki> divider between the identifier and the display text. e.g.
 +
:: <nowiki>[[Manual:Mapper_Functions#getCustomLines|getCustomLines()]]</nowiki>
 +
rather than:
 +
:: <nowiki>[[#getCustomLines|getCustomLines()]]</nowiki>
 +
which would refer to a link within the ''current'' (in this case '''Area 51''') section. Note that this ought to be removed once the article is moved to the main wiki area!
  
{{MudletVersion|4.11}}
+
The following headings reflect those present in the main Wiki area of the Lua API functions. It is suggested that new entries are added so as to maintain a sorted alphabetical order under the appropriate heading.
  
;Parameters
 
* ''name'': optional command line name, if skipped main command line will be used
 
* ''suggestion'' - suggestion as a single word to add to tab completion (only the following are allowed: ''0-9A-Za-z_'')
 
 
Example:
 
<syntaxhighlight lang="lua">
 
addCmdLineSuggestion("help")
 
 
local suggestions = {"Pneumonoultramicroscopicsilicovolcanoconiosis", "supercalifragilisticexpialidocious", "serendipitous"}
 
for _, suggestion in ipairs(suggestions) do
 
  addCmdLineSuggestion(suggestion)
 
end
 
</syntaxhighlight>
 
 
==adjustStopWatch==
 
;adjustStopWatch(watchID/watchName, amount)
 
: Adjusts the elapsed time on the stopwatch forward or backwards by the amount of time. It will work even on stopwatches that are not running, and thus can be used to preset a newly created stopwatch with a negative amount so that it runs down from a negative time towards zero at the preset time.
 
 
;Parameters
 
* watchID (number) / watchName (string): The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].
 
* amount (decimal number): An amount in seconds to adjust the stopwatch by, positive amounts increase the recorded elapsed time.
 
 
;Returns
 
* true on success if the stopwatch was found and thus adjusted, or nil and an error message if not.
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- demo of a persistent stopWatch used to real time a mission
 
-- called with a positive number of seconds it will start a "missionStopWatch"
 
-- unless there already is one in which case it will instead report on
 
-- the deadline. use 'stopStopWatch("missionStopWatch")' when the mission
 
-- is done and 'deleteStopWatch("missionStopWatch")' when the existing mission
 
-- is to be disposed of. Until then repeated use of 'mission(interval)' will
 
-- just give updates...
 
function mission(time)
 
  local missionTimeTable = missionTimeTable or {}
 
 
  if createStopWatch("missionStopWatch") then
 
    adjustStopWatch("missionStopWatch", -tonumber(time))
 
    setStopWatchPersistence("missionStopWatch", true)
 
    missionTimeTable = getStopWatchBrokenDownTime("missionStopWatch")
 
 
    echo(string.format("Get cracking, you have %02i:%02i:%02i hg:m:s left.\n", missionTimeTable.hours, missionTimeTable.minutes, missionTimeTable.seconds))
 
    startStopWatch("missionStopWatch")
 
  else
 
    -- it already exists, so instead report what is/was the time on it
 
    --[=[ We know that the stop watch exists - we just need to find the ID
 
      so we can get the running detail which is only available from the getStopWatches()
 
      table and that is indexed by ID]=]
 
    for k,v in pairs(getStopWatches()) do
 
      if v.name == "missionStopWatch" then
 
        missionTimeTable = v
 
      end
 
    end
 
    if missionTimeTable.isRunning then
 
      if missionTimeTable.elapsedTime.negative then
 
        echo(string.format("Better hurry up, the clock is ticking on an existing mission and you only have %02i:%02i:%02i h:m:s left.\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))
 
      else
 
        echo(string.format("Bad news, you are past the deadline on an existing mission by %02i:%02i:%02i h:m:s !\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))
 
      end
 
    else
 
      if missionTimeTable.elapsedTime.negative then
 
        echo(string.format("Well done! You have already completed a mission %02i:%02i:%02i h:m:s before the deadline ...\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))
 
      else
 
        echo(string.format("Uh oh! You failed to meet the deadline on an existing mission by %02i:%02i:%02i h:m:s !\n", missionTimeTable.elapsedTime.hours, missionTimeTable.elapsedTime.minutes, missionTimeTable.elapsedTime.seconds))
 
      end
 
    end
 
  end
 
end
 
  
 +
=Basic Essential Functions=
 +
:These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.
  
-- in use:
+
=Database Functions=
lua mission(60*60)
+
:A collection of functions for helping deal with the database.
Get cracking, you have 01:00:00 h:m:s left.
 
  
lua mission(60*60)
+
=Date/Time Functions=
Better hurry up, the clock is ticking on an existing mission and you only have 00:59:52 h:m:s left.
+
: A collection of functions for handling date & time.
</syntaxhighlight>
 
  
{{MudletVersion|4.4}}
+
=File System Functions=
 +
: A collection of functions for interacting with the file system.
  
==appendScript==
+
=Mapper Functions=
;appendScript(scriptName, luaCode, [occurrence])
+
: A collection of functions that manipulate the mapper and its related features.
: Appends Lua code to the script "scriptName". If no occurrence given it sets the code of the first found script.
 
  
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#getScript|getScript()]], [[Manual:Lua_Functions#setScript|setScript()]]
+
==updateMap==
 +
;updateMap()
  
;Returns
+
:Updates the mapper display (redraws it). While longer necessary since Mudlet 4.18, you can use this this function to redraw the map after changing it via API.
* a unique id number for that script.
 
  
;Parameters
+
: See also: [[#centerview|centerview()]]
* ''scriptName'': name of the script
 
* ''luaCode'': scripts luaCode to append
 
* ''occurence'': (optional) the occurrence of the script in case you have many with the same name
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- an example of appending the script lua code to the first occurrence of "testscript"
+
-- delete a some room
appendScript("testscript", [[echo("This is a test\n")]], 1)
+
deleteRoom(500)
 +
-- now make the map show that it's gone
 +
updateMap()
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{MudletVersion|4.8}}
 
  
==appendCmdLine==
+
==mapSymbolFontInfo, PR #4038 closed==
;appendCmdLine([name], text)
+
;mapSymbolFontInfo()
: Appends text to the main input line.
+
: See also: [[#setupMapSymbolFont|setupMapSymbolFont()]]
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]], [[#clearCmdLine|clearCmdLine()]]
 
  
;Parameters
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/4038
* ''name'': (optional) name of the command line. If not given, the text will be appended to the main commandline.
 
* ''text'': text to append
 
  
 +
;returns
 +
* either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:
 +
:* ''fontName'' - a string of the family name of the font specified
 +
:* ''onlyUseThisFont'' - a boolean indicating whether glyphs from just the ''fontName'' font are to be used or if there is not a ''glyph'' for the required ''grapheme'' (''character'') then a ''glyph'' from the most suitable different font will be substituted instead. Should this be ''true'' and the specified font does not have the required glyph then the replacement character (typically something like ''�'') could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.
 +
:* ''scalingFactor'' - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).
 +
* or ''nil'' and an error message on failure.
  
;Example
+
::As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).
<syntaxhighlight lang="lua">
 
-- adds the text "55 backpacks" to whatever is currently in the input line
 
appendCmdLine("55 backpacks")
 
  
-- makes a link, that when clicked, will add "55 backpacks" to the input line
+
==moveMapLabel, PR #6014 open==
echoLink("press me", "appendCmdLine'55 backpack'", "Press me!")
+
;moveMapLabel(areaID/Name, labeID/Text, coordX/deltaX, coordY/deltaY[, coordZ/deltaZ][, absoluteNotRelativeMove])
</syntaxhighlight>
+
Re-positions a map label within an area in the 2D mapper, in a similar manner as the [[#moveRoom|moveRoom()]] function does for rooms and their custom exit lines. When moving a label to given coordinates this is the position that the top-left corner of the label will be positioned at; since the space allocated to a particular room on the map is ± 0.5 around the integer value of its x and y coordinates this means for a label which has a size of 1.0 x 1,0 (w x h) to position it centrally in the space for a single room at the coordinates (x, y, z) it should be positioned at (x - 0.5, y + 0.5, z).
  
==clearCmdLine==
+
:See also: [[Manual:Mapper_Functions#getMapLabels|getMapLabels()]], [[Manual:Mapper_Functions#getMapLabel|getMapLabel()]].
;clearCmdLine([name])
 
: Clears the input line of any text that's been entered.
 
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]
 
  
;Parameters
+
{{MudletVersion| ?.??}}
* ''name'': (optional) name of the command line. If not given, the main commandline's text will be cleared.
 
  
;Example
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6014
<syntaxhighlight lang="lua">
 
-- don't be evil with this!
 
clearCmdLine()
 
</syntaxhighlight>
 
  
==clearCmdLineSuggestions==
+
;Parameters
;clearCmdLineSuggestions([name])
+
* ''areaID/Name:''
 +
: Area ID as number or AreaName as string containing the map label.
  
: Clears all suggestions for command line.
+
* ''labelID/Text:''
 +
: Label ID as number (which will be 0 or greater) or the LabelText on a text label. All labels will have a unique ID number but there may be more than one ''text'' labels with a non-empty text string; only the first matching one will be moved by this function and image labels also have no text and will match the empty string.  with mo or AreaName as string containing the map label.
  
: See also: [[Manual:Lua_Functions#addCmdLineSuggestion|addCmdLineSuggestion()]], [[Manual:Lua_Functions#removeCmdLineSuggestion|removeCmdLineSuggestion()]]
+
* ''coordX/deltaX:''
 +
: A floating point number for the absolute coordinate to use or the relative amount to move the label in "room coordinates" along the X-axis.
  
;Parameter
+
* ''coordY/deltaY:''
* ''name'': (optional) name of the command line. If not given the main commandline's suggestions will be cleared.
+
: A floating point number for the absolute coordinate to use or the relative amount to move the label in "room coordinates" along the Y-axis.
  
<syntaxhighlight lang="lua">
+
* ''coordZ/deltaZ:''
clearCmdLineSuggestions()
+
: (Optional) A floating point number for the absolute coordinate to use or the relative amount to move the label in "room coordinates" along the Z-axis, if omitted the label is not moved in the z-axis at all.
</syntaxhighlight>
 
  
==createStopWatch==
+
* ''absoluteNotRelativeMove:''
;createStopWatch([name], [start immediately])
+
: (Optional) a boolean value (defaults to ''false'' if omitted) as to whether to move the label to the absolute coordinates (''true'') or to move it the relative amount from its current location (''false'').
;createStopWatch([start immediately])
 
Before Mudlet 4.4.0:
 
;createStopWatch()
 
  
: This function creates a stopwatch, a high resolution time measurement tool. Stopwatches can be started, stopped, reset, asked how much time has passed since the stop watch has been started and, following an update for Mudlet 4.4.0: be adjusted, given a name and be made persistent between sessions (so can time real-life things). Prior to 4.4.0 the function took no parameters '''and the stopwatch would start automatically when it was created'''.
+
;Returns
 +
: ''true'' on success or ''nil'' and an error message on failure, if successful it will also refresh the map display to show the result.
  
;Parameters:
+
;Example
* ''start immediately'' (bool) used to override the behaviour prior to Mudlet 4.4.0 so that if it is the ''only'' argument then a ''false'' value will cause the stopwatch to be created but be in a ''stopped'' state, however if a name parameter is provided then this behaviour is assumed and then a ''true'' value is required should it be desired for the stopwatch to be started on creation. This difference between the cases with and without a name argument is to allow for older scripts to continue to work with 4.4.0 or later versions of Mudlet without change, yet to allow for more functionality - such as presetting a time when the stopwatch is created but not to start it counting down until some time afterwards - to be performed as well with a named stopwatch.
+
<syntaxhighlight lang="lua">
 +
-- move the first label in the area with the ID number of 2, three spaces to the east and four spaces to the north
 +
moveMapLabel(0, 2, 3.0, 4.0)
  
* ''name'' (string) a ''unique'' text to use to identify the stopwatch.
+
-- move the first label in the area with the ID number of 2, one space to the west, note the final boolean argument is unneeded
 +
moveMapLabel(0, 2, -1.0, 0.0, false)
  
;Returns:
+
-- move the second label in the area with the ID number of 2, three and a half spaces to the west, and two south **of the center of the current level it is on in the map**:
* the ID (number) of a stopwatch; or, from '''4.4.0''': a nil + error message if the name has already been used.
+
moveRoom(1, 2, -3.5, -2.0, true)
  
: See also: [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#resetStopWatch|resetStopWatch()]], [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]] or, from 4.4.0: [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatches|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]], [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]], [[Manual:Lua_Functions#setStopWatchPersistence|setStopWatchPersistence()]]
+
-- move the second label in the area with the ID number of 2, up three levels
 +
moveRoom(1, 2, 0.0, 0.0, 3.0)
  
;Example
+
-- move the second label in the "Test 1" area one space to the west, note the last two arguments are unneeded
: (Prior to Mudlet 4.4.0) in a global script you can create all stop watches that you need in your system and store the respective stopWatch-IDs in global variables:
+
moveRoom("Test 1", 1, -1.0, 0.0, 0.0, false)
<syntaxhighlight lang="lua">
 
fightStopWatch = fightStopWatch or createStopWatch() -- create, or re-use a stopwatch, and store the watchID in a global variable to access it from anywhere
 
  
-- then you can start the stop watch in some trigger/alias/script with:
+
-- move the (top-left corner of the first) label with the text "Home" in the area with ID number 5 to the **center of the whole map**, note the last two arguments are required in this case:
startStopWatch(fightStopWatch)
+
moveRoom(5, "Home", 0.0, 0.0, 0.0, true)
  
-- to stop the watch and measure its time in e.g. a trigger script you can write:
+
-- all of the above will return the 'true'  boolean value assuming there are the indicated labels and areas
fightTime = stopStopWatch(fightStopWatch)
 
echo("The fight lasted for " .. fightTime .. " seconds.")
 
resetStopWatch(fightStopWatch)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
: (From Mudlet 4.4.0) in a global script you can create all stop watches that you need in your system with unique names:
+
==moveRoom, PR #6010 open==
<syntaxhighlight lang="lua">
+
;moveRoom(roomID, coordX/deltaX, coordY/deltaY[, coordZ/deltaZ][, absoluteNotRelativeMove])
createStopWatch("fightStopWatch") -- creates the stopwatch or returns nil+msg if it already exists
+
Re-positions a room within an area, in the same manner as the "move to" context menu item for one or more rooms in the 2D mapper. Like that method this will also shift the entirety of any custom exit lines defined for the room concerned. This contrasts with the behavior of the [[Manual:Mapper_Functions#setRoomCoordinates|setRoomCoordinates()]] which only moves the starting point of such custom exit lines so that they still emerge from the room to which they belong but otherwise remain pointing to the original place.
  
-- then you can start the stop watch (if it is not already started) in some trigger/alias/script with:
+
:See also: [[Manual:Mapper_Functions#setRoomCoordinates|setRoomCoordinates()]]
startStopWatch("fightStopWatch")
 
  
-- to stop the watch and measure its time in e.g. a trigger script you can write:
+
{{MudletVersion| ?.??}}
fightTime = stopStopWatch("fightStopWatch")
 
echo("The fight lasted for " .. fightTime .. " seconds.")
 
resetStopWatch("fightStopWatch")
 
</syntaxhighlight>
 
  
:You can also measure the elapsed time without having to stop the stop watch (equivalent to getting a ''lap-time'') with [[#getStopWatchTime|getStopWatchTime()]].
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6010
  
{{note}} it's best to re-use stopwatch IDs if you can for Mudlet prior to 4.4.0 as they cannot be deleted, so creating more and more would use more memory. From 4.4.0 the revised internal design has been changed such that there are no internal timers created for each stopwatch - instead either a timestamp or a fixed elapsed time record is used depending on whether the stopwatches is running or stopped so that there are no "moving parts" in the later design and less resources are used - and they can be removed if no longer required.
+
;Parameters
 +
* ''roomID:''
 +
: Room ID number to move.
  
==deleteAllNamedTimers==
+
* ''coordX/deltaX:''
; deleteAllNamedTimers(userName)
+
: The absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the X-axis.
  
:Deletes all named timers and prevents them from firing any more. Information is deleted and cannot be retrieved.
+
* ''coordY/deltaY:''
 +
: The absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the Y-axis.
  
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]]
+
* ''coordZ/deltaZ:''
 +
: (Optional) the absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the Z-axis, if omitted the room is not moved in the z-axis at all.
  
{{MudletVersion|4.14}}
+
* ''absoluteNotRelativeMove:''
 +
: (Optional) a boolean value (defaults to ''false'' if omitted) as to whether to move the room to the absolute coordinates (''true'') or the relative amount from its current location (''false'').
  
;Parameters
+
;Returns
* ''userName:''
+
: ''true'' on success or ''nil'' and an error message on failure, if successful it will also refresh the map display to show the result.
: The user name the event handler was registered under.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
deleteAllNamedTimers("Demonnic") -- emergency stop or debugging situation, most likely.
+
-- move the first room one space to the east and two spaces to the north
</syntaxhighlight>
+
moveRoom(1, 1, 2)
  
==deleteNamedTimer==
+
-- move the first room one space to the west, note the final boolean argument is unneeded
; success = deleteNamedTimer(userName, handlerName)
+
moveRoom(1, -1, 0, false)
  
:Deletes a named timer with name handlerName and prevents it from firing any more. Information is deleted and cannot be retrieved.
+
-- move the first room three spaces to the west, and two south **of the center of the current level it is on in the map**:
 +
moveRoom(1, -3, -2, true)
  
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]]
+
-- move the second room up three levels
 +
moveRoom(2, 0, 0, 3)
  
{{MudletVersion|4.14}}
+
-- move the second room one space to the west, note the last two arguments are unneeded
 +
moveRoom(2, -1, 0, 0, false)
  
;Parameters
+
-- move the second room to the **center of the whole map**, note the last two arguments are required in this case:
* ''userName:''
+
moveRoom(2, 0, 0, 0, true)
: The user name the event handler was registered under.
 
* ''handlerName:''
 
: The name of the handler to stop. Same as used when you called [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
 
  
;Returns
+
-- all of the above will return the 'true' boolean value assuming there are rooms with 1 and 2 as ID numbers
* true if successful, false if it didn't exist
 
;Example
 
<syntaxhighlight lang="lua">
 
local deleted = deleteNamedTimer("Demonnic", "DemonVitals")
 
if deleted then
 
  cecho("DemonVitals deleted forever!!")
 
else
 
  cecho("DemonVitals doesn't exist and so could not be deleted.")
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==deleteStopWatch==
+
==setupMapSymbolFont, PR #4038 closed==
;deleteStopWatch(watchID/watchName)
+
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])
 +
:configures the font used for symbols in the (2D) map.
 +
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]
  
: This function removes an existing stopwatch, whether it only exists for this session or is set to be otherwise saved between sessions by using [[Manual:Lua_Functions#setStopWatchPersistence|setStopWatchPersistence()]] with a ''true'' argument.
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/4038
  
 
;Parameters
 
;Parameters
* ''watchID'' (number) / ''watchName'' (string): The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].
+
* ''fontName'' one of:
 +
:* - a string that is the family name of the font to use;
 +
:* - the empty string ''""'' to reset to the default {which is '''"Bitstream Vera Sans Mono"'''};
 +
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.
 +
* ''onlyUseThisFont'' (optional) one of:
 +
:* - a Lua boolean ''true'' to require Mudlet to use graphemes (''character'') '''only''' from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;
 +
:* - a Lua boolean ''false'' to allow Mudlet to get a different ''glyph'' for a particular ''grapheme'' from the most suitable other font found in the system should there not be a ''glyph'' for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;
 +
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.
 +
* ''scalingFactor'' (optional): a floating point value in the range ''0.5'' to ''2.0'' (default ''1.0'') that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.
  
;Returns:
+
;Returns
* ''true'' if the stopwatch was found and thus deleted, or ''nil'' and an error message if not - obviously using it twice with the same argument will fail the second time unless another one with the same name or ID was recreated before the second use.  Note that an empty string as a name ''will'' find the lowest ID numbered ''unnamed'' stopwatch and that will then find the next lowest ID number of unnamed ones until there are none left, if used repetitively!
+
* ''true'' on success
 
+
* ''nil'' and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).
<syntaxhighlight lang="lua">
 
lua MyStopWatch = createStopWatch("stopwatch_mine")
 
true
 
 
 
lua display(MyStopWatch)
 
4
 
 
 
lua deleteStopWatch(MyStopWatch)
 
true
 
  
lua deleteStopWatch(MyStopWatch)
+
=Miscellaneous Functions=
nil
+
: Miscellaneous functions.
  
"stopwatch with id 4 not found"
+
==compare, PR#7122 open==
  
lua deleteStopWatch("stopwatch_mine")
+
; sameValue = compare(a, b)
nil
 
  
"stopwatch with name "stopwatch_mine" not found"
+
:This function takes two items, and compares their values. It will compare numbers, strings, but most importantly it will compare two tables by value, not reference. For instance, ''{} == {}'' is ''false'', but ''compare({}, {})'' is ''true''
</syntaxhighlight>
 
  
: See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]],
+
;See also: [[Manual:Lua_Functions#table.complement|table.complement()]], [[Manual:Lua_Functions#table.n_union|table.n_union()]]
  
{{MudletVersion|4.4}}
+
{{MudletVersion|4.18}}
 
 
{{note}} Stopwatches that are not set to be persistent will be deleted automatically at the end of a session (or if [[Manual:Miscellaneous_Functions#resetProfile|resetProfile()]] is called).
 
 
 
==removeCmdLineSuggestion==
 
;removeCmdLineSuggestion([name], suggestion)
 
: Remove a suggestion for tab completion for specified command line.
 
 
 
: See also: [[Manual:Lua_Functions#addCmdLineSuggestion|addCmdLineSuggestion()]], [[Manual:Lua_Functions#clearCmdLineSuggestions|clearCmdLineSuggestions()]]
 
 
 
{{MudletVersion|4.11}}
 
  
 
;Parameters
 
;Parameters
* ''name'': optional command line name, if skipped main command line will be used
+
* ''a:''
* ''suggestion'' - text to add to tab completion, non words characters at start and end of word should not be used (all characters except: `0-9A-Za-z_`)
+
: The first item to compare
 +
* ''b:''
 +
: The second item to compare
  
Example:
+
;Returns
<syntaxhighlight lang="lua">
+
* Boolean true if the items have the same value, otherwise boolean false
removeCmdLineSuggestion("help")
 
</syntaxhighlight>
 
  
==disableAlias==
+
;Example
;disableAlias(name)
 
:Disables/deactivates the alias by its name. If several aliases have this name, they'll all be disabled. If you disable an alias group, all the aliases inside the group will be disabled as well.
 
 
 
: See also: [[#enableAlias|enableAlias()]], [[#disableTrigger|disableTrigger()]], [[#disableTimer|disableTimer()]], [[#disableKey|disableKey()]], [[#disableScript|disableScript()]].
 
 
 
;Parameters
 
* ''name:''
 
: The name of the alias. Passed as a string.
 
 
 
;Examples
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--Disables the alias called 'my alias'
+
local tblA = { 255, 0, 0 }
disableAlias("my alias")
+
local tblB = color_table.red
 +
local same = compare(tblA, tblB)
 +
display(same)
 +
-- this will return true
 +
display(tblA == tblB)
 +
-- this will display false, as they are different tables
 +
-- even though they have the same value
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==disableKey==
+
; Additional development notes
;disableKey(name)
+
This is just exposing the existing _comp function, which is currently the best way to compare two tables by value. --[[User:Demonnic|Demonnic]] ([[User talk:Demonnic|talk]]) 18:51, 7 February 2024 (UTC)
:Disables key a key (macro) or a key group. When you disable a key group, all keys within the group will be implicitly disabled as well.
 
 
 
: See also: [[#enableKey|enableKey()]]
 
  
;Parameters
+
==createVideoPlayer, PR #6439==
* ''name:''
+
;createVideoPlayer([name of userwindow], x, y, width, height)
: The name of the key or group to identify what you'd like to disable.
 
  
;Examples
+
:Creates a miniconsole window for the video player to render in, the with the given dimensions. One can only create one video player at a time (currently), and it is not currently possible to have a label on or under the video player - otherwise, clicks won't register.
  
<syntaxhighlight lang="lua">
+
{{note}} A video player may also be created through use of the [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]], the [[Manual:Miscellaneous_Functions#playVideoFile|playVideoFile()]] API command, or adding a Geyser.VideoPlayer object to ones user interface such as the example below.
-- you could set multiple keys on the F1 key and swap their use as you wish by disabling and enabling them
 
disableKey("attack macro")
 
disableKey("jump macro")
 
enableKey("greet macro")
 
</syntaxhighlight>
 
  
==disableScript==
+
{{Note}} The Main Toolbar will show a '''Video''' button to hide/show the video player, which is located in a userwindow generated through createVideoPlayer, embedded in a user interface, or a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the '''Video''' button will toggle between showing and hiding the map whether it was created using the ''createVideo'' function or as a dock-able widget.
;disableScript(name)
 
:Disables a script that was previously enabled. Note that disabling a script only stops it from running in the future - it won't "undo" anything the script has made, such as labels on the screen.
 
  
: See also: [[#permScript|permScript()]], [[#appendScript|appendScript()]], [[#enableScript|enableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]
+
See also: [[Manual:Miscellaneous_Functions#loadSoundFile|loadSoundFile()]], [[Manual:Miscellaneous Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous Functions#loadVideoFile|loadVideoFile()]], [[Manual:Miscellaneous Functions#playSoundFile|playSoundFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous Functions#playVideoFile|playVideoFile()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]], [[Manual:Miscellaneous Functions#stopVideos|stopVideos()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
  
;Parameters
+
{{MudletVersion|4.??}}
* ''name'': name of the script.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--Disables the script called 'my script'
+
-- Create a 300x300 video player in the top-left corner of Mudlet
disableScript("my script")
+
createVideoPlayer(0,0,300,300)
 +
 
 +
-- Alternative examples using Geyser.VideoPlayer
 +
GUI.VideoPlayer = GUI.VideoPlayer or Geyser.VideoPlayer:new({name="GUI.VideoPlayer", x = 0, y = 0, width = "25%", height = "25%"})
 +
 +
GUI.VideoPlayer = GUI.VideoPlayer or Geyser.VideoPlayer:new({
 +
  name = "GUI.VideoPlayer",
 +
  x = "70%", y = 0, -- edit here if you want to move it
 +
  width = "30%", height = "50%"
 +
}, GUI.Right)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{MudletVersion|4.8}}
+
==loadVideoFile, PR #6439==
 +
;loadVideoFile(settings table) or loadVideoFile(name, [url])
 +
:Loads video files from the Internet or the local file system to the "media" folder of the profile for later use with [[Manual:Miscellaneous_Functions#playVideoFile|playVideoFile()]] and [[Manual:Miscellaneous_Functions#stopVideos|stopVideos()]]. Although files could be loaded or streamed directly at playing time from [[Manual:Miscellaneous_Functions#playVideoFile|playVideoFile()]], loadVideoFile() provides the advantage of loading files in advance.
 +
 
 +
{{note}} Video files consume drive space on your device. Consider using the streaming feature of [[Manual:Miscellaneous_Functions#playVideoFile|playVideoFile()]] for large files.
  
==disableTimer==
+
{| class="wikitable"
;disableTimer(name)
+
!Required
:Disables a timer from running it’s script when it fires - so the timer cycles will still be happening, just no action on them. If you’d like to permanently delete it, use [[Manual:Lua_Functions#killTrigger|killTrigger]] instead.
+
!Key
 +
!Value
 +
! style="text-align:left;" |Purpose
 +
|- style="color: green;"
 +
| style="text-align:center;" |Yes
 +
|name
 +
|<file name>
 +
| style="text-align:left;" |
 +
*Name of the media file.
 +
*May contain directory information (i.e. weather/maelstrom.mp4).
 +
*May be part of the profile (i.e. getMudletHomeDir().. "/congratulations.mp4")
 +
*May be on the local device (i.e. "C:/Users/YourNameHere/Movies/nevergoingtogiveyouup.mp4")
 +
|- style="color: blue;"
 +
| style="text-align:center;" |Maybe
 +
|url
 +
|<url>
 +
| style="text-align:left;" |
 +
*Resource location where the media file may be downloaded.
 +
*Only required if file to load is not part of the profile or on the local file system.
 +
|-
 +
|}
  
: See also: [[#enableTimer|enableTimer()]], [[#disableTrigger|disableTrigger()]], [[#disableAlias|disableAlias()]], [[#disableKey|disableKey()]], [[#disableScript|disableScript()]].
+
See also: [[Manual:Miscellaneous_Functions#playSoundFile|loadSoundFile()]], [[Manual:Miscellaneous Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous Functions#playSoundFile|playSoundFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous Functions#playVideoFile|playVideoFile()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]], [[Manual:Miscellaneous Functions#stopVideos|stopVideos()]], [[Manual:Miscellaneous Functions#createVideoPlayer|createVideoPlayer()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
  
;Parameters
+
{{MudletVersion|4.??}}
* ''name:''
 
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.
 
  
 
;Example
 
;Example
 +
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--Disables the timer called 'my timer'
+
---- Table Parameter Syntax ----
disableTimer("my timer")
 
</syntaxhighlight>
 
  
==disableTrigger==
+
-- Download from the Internet
;disableTrigger(name)
+
loadVideoFile({
:Disables a permanent (one in the trigger editor) or a temporary trigger. When you disable a group, all triggers inside the group are disabled as well
+
    name = "TextInMotion-VideoSample-1080p.mp4"
 +
    , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
 +
})
  
: See also: [[#enableTrigger|enableTrigger()]], [[#disableAlias|disableAlias()]], [[#disableTimer|disableTimer()]], [[#disableKey|disableKey()]], [[#disableScript|disableScript()]].
+
-- OR download from the profile
 +
loadVideoFile({name = getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4"})
  
;Parameters
+
-- OR download from the local file system
* ''name:''
+
loadVideoFile({name = "C:/Users/Tamarindo/Movies/TextInMotion-VideoSample-1080p.mp4"})
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.
+
</syntaxhighlight>
 
 
;Example
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- Disables the trigger called 'my trigger'
+
---- Ordered Parameter Syntax of loadVideoFile(name[, url]) ----
disableTrigger("my trigger")
 
</syntaxhighlight>
 
 
 
==enableAlias==
 
;enableAlias(name)
 
:Enables/activates the alias by it’s name. If several aliases have this name, they’ll all be enabled.
 
  
: See also: [[#disableAlias|disableAlias()]]
+
-- Download from the Internet
 +
loadVideoFile(
 +
    "TextInMotion-VideoSample-1080p.mp4"
 +
    , "https://d2qguwbxlx1sbt.cloudfront.net/"
 +
)
  
;Parameters
+
-- OR download from the profile
* ''name:''
+
loadVideoFile(getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4")
: Expects the alias ID that was returned by [[Manual:Lua_Functions#tempAlias|tempAlias]] on creation of the alias or the name of the alias in case of a GUI alias.
 
  
;Example
+
-- OR download from the local file system
<syntaxhighlight lang="lua">
+
loadVideoFile("C:/Users/Tamarindo/Movies/TextInMotion-VideoSample-1080p.mp4")
--Enables the alias called 'my alias'
 
enableAlias("my alias")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==enableKey==
+
==playVideoFile, PR #6439==
;enableKey(name)
+
;playVideoFile(settings table)
:Enables a key (macro) or a group of keys (and thus all keys within it that aren't explicitly deactivated).
+
:Plays video files from the Internet or the local file system for later use with [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]]. Video files may be downloaded to the device and played, or streamed from the Internet when the value of the <code>stream</code> parameter is <code>true</code>.
  
;Parameters
+
{| class="wikitable"
* ''name:''
+
!Required
: The name of the group that identifies the key.
+
!Key
 +
!Value
 +
!Default
 +
! style="text-align:left;" |Purpose
 +
|- style="color: green;"
 +
| style="text-align:center;" |Yes
 +
|name
 +
|<file name>
 +
|&nbsp;
 +
| style="text-align:left;" |
 +
*Name of the media file.
 +
*May contain directory information (i.e. weather/maelstrom.mp4).
 +
*May be part of the profile (i.e. getMudletHomeDir().. "/cow.mp4")
 +
* May be on the local device (i.e. "C:/Users/YourNameHere/Documents/nevergoingtogiveyouup.mp4")
 +
*Wildcards ''*'' and ''?'' may be used within the name to randomize media files selection.
 +
|-
 +
| style="text-align:center;" |No
 +
| volume
 +
|1 to 100
 +
|50
 +
| style="text-align:left;" |
 +
*Relative to the volume set on the player's client.
 +
|-
 +
| style="text-align:center;" |No
 +
|fadein
 +
|<msec>
 +
|
 +
|
 +
*Volume increases, or fades in, ranged across a linear pattern from one to the volume set with the "volume" key.
 +
*Start position:  Start of media.
 +
*End position:  Start of media plus the number of milliseconds (msec) specified.
 +
*1000 milliseconds = 1 second.
 +
|-
 +
| style="text-align:center;" |No
 +
|fadeout
 +
|<msec>
 +
|
 +
|
 +
*Volume decreases, or fades out, ranged across a linear pattern from the volume set with the "volume" key to one.
 +
*Start position:  End of the media minus the number of milliseconds (msec) specified.
 +
*End position:  End of the media.
 +
*1000 milliseconds = 1 second.
 +
|-
 +
| style="text-align:center;" |No
 +
|start
 +
|<msec>
 +
| 0
 +
| style="text-align:left;" |
 +
*Begin play at the specified position in milliseconds.
 +
|-
 +
| style="text-align:center;" |No
 +
|loops
 +
| -1, or >= 1
 +
|1
 +
| style="text-align:left;" |
 +
*Number of iterations that the media plays.
 +
*A value of -1 allows the media to loop indefinitely.
 +
|-
 +
| style="text-align:center;" |No
 +
|key
 +
|<key>
 +
|&nbsp;
 +
| style="text-align:left;" |
 +
*Uniquely identifies media files with a "key" that is bound to their "name" or "url".
 +
*Halts the play of current media files with the same "key" that have a different "name" or "url" while this media plays.
 +
|-
 +
| style="text-align:center;" |No
 +
|tag
 +
|<tag>
 +
|&nbsp;
 +
| style="text-align:left;" |
 +
*Helps categorize media.
 +
|-
 +
| style="text-align:center;" |No
 +
|continue
 +
|true or false
 +
|true
 +
| style="text-align:left;" |
 +
*Continues playing matching new video files when true.
 +
*Restarts matching new video files when false.
 +
|- style="color: blue;"
 +
| style="text-align:center;" |Maybe
 +
|url
 +
|<url>
 +
|&nbsp;
 +
| style="text-align:left;" |
 +
*Resource location where the media file may be downloaded.
 +
*Only required if the file is to be downloaded remotely or for streaming from the Internet.
 +
|- style="color: blue;"
 +
| style="text-align:center;" |Maybe
 +
|stream
 +
|true or false
 +
|false
 +
| style="text-align:left;" |
 +
*Streams files from the Internet when true.
 +
*Download files when false (default).
 +
*Used in combination with the `url` key.
 +
|-
 +
|}
  
<syntaxhighlight lang="lua">
+
See also: [[Manual:Miscellaneous Functions#loadSoundFile|loadSoundFile()]], [[Manual:Miscellaneous Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous Functions#loadVideoFile|loadVideoFile()]], [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]], [[Manual:Miscellaneous Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous Functions#stopMusic|stopMusic()]], [[Manual:Miscellaneous Functions#stopVideos|stopVideos()]], [[Manual:Miscellaneous Functions#createVideoPlayer|createVideoPlayer()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
-- you could use this to disable one key set for the numpad and activate another
 
disableKey("fighting keys")
 
enableKey("walking keys")
 
</syntaxhighlight>
 
{{note}} From Version '''3.10'' returns ''true'' if one or more keys or groups of keys were found that matched the name given or ''false'' if not; prior to then it returns ''true'' if there were '''any''' keys - whether they matched the name or not!
 
  
==enableScript==
+
{{MudletVersion|4.??}}
;enableScript(name)
 
:Enables / activates a script that was previously disabled.  
 
  
: See also: [[#permScript|permScript()]], [[#appendScript|appendScript()]], [[#disableScript|disableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]
+
;Example
  
;Parameters
 
* ''name'': name of the script.
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- enable the script called 'my script' that you created in Mudlet's script section
+
---- Table Parameter Syntax ----
enableScript("my script")
 
</syntaxhighlight>
 
  
{{MudletVersion|4.8}}
+
-- Stream a video file from the Internet and play it.
 +
playVideoFile({
 +
    name = "TextInMotion-VideoSample-1080p.mp4"
 +
    , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
 +
    , stream = true
 +
})
  
==enableTimer==
+
-- Play a video file from the Internet, storing it in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media) so you don't need to download it over and over.  You could add ", stream = false" below, but that is the default and is not needed.
;enableTimer(name)
 
:Enables or activates a timer that was previously disabled.  
 
  
;Parameters
+
playVideoFile({
* ''name:''
+
    name = "TextInMotion-VideoSample-1080p.mp4"
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.
+
    , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
<syntaxhighlight lang="lua">
+
})
-- enable the timer called 'my timer' that you created in Mudlets timers section
 
enableTimer("my timer")
 
</syntaxhighlight>
 
  
<syntaxhighlight lang="lua">
+
-- Play a video file stored in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media)
-- or disable & enable a tempTimer you've made
+
playVideoFile({
timerID = tempTimer(10, [[echo("hi!")]])
+
    name = "TextInMotion-VideoSample-1080p.mp4"
 +
})
  
-- it won't go off now
+
-- OR copy once from the game's profile, and play a video file stored in the profile's media directory
disableTimer(timerID)
+
---- [volume] of 75 (1 to 100)
-- it will continue going off again
+
playVideoFile({
enableTimer(timerID)
+
    name = getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4"
</syntaxhighlight>
+
    , volume = 75
 +
})
  
==enableTrigger==
+
-- OR copy once from the local file system, and play a video file stored in the profile's media directory
;enableTrigger(name)
+
---- [volume] of 75 (1 to 100)
:Enables or activates a trigger that was previously disabled.  
+
playVideoFile({
 +
    name = "C:/Users/Tamarindo/Movies/TextInMotion-VideoSample-1080p.mp4"
 +
    , volume = 75
 +
})
  
;Parameters
+
-- OR download once from the Internet, and play a video stored in the profile's media directory
* ''name:''
+
---- [fadein] and increase the volume from 1 at the start position to default volume up until the position of 10 seconds
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or by any other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.
+
---- [fadeout] and decrease the volume from default volume to one, 15 seconds from the end of the video
<syntaxhighlight lang="lua">
+
---- [start] 5 seconds after position 0 (fadein scales its volume increase over a shorter duration, too)
-- enable the trigger called 'my trigger' that you created in Mudlets triggers section
+
---- [key] reference of "text" for stopping this unique video later
enableTrigger("my trigger")
+
---- [tag] reference of "ambience" to stop any video later with the same tag
 +
---- [continue] playing this video if another request for the same video comes in (false restarts it)
 +
---- [url] resource location where the file may be accessed on the Internet
 +
---- [stream] download once from the Internet if the video does not exist in the profile's media directory when false (true streams from the Internet and will not download to the device)
 +
playVideoFile({
 +
    name = "TextInMotion-VideoSample-1080p.mp4"
 +
    , volume = nil -- nil lines are optional, no need to use
 +
    , fadein = 10000
 +
    , fadeout = 15000
 +
    , start = 5000
 +
    , loops = nil -- nil lines are optional, no need to use
 +
    , key = "text"
 +
    , tag = "ambience"
 +
    , continue = true
 +
    , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
 +
    , stream = false
 +
})
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- or disable & enable a tempTrigger you've made
+
---- Ordered Parameter Syntax of playVideoFile(name[,volume][,fadein][,fadeout][,loops][,key][,tag][,continue][,url][,stream]) ----
triggerID = tempTrigger("some text that will match in a line", [[echo("hi!")]])
 
  
-- it won't go off now when a line with matching text comes by
+
-- Stream a video file from the Internet and play it.
disableTrigger(triggerID)
+
playVideoFile(
 +
    "TextInMotion-VideoSample-1080p.mp4"
 +
    , nil -- volume
 +
    , nil -- fadein
 +
    , nil -- fadeout
 +
    , nil -- start
 +
    , nil -- loops
 +
    , nil -- key
 +
    , nil -- tag
 +
    , true -- continue
 +
    , "https://d2qguwbxlx1sbt.cloudfront.net/" -- url
 +
    , false -- stream
 +
)
  
-- and now it will continue going off again
+
-- Play a video file from the Internet, storing it in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media) so you don't need to download it over and over.
enableTrigger(triggerID)
+
playVideoFile(
</syntaxhighlight>
+
    "TextInMotion-VideoSample-1080p.mp4"
 +
    , nil -- volume
 +
    , nil -- fadein
 +
    , nil -- fadeout
 +
    , nil -- start
 +
    , nil -- loops
 +
    , nil -- key
 +
    , nil -- tag
 +
    , true -- continue
 +
    , "https://d2qguwbxlx1sbt.cloudfront.net/" -- url
 +
    , false -- stream
 +
)
  
==exists==
+
-- Play a video file stored in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media)
;exists(name/IDnumber, type)
+
playVideoFile(
:Returns the number of things with the given name or number of the given type - and 0 if none are present. Beware that all numbers are true in Lua, including zero.
+
    "TextInMotion-VideoSample-1080p.mp4"  -- name
 +
)
  
;Parameters
+
-- OR copy once from the game's profile, and play a video file stored in the profile's media directory
* ''name:''
+
---- [volume] of 75 (1 to 100)
: The name (as a string) or, from '''Mudlet 4.17.0''', the ID number of a single item, (which will be that returned by a ''temp*'' or ''perm*'' function to create such an item to identify the item).
+
playVideoFile(
* ''type:''
+
    getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4" -- name
: The type can be 'alias', 'button' (Mudlet 4.10+), 'trigger', 'timer', 'keybind' (Mudlet 3.2+), or 'script' (Mudlet 3.17+).
+
    , 75 -- volume
 +
)
  
:See also: [[#isActive|isActive(...)]]
+
-- OR copy once from the local file system, and play a video file stored in the profile's media directory
 +
---- [volume] of 75 (1 to 100)
 +
playVideoFile(
 +
    "C:/Users/Tamarindo/Documents/TextInMotion-VideoSample-1080p.mp4" -- name
 +
    , 75 -- volume
 +
)
  
;Example
+
-- OR download once from the Internet, and play a video stored in the profile's media directory
<syntaxhighlight lang="lua">
+
---- [fadein] and increase the volume from 1 at the start position to default volume up until the position of 10 seconds
echo("I have " .. exists("my trigger", "trigger") .. " triggers called 'my trigger'!")
+
---- [fadeout] and decrease the volume from default volume to one, 15 seconds from the end of the video
 +
---- [start] 5 seconds after position 0 (fadein scales its volume increase over a shorter duration, too)
 +
---- [key] reference of "text" for stopping this unique video later
 +
---- [tag] reference of "ambience" to stop any video later with the same tag
 +
---- [continue] playing this video if another request for the same video comes in (false restarts it)
 +
---- [url] resource location where the file may be accessed on the Internet
 +
---- [stream] download once from the Internet if the video does not exist in the profile's media directory when false (true streams from the Internet and will not download to the device)
 +
playVideoFile(
 +
    "TextInMotion-VideoSample-1080p.mp4" -- name
 +
    , nil -- volume
 +
    , 10000 -- fadein
 +
    , 15000 -- fadeout
 +
    , 5000 -- start
 +
    , nil -- loops
 +
    , "text" -- key
 +
    , "ambience" -- tag
 +
    , true -- continue
 +
    , "https://d2qguwbxlx1sbt.cloudfront.net/" -- url
 +
    , false -- stream
 +
)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
: You can also use this alias to avoid creating duplicate things, for example:
 
<syntaxhighlight lang="lua">
 
-- this code doesn't check if an alias already exists and will keep creating new aliases
 
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])
 
  
-- while this code will make sure that such an alias doesn't exist first
+
==stopVideos, PR #6439==
-- we do == 0 instead of 'not exists' because 0 is considered true in Lua
+
;stopVideos(settings table)
if exists("Attack", "alias") == 0 then
+
:Stop all videos (no filter), or videos that meet a combination of filters (name, key, and tag) intended to be paired with [[Manual:Miscellaneous_Functions#playVideoFile|playVideoFile()]].
    permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])
 
end
 
</syntaxhighlight>
 
  
: Especially helpful when working with [[Manual:Lua_Functions#permTimer|permTimer]]:
+
{| class="wikitable"
<syntaxhighlight lang="lua">
+
!Required
if not exists("My animation timer", "timer") then
+
!Key
  vdragtimer = permTimer("My animation timer", "", .016, onVDragTimer) -- 60fps timer!
+
!Value
end
+
! style="text-align:left;" |Purpose
+
|-
enableTimer("My animation timer")
+
| style="text-align:center;" |No
</syntaxhighlight>
+
| name
 +
| <file name>
 +
| style="text-align:left;" |
 +
* Name of the media file.
 +
|-
 +
| style="text-align:center;" |No
 +
|key
 +
|<key>
 +
| style="text-align:left;" |
 +
*Uniquely identifies media files with a "key" that is bound to their "name" or "url".
 +
*Halts the play of current media files with the same "key" that have a different "name" or "url" while this media plays.
 +
|-
 +
| style="text-align:center;" |No
 +
|tag
 +
|<tag>
 +
| style="text-align:left;" |
 +
*Helps categorize media.
 +
|-
 +
|}
  
{{Note}} A positive ID number will return either a ''1'' or ''0'' value and not a lua boolean ''true'' or ''false'' as might otherwise be expected, this is for constancy with the way the function behaves for a name.
+
See also: [[Manual:Miscellaneous_Functions#loadSoundFile|loadSoundFile()]], [[Manual:Miscellaneous_Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous_Functions#loadVideoFile|loadVideoFile()]], [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous_Functions#playVideoFile|playVideoFile()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous Functions#stopMusic|stopMusic()]], [[Manual:Miscellaneous Functions#createVideoPlayer|createVideoPlayer()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
  
==getButtonState==
+
{{MudletVersion|4.??}}
;getButtonState([ButtonNameOrID])
 
:This function can be used within checkbox button scripts (2-state buttons) to determine the current state of the checkbox.
 
  
: See also: [[#setButtonState|setButtonState()]].
+
;Example
{{note}} Function can be used in any Mudlet script outside of a button's own script with parameter ButtonNameOrID available from Mudlet version 4.13.0+
 
  
;Parameters
+
<syntaxhighlight lang="lua">
* ''ButtonNameOrID:''
+
---- Table Parameter Syntax ----
: a numerical ID or string name to identify the checkbox button.
 
  
;Returns
+
-- Stop all playing video files for this profile associated with the API
* ''2'' if the button has "checked" state, or ''1'' if the button is not checked. (or a ''nil'' and an error message if ButtonNameOrID did not identify a check-able button)
+
stopVideos()
  
;Example
+
-- Stop playing the text mp4 by name
<syntaxhighlight lang="lua">
+
stopVideos({name = "TextInMotion-VideoSample-1080p.mp4"})
-- check from within the script of a check-able button:
 
local checked = getButtonState()
 
if checked == 1 then
 
    hideExits()
 
else
 
    showExits()
 
end
 
</syntaxhighlight>
 
  
<syntaxhighlight lang="lua">
+
-- Stop playing the unique sound identified as "text"
-- check from anywhere in another Lua script of the same profile (available from Mudlet 4.13.0)
+
stopVideos({
local checked, errMsg = getButtonState("Sleep")
+
     name = nil  -- nil lines are optional, no need to use
if checked then
+
     , key = "text" -- key
     shouldBeMounted = shouldBeMounted or false
+
     , tag = nil  -- nil lines are optional, no need to use
     sendAll("wake", "stand")
+
})
    if shouldBeMounted then
 
        send("mount horse")
 
    end
 
else
 
     -- Global used to record if we were on a horse before our nap:
 
    shouldBeMounted = mounted or false
 
    if shouldBeMounted then
 
        send("dismount")
 
    end
 
    sendAll("sit", "sleep")
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==getCmdLine==
 
;getCmdLine([name])
 
: Returns the current content of the given command line.
 
: See also: [[Manual:Lua_Functions#printCmdLine|printCmdLine()]]
 
 
{{MudletVersion|3.1}}
 
 
;Parameters
 
* ''name'': (optional) name of the command line. If not given, it returns the text of the main commandline.
 
 
;Example
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- replaces whatever is currently in the input line by "55 backpacks"
+
---- Ordered Parameter Syntax of stopVideos([name][,key][,tag]) ----
printCmdLine("55 backpacks")
 
 
 
--prints the text "55 backpacks" to the main console
 
echo(getCmdLine())
 
</syntaxhighlight>
 
  
==getConsoleBufferSize==
+
-- Stop all playing video files for this profile associated with the API
;local lineLimit, sizeOfBatchDeletion = getConsoleBufferSize([consoleName])
+
stopVideos()
:Returns, on success, the maximum number of lines a buffer (main window or a miniconsole) can hold and how many will be removed at a time when that limit is exceeded; returns a ''nil'' and an error message on failure.
 
: See also: [[Manual:Mudlet_Object_Functions#setConsoleBufferSize|setConsoleBufferSize()]]
 
  
;Parameters
+
-- Stop playing the text mp4 by name
* ''consoleName:''
+
stopVideos("TextInMotion-VideoSample-1080p.mp4")
: (optional) The name of the window. If omitted, uses the main console.
 
;Example
 
<syntaxhighlight lang="lua">
 
-- sets the main window's size and how many lines will be deleted
 
-- when it gets to that size to be as small as possible:
 
setConsoleBufferSize("main", 1, 1)
 
true
 
  
-- find out what the numbers are:
+
-- Stop playing the unique sound identified as "text"
local lineLimit, sizeOfBatchDeletion = getConsoleBufferSize()
+
stopVideos(
echo("\nWhen the main console gets to " .. lineLimit .. " lines long, the first " .. sizeOfBatchDeletion .. " lines will be removed.\n")
+
    nil -- name
When the main console gets to 100 lines long, the first 1 lines will be removed.
+
    , "text" -- key
 +
    , nil -- tag
 +
)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{MudletVersion|4.17}}
 
  
==getNamedTimers==
+
==getCustomLoginTextId, PR #3952 open==
; timers = getNamedTimers(userName)
+
;getCustomLoginTextId()
  
:Returns a list of all the named timers' names as a table.
+
Returns the Id number of the custom login text setting from the profile's preferences. Returns ''0'' if the option is disabled or a number greater than that for the item in the table; note it is possible if using an old saved profile in the future that the number might be higher than expected. As a design policy decision it is not permitted for a script to change the setting, this function is intended to allow a script or package to check that the setting is what it expects.
  
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
+
Introduced along with four other functions to enable game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined ''doLogin()'' function, a replacement for which is shown below.
 +
:See also: [[#getCharacterName|getCharacterName()]], [[#sendCharacterName|sendCharacterName()]], [[#sendCustomLoginText|sendCustomLoginText()]], [[#sendPassword|sendPassword()]].
  
{{MudletVersion|4.14}}
+
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952
  
;Parameters
+
Only one custom login text has been defined initially:
* ''userName:''
+
{| class="wikitable"
: The user name the event handler was registered under.
+
|+Predefined custom login texts
 +
|-
 +
!Id!!Custom text!!Introduced in Mudlet version
 +
|-
 +
|1||"connect {character name} {password}"||TBD
 +
|}
  
;Returns
+
The addition of further texts would be subject to negotiation with the Mudlet Makers.
* a table of handler names. { "DemonVitals", "DemonInv" } for example. {} if none are registered
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
  local timers = getNamedTimers("Demonnic")
+
-- A replacement for the default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:
   display(timers)
+
function doLogin()
  -- {}
+
   if getCustomLoginTextId() ~= 1 then
  registerNamedTimer("Test1", "testEvent", "testFunction")
+
    -- We need this particular option but it is not permitted for a script to change the setting, it can only check what it is
   registerNamedTimer("Test2", "someOtherEvent", myHandlerFunction)
+
    echo("\nUnable to login - please select the 'connect {character name} {password}` custom login option in the profile preferences.\n")
   timers = getNamedTimers("Demonnic")
+
   else
  display(timers)
+
    tempTime(2.0, [[sendCustomLoginText()]], 1)
  -- { "Test1", "Test2" }
+
   end
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== getProfileStats==
+
==sendCharacterName, PR #3952 open==
;getProfileStats()
+
;sendCharacterName()
  
:Returns a table with profile statistics for how many triggers, patterns within them, aliases, keys, timers, and scripts the profile has. Similar to the Statistics button in the script editor, accessible to Lua scripting.
+
Sends the name entered into the "Character name" field on the Connection Preferences form directly to the game server. Returns ''true'' unless there is nothing set in that entry in which case a ''nil'' and an error message will be returned instead.
  
{{MudletVersion|4.15}}
+
Introduced along with four other functions to enable game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined ''doLogin()'' function that may be replaced for more sophisticated requirements.
 +
:See also: [[#getCharacterName|getCharacterName()]], [[#sendCharacterPassword|sendCharacterPassword()]], [[#sendCustomLoginText|sendCustomLoginText()]], [[#getCustomLoginTextId|getCustomLoginTextId()]].
  
;Example
+
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952
<syntaxhighlight lang="lua">
 
-- show all stats
 
display(getProfileStats())
 
  
-- check how many active triggers there are
+
==sendCharacterPassword, PR #3952 open==
activetriggers = getProfileStats().triggers.active
+
;sendCharacterPassword()
cecho(f"<PaleGreen>We have <SlateGrey>{activetriggers}<PaleGreen> active triggers!\n")
 
  
-- triggers can have many patterns, so let's check that as well
+
Sends the password entered into the "Password" field on the Connection Preferences form directly to the game server. Returns ''true'' unless there is nothing set in that entry or it is too long after (or before) a connection was successfully made in which case a ''nil'' and an error message will be returned instead.
patterns = getProfileStats().triggers.patterns.active
 
triggers = getProfileStats().triggers.active
 
cecho(f"<PaleGreen>We have <SlateGrey>{patterns}<PaleGreen> active patterns within <SlateGrey>{triggers}<PaleGreen> triggers!\n")
 
</syntaxhighlight>
 
  
==getStopWatches==
+
Introduced along with four other functions to enable game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined ''doLogin()'' function, reproduced below, that may be replaced for more sophisticated requirements.
;table = getStopWatches()
+
:See also: [[#getCharacterName|getCharacterName()]], [[#sendCustomLoginText|sendCustomLoginText()]], [[#getCustomLoginTextId|getCustomLoginTextId()]], [[#sendCharacterName|sendCharacterName()]].
  
: Returns a table of the details for each stopwatch in existence, the keys are the watch IDs but since there can be gaps in the ID number allocated for the stopwatches it will be necessary to use the ''pairs(...)'' rather than the ''ipairs(...)'' method to iterate through all of them in ''for'' loops!
+
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952
: Each stopwatch's details will list the following items: ''name'' (string), ''isRunning'' (boolean), ''isPersistent'' (boolean), ''elapsedTime'' (table).  The last of these contains the same data as is returned by the results table from the [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]] function - namely ''days'' (positive integer), ''hours'' (integer, 0 to 23), ''minutes'' (integer, 0 to 59), ''second'' (integer, 0 to 59), ''milliSeconds'' (integer, 0 to 999), ''negative'' (boolean) with an additional ''decimalSeconds'' (number of seconds, with a decimal portion for the milli-seconds and possibly a negative sign, representing the whole elapsed time recorded on the stopwatch) - as would also be returned by the [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]] function.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- on the command line:
+
-- The default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:
lua getStopWatches()
+
function doLogin()
-- could return something like:
+
   if getCharacterName() ~= "" then
{
+
     tempTime(2.0, [[sendCharacterName()]], 1)
   {
+
     tempTime(3.0, [[sendCharacterPassword()]], 1)
    isPersistent = true,
+
   end
    elapsedTime = {
+
end
      minutes = 15,
 
      seconds = 2,
 
      negative = false,
 
      milliSeconds = 66,
 
      hours = 0,
 
      days = 18,
 
      decimalSeconds = 1556102.066
 
    },
 
    name = "Playing time",
 
     isRunning = true
 
  },
 
  {
 
    isPersistent = true,
 
    elapsedTime = {
 
      minutes = 47,
 
      seconds = 1,
 
      negative = true,
 
      milliSeconds = 657,
 
      hours = 23,
 
      days = 2,
 
      decimalSeconds = -258421.657
 
    },
 
    name = "TMC Vote",
 
     isRunning = true
 
  },
 
  {
 
    isPersistent = false,
 
    elapsedTime = {
 
      minutes = 26,
 
      seconds = 36,
 
      negative = false,
 
      milliSeconds = 899,
 
      hours = 3,
 
      days = 0,
 
      decimalSeconds = 12396.899
 
    },
 
    name = "",
 
    isRunning = false
 
  },
 
  [5] = {
 
    isPersistent = false,
 
    elapsedTime = {
 
      minutes = 0,
 
      seconds = 38,
 
      negative = false,
 
      milliSeconds = 763,
 
      hours = 0,
 
      days = 0,
 
      decimalSeconds = 38.763
 
    },
 
    name = "",
 
    isRunning = true
 
   }
 
}
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{MudletVersion|4.4}}
+
==sendCustomLoginText, PR #3952 open ==
 +
;sendCustomLoginText()
 +
 
 +
Sends the custom login text (which does NOT depend on the user's choice of GUI language) selected in the preferences for this profile. The {password} (and {character name} if present) fields will be replaced with the values entered into the "Password" and "Character name" fields on the Connection Preferences form and then sent directly to the game server. Returns ''true'' unless there is nothing set in either of those entries (though only if required for the character name) or it is too long after (or before) a connection was successfully made or if the custom login feature is disabled, in which case a ''nil'' and an error message will be returned instead.
  
==getStopWatchTime==
+
Introduced along with four other functions to enable game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined ''doLogin()'' function, a replacement for which is shown below.
;time = getStopWatchTime(watchID [or watchName from Mudlet 4.4.0])
+
:See also: [[#getCharacterName|getCharacterName()]], [[#sendCharacterName|sendCharacterName()]], [[#sendPassword|sendPassword()]], [[#getCustomLoginTextId|getCustomLoginTextId()]].
: Returns the time as a decimal number of seconds with up to three decimal places to give a milli-seconds (thousandths of a second) resolution.
 
: Please note that, prior to 4.4.0 it was not possible to retrieve the elapsed time after the stopwatch had been stopped, retrieving the time was not possible as the returned value then was an indeterminate, meaningless time; from the 4.4.0 release, however, the elapsed value can be retrieved at any time, even if the stopwatch has not been started since creation or modified with the [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]] function introduced in that release.
 
  
: See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatch es|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchBrokenDownTime|getStopWatchBrokenDownTime()]].
+
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952
  
:Returns a number
+
Only one custom login text has been defined initially:
 +
{| class="wikitable"
 +
|+Predefined custom login texts
 +
|-
 +
!Id!!Custom text!!Introduced in Mudlet version
 +
|-
 +
|1||"connect {character name} {password}"||TBD
 +
|}
  
;Parameters
+
The addition of further texts would be subject to negotiation with the Mudlet Makers.
* ''watchID''
 
: The ID number of the watch.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- an example of showing the time left on the stopwatch
+
-- A replacement for the default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:
teststopwatch = teststopwatch or createStopWatch()
+
function doLogin()
startStopWatch(teststopwatch)
+
  if getCustomLoginTextId() ~= 1 then
echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))
+
    -- We need this particular option but it is not permitted for a script to change the setting, it can only check what it is
tempTimer(1, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])
+
    echo("\nUnable to login - please select the 'connect {character name} {password}` custom login option in the profile preferences.\n")
tempTimer(2, [[echo("Time on stopwatch: "..getStopWatchTime(teststopwatch))]])
+
  else
stopStopWatch(teststopwatch)
+
    tempTime(2.0, [[sendCustomLoginText()]], 1)
 +
  end
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getStopWatchBrokenDownTime==
+
=Mudlet Object Functions=
; brokenDownTimeTable = getStopWatchBrokenDownTime(watchID or watchName)
+
:A collection of functions that manipulate Mudlet's scripting objects - triggers, aliases, and so forth.
: Returns the current stopwatch time, whether the stopwatch is running or is stopped, as a table, broken down into:
+
 
* "days" (integer)
+
==ancestors, new in PR #6726==
* "hours" (integer, 0 to 23)
+
;ancestors(IDnumber, type)
* "minutes" (integer, 0 to 59)
+
:You can use this function to find out about all the ancestors of something.
* "seconds" (integer, 0 to 59)
 
* "milliSeconds" (integer, 0 to 999)
 
* "negative" (boolean, true if value is less than zero)
 
  
: See also: [[Manual:Lua_Functions#startStopWatch|startStopWatch()]], [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]], [[Manual:Lua_Functions#deleteStopWatch|deleteStopWatch()]], [[Manual:Lua_Functions#getStopWatch es|getStopWatches()]], [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]].
+
:Returns a list as a table with the details of each successively distance ancestor (if any) of the given item; the details are in the form of a sub-table, within each containing specifically:
 +
:* its IDnumber as a number
 +
:* its name as a string
 +
:* whether it is active as a boolean
 +
:* its "node" (type) as a string, one of "item", "group" (folder) or "package" (module)
 +
:Returns ''nil'' and an error message if either parameter is not valid
  
 
;Parameters
 
;Parameters
* ''watchID'' / ''watchName''
+
* ''IDnumber:''
: The ID number or the name of the watch.
+
: The ID number of a single item, (which will be that returned by a ''temp*'' or ''perm*'' function to create such an item to identify the item).
 +
* ''type:''
 +
: The type can be 'alias', 'button', 'trigger', 'timer', 'keybind', or 'script'.
 +
 
 +
: See also: [[#isAncestorsActive|isAncestorsActive(...)]], [[#isActive|isActive(...)]]
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--an example, showing the presetting of a stopwatch.
+
-- To do
 
 
--This will fail if the stopwatch with the given name
 
-- already exists, but then we can use the existing one:
 
local watchId = createStopWatch("TopMudSiteVoteStopWatch")
 
if watchId ~= nil then
 
  -- so we have just created the stopwatch, we want it
 
  -- to be saved for future sessions:
 
  setStopWatchPersistence("TopMudSiteVoteStopWatch", true)
 
  -- and set it to count down the 12 hours until we can
 
  -- revote:
 
  adjustStopWatch("TopMudSiteVoteStopWatch", -60*60*12)
 
  -- and start it running
 
  startStopWatch("TopMudSiteVoteStopWatch")
 
 
 
  openWebPage("http://www.topmudsites.com/vote-wotmud.html")
 
end
 
 
 
--[[ now I can check when it is time to vote again, even when
 
I stop the session and restart later by running the following
 
from a perm timer - perhaps on a 15 minute interval. Note that
 
when loaded in a new session the Id it gets is unlikely to be
 
the same as that when it was created - but that is not a
 
problem as the name is preserved and, if the timer is running
 
when the profile is saved at the end of the session then the
 
elapsed time will continue to increase to reflect the real-life
 
passage of time:]]
 
 
 
local voteTimeTable = getStopWatchBrokenDownTime("TopMudSiteVoteStopWatch")
 
 
 
if voteTimeTable["negative"] then
 
  if voteTimeTable["hours"] == 0 and voteTimeTable["minutes"] < 30 then
 
    echo("Voting for WotMUD on Top Mud Site in " .. voteTimeTable["minutes"] .. " minutes...")
 
  end
 
else
 
  echo("Oooh, it is " .. voteTimeTable["days"] .. " days, " .. voteTimeTable["hours"] .. " hours and " .. voteTimeTable["minutes"] .. " minutes past the time to Vote on Top Mud Site - doing it now!")
 
  openWebPage("http://www.topmudsites.com/vote-wotmud.html")
 
  resetStopWatch("TopMudSiteVoteStopWatch")
 
  adjustStopWatch("TopMudSiteVoteStopWatch", -60*60*12)
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{MudletVersion|4.7}}
+
==findItems, new in PR #6742==
 +
;findItems("name", "type"[, exact[, case sensitive]])
 +
: You can use this function to determine the ID number or numbers of items of a particular type with a given name.
  
==getScript==
+
:Returns a list as a table with ids of each Mudlet item that matched or ''nil'' and an error message should an incorrect type string be given.
; getScript(scriptName, [occurrence])
 
: Returns the script with the given name. If you have more than one script with the same name, specify the occurrence to pick a different one. Returns -1 if the script doesn't exist.
 
 
 
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#setScript|setScript()]], [[Manual:Lua_Functions#appendScript|appendScript()]]
 
  
 
;Parameters
 
;Parameters
* ''scriptName'': name of the script.
+
* ''name:''
* ''occurrence'': (optional) occurence of the script in case you have many with the same name.
+
:The name (as a string) of the item, (which will be that returned by a ''temp*'' or ''perm*'' function to create such an item to identify the item).
 +
* ''type:''
 +
:The type (as a string) can be 'alias', 'button', 'trigger', 'timer', 'keybind' , or 'script'.
 +
* ''exact:''
 +
:(Optional) a boolean which if omitted or ''true'' specifies to match the given name against the whole of the names for items or only as a sub-string of them. As a side effect, if this is provided and is ''false'' and an empty string (i.e. ''""'') is given as the first argument then the function will return the ID numbers of ''all'' items (both temporary and permanent) of the given type in existence at the time.
 +
* ''case sensitive:''
 +
:(Optional) a boolean which if omitted or ''true'' specifies to match in a case-sensitive manner the given name against the names for items.
  
 
;Example
 
;Example
 +
Given a profile with just the default packages installed (automatically) - including the '''echo''' one:
 +
[[File:View of standard aliases with focus on echo package.png|border|none|400px|link=]]
 +
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- show the "New script" on screen
+
-- Should find just the package with the name:
print(getScript("New script"))
+
lua findItems("echo", "alias")
 
+
{ 3 }
-- an example of returning the script Lua code from the second occurrence of "testscript"
 
test_script_code = getScript("testscript", 2)
 
</syntaxhighlight>
 
  
{{MudletVersion|4.8}}
+
-- Should find both the package and the alias - as the latter contains "echo" with another character
 +
lua findItems("echo", "alias", false)
 +
{ 3, 4 }
  
==invokeFileDialog==
+
-- Finds the ID numbers of all the aliases:
;invokeFileDialog(fileOrFolder, dialogTitle)
+
lua findItems("", "alias", false)
:Opens a file chooser dialog, allowing the user to select a file or a folder visually. The function returns the selected path or "" if there was none chosen.
+
{ 1, 2, 3, 4, 5, 6, 7 }
  
;Parameters
+
-- Will still find the package with the name "echo" as we are not concerned with the casing now:
* ''fileOrFolder:'' ''true'' for file selection, ''false'' for folder selection.
+
lua findItems("Echo", "alias", true, false)
* ''dialogTitle'': what to say in the window title.
+
{ 3 }
  
;Examples
+
-- Won't find the package with the name "echo" now as we are concerned with the casing:
<syntaxhighlight lang="lua">
+
lua findItems("Echo", "alias", true, true)
function whereisit()
+
{}
  local path = invokeFileDialog(false, "Where should we save the file? Select a folder and click Open")
 
 
 
  if path == "" then return nil else return path end
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==isActive==
+
==isActive, modified by PR #6726==
 
 
 
;isActive(name/IDnumber, type[, checkAncestors])
 
;isActive(name/IDnumber, type[, checkAncestors])
 
:You can use this function to check if something, or somethings, are active.  
 
:You can use this function to check if something, or somethings, are active.  
Line 893: Line 838:
 
{{note}} A positive ID number that does not exist will still return a ''0'' value, this is for constancy with the way the function behaves for a name that does not refer to any item either. If necessary the existence of an item should be confirmed with [[#exists|exists(...)]] first.
 
{{note}} A positive ID number that does not exist will still return a ''0'' value, this is for constancy with the way the function behaves for a name that does not refer to any item either. If necessary the existence of an item should be confirmed with [[#exists|exists(...)]] first.
  
==isAncestorsActive==
+
==isAncestorsActive, new in PR #6726==
 
 
 
;isAncestorsActive(IDnumber, "type")
 
;isAncestorsActive(IDnumber, "type")
 
:You can use this function to check if '''all''' the ancestors of something are active independent of whether it itself is, (for that use the two argument form of [[#isActive|isActive(...)]]).  
 
:You can use this function to check if '''all''' the ancestors of something are active independent of whether it itself is, (for that use the two argument form of [[#isActive|isActive(...)]]).  
Line 913: Line 857:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==isPrompt==
+
=Networking Functions=
;isPrompt()
+
:A collection of functions for managing networking.
:Returns true or false depending on if the line at the cursor position is a prompt. This infallible feature is available for games that supply GA events (to check if yours is one, look to bottom-right of the main window - if it doesn’t say <No GA>, then it supplies them).
+
==sendSocket revised in PR #7066 (Open)==
 
 
:Example use could be as a Lua function, making closing gates on a prompt real easy.
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- make a trigger pattern with 'Lua function', and this will trigger on every prompt!
 
-- note that this is deprecated as we now have the prompt trigger type which does the same thing
 
-- the function can still be useful for detecting if you're running code on a prompt for other reasons
 
-- but you should be using a prompt trigger for this rather than a Lua function trigger.
 
return isPrompt()
 
</syntaxhighlight>
 
 
 
==killAlias==
 
;killAlias(aliasID)
 
:Deletes a temporary alias with the given ID.
 
 
 
;Parameters
 
* ''aliasID:''
 
: The id returned by [[Manual:Lua_Functions#tempAlias|tempAlias]] to identify the alias.
 
 
 
<syntaxhighlight lang="lua">
 
-- deletes the alias with ID 5
 
killAlias(5)
 
</syntaxhighlight>
 
 
 
==killKey==
 
;killKey(name)
 
:Deletes a keybinding with the given name. If several keybindings have this name, they'll all be deleted.
 
  
;Parameters
+
;sendSocket(data)
* ''name:''
 
: The name or the id returned by [[Manual:Lua_Functions#tempKey|tempKey]] to identify the key.
 
  
{{MudletVersion|3.2}}
+
:Sends given binary data as-is (or with some predefined special tokens converted to byte values) to the game. You can use this to implement support for a [[Manual:Supported_Protocols#Adding_support_for_a_telnet_protocol|new telnet protocol]], [http://forums.mudlet.org/viewtopic.php?f=5&t=2272 simultronics] [http://forums.mudlet.org/viewtopic.php?f=5&t=2213#p9810 login] etc.
  
<syntaxhighlight lang="lua">
+
; success = sendSocket("data")
-- make a temp key
 
local keyid = tempKey(mudlet.key.F8, [[echo("hi!")]])
 
  
-- delete the said temp key
+
;See also: [[Manual:Lua_Functions#feedTelnet|feedTelnet()]], [[Manual:Lua_Functions#feedTriggers|feedTriggers()]]
killKey(keyid)
 
</syntaxhighlight>
 
  
==killTimer==
+
{{note}} Modified in Mudlet '''tbd''' to accept some tokens like "''<NUL>''" to include byte values that are not possible to insert with the standard Lua string escape "''\###''" form where ### is a three digit number between 000 and 255 inclusive or where the value is more easily provided via a mnemonic. For the table of the tokens that are known about, see the one in [[Manual:Lua_Functions#feedTelnet|feedTelnet()]].
;killTimer(id)
 
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTimer]].
 
  
{{note}} Non-temporary timers that you have set up in the GUI or by using [[#permTimer|permTimer]] cannot be deleted with this function. Use [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#enableTimer|enableTimer()]] to turn them on or off.
+
{{note}} The data (as bytes) once the tokens have been converted to their byte values is sent as is to the Game Server; any encoding to, say, a UTF-8 representation or to duplicate ''0xff'' byte values so they are not considered to be Telnet ''<IAC>'' (Interpret As Command) bytes must be done to the data prior to calling this function.
  
 
;Parameters
 
;Parameters
* ''id:'' the ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]].
+
* ''data:''
 +
: String containing the bytes to send to the Game Server possibly containing some tokens that are to be converted to bytes as well.
  
: Returns true on success and false if the timer id doesn’t exist anymore (timer has already fired) or the timer is not a temp timer.
+
;Returns  
 +
* (Only since Mudlet '''tbd''') Boolean ''true'' if the whole data string (after token replacement) was sent to the Server, ''false'' if that failed for any reason (including if the Server has not been connected or is now disconnected). ''nil'' and an error message for any other defect.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- create the timer and remember the timer ID
+
-- Tell the Server that we are now willing and able to process  to process Ask the Server to a comment explaining what is going on, if there is multiple functionalities (or optional parameters) the examples should start simple and progress in complexity if needed!
timerID = tempTimer(10, [[echo("hello!")]])
+
-- the examples should be small, but self-contained so new users can copy & paste immediately without going diving in lots other function examples first.
 +
-- comments up top should introduce / explain what it does
  
-- delete the timer
+
local something = function(exampleValue)
killTimer(timerID)
+
if something then
-- reset the reference to it
+
  -- do something with something (assuming there is a meaningful return value)
timerID = nil
+
end
</syntaxhighlight>
 
 
 
==killTrigger==
 
;killTrigger(id)
 
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTrigger]], or a trigger made with one of the ''temp<type>Trigger()'' functions.
 
 
 
{{note}} When used in out of trigger contexts, the triggers are disabled and deleted upon the next line received from the game - so if you are testing trigger deletion within an alias, the 'statistics' window will be reporting trigger counts that are disabled and pending removal, and thus are no cause for concern.
 
 
 
;Parameters
 
* ''id:''
 
: The ID returned by a ''temp<type>Trigger'' to identify the item. ID is a string and not a number.
 
 
 
:Returns true on success and false if the trigger id doesn’t exist anymore (trigger has already fired) or the trigger is not a temp trigger.
 
 
 
{{note}} As of Mudlet version 4.16.0, triggers created with [[#tempComplexRegexTrigger|tempComplexRegexTrigger]] can only be killed using the name string specified during creation.
 
 
 
==permAlias==
 
;permAlias(name, parent, regex, lua code)
 
 
 
:Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.
 
 
 
;Parameters
 
* ''name:''
 
: The name you’d like the alias to have.
 
* ''parent:''
 
: The name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.
 
* ''regex:''
 
: The pattern that you’d like the alias to use.
 
* ''lua code:''
 
: The script the alias will do when it matches.
 
;Example
 
<syntaxhighlight lang="lua">
 
-- creates an alias called "new alias" in a group called "my group"
 
permAlias("new alias", "my group", "^test$", [[echo ("say it works! This alias will show up in the script editor too.")]])
 
</syntaxhighlight>
 
 
 
{{note}} Mudlet by design allows duplicate names - so calling permAlias with the same name will keep creating new aliases. You can check if an alias already exists with the [[Manual:Lua_Functions#exists|exists]] function.
 
  
==permGroup==
+
-- maybe another example for the optional second case
;permGroup(name, itemtype, [parent])
+
local somethingElse = function(exampleValue, anotherValue)
  
:Creates a new group of a given type. This group will persist through Mudlet restarts.
+
-- lastly, include an example with error handling to give an idea of good practice
;Parameters
+
local ok, err = function()
* ''name'':
+
if not ok then
: The name of the new group item you want to create.
+
   debugc(f"Error: unable to do <particular thing> because {err}\n")
* ''itemtype'' :
+
  return
: The type of the item, can be one of the following:
 
:: trigger
 
:: alias
 
:: timer
 
:: script (available in Mudlet 4.7+)
 
:: key (available in Mudlet 4.11+)
 
* ''parent'' (available in Mudlet 3.1+):
 
: (optional) Name of existing item which the new item will be created as a child of. If none is given, item will be at the root level (not nested in any other groups)
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
--create a new trigger group
 
permGroup("Combat triggers", "trigger")
 
 
 
--create a new alias group only if one doesn't exist already
 
if exists("Defensive aliases", "alias") == 0 then
 
   permGroup("Defensive aliases", "alias")
 
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==permPromptTrigger==
+
; Additional development notes
;permPromptTrigger(name, parent, lua code)
+
-- This function is still being written up.
:Creates a persistent trigger for the in-game prompt that stays after Mudlet is restarted and shows up in the Script Editor.
 
 
 
{{note}} If the trigger is not working, check that the '''N:''' bottom-right has a number. This feature requires telnet Go-Ahead (GA) or End-of-Record (EOR) to be enabled in your game. Available in Mudlet 3.6+
 
  
;Parameters:
+
==feedTelnet added in PR #7066 (Open)====
* ''name'' is the name you’d like the trigger to have.
 
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.
 
* ''lua code'' is the script the trigger will do when it matches.
 
  
;Example:
+
; feedTelnet(data)
<syntaxhighlight lang="lua">
 
permPromptTrigger("echo on prompt", "", [[echo("hey! this thing is working!\n")]])
 
</syntaxhighlight>
 
  
 +
:Sends given binary data with some predefined special tokens converted to byte values, to the internal telnet engine, as if it had been received from the game. This is primarily to enable testing when new Telnet sub-options/protocols are being developed. The data has to be injected into the system nearer to the point where the Game Server's data starts out than ''feedTriggers()'' and unlike the latter the data is not subject to any encoding so as to match the current profile's setting (which normally happens with ''feedTriggers()''). Furthermore - to prevent this function from putting the telnet engine into a state which could damage the processing of real game data it will refuse to work unless the Profile is completely disconnected from the game server.
  
==permRegexTrigger==
+
;See also: [[Manual:Lua_Functions#feedTriggers|feedTriggers()]], [[Manual:Lua_Functions#sendSocket|sendSocket()]]
;permRegexTrigger(name, parent, pattern table, lua code)
 
:Creates a persistent trigger with one or more ''regex'' patterns that stays after Mudlet is restarted and shows up in the Script Editor.
 
  
;Parameters
+
{{MudletVersion|tbd}}
* ''name'' is the name you’d like the trigger to have.
 
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.
 
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.
 
* ''lua code'' is the script the trigger will do when it matches.
 
;Example
 
<syntaxhighlight lang="lua">
 
-- Create a regex trigger that will match on the prompt to record your status
 
permRegexTrigger("Prompt", "", {"^(\d+)h, (\d+)m"}, [[health = tonumber(matches[2]); mana = tonumber(matches[3])]])
 
</syntaxhighlight>
 
{{note}} Mudlet by design allows duplicate names - so calling permRegexTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.
 
  
==permBeginOfLineStringTrigger==
+
{{note}} This is not really intended for end-user's but might be useful in some circumstances.
;permBeginOfLineStringTrigger(name, parent, pattern table, lua code)
 
:Creates a persistent trigger that stays after Mudlet is restarted and shows up in the Script Editor. The trigger will go off whenever one of the ''regex'' patterns it's provided with matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.
 
  
 
;Parameters
 
;Parameters
* ''name'' is the name you’d like the trigger to have.
+
* ''data''
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.
+
: String containing the bytes to send to the internal telnet engine as if it had come from the Game Server, it can containing some tokens listed below that are to be converted to bytes as well.
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.
 
* ''lua code'' is the script the trigger will do when it matches.
 
  
;Examples
+
;Returns
<syntaxhighlight lang="lua">
+
* Boolean ''true'' if the ''data'' string was sent to the internal telnet engine. ''nil'' and an error message otherwise, specifically the case when there is some traces of a connection or a complete connection to the socket that passes the data to and from the game server. Additionally, if the data is an empty string ''""'' a second return value will be provided as an integer number representing a version for the table of tokens - which will be incremented each time a change is made to that table so that which tokens are valid can be determined. Note that unrecognised tokens should be passed through as is and not get replaced.
-- Create a trigger that will match on anything that starts with "You sit" and do "stand".
 
-- It will not go into any groups, so it'll be on the top.
 
permBeginOfLineStringTrigger("Stand up", "", {"You sit"}, [[send ("stand")]])
 
  
-- Another example - lets put our trigger into a "General" folder and give it several patterns.
+
{| class="wikitable sortable"
permBeginOfLineStringTrigger("Stand up", "General", {"You sit", "You fall", "You are knocked over by"}, [[send ("stand")]])
+
|+ Token value table
</syntaxhighlight>
+
|-
{{note}} Mudlet by design allows duplicate names - so calling permBeginOfLineStringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.
+
! Token !! Byte !! Version!! Notes
 +
|-
 +
|| <00> || \0x00 || 1 || 0 dec.
 +
|-
 +
|| <O_BINARY> || \0x00 || 1 || Telnet option: Binary
 +
|-
 +
|| <NUL> || \0x00 || 1 || ASCII control character: NULL
 +
|-
 +
|| <01> || \x01 || 1 || 1 dec.
 +
|-
 +
|| <O_ECHO> || \x01 || 1 || Telnet option: Echo
 +
|-
 +
|| <SOH> || \x01 || 1 || ASCII control character: Start of Heading
 +
|-
 +
|| <02> || \x02 || 1 || 2 dec. Telnet option: Reconnect
 +
|-
 +
|| <STX> || \x02 || 1 || ASCII control character: Start of Text
 +
|-
 +
|| <03> || \x03 || 1 || 3 dec.
 +
|-
 +
|| <O_SGA> || \x03 || 1 || Telnet option: Suppress Go Ahead
 +
|-
 +
|| <ETX> || \x03 || 1 || ASCII control character: End of Text
 +
|-
 +
|| <04> || \x04 || 1 || Telnet option: Approx Message Size Negotiation
 +
|-
 +
|| <EOT> || \x04 || 1 || ASCII control character: End of Transmission
 +
|-
 +
|| <05> || \x05 || 1 ||
 +
|-
 +
|| <O_STATUS> || \x05 || 1 ||
 +
|-
 +
|| <ENQ> || \x05 || 1 || ASCII control character: Enquiry
 +
|-
 +
|| <06> || \x06 || 1 || Telnet option: Timing Mark
 +
|-
 +
|| <ACK> || \x06 || 1 || ASCII control character: Acknowledge
 +
|-
 +
|| <07> || \x07 || 1 || Telnet option: Remote Controlled Trans and Echo
 +
|-
 +
|| <BELL> || \x07 || 1 || ASCII control character: Bell
 +
|-
 +
|| <08> || \x08 || 1 || Telnet option: Output Line Width
 +
|-
 +
|| <BS> || \x08 || 1 ||
 +
|-
 +
|| <09> || \x09 || 1 || Telnet option: Output Page Size
 +
|-
 +
|| <HTAB> || \x09 || 1 || ASCII control character: Horizontal Tab
 +
|-
 +
|| <0A> || \x0a || 1 || Telnet option: Output Carriage-Return Disposition
 +
|-
 +
|| <LF> || \x0a || 1 || ASCII control character: Line-Feed
 +
|-
 +
|| <0B> || \x0b || 1 || Telnet option: Output Horizontal Tab Stops
 +
|-
 +
|| <VTAB> || \x0b || 1 || ASCII control character: Vertical Tab
 +
|-
 +
|| <0C> || \x0c || 1 || Telnet option: Output Horizontal Tab Disposition
 +
|-
 +
|| <FF> || \x0c || 1 || ASCII control character: Form-Feed
 +
|-
 +
|| <0D> || \x0d || 1 || Telnet option: Output Form-feed Disposition
 +
|-
 +
|| <CR> || \x0d || 1 || ASCII control character: Carriage-Return
 +
|-
 +
|| <0E> || \x0e || 1 || Telnet option: Output Vertical Tab Stops
 +
|-
 +
|| <SO> || \x0e || 1 || ASCII control character: Shift-Out
 +
|-
 +
|| <0F> || \x0f || 1 || Telnet option: Output Vertical Tab Disposition
 +
|-
 +
|| <SI> || \x0f || 1 || ASCII control character: Shift-In
 +
|-
 +
|| <10> || \x10 || 1 || Telnet option: Output Linefeed Disposition
 +
|-
 +
|| <DLE> || \x10 || 1 || ASCII control character: Data Link Escape
 +
|-
 +
|| <11> || \x11 || 1 || Telnet option: Extended ASCII
 +
|-
 +
|| <DC1> || \x11 || 1 || ASCII control character: Device Control 1
 +
|-
 +
|| <12> || \x12 || 1 || Telnet option: Logout
 +
|-
 +
|| <DC2" || \x12 || 1 || ASCII control character: Device Control 2
 +
|-
 +
|| <13> || \x13 || 1 || Telnet option: Byte Macro
 +
|-
 +
|| <DC3> || \x13 || 1 || ASCII control character: Device Control 3
 +
|-
 +
|| <14> || \x14 || 1 || Telnet option: Data Entry Terminal
 +
|-
 +
|| <DC4> || \x14 || 1 || ASCII control character: Device Control 4
 +
|-
 +
|| <15> || \x15 || 1 || Telnet option: SUPDUP
 +
|-
 +
|| <NAK> || \x15 || 1 || ASCII control character: Negative Acknowledge
 +
|-
 +
|| <16> || \x16 || 1 || Telnet option: SUPDUP Output
 +
|-
 +
|| <SYN> || \x16 || 1 || ASCII control character: Synchronous Idle
 +
|-
 +
|| <17> || \x17 || 1 || Telnet option: Send location
 +
|-
 +
|| <ETB> || \x17 || 1 || ASCII control character: End of Transmission Block
 +
|-
 +
|| <18> || \x18 || 1 ||
 +
|-
 +
|| <O_TERM> || \x18 || 1 || Telnet option: Terminal Type
 +
|-
 +
|| <CAN> || \x18 || 1 || ASCII control character: Cancel
 +
|-
 +
|| <19> || \x19 || 1 ||
 +
|-
 +
|| <O_EOR> || \x19 || 1 || Telnet option: End-of-Record
 +
|-
 +
|| <nowiki><EM></nowiki> || \x19 || 1 || ASCII control character: End of Medium
 +
|-
 +
|| <1A> || \x1a || 1 || Telnet option:  TACACS User Identification
 +
|-
 +
|| <nowiki><SUB></nowiki> || \x1a || 1 || ASCII control character: Substitute
 +
|-
 +
|| <1B> || \x1b || 1 || Telnet option: Output Marking
 +
|-
 +
|| <ESC> || \x1b || 1 || ASCII control character: Escape
 +
|-
 +
|| <1C> || \x1c || 1 || Telnet option: Terminal Location Number
 +
|-
 +
|| <FS> || \x1c || 1 || ASCII control character: File Separator
 +
|-
 +
|| <1D> || \x1d || 1 || Telnet option: Telnet 3270 Regime
 +
|-
 +
|| <GS> || \x1d || 1 || ASCII control character: Group Separator
 +
|-
 +
|| <1E> || \x1e || 1 || Telnet option: X.3 PAD
 +
|-
 +
|| <RS> || \x1e || 1 || ASCII control character: Record Separator
 +
|-
 +
|| <1F> || \x1f || 1 ||
 +
|-
 +
|| <O_NAWS> || \x1f || 1 || Telnet option: Negotiate About Window Size
 +
|-
 +
|| <US> || \x1f || 1 || ASCII control character: Unit Separator
 +
|-
 +
|| <SP> || \x20 || 1 || 32 dec. ASCII character: Space
 +
|-
 +
|| <O_NENV> || \x27 || 1 || 39 dec. Telnet option: New Environment (also MNES)
 +
|-
 +
|| <O_CHARS> || \x2a || 1 || 42 dec. Telnet option: Character Set
 +
|-
 +
|| <O_KERMIT> || \x2f || 1 || 47 dec. Telnet option: Kermit
 +
|-
 +
|| <O_MSDP> || \x45 || 1 || 69 dec. Telnet option: Mud Server Data Protocol
 +
|-
 +
|| <O_MSSP> || \x46 || 1 || 70 dec. Telnet option: Mud Server Status Protocol
 +
|-
 +
|| <O_MCCP> || \x55 || 1 || 85 dec
 +
|-
 +
|| <O_MCCP2> || \x56 || 1 || 86 dec
 +
|-
 +
|| <O_MSP> || \x5a || 1 || 90 dec. Telnet option: Mud Sound Protocol
 +
|-
 +
|| <O_MXP> || \x5b || 1 || 91 dec. Telnet option: Mud eXtension Protocol
 +
|-
 +
|| <O_ZENITH> || \x5d || 1 || 93 dec. Telnet option: Zenith Mud Protocol
 +
|-
 +
|| <O_AARDWULF> || \x66 || 1 || 102 dec. Telnet option: Aardwuld Data Protocol
 +
|-
 +
|| <nowiki><DEL></nowiki> || \x7f || 1 || 127 dec. ASCII control character: Delete
 +
|-
 +
|| <O_ATCP> || \xc8 || 1 || 200 dec
 +
|-
 +
|| <O_GMCP> || \xc9 || 1 || 201 dec
 +
|-
 +
|| <T_EOR> || \xef || 1 || 239 dec
 +
|-
 +
|| <F0> || \xf0 || 1 ||
 +
|-
 +
|| <T_SE> || \xf0 || 1 ||
 +
|-
 +
|| <F1> || \xf1 || 1 ||
 +
|-
 +
|| <T_NOP> || \xf1 || 1 ||
 +
|-
 +
|| <F2> || \xf2 || 1 ||
 +
|-
 +
|| <T_DM> || \xf2 || 1 ||
 +
|-
 +
|| <F3> || \xf3 || 1 ||
 +
|-
 +
|| <T_BRK> || \xf3 || 1 ||
 +
|-
 +
|| <F4> || \xf4 || 1 ||
 +
|-
 +
|| <T_IP> || \xf4 || 1 ||
 +
|-
 +
|| <F5> || \xf5 || 1 ||
 +
|-
 +
|| <T_ABOP> || \xf5 || 1 ||
 +
|-
 +
|| <F6> || \xf6 || 1 ||
 +
|-
 +
|| <T_AYT> || \xf6 || 1 ||
 +
|-
 +
|| <F7> || \xf7 || 1 ||
 +
|-
 +
|| <T_EC> || \xf7 || 1 ||
 +
|-
 +
|| <F8> || \xf8 || 1 ||
 +
|-
 +
|| <T_EL> || \xf8 || 1 ||
 +
|-
 +
|| <F9> || \xf9 || 1 ||
 +
|-
 +
|| <T_GA> || \xf9 || 1 ||
 +
|-
 +
|| <FA> || \xfa || 1 ||
 +
|-
 +
|| <T_SB> || \xfa || 1 ||
 +
|-
 +
|| <FB> || \xfb || 1 ||
 +
|-
 +
|| <T_WILL> || \xfb || 1 ||
 +
|-
 +
|| <FC> || \xfc || 1 ||
 +
|-
 +
|| <T_WONT> || \xfc || 1 ||
 +
|-
 +
|| <FD> || \xfd || 1 ||
 +
|-
 +
|| <T_DO> || \xfd || 1 ||
 +
|-
 +
|| <FE> || \xfe || 1 ||
 +
|-
 +
|| <T_DONT> || \xfe || 1 ||
 +
|-
 +
|| <FF> || \xff || 1 ||
 +
|-
 +
|| <T_IAC> || \xff'
 +
|}
  
==permSubstringTrigger==
 
;permSubstringTrigger( name, parent, pattern table, lua code )
 
:Creates a persistent trigger with one or more ''substring'' patterns that stays after Mudlet is restarted and shows up in the Script Editor.
 
;Parameters
 
* ''name'' is the name you’d like the trigger to have.
 
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.
 
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.
 
* ''lua code'' is the script the trigger will do when it matches.
 
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- Create a trigger to highlight the word "pixie" for us
+
-- a comment explaining what is going on, if there is multiple functionalities (or optional parameters) the examples should start simple and progress in complexity if needed!
permSubstringTrigger("Highlight stuff", "General", {"pixie"},
+
-- the examples should be small, but self-contained so new users can copy & paste immediately without going diving in lots other function examples first.
[[selectString(line, 1) bg("yellow") resetFormat()]])
+
-- comments up top should introduce / explain what it does
  
-- Or another trigger to highlight several different things
+
local something = feedTelnet(exampleValue)
permSubstringTrigger("Highlight stuff", "General", {"pixie", "cat", "dog", "rabbit"},
+
if something then
[[selectString(line, 1) fg ("blue") bg("yellow") resetFormat()]])
+
  -- do something with something (assuming there is a meaningful return value)
</syntaxhighlight>
+
end
{{note}} Mudlet by design allows duplicate names - so calling permSubstringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.
 
 
 
==permScript==
 
;permScript(name, parent, lua code)
 
: Creates a new script in the Script Editor that stays after Mudlet is restarted.
 
 
 
;Parameters
 
* ''name'': name of the script.
 
* ''parent'': name of the script group you want the script to go in.
 
* ''lua code'': is the code with string you are putting in your script.
 
 
 
;Returns
 
* a unique id number for that script.
 
 
 
: See also: [[#enableScript|enableScript()]], [[#exists|exists()]], [[#appendScript|appendScript()]], [[#disableScript|disableScript()]], [[#getScript|getScript()]], [[#setScript|setScript()]]
 
  
;Example:
+
-- maybe another example for the optional second case
<syntaxhighlight lang="lua">
+
local somethingElse = function(exampleValue, anotherValue)
-- create a script in the "first script group" group
 
permScript("my script", "first script group", [[send ("my script that's in my first script group fired!")]])
 
-- create a script that's not in any group; just at the top
 
permScript("my script", "", [[send ("my script that's in my first script group fired!")]])
 
  
-- enable Script - a script element is disabled at creation
+
-- lastly, include an example with error handling to give an idea of good practice
enableScript("my script")
+
local ok, err = function()
</syntaxhighlight>
+
if not ok then
 
+
  debugc(f"Error: unable to do <particular thing> because {err}\n")
{{note}} The script is called once but NOT active after creation, it will need to be enabled by [[#enableScript|enableScript()]].
+
   return
 
 
{{note}} Mudlet by design allows duplicate names - so calling permScript with the same name will keep creating new script elements. You can check if a script already exists with the [[Manual:Lua_Functions#exists|exists()]] function.
 
 
 
{{note}} If the ''lua code'' parameter is an empty string, then the function will create a script group instead.
 
 
 
 
 
{{MudletVersion|4.8}}
 
 
 
==permTimer==
 
;permTimer(name, parent, seconds, lua code)
 
: Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.
 
 
 
;Parameters
 
* ''name''
 
:name of the timer.
 
* ''parent''
 
:name of the timer group you want the timer to go in.
 
* ''seconds''
 
:a floating point number specifying a delay in seconds after which the timer will do the lua code (stored as the timer's "script") you give it as a string.
 
* ''lua code'' is the code with string you are doing this to.
 
 
 
;Returns
 
* a unique id number for that timer.
 
 
 
;Example:
 
<syntaxhighlight lang="lua">
 
-- create a timer in the "first timer group" group
 
permTimer("my timer", "first timer group", 4.5, [[send ("my timer that's in my first timer group fired!")]])
 
-- create a timer that's not in any group; just at the top
 
permTimer("my timer", "", 4.5, [[send ("my timer that's in my first timer group fired!")]])
 
 
 
-- enable timer - they start off disabled until you're ready
 
enableTimer("my timer")
 
</syntaxhighlight>
 
 
 
{{note}} The timer is NOT active after creation, it will need to be enabled by a call to [[#enableTimer|enableTimer()]] before it starts.
 
 
 
{{note}} Mudlet by design allows duplicate names - so calling permTimer with the same name will keep creating new timers. You can check if a timer already exists with the [[Manual:Lua_Functions#exists|exists()]] function.
 
 
 
==permKey==
 
;permKey(name, parent, [modifier], key code, lua code)
 
: Creates a persistent key that stays after Mudlet is restarted and shows up in the Script Editor.
 
 
 
;Parameters
 
* ''name''
 
:name of the key.
 
* ''parent''
 
:name of the timer group you want the timer to go in or "" for the top level.
 
* ''modifier''
 
:(optional) modifier to use - can be one of ''mudlet.keymodifier.Control'', ''mudlet.keymodifier.Alt'', ''mudlet.keymodifier.Shift'', ''mudlet.keymodifier.Meta'', ''mudlet.keymodifier.Keypad'', or ''mudlet.keymodifier.GroupSwitch'' or the default value of ''mudlet.keymodifier.None'' which is used if the argument is omitted. To use multiple modifiers, add them together: ''(mudlet.keymodifier.Shift + mudlet.keymodifier.Control)''
 
* ''key code''
 
: actual key to use - one of the values available in ''mudlet.key'', e.g. ''mudlet.key.Escape'', ''mudlet.key.Tab'', ''mudlet.key.F1'', ''mudlet.key.A'', and so on. The list is a bit long to list out in full so it is [https://github.com/Mudlet/Mudlet/blob/development/src/mudlet-lua/lua/KeyCodes.lua#L2 available here].
 
: set to -1 if you want to create a key folder instead.
 
* ''lua code'
 
: code you would like the key to run.
 
 
 
;Returns
 
* a unique id number for that key.
 
 
 
{{MudletVersion|3.2+, creating key folders in Mudlet 4.10}}
 
 
 
;Example:
 
<syntaxhighlight lang="lua">
 
-- create a key at the top level for F8
 
permKey("my key", "", mudlet.key.F8, [[echo("hey this thing actually works!\n")]])
 
 
 
-- or Ctrl+F8
 
permKey("my key", "", mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hey this thing actually works!\n")]])
 
 
 
-- Ctrl+Shift+W
 
permKey("jump keybinding", "", mudlet.keymodifier.Control + mudlet.keymodifier.Shift, mudlet.key.W, [[send("jump")]])
 
</syntaxhighlight>
 
 
 
{{note}} Mudlet by design allows duplicate names - so calling permKey with the same name will keep creating new keys. You can check if a key already exists with the [[Manual:Lua_Functions#exists|exists()]] function.  The key will be created even if the lua code does not compile correctly - but this will be apparent as it will be seen in the Editor.
 
 
 
==printCmdLine==
 
;printCmdLine([name], text)
 
 
 
: Replaces the current text in the input line, and sets it to the given text.
 
: See also: [[Manual:Lua_Functions#clearCmdLine|clearCmdLine()]], [[#appendCmdLine|appendCmdLine()]]
 
 
 
;Parameters
 
* ''name'': (optional) name of the command line. If not given, main commandline's text will be set.
 
* ''text'': text to set
 
 
 
<syntaxhighlight lang="lua">
 
printCmdLine("say I'd like to buy ")
 
</syntaxhighlight>
 
 
 
==raiseEvent==
 
;raiseEvent(event_name, arg-1, … arg-n)
 
 
 
: Raises the event event_name. The event system will call the main function (the one that is called exactly like the script name) of all such scripts in this profile that have registered event handlers. If an event is raised, but no event handler scripts have been registered with the event system, the event is ignored and nothing happens. This is convenient as you can raise events in your triggers, timers, scripts etc. without having to care if the actual event handling has been implemented yet - or more specifically how it is implemented. Your triggers raise an event to tell the system that they have detected a certain condition to be true or that a certain event has happened. How - and if - the system is going to respond to this event is up to the system and your trigger scripts don’t have to care about such details. For small systems it will be more convenient to use regular function calls instead of events, however, the more complicated your system will get, the more important events will become because they help reduce complexity very much.
 
 
 
:The corresponding event handlers that listen to the events raised with raiseEvent() need to use the script name as function name and take the correct number of arguments.
 
 
 
:See also: [[#raiseGlobalEvent|raiseGlobalEvent]]
 
 
 
{{note}} possible arguments can be string, number, boolean, table, function, or nil.
 
 
 
;Example:
 
 
 
:raiseEvent("fight") a correct event handler function would be: myScript( event_name ). In this example raiseEvent uses minimal arguments, name the event name. There can only be one event handler function per script, but a script can still handle multiple events as the first argument is always the event name - so you can call your own special handlers for individual events. The reason behind this is that you should rather use many individual scripts instead of one huge script that has all your function code etc. Scripts can be organized very well in trees and thus help reduce complexity on large systems.
 
 
 
Where the number of arguments that your event may receive is not fixed you can use [http://www.lua.org/manual/5.1/manual.html#2.5.9 ''...''] as the last argument in the ''function'' declaration to handle any number of arguments. For example:
 
 
 
<syntaxhighlight lang="lua">
 
-- try this function out with "lua myscripthandler(1,2,3,4)"
 
function myscripthandler(a, b, ...)
 
  print("Arguments a and b are: ", a,b)
 
   -- save the rest of the arguments into a table
 
  local otherarguments = {...}
 
  print("Rest of the arguments are:")
 
  display(otherarguments)
 
 
 
  -- access specific otherarguments:
 
  print("First and second otherarguments are: ", otherarguments[1], otherarguments[2])
 
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==raiseGlobalEvent==
+
; Additional development notes
;raiseGlobalEvent(event_name, arg-1, … arg-n)
+
-- This function is still being written up.
 
 
: Like [[Manual:Lua_Functions#raiseEvent|raiseEvent()]] this raises the event "event_name", but this event is sent to all '''other''' opened profiles instead. The profiles receive the event in circular alphabetical order (if profile "C" raised this event and we have profiles "A", "C", and "E", the order is "E" -> "A", but if "E" raised the event the order would be "A" -> "C"); execution control is handed to the receiving profiles so that means that long running events may lock up the profile that raised the event.
 
 
 
: The sending profile's name is automatically appended as the last argument to the event.
 
  
{{note}} possible arguments can be string, number, boolean, or nil, but not table or function.
+
=String Functions=
 +
:These functions are used to manipulate strings.
  
;Example:
+
=Table Functions=
 +
:These functions are used to manipulate tables. Through them you can add to tables, remove values, check if a value is present in the table, check the size of a table, and more.
  
<syntaxhighlight lang="lua">
+
=Text to Speech Functions=
-- from profile called "My game" this raises an event "my event" with additional arguments 1, 2, 3, "My game" to all profiles except the original one
+
:These functions are used to create sound from written words. Check out our [[Special:MyLanguage/Manual:Text-to-Speech|Text-To-Speech Manual]] for more detail on how this all works together.
raiseGlobalEvent("my event", 1, 2, 3)
 
  
-- want the current profile to receive it as well? Use raiseEvent
+
=UI Functions=
raiseEvent("my event", 1, 2, 3)
+
:These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation as well as displaying or formatting information on the screen.
</syntaxhighlight>
 
  
<syntaxhighlight lang="lua>
+
==cecho2decho PR#6849 merged==
-- example of calling functions in one profile from another:
+
; convertedString = cecho2decho(str)
-- profile B:
 
control = control or {}
 
function control.updateStatus()
 
  disableTrigger("test triggers")
 
  print("disabling triggers worked!")
 
end
 
  
-- this handles calling the right function in the control table
+
:Converts a cecho formatted string to a decho formatted one.  
function control.marshaller(_, callfunction)
+
;See also: [[Manual:Lua_Functions#decho2cecho|decho2cecho()]], [[Manual:Lua_Functions#cecho2html|cecho2html()]]
  if control[callfunction] then control[callfunction]()
 
  else
 
    cecho("<red>Asked to call an unknown function: "..callfunction)
 
  end
 
end
 
  
registerAnonymousEventHandler("sysSendAllProfiles", "control.marshaller")
+
{{MudletVersion|4.18}}
 
 
-- profile A:
 
raiseGlobalEvent("sysSendAllProfiles", "updateStatus")
 
raiseGlobalEvent("sysSendAllProfiles", "invalidfunction")
 
</syntaxhighlight>
 
 
 
{{MudletVersion|3.1.0}}
 
 
 
Tip: you might want to add the [[Manual:Miscellaneous_Functions#getProfileName|profile name]] to your plain [[Manual:Miscellaneous_Functions#raiseEvent|raiseEvent()]] arguments. This'll help you tell which profile your event came from similar to [[#raiseGlobalEvent|raiseGlobalEvent()]].
 
 
 
==registerNamedTimer==
 
; success = registerNamedTimer(userName, timerName, time, functionReference, [repeating])
 
 
 
:Registers a named timer with name timerName. Named timers are protected from duplication and can be stopped and resumed, unlike normal tempTimers. A separate list is kept for each userName, to enforce name spacing and avoid collisions
 
 
 
;See also: [[Manual:Lua_Functions#tempTimer|tempTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]], [[Manual:Lua_Functions#resumeNamedTimer|resumeNamedTimer()]], [[Manual:Lua_Functions#deleteNamedTimer|deleteNamedTimer()]], [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]]
 
 
 
{{MudletVersion|4.14}}
 
  
 
;Parameters
 
;Parameters
* ''userName:''
+
* ''str''
: The user name the event handler was registered under.
+
: string you wish to convert from cecho to decho
* ''timerName:''
 
: The name of the handler. Used to reference the handler in other functions and prevent duplicates. Recommended you use descriptive names, "hp" is likely to collide with something else, "DemonVitals" less so.
 
* ''time:''
 
: The amount of time in seconds to wait before firing.
 
* ''functionReference:''
 
: The function reference to run when the event comes in. Can be the name of a function, "handlerFunction", or the lua function itself.
 
* ''repeating:''
 
: (optional) if true, the timer continue to fire until the stop it using [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]]
 
 
;Returns  
 
;Returns  
* true if successful, otherwise errors.
+
* a string formatted for decho
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- establish a named timer called "Check balance" which runs balanceChecker() after 1 second
+
-- convert to a decho string and use decho to display it
-- it is started automatically when registered, and fires only once despite being run twice
+
local cechoString = "<red><b>!!ALERT!!:</b><orange> Something has gone wrong!\n"
-- you wouldn't do this intentionally, but illustrates the duplicate protection
+
decho(cecho2decho(cechoString))
registerNamedTimer("Demonnic", "Check Balance", 1, balanceChecker)
 
registerNamedTimer("Demonnic", "Check Balance", 1, balanceChecker)
 
 
 
-- then the next time you want to make/use the same timer, you can shortcut it with
 
resumeNamedTimer("Demonnic", "Check Balance")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==remainingTime==
+
==cecho2hecho PR#6849 merged==
;remainingTime(timer id number or name)
+
; convertedString = cecho2hecho(str)
  
: Returns the remaining time in floating point form in seconds (if it is active) for the timer (temporary or permanent) with the id number or the (first) one found with the name.
+
:Converts a cecho formatted string to an hecho formatted one.  
: If the timer is inactive or has expired or is not found it will return a ''nil'' and an ''error message''. It, theoretically could also return 0 if the timer is overdue, i.e. it has expired but the internal code has not yet been run but that has not been seen in during testing. Permanent ''offset timers'' will only show as active during the period when they are running after their parent has expired and started them.
+
;See also: [[Manual:Lua_Functions#hecho2cecho|hecho2cecho()]], [[Manual:Lua_Functions#cecho2html|cecho2html()]]
  
{{MudletVersion|3.20}}
+
{{MudletVersion|4.18}}
 
 
;Example:
 
 
 
<syntaxhighlight lang="lua">
 
tid = tempTimer(600, [[echo("\nYour ten minutes are up.\n")]])
 
echo("\nYou have " .. remainingTime(tid) .. " seconds left, use it wisely... \n")
 
 
 
-- Will produce something like:
 
 
 
You have 599.923 seconds left, use it wisely...
 
 
 
-- Then ten minutes time later:
 
 
 
Your ten minutes are up.
 
 
 
</syntaxhighlight>
 
 
 
==resetProfileIcon==
 
;resetProfileIcon()
 
: Resets the profile's icon in the connection screen to default.
 
 
 
See also: [[#setProfileIcon|setProfileIcon()]].
 
 
 
{{MudletVersion|4.0}}
 
 
 
;Example:
 
 
 
<syntaxhighlight lang="lua">
 
resetProfileIcon()
 
</syntaxhighlight>
 
 
 
==resetStopWatch==
 
;resetStopWatch(watchID)
 
:This function resets the time to 0:0:0.0, but does not stop or start the stop watch. You can stop it with [[Manual:Lua_Functions#stopStopWatch | stopStopWatch]] or start it with [[Manual:Lua_Functions#startStopWatch | startStopWatch]] → [[Manual:Lua_Functions#createStopWatch | createStopWatch]]
 
 
 
==resumeNamedTimer==
 
; success = resumeNamedTimer(userName, handlerName)
 
 
 
:Resumes a named timer with name handlerName and causes it to fire again. One time unless it was registered as repeating.
 
 
 
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]]
 
 
 
{{MudletVersion|4.14}}
 
 
 
;Parameter
 
* ''userName:''
 
: The user name the event handler was registered under.s
 
* ''handlerName:''
 
: The name of the handler to resume. Same as used when you called [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
 
  
 +
;Parameters
 +
* ''str''
 +
: string you wish to convert from cecho to decho
 
;Returns  
 
;Returns  
* true if successful, false if it didn't exist. If the timer is waiting to fire it will be restarted at 0.
+
* a string formatted for hecho
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
local resumed = resumeNamedTimer("Demonnic", "DemonVitals")
+
-- convert to an hecho string and use hecho to display it
if resumed then
+
local cechoString = "<red><b>!!ALERT!!:</b><orange> Something has gone wrong!\n"
  cecho("DemonVitals resumed!")
+
hecho(cecho2hecho(cechoString))
else
 
  cecho("DemonVitals doesn't exist, so cannot resume it.")
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==setButtonState==
+
==cecho2html PR#6849 merged==
;setButtonState(ButtonNameOrID, checked)
+
; convertedString = cecho2html(str[, resetFormat])
:Sets the state of a check-able ("push-down") type button from any Mudlet item's script - but does not cause the script or one of the commands associated with that button to be run/sent.
 
: See also: [[#getButtonState|getButtonState()]].
 
{{MudletVersion|4.13}}
 
 
 
;Parameters
 
* ''ButtonNameOrID:''
 
: The name of the button as a string or a unique ID (positive) integer number {for a name only one matching one will be affected - it will be the same one that the matching [[#getButtonState|getButtonState()]] reports upon}.
 
* ''checked:''
 
: boolean value that indicated whether the state required is down (''true'') or up (''false'').
 
 
 
;Returns:
 
* A boolean value indicating ''true'' if the visible state was actually changed, i.e. had any effect. This function will return a ''nil'' and a suitable error message if the identifying name or ID was not found or was not a check-able (push-down) button item (i.e. was a non-checkable button or a menu or a toolbar instead).
 
  
;Example
+
:Converts a cecho formatted string to an html formatted one.
<syntaxhighlight lang="lua">
+
;See also: [[Manual:Lua_Functions#decho2cecho|decho2cecho()]], [[Manual:Lua_Functions#decho2html|cecho2html()]]
-- inside, for example, an initialization script for a GUI package:
 
setButtonState("Sleep", false)
 
setButtonState("Sit", false)
 
-- these are going to be used as "radio" buttons where setting one
 
-- of them will unset all the others, they will each need something
 
-- similar in their own scripts to unset all the others in the set
 
-- and also something to prevent them from being unset by clicking
 
-- on themselves:
 
setButtonState("Wimpy", true)
 
setButtonState("Defensive", false)
 
setButtonState("Normal", false)
 
setButtonState("Brave", false)
 
if character.type == "Warrior" then
 
    -- Only one type has this mode - and it can only be reset by
 
    -- something dying (though that could be us!)
 
    setButtonState("Beserk!!!", false)
 
end
 
</syntaxhighlight>
 
  
==setConsoleBufferSize==
+
{{MudletVersion|4.18}}
;setConsoleBufferSize([consoleName], linesLimit, sizeOfBatchDeletion)
 
:Sets the maximum number of lines a buffer (main window or a miniconsole) can hold. Default is 10,000.
 
:Returns nothing on success (up to '''Mudlet 4.16''') or ''true'' (from '''Mudlet 4.17'''); ''nil'' and an error message on failure.
 
  
 
;Parameters
 
;Parameters
* ''consoleName:''
+
* ''str''
: (optional) The name of the window. If omitted, uses the main console.
+
: string you wish to convert from cecho to decho
* ''linesLimit:''
+
* ''resetFormat''
: Sets the amount of lines the buffer should have.
+
: optional table of default formatting options. As returned by [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]
{{note}} Mudlet performs extremely efficiently with even huge numbers, but there is of course a limit to your computer's memory. As of Mudlet 4.7+, this amount will be capped to that limit on macOS and Linux (on Windows, it's capped lower as Mudlet on Windows is 32bit).
+
;Returns
* ''sizeOfBatchDeletion:''
+
* a string formatted for html
: Specifies how many lines should Mudlet delete at once when you go over the limit - it does it in bulk because it's efficient to do so.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- sets the main windows size to 1 million lines maximum - which is more than enough!
+
-- create the base string
setConsoleBufferSize("main", 1000000, 1000)
+
local cechoString = "<red><b>!!ALERT!!:</b><orange> Something has gone wrong!\n"
</syntaxhighlight>
 
 
 
==setProfileIcon==
 
;setProfileIcon(iconPath)
 
:Set a custom icon for this profile in the connection screen.
 
 
 
:Returns true if successful, or nil+error message if not.
 
 
 
:See also: [[#resetProfileIcon|resetProfileIcon()]].
 
  
{{MudletVersion|4.0}}
+
-- create a label to display the result onto
 +
testLabel = Geyser.Label:new({name = "testLabel"})
  
;Parameters
+
-- convert the cecho string to an html one, using the default formatting of testLabel created above
* ''iconPath:''
+
local htmlString = cecho2html(cechoString, testLabel:getFormat())
: Full location of the icon - can be .png or .jpg with ideal dimensions of 120x30.
 
  
;Example
+
-- and finally echo it to the label to see
<syntaxhighlight lang="lua">
+
-- I use rawEcho as that displays the html exactly as given.
-- set a custom icon that is located in an installed package called "mypackage"
+
testLabel:rawEcho(htmlString)
setProfileIcon(getMudletHomeDir().."/mypackage/icon.png")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==setScript==
+
==decho2cecho PR#6849 merged==
;setScript(scriptName, luaCode, [occurrence])
+
; convertedString = decho2cecho(str)
: Sets the script's Lua code, replacing existing code. If you have many scripts with the same name, use the 'occurrence' parameter to choose between them.
 
: If you'd like to add code instead of replacing it, have a look at [[Manual:Lua_Functions#appendScript|appendScript()]].
 
: Returns -1 if the script isn't found - to create a script, use [[Manual:Lua_Functions#permScript|permScript()]].
 
  
: See also: [[Manual:Lua_Functions#permScript|permScript()]], [[Manual:Lua_Functions#enableScript|enableScript()]], [[Manual:Lua_Functions#disableScript|disableScript()]], [[Manual:Lua_Functions#getScript|getScript()]], [[Manual:Lua_Functions#appendScript|appendScript()]]
+
:Converts a decho formatted string to a cecho formatted one.
 +
;See also: [[Manual:Lua_Functions#cecho2decho|cecho2decho()]], [[Manual:Lua_Functions#decho2html|decho2html()]]
  
;Returns
+
{{MudletVersion|4.18}}
* a unique id number for that script.
 
  
 
;Parameters
 
;Parameters
* ''scriptName'': name of the script to change the code.
+
* ''str''
* ''luaCode'': new Lua code to set.
+
: string you wish to convert from decho to cecho
* ''occurrence'': The position of the script. Optional, defaults to 1 (first).
+
;Returns
 +
* a string formatted for cecho
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- make sure a script named "testscript" exists first, then do:
+
-- convert to a decho string and use cecho to display it
setScript("testscript", [[echo("This is a test\n")]], 1)
+
local dechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n"
 +
cecho(decho2cecho(dechoString))
 
</syntaxhighlight>
 
</syntaxhighlight>
{{MudletVersion|4.8}}
 
 
==setStopWatchName==
 
;setStopWatchName(watchID/currentStopWatchName, newStopWatchName)
 
 
;Parameters
 
* ''watchID'' (number) / ''currentStopWatchName'' (string): The stopwatch ID you get from [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name supplied to that function at that time, or previously applied with this function.
 
* ''newStopWatchName'' (string): The name to use for this stopwatch from now on.
 
 
;Returns
 
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found.
 
 
{{note}} Either ''currentStopWatchName'' or ''newStopWatchName'' may be empty strings: if the first of these is so then the ''lowest'' ID numbered stopwatch without a name is chosen; if the second is so then an existing name is removed from the chosen stopwatch.
 
 
==setStopWatchPersistence==
 
;setStopWatchPersistence(watchID/watchName, state)
 
 
;Parameters
 
* ''watchID'' (number) / ''watchName'' (string): The stopwatch ID you get from [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or the name supplied to that function or applied later with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]]
 
* ''state'' (boolean): if ''true'' the stopWatch will be saved.
 
 
;Returns
 
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found.
 
  
:Sets or resets the flag so that the stopwatch is saved between sessions or after a [[Manual:Miscellaneous_Functions#resetProfile|resetProfile()]] call. If set then, if ''stopped'' the elapsed time recorded will be unchanged when the stopwatch is reloaded in the next session; if ''running'' the elapsed time will continue to increment and it will include the time that the profile was not loaded, therefore it can be used to measure events in real-time, outside of the profile!
+
==decho2hecho PR#6849 merged==
 +
; convertedString = decho2hecho(str)
  
{{note}} When a persistent stopwatch is reloaded in a later session (or after a use of ''resetProfile()'') the stopwatch may not be allocated the same ID number as before - therefore it is advisable to assign any persistent stopwatches a name, either when it is created or before the session is ended.
+
:Converts a decho formatted string to an hecho formatted one.
 +
;See also: [[Manual:Lua_Functions#hecho2decho|hecho2decho()]], [[Manual:Lua_Functions#decho2html|decho2html()]]
  
==setTriggerStayOpen==
+
{{MudletVersion|4.18}}
;setTriggerStayOpen(name, number of lines)
 
:Sets for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched - so this allows you to extend or shorten the ''fire length'' of a trigger. The main use of this function is to close a chain when a certain condition has been met.
 
  
 
;Parameters
 
;Parameters
* ''name:'' The name of the trigger which has a fire length set (and which opens the chain).
+
* ''str''
* ''number of lines'': 0 to close the chain, or a positive number to keep the chain open that much longer.
+
: string you wish to convert from decho to decho
 
+
;Returns  
;Examples
+
* a string formatted for hecho
<syntaxhighlight lang="lua">
 
-- if you have a trigger that opens a chain (has some fire length) and you'd like it to be closed
 
-- on the next prompt, you could make a prompt trigger inside the chain with a script of:
 
setTriggerStayOpen("Parent trigger name", 0)
 
-- to close it on the prompt!
 
</syntaxhighlight>
 
 
 
==startStopWatch==
 
;startStopWatch(watchName or watchID, [resetAndRestart])
 
 
 
:Stopwatches can be stopped (with [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]]) and then re-started any number of times. '''To ensure backwards compatibility, if the stopwatch is identified by a ''numeric'' argument then, ''unless a second argument of false is supplied as well'' this function will also reset the stopwatch to zero and restart it - whether it is running or not'''; otherwise only a stopped watch can be started and only a started watch may be stopped. Trying to repeat either will produce a nil and an error message instead; also the recorded time is no longer reset so that they can now be used to record a total of isolated periods of time like a real stopwatch.
 
 
 
:See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]],  [[Manual:Lua_Functions#stopStopWatch|stopStopWatch()]]
 
 
 
;Parameters
 
* ''watchID''/''watchName'': The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]], or from '''4.4.0''' the name assigned with that function or [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].
 
* ''resetAndRestart'': Boolean flag needed (as ''false'') to make the function from '''4.4.0''', when supplied with a numeric watch ID, to '''not''' reset the stopwatch and only start a previously stopped stopwatch. This behavior is automatic when a string watch name is used to identify the stopwatch but differs from how the function behaved prior to that version.
 
 
 
;Returns
 
* ''true'' on success, ''nil'' and an error message if no matching stopwatch is found or if it cannot be started (because the later style behavior was indicated and it was already running).
 
 
 
;Examples
 
<syntaxhighlight lang="lua">
 
-- this is a common pattern for re-using stopwatches prior to 4.4.0 and starting them:
 
watch = watch or createStopWatch()
 
startStopWatch(watch)
 
</syntaxhighlight>
 
 
 
:: After 4.4.0 the above code will work the same as it does not provide a second argument to the ''startStopWatch()'' function - if a ''false'' was used there it would be necessary to call ''stopStopWatch(...)'' and then ''resetStopWatch(...)'' before using ''startStopWatch(...)'' to re-use the stopwatch if the ID form is used, '''this is thus not quite the same behavior but it is more consistent with the model of how a real stopwatch would act.'''
 
 
 
==stopAllNamedTimers==
 
; stopAllNamedTimers(userName)
 
 
 
:Stops all named timers for userName and prevents them from firing any more. Information is retained and timers can be resumed.
 
 
 
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]], [[Manual:Lua_Functions#resumeNamedTimer|resumeNamedTimer()]]
 
 
 
{{MudletVersion|4.14}}
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
stopAllNamedTimers("Demonnic") -- emergency stop situation, most likely.
+
-- convert to an hecho string and use hecho to display it
 +
local dechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n"
 +
hecho(decho2hecho(dechoString))
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==stopNamedTimer==
+
==decho2html PR#6849 merged==
; success = stopNamedTimer(userName, handlerName)
+
; convertedString = decho2html(str[, resetFormat])
 
 
:Stops a named timer with name handlerName and prevents it from firing any more. Information is stored so it can be resumed later if desired.
 
  
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#resumeNamedTimer|resumeNamedTimer()]]
+
:Converts a decho formatted string to an html formatted one.
 +
;See also: [[Manual:Lua_Functions#cecho2decho|cecho2decho()]], [[Manual:Lua_Functions#decho2html|decho2html()]]
  
{{MudletVersion|4.14}}
+
{{MudletVersion|4.18}}
  
 
;Parameters
 
;Parameters
* ''userName:''
+
* ''str''
: The user name the event handler was registered under.
+
: string you wish to convert from decho to decho
* ''handlerName:''
+
* ''resetFormat''
: The name of the handler to stop. Same as used when you called [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
+
: optional table of default formatting options. As returned by [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]
 
 
 
;Returns  
 
;Returns  
* true if successful, false if it didn't exist or was already stopped
+
* a string formatted for html
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
local stopped = stopNamedTimer("Demonnic", "DemonVitals")
+
-- create the base string
if stopped then
+
local dechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n"
  cecho("DemonVitals stopped!")
 
else
 
  cecho("DemonVitals doesn't exist or already stopped; either way it won't fire any more.")
 
end
 
</syntaxhighlight>
 
 
 
==stopStopWatch==
 
;stopStopWatch(watchID or watchName)
 
:"Stops" (though see the note below) the stop watch and returns (only the '''first''' time it is called after the stopwatch has been set running with [[Manual:Lua_Functions#startStopWatch|startStopWatch()]]) the elapsed time as a number of seconds, with a decimal portion give a resolution in milliseconds (thousandths of a second). You can also retrieve the current time without stopping the stopwatch with [[Manual:Lua_Functions#getStopWatchTime|getStopWatchTime()]], [[Manual:Lua_Functions#getBrokenDownStopWatchTime|getBrokenDownStopWatchTime()]].
 
 
 
:See also: [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]
 
 
 
;Parameters
 
* ''watchID:'' The stopwatch ID you get with [[Manual:Lua_Functions#createStopWatch|createStopWatch()]] or from Mudlet '''4.4.0''' the name given to that function or later set with [[Manual:Lua_Functions#setStopWatchName|setStopWatchName()]].
 
 
 
;Returns
 
* the elapsed time as a floating-point number of seconds - it may be negative if the time was previously adjusted/preset to a negative amount (with [[Manual:Lua_Functions#adjustStopWatch|adjustStopWatch()]]) and that period has not yet elapsed.
 
  
;Examples
+
-- create a label to display the result onto
<syntaxhighlight lang="lua">
+
testLabel = Geyser.Label:new({name = "testLabel"})
-- this is a common pattern for re-using stopwatches and starting them:
 
watch = watch or createStopWatch()
 
startStopWatch(watch)
 
  
-- do some long-running code here ...
+
-- convert the decho string to an html one, using the default formatting of testLabel created above
 +
local htmlString = decho2html(dechoString, testLabel:getFormat())
  
print("The code took: "..stopStopWatch(watch).."s to run.")
+
-- and finally echo it to the label to see
 +
-- I use rawEcho as that displays the html exactly as given.
 +
testLabel:rawEcho(htmlString)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==tempAnsiColorTrigger==
+
==deleteMultiline PR #6779 merged==
;tempAnsiColorTrigger(foregroundColor[, backgroundColor], code[, expireAfter])
 
:This is an alternative to [[Manual:Lua_Functions#tempColorTrigger|tempColorTrigger()]] which supports the full set of 256 ANSI color codes directly and makes a color trigger that triggers on the specified foreground and background color. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.
 
 
 
;Parameters
 
* ''foregroundColor:'' The foreground color you'd like to trigger on.
 
* ''backgroundColor'': The background color you'd like to trigger on.
 
* ''code to do'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function.
 
* ''expireAfter'': Delete trigger after a specified number of matches. You can make a trigger match not count towards expiration by returning true after it fires.
 
 
 
''BackgroundColor'' and/or ''expireAfter'' may be omitted.
 
 
 
;Color codes (note that the values greater than or equal to zero are the actual number codes that ANSI and the game server uses for the 8/16/256 color modes)
 
 
 
::Special codes (may be extended in the future):
 
:::-2 = default text color (what is used after an ANSI SGR 0 m code that resets the foreground and background colors to those set in the preferences)
 
:::-1 = ignore (only '''one''' of the foreground or background codes can have this value - otherwise it would not be a ''color'' trigger!)
 
 
 
::ANSI 8-color set:
 
:::0 = (dark) black
 
:::1 = (dark) red
 
:::2 = (dark) green
 
:::3 = (dark) yellow
 
:::4 = (dark) blue
 
:::5 = (dark) magenta
 
:::6 = (dark) cyan
 
:::7 = (dark) white {a.k.a. light gray}
 
 
 
::Additional colors in 16-color set:
 
:::8 = light black {a.k.a. dark gray}
 
:::9 = light red
 
:::10 = light green
 
:::11 = light yellow
 
:::12 = light blue
 
:::13 = light magenta
 
:::14 = light cyan
 
:::15 = light white
 
 
 
::6 x 6 x 6 RGB (216) colors, shown as a 3x2-digit hex code
 
:::16 = #000000
 
:::17 = #000033
 
:::18 = #000066
 
:::...
 
:::229 = #FFFF99
 
:::230 = #FFFFCC
 
:::231 = #FFFFFF
 
 
 
::24 gray-scale, also show as a 3x2-digit hex code
 
:::232 = #000000
 
:::233 = #0A0A0A
 
:::234 = #151515
 
:::...
 
:::253 = #E9E9E9
 
:::254 = #F4F4F4
 
:::255 = #FFFFFF
 
  
;Examples
+
; ok,err = deleteMultiline([triggerDelta])
<syntaxhighlight lang="lua">
 
-- This script will re-highlight all text in a light cyan foreground color on any background with a red foreground color
 
-- until another foreground color in the current line is being met. temporary color triggers do not offer match_all
 
-- or filter options like the GUI color triggers because this is rarely necessary for scripting.
 
-- A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.
 
tempAnsiColorTrigger(14, -1, [[selectString(matches[1],1) fg("red")]])
 
-- or:
 
tempAnsiColorTrigger(14, -1, function()
 
  selectString(matches[1], 1)
 
  fg("red")
 
end)
 
  
-- match the trigger only 4 times
+
:Deletes all lines between when the multiline trigger fires and when the first trigger matched. Put another way, it deletes everything since the pattern in slot 1 matched.
tempColorTrigger(14, -1, [[selectString(matches[1],1) fg("red")]], 4)
+
;See also: [[Manual:Lua_Functions#deleteLine|deleteLine()]], [[Manual:Lua_Functions#replaceLine|replaceLine()]]
</syntaxhighlight>
 
  
{{MudletVersion|3.17}}
+
{{MudletVersion|4.18}}
  
==tempAlias==
+
{{note}} This deletes all the lines since the first match of the multiline trigger matched. Do not use this if you do not want to delete ALL of those lines.
;aliasID = tempAlias(regex, code to do)
 
:Creates a temporary alias - temporary in the sense that it won't be saved when Mudlet restarts (unless you re-create it). The alias will go off as many times as it matches, it is not a one-shot alias. The function returns an ID for subsequent [[Manual:Lua_Functions#enableAlias|enableAlias()]], [[Manual:Lua_Functions#disableAlias|disableAlias()]] and [[Manual:Lua_Functions#killAlias|killAlias()]] calls.
 
  
 
;Parameters
 
;Parameters
* ''regex:'' Alias pattern in regex.
+
* ''[optional]triggerDelta:''
* ''code to do:'' The code to do when the alias fires - wrap it in [[ ]].
+
: The line delta from the multiline trigger it is being called from. It is best to pass this in to ensure all lines are caught. If not given it will try to guess based on the number of patterns how many lines at most it might have to delete.
  
;Examples
+
;Returns
<syntaxhighlight lang="lua">
+
* true if the function was able to run successfully, nil+error if something went wrong.
myaliasID = tempAlias("^hi$", [[send ("hi") echo ("we said hi!")]])
 
  
-- you can also delete the alias later with:
+
;Example
killAlias(myaliasID)
 
 
 
-- tempAlias also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for an alias look less messy:
 
 
 
local variable = matches[2]
 
tempAlias("^hi$", function () send("hello, " .. variable) end)
 
</syntaxhighlight>
 
 
 
==tempBeginOfLineTrigger==
 
;tempBeginOfLineTrigger(part of line, code, expireAfter)
 
:Creates a trigger that will go off whenever the part of line it's provided with matches the line right from the start (doesn't matter what the line ends with). The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.
 
 
 
;Parameters
 
* ''part of line'': start of the line that you'd like to match. This can also be regex.
 
* ''code to do'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).
 
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.
 
 
 
;Examples
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
mytriggerID = tempBeginOfLineTrigger("Hello", [[echo("We matched!")]])
+
-- if this trigger has a line delta of 3, you would call
 +
deleteMultiline(3)
  
--[[ now this trigger will match on any of these lines:
+
-- same thing, but with error handling
Hello
+
local ok,err = deleteMultiline(3)
Hello!
+
if not ok then
Hello, Bob!
+
  cecho("\n<firebrick>I could not delete the lines because: " .. err)
 
+
end
but not on:
 
Oh, Hello
 
Oh, Hello!
 
]]
 
 
 
-- or as a function:
 
mytriggerID = tempBeginOfLineTrigger("Hello", function() echo("We matched!") end)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<syntaxhighlight lang="lua">
+
; Additional development notes
-- you can make the trigger match only a certain amount of times as well, 5 in this example:
 
tempBeginOfLineTrigger("This is the start of the line", function() echo("We matched!") end, 5)
 
 
 
-- if you want a trigger match not to count towards expiration, return true. In this example it'll match 5 times unless the line is "Start of line and this is the end."
 
tempBeginOfLineTrigger("Start of line",
 
function()
 
  if line == "Start of line and this is the end." then
 
    return true
 
  else
 
    return false
 
  end
 
end, 5)
 
</syntaxhighlight>
 
  
==tempButton==
+
==echoPopup, revised in PR #6946==
;tempButton(toolbar name, button text, orientation)
+
;echoPopup([windowName,] text, {commands}, {hints}[, useCurrentFormatElseDefault])
:Creates a temporary button. Temporary means, it will disappear when Mudlet is closed.
+
: 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; if there is one extra hint then the first one will be used as a (maybe containing Qt rich-text markup) tool-tip for the text otherwise the remaining hints will be concatenated, one-per-line, as a tool-tip when the text is hovered over by the pointer.
  
;Parameters:
+
; Parameters
* ''toolbar name'': The name of the toolbar to place the button into.
+
* ''windowName:''
* ''button text'': The text to display on the button.
+
: (optional) name of the window as a string to echo to. Use either ''main'' or omit for the main window, or the miniconsole's or user-window's name otherwise.
* ''orientation'': a number 0 or 1 where 0 means horizontal orientation for the button and 1 means vertical orientation for the button. This becomes important when you want to have more than one button in the same toolbar.
+
* ''text:''
 +
: the text string to display.
 +
* ''{commands}:''
 +
: a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. <syntaxhighlight lang="lua" inline="">{[[send("hello")]], function() echo("hi!") end}</syntaxhighlight>.
 +
* ''{hints}:''
 +
: a table of strings which will be shown on the right-click menu and as a tool-tip for the ''text''. If the number is the same as that of the ''commands'' table then they all will be used for the right-click menu and listed (one per line) as a plain text tooltip; alternatively if there is one extra in number than the ''commands'' table the first will be used purely for the tool tip and the remainder will be used for the right-click menu. This additional entry may be formatted as Qt style "rich-text" (in the same manner as labels elsewhere in the GUI).
 +
::* If a particular position in the ''commands'' table is an empty string ''""'' but there is something in the ''hints'' table then it will be listed in the right-click menu but as it does not do anything it will be shown ''greyed-out'' i.e. disabled and will not be clickable.
 +
::* If a particular position in '''both''' the ''commands'' and the ''hints'' table are empty strings ''""'' then this item will show as a ''separator'' (usually as a horizontal-line) in the right-click menu and it will not be clickable/do anything.
 +
* ''useCurrentFormatElseDefault:''
 +
: (optional) a boolean value for using either the current formatting options (color, underline, italic and other effects) if ''true'' or the link default (blue underline) if ''false'', if omitted the default format is used.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- makes a temporary toolbar with two buttons at the top of the main Mudlet window
+
-- Create some text as a clickable with a popup menu, a left click will ''send "sleep"'':
lua tempButtonToolbar("topToolbar", 0, 0)
+
echoPopup("activities to do", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})
lua tempButton("topToolbar", "leftButton", 0)
 
lua tempButton("topToolbar", "rightButton", 0)
 
</syntaxhighlight>
 
  
{{note}} ''This function is not that useful as there is no function yet to assign a Lua script or command to such a temporary button - though it may have some use to flag a status indication!''
+
-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)
 +
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})
  
==tempButtonToolbar==
+
-- one can also provide helpful information
;tempButtonToolbar(name, location, orientation)
 
:Creates a temporary button toolbar. Temporary means, it will disappear when Mudlet is closed.
 
  
;Parameters:
+
-- todo: an example with rich-text in the tool-tips(s) - not complete yet!
* ''name'': The name of the toolbar.
+
echoPopup("Fancy popup", {[[echo("Doing command 1 (default one)")]], "", "", [[echo("Doing command 3")]], [[echo("Doing another command (number 4)"]], [[echo("Doing another command (number 5)"]])}, {"<p>This tooltip has HTML type tags in/around it, and it will get word-wrapped automatically to fit into a reasonable rectangle.</p><p><b>Plus</b> it can have those HTML like <i>effects</i> and be easily formatted into more than one paragraph and with <span style=\"color:cyan\">bits</span> in <span style=\"color:lime\">different</span> colors!</p><p>This example also demonstrates how to produce disabled menu (right-click) items, how to insert separators and how it now will handle multiple items with the same hint (prior to PR 6945 such duplicates will all run the command associated with the last one!) If the first command/function is an empty string then clicking on the text will have no effect, but hovering the mouse over the text will still produce the tooltip, this could be useful to display extra information about the text without doing anything by default.</p>", "Command 1 (default)", "", "Command 2 (disabled)", "Command 3", "Another command", "Another command"}, true)
* ''location'': a number from 0 to 3, where 0 means "at the top of the screen", 1 means "left side", 2 means "right side" and 3 means "in a window of its own" which can be dragged and attached to the main Mudlet window if needed.
+
echo(" remaining text.\n")
* ''orientation'': a number 0 or 1, where 0 means horizontal orientation for the toolbar and 1 means vertical orientation for the toolbar. This becomes important when you want to have more than one toolbar in the same location of the window.
 
  
;Example
 
<syntaxhighlight lang="lua">
 
-- makes a temporary toolbar with two buttons at the top of the main Mudlet window
 
lua tempButtonToolbar("topToolbar", 0, 0)
 
lua tempButton("topToolbar", "leftButton", 0)
 
lua tempButton("topToolbar", "rightButton", 0)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==tempColorTrigger==
+
==hecho2cecho PR#6849 merged==
;tempColorTrigger(foregroundColor, backgroundColor, code, expireAfter)
+
; convertedString = hecho2cecho(str)
:Makes a color trigger that triggers on the specified foreground and background color. Both colors need to be supplied in form of these simplified ANSI 16 color mode codes. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.
 
See also: [[Manual:Mudlet Object Functions#tempAnsiColorTrigger|tempAnsiColorTrigger]]
 
;Parameters
 
* ''foregroundColor:'' The foreground color you'd like to trigger on (for ANSI colors, see [[Manual:Mudlet Object Functions#tempAnsiColorTrigger|tempAnsiColorTrigger]]).
 
* ''backgroundColor'': The background color you'd like to trigger on (same as above).
 
* ''code to do'': The code to do when the trigger runs - wrap it in <code>[[</code> and <code>]]</code>, or give it a Lua function, ie. <code>function() <nowiki><your code here></nowiki> end</code> (since Mudlet 3.5.0).
 
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.
 
  
;Color codes
+
:Converts a hecho formatted string to a cecho formatted one.  
<syntaxhighlight lang="lua">
+
;See also: [[Manual:Lua_Functions#cecho2decho|cecho2decho()]], [[Manual:Lua_Functions#hecho2html|hecho2html()]]
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
 
</syntaxhighlight>
 
 
 
;Examples
 
<syntaxhighlight lang="lua">
 
-- This script will re-highlight all text in blue foreground colors on a black background with a red foreground color
 
-- on a blue background color until another color in the current line is being met. temporary color triggers do not
 
-- offer match_all or filter options like the GUI color triggers because this is rarely necessary for scripting.
 
-- A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.
 
tempColorTrigger(9, 2, [[selectString(matches[1],1) fg("red") bg("blue")]])
 
-- or:
 
tempColorTrigger(9, 2, function()
 
  selectString(matches[1], 1)
 
  fg("red")
 
  bg("blue")
 
end)
 
 
 
-- match the trigger only 4 times
 
tempColorTrigger(9, 2, [[selectString(matches[1],1) fg("red") bg("blue")]], 4)
 
</syntaxhighlight>
 
  
==tempComplexRegexTrigger==
+
{{MudletVersion|4.18}}
;tempComplexRegexTrigger(name, regex, code, multiline, fg color, bg color, filter, match all, highlight fg color, highlight bg color, play sound file, fire length, line delta, expireAfter)
 
:Allows you to create a temporary trigger in Mudlet, using any of the UI-available options. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.
 
:Returns the trigger ID or nil and an error message (on error).
 
  
 
;Parameters
 
;Parameters
* ''name'' - The name you call this trigger. You can use this with [[Manual:Lua_Functions#killTrigger|killTrigger()]].
+
* ''str''
* ''regex'' - The regular expression you want to match.
+
: string you wish to convert from hecho to cecho
* ''code'' - Code to do when the trigger runs. You need to wrap it in [[ ]], or give a Lua function (since Mudlet 3.5.0).
+
;Returns
* ''multiline'' - Set this to 1, if you use multiple regex (see note below), and you need the trigger to fire only if all regex have been matched within the specified line delta. Then all captures will be saved in ''multimatches'' instead of ''matches''. If this option is set to 0, the trigger will fire when any regex has been matched.
+
* a string formatted for cecho
* ''fg color'' - The foreground color you'd like to trigger on - '''Not currently implemented.'''
 
* ''bg color'' - The background color you'd like to trigger on - '''Not currently implemented.'''
 
* ''filter'' - Do you want only the filtered content (=capture groups) to be passed on to child triggers? Otherwise also the initial line.
 
* ''match all'' - Set to 1, if you want the trigger to match all possible occurrences of the regex in the line. When set to 0, the trigger will stop after the first successful match.
 
* ''highlight fg color'' - The foreground color you'd like your match to be highlighted in. e.g. <code>"yellow"</code>, <code>"#ff0"</code> or <code>"#ffff00"</code>
 
* ''highlight bg color'' - The background color you'd like your match to be highlighted in. e.g. <code>"red"</code>, <code>"#f00"</code> or <code>"#ff0000"</code>
 
* ''play sound file'' - Set to the name of the sound file you want to play upon firing the trigger. e.g. <code>"C:/windows/media/chord.wav"</code>
 
* ''fire length'' - Number of lines within which all condition must be true to fire the trigger.
 
* ''line delta'' - Keep firing the script for x more lines, after the trigger or chain has matched.
 
* ''expireAfter'' - Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.
 
 
 
{{Note}} Set the options starting at ''multiline'' to 0, if you don't want to use those options. Otherwise enter 1 to activate or the value you want to use.
 
 
 
{{Note}} If you want to use the color option, you need to provide both fg and bg together. - '''Not currently implemented.'''
 
 
 
;Examples
 
  
 +
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- This trigger will be activated on any new line received.
+
-- convert to a hecho string and use cecho to display it
triggerNumber = tempComplexRegexTrigger("anyText", "^(.*)$", [[echo("Text received!")]], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, nil)
+
local hechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n""
 
+
cecho(hecho2cecho(hechoString))
-- This trigger will match two different regex patterns:
 
tempComplexRegexTrigger("multiTrigger", "first regex pattern", [[]], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, nil)
 
tempComplexRegexTrigger("multiTrigger", "second regex pattern", [[echo("Trigger matched!")]], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, nil)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{Note}} For making a multiline trigger like in the second example, you need to use the same trigger name and options, providing the new pattern to add. Note that only the last script given will be set, any others ignored.
+
==hecho2decho PR#6849 merged==
 +
; convertedString = hecho2decho(str)
  
==tempExactMatchTrigger==
+
:Converts a hecho formatted string to a decho formatted one.  
;tempExactMatchTrigger(exact line, code, expireAfter)
+
;See also: [[Manual:Lua_Functions#decho2hecho|decho2hecho()]], [[Manual:Lua_Functions#hecho2html|hecho2html()]]
:Creates a trigger that will go off whenever the line from the game matches the provided line exactly (ends the same, starts the same, and looks the same). You don't need to use any of the regex symbols here (^ and $). The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.
 
  
;Parameters
+
{{MudletVersion|4.18}}
* ''exact line'': exact line you'd like to match.
 
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).
 
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.
 
 
 
;Examples
 
<syntaxhighlight lang="lua">
 
mytriggerID = tempExactMatchTrigger("You have recovered balance on all limbs.", [[echo("We matched!")]])
 
 
 
-- as a function:
 
mytriggerID = tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("We matched!") end)
 
 
 
-- expire after 4 matches:
 
tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("Got balance back!\n") end, 4)
 
 
 
-- you can also avoid expiration by returning true:
 
tempExactMatchTrigger("You have recovered balance on all limbs.", function() echo("Got balance back!\n") return true end, 4)
 
</syntaxhighlight>
 
 
 
==tempKey==
 
;tempKey([modifier], key code, lua code)
 
:Creates a keybinding. This keybinding isn't temporary in the sense that it'll go off only once (it'll go off as often as you use it), but rather it won't be saved when Mudlet is closed.
 
 
 
: See also: [[#permKey|permKey()]], [[#killKey|killKey()]]
 
 
 
* ''modifier''
 
:(optional) modifier to use - can be one of ''mudlet.keymodifier.Control'', ''mudlet.keymodifier.Alt'', ''mudlet.keymodifier.Shift'', ''mudlet.keymodifier.Meta'', ''mudlet.keymodifier.Keypad'', or ''mudlet.keymodifier.GroupSwitch'' or the default value of ''mudlet.keymodifier.None'' which is used if the argument is omitted. To use multiple modifiers, add them together: ''(mudlet.keymodifier.Shift + mudlet.keymodifier.Control)''
 
* ''key code''
 
: actual key to use - one of the values available in ''mudlet.key'', e.g. ''mudlet.key.Escape'', ''mudlet.key.Tab'', ''mudlet.key.F1'', ''mudlet.key.A'', and so on. The list is a bit long to list out in full so it is [https://github.com/Mudlet/Mudlet/blob/development/src/mudlet-lua/lua/KeyCodes.lua#L2 available here].
 
* ''lua code'
 
: code you'd like the key to run - wrap it in [[ ]].
 
 
 
;Returns
 
* a unique id number for that key.
 
 
 
;Examples
 
<syntaxhighlight lang="lua">
 
keyID = tempKey(mudlet.key.F8, [[echo("hi")]])
 
 
 
anotherKeyID = tempKey(mudlet.keymodifier.Control, mudlet.key.F8, [[echo("hello")]])
 
 
 
-- bind Ctrl+Shift+W:
 
tempKey(mudlet.keymodifier.Control + mudlet.keymodifier.Shift, mudlet.key.W, [[send("jump")]])
 
 
 
-- delete it if you don't like it anymore
 
killKey(keyID)
 
 
 
-- tempKey also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for tempKeys look less messy:
 
 
 
tempKey(mudlet.key.F8, function() echo("Hi\n") end)
 
</syntaxhighlight>
 
 
 
==tempLineTrigger==
 
;tempLineTrigger(from, howMany, code)
 
:Temporary trigger that will fire on ''n'' consecutive lines following the current line. This is useful to parse output that is known to arrive in a certain line margin or to delete unwanted output from the game - the trigger does not require any patterns to match on. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.
 
 
 
;Parameters:
 
* ''from'': from which line after this one should the trigger activate - 1 will activate right on the next line.
 
* ''howMany'': how many lines to run for after the trigger has activated.
 
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).
 
 
 
;Example:
 
<syntaxhighlight lang="lua">
 
-- Will fire 3 times with the next line from the game
 
tempLineTrigger(1, 3, function() print(" trigger matched!") end)
 
 
 
-- Will fire 5 lines after the current line and fire twice on 2 consecutive lines
 
tempLineTrigger(5, 2, function() print(" trigger matched!") end, 7)
 
</syntaxhighlight>
 
 
 
==tempPromptTrigger==
 
;tempPromptTrigger(code, expireAfter)
 
:Temporary trigger that will match on the games prompt. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.
 
 
 
{{note}} If the trigger is not working, check that the '''N:''' bottom-right has a number. This feature requires telnet Go-Ahead to be enabled in the game.
 
 
 
{{MudletVersion|3.6}}
 
 
 
;Parameters:
 
* ''code'':
 
: code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function.
 
* ''expireAfter'': (available in Mudlet 3.11+)
 
: Delete trigger after a specified number of matches. You can make a trigger match not count towards expiration by returning true after it fires.
 
 
 
;Example:
 
<syntaxhighlight lang="lua">
 
tempPromptTrigger(function()
 
  echo("hello! this is a prompt!")
 
end)
 
 
 
-- match only 2 times:
 
tempPromptTrigger(function()
 
  echo("hello! this is a prompt!")
 
end, 2)
 
 
 
-- match only 2 times, unless the prompt is "55 health."
 
tempPromptTrigger(function()
 
  if line == "55 health." then return true end
 
end, 2)
 
</syntaxhighlight>
 
 
 
==tempRegexTrigger==
 
;tempRegexTrigger(regex, code, expireAfter)
 
:Creates a temporary regex trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.
 
 
 
;Parameters:
 
* ''regex:'' regular expression that lines will be matched on.
 
* ''code'': code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5.0).
 
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.
 
 
 
;Examples:
 
<syntaxhighlight lang="lua">
 
-- create a non-duplicate trigger that matches on any line and calls a function
 
html5log = html5log or {}
 
if html5log.trig then killTrigger(html5log.trig) end
 
html5log.trig = tempRegexTrigger("^", [[html5log.recordline()]])
 
-- or a simpler variant:
 
html5log.trig = tempRegexTrigger("^", html5log.recordline)
 
 
 
-- only match 3 times:
 
tempRegexTrigger("^You prick (.+) twice in rapid succession with", function() echo("Hit "..matches[2].."!\n") end, 3)
 
 
 
-- since Mudlet 4.11+ you can use named capturing groups
 
tempRegexTrigger("^You see (?<material>\\w+) axe inside chest\\.", function() echo("\nAxe is " .. matches.material) end)
 
</syntaxhighlight>
 
 
 
==tempTimer==
 
;tempTimer(time, code to do[, repeating])
 
:Creates a temporary one-shot timer and returns the timer ID, which you can use with [[Manual:Lua_Functions#enableTimer|enableTimer()]], [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#killTimer|killTimer()]] functions. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and destroyed, so it will only go off once. Here is a [[Manual:Introduction#Timers|more detailed introduction to tempTimer]].
 
  
 
;Parameters
 
;Parameters
* ''time:'' The time in seconds for which to set the timer for - you can use decimals here for precision. The timer will go off ''x'' given seconds after you make it.
+
* ''str''
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.
+
: string you wish to convert from hecho to decho
* ''repeating'': (optional) if true, keep firing the timer over and over until you kill it (available in Mudlet 4.0+).
+
;Returns
 +
* a string formatted for decho
  
;Examples
+
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- wait half a second and then run the command
+
-- convert to a decho string and use decho to display it
tempTimer(0.5, function() send("kill monster") end)
+
local hechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n""
 
+
decho(hecho2decho(hechoString))
-- echo between 1 and 5 seconds after creation
 
tempTimer(math.random(1, 5), function() echo("hi!") end)
 
 
 
-- or an another example - two ways to 'embed' variable in a code for later:
 
local name = matches[2]
 
tempTimer(2, [[send("hello, ]]..name..[[ !")]])
 
-- or:
 
tempTimer(2, function()
 
  send("hello, "..name)
 
end)
 
 
 
-- create a looping timer
 
timerid = tempTimer(1, function() display("hello!") end, true)
 
 
 
-- later when you'd like to stop it:
 
killTimer(timerid)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{note}} Double brackets, e.g: [[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.
+
=Discord Functions=
 +
:All functions to customize the information Mudlet displays in Discord's rich presence interface. For an overview on how all of these functions tie in together, see our [[Special:MyLanguage/Manual:Scripting#Discord_Rich_Presence|Discord scripting overview]].
  
{{note}} Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:
+
=Mud Client Media Protocol=
 +
:All GMCP functions to send sound and music events. For an overview on how all of these functions tie in together, see our [[Special:MyLanguage/Manual:Scripting#MUD_Client_Media_Protocol|MUD Client Media Protocol scripting overview]].
  
<syntaxhighlight lang="lua">
+
=Supported Protocols=
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )
 
  
-- tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:
+
=Events=
 +
:New or revised events that Mudlet can raise to inform a profile about changes. See [[Manual:Event_Engine#Mudlet-raised_events|Mudlet-raised events]] for the existing ones.
  
local variable = matches[2]
+
===sysMapAreaChanged, PR #6615===
tempTimer(3, function () send("hello, " .. variable) end)
+
Raised when the area being viewed in the mapper is changed, either by the player-room being set to a new area or the user selecting a different area in the area selection combo-box in the mapper controls area. Returns two additional arguments being the areaID of the area being switched to and then the one for the area that is being left.
</syntaxhighlight>
 
 
 
==tempTrigger==
 
;tempTrigger(substring, code, expireAfter)
 
:Creates a substring trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger is temporary in the sense that it won't stay when you close Mudlet, and it will go off multiple times until you disable or destroy it. You can also make it be temporary and self-delete after a number of matches with the ''expireAfter'' parameter.
 
 
 
;Parameters:
 
* ''substring'': The substring to look for - this means a part of the line. If your provided text matches anywhere within the line from the game, the trigger will go off.
 
* ''code'': The code to do when the trigger runs - wrap it in [[ ]], or give it a Lua function (since Mudlet 3.5)
 
* ''expireAfter'': Delete trigger after a specified number of matches (since Mudlet 3.11). You can make a trigger match not count towards expiration by returning true after it fires.
 
 
 
Example:
 
<syntaxhighlight lang="lua">
 
-- this example will highlight the contents of the "target" variable.
 
-- it will also delete the previous trigger it made when you call it again, so you're only ever highlighting one name
 
if id then killTrigger(id) end
 
id = tempTrigger(target, [[selectString("]] .. target .. [[", 1) fg("gold") resetFormat()]])
 
  
-- you can also write the same line as:
+
{{MudletVersion| ?.??}}
id = tempTrigger(target, function() selectString(target, 1) fg("gold") resetFormat() end)
 
  
-- or like so if you have a highlightTarget() function somewhere
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6615
id = tempTrigger(target, highlightTarget)
 
</syntaxhighlight>
 
  
<syntaxhighlight lang="lua">
+
===sysMapWindowMousePressEvent, PR #6962===
-- a simpler trigger to replace "hi" with "bye" whenever you see it
+
Raised when the mouse is left-clicked on the mapper window.
tempTrigger("hi", [[selectString("hi", 1) replace("bye")]])
 
</syntaxhighlight>
 
  
<syntaxhighlight lang="lua">
+
{{MudletVersion| ?.??}}
-- this trigger will go off only 2 times
 
tempTrigger("hi", function() selectString("hi", 1) replace("bye") end, 2)
 
</syntaxhighlight>
 
 
 
<syntaxhighlight lang="lua">
 
-- table to store our trigger IDs in
 
nameIDs = nameIDs or {}
 
-- delete any existing triggers we've already got
 
for _, id in ipairs(nameIDs) do killTrigger(id) end
 
 
 
-- create new ones, avoiding lots of ]] [[ to embed the name
 
for _, name in ipairs{"Alice", "Ashley", "Aaron"} do
 
  nameIDs[#nameIDs+1] = tempTrigger(name, function() print(" Found "..name.."!") end)
 
end
 
</syntaxhighlight>
 
  
;Additional Notes:
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6962
tempTriggers begin matching on the same line they're created on.  
 
  
If your ''code'' deletes and recreates the tempTrigger, or if you ''send'' a matching command again, it's possible to get into an infinite loop.
+
===sysWindowOverflowEvent, PR #6872===
 +
Raised when the content in a mini-console/user window that has been set to be '''non-scrolling''' (see: [[#enableScrolling|enableScrolling(...)]] and [[#disableScrolling|disableScrolling(...)]]) overflows - i.e. fills the visible window and overflows off the bottom. Returns two additional arguments being the window's name as a string and the number of lines that have gone past that which can be shown on the current size of the window.
  
Make use of the ''expireAfter'' parameter, [[Manual:Lua_Functions#disableTrigger|disableTrigger()]], or [[Manual:Lua_Functions#killTrigger|killTrigger()]] to prevent a loop from forming.
+
{{MudletVersion| ?.??}}
  
[[Category:Mudlet Manual]]
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6872 and https://github.com/Mudlet/Mudlet/pull/6848 for the Lua API functions (that also need documenting).
[[Category:Mudlet API]]
 

Latest revision as of 07:18, 21 July 2024

This page is for the development of documentation for Lua API functions that are currently being worked on. Ideally the entries here can be created in the same format as will be eventually used in Lua Functions and its sub-sites.

Please use the Area_51/Template to add new entries in the sections below.

Links to other functions or parts in other sections (i.e. the main Wiki area) need to include the section details before the '#' character in the link identifier on the left side of the '|' divider between the identifier and the display text. e.g.

[[Manual:Mapper_Functions#getCustomLines|getCustomLines()]]

rather than:

[[#getCustomLines|getCustomLines()]]

which would refer to a link within the current (in this case Area 51) section. Note that this ought to be removed once the article is moved to the main wiki area!

The following headings reflect those present in the main Wiki area of the Lua API functions. It is suggested that new entries are added so as to maintain a sorted alphabetical order under the appropriate heading.


Basic Essential Functions

These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.

Database Functions

A collection of functions for helping deal with the database.

Date/Time Functions

A collection of functions for handling date & time.

File System Functions

A collection of functions for interacting with the file system.

Mapper Functions

A collection of functions that manipulate the mapper and its related features.

updateMap

updateMap()
Updates the mapper display (redraws it). While longer necessary since Mudlet 4.18, you can use this this function to redraw the map after changing it via API.
See also: centerview()
Example
-- delete a some room
deleteRoom(500)
-- now make the map show that it's gone
updateMap()


mapSymbolFontInfo, PR #4038 closed

mapSymbolFontInfo()
See also: setupMapSymbolFont()

Note Note: pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/4038

returns
  • either a table of information about the configuration of the font used for symbols in the (2D) map, the elements are:
  • fontName - a string of the family name of the font specified
  • onlyUseThisFont - a boolean indicating whether glyphs from just the fontName font are to be used or if there is not a glyph for the required grapheme (character) then a glyph from the most suitable different font will be substituted instead. Should this be true and the specified font does not have the required glyph then the replacement character (typically something like ) could be used instead. Note that this may not affect the use of Color Emoji glyphs that are automatically used in some OSes but that behavior does vary across the range of operating systems that Mudlet can be run on.
  • scalingFactor - a floating point number between 0.50 and 2.00 which modifies the size of the symbols somewhat though the extremes are likely to be unsatisfactory because some of the particular symbols may be too small (and be less visible at smaller zoom levels) or too large (and be clipped by the edges of the room rectangle or circle).
  • or nil and an error message on failure.
As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialized, by activating a map window).

moveMapLabel, PR #6014 open

moveMapLabel(areaID/Name, labeID/Text, coordX/deltaX, coordY/deltaY[, coordZ/deltaZ][, absoluteNotRelativeMove])

Re-positions a map label within an area in the 2D mapper, in a similar manner as the moveRoom() function does for rooms and their custom exit lines. When moving a label to given coordinates this is the position that the top-left corner of the label will be positioned at; since the space allocated to a particular room on the map is ± 0.5 around the integer value of its x and y coordinates this means for a label which has a size of 1.0 x 1,0 (w x h) to position it centrally in the space for a single room at the coordinates (x, y, z) it should be positioned at (x - 0.5, y + 0.5, z).

See also: getMapLabels(), getMapLabel().
Mudlet VersionAvailable in Mudlet ?.??+

Note Note: pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6014

Parameters
  • areaID/Name:
Area ID as number or AreaName as string containing the map label.
  • labelID/Text:
Label ID as number (which will be 0 or greater) or the LabelText on a text label. All labels will have a unique ID number but there may be more than one text labels with a non-empty text string; only the first matching one will be moved by this function and image labels also have no text and will match the empty string. with mo or AreaName as string containing the map label.
  • coordX/deltaX:
A floating point number for the absolute coordinate to use or the relative amount to move the label in "room coordinates" along the X-axis.
  • coordY/deltaY:
A floating point number for the absolute coordinate to use or the relative amount to move the label in "room coordinates" along the Y-axis.
  • coordZ/deltaZ:
(Optional) A floating point number for the absolute coordinate to use or the relative amount to move the label in "room coordinates" along the Z-axis, if omitted the label is not moved in the z-axis at all.
  • absoluteNotRelativeMove:
(Optional) a boolean value (defaults to false if omitted) as to whether to move the label to the absolute coordinates (true) or to move it the relative amount from its current location (false).
Returns
true on success or nil and an error message on failure, if successful it will also refresh the map display to show the result.
Example
-- move the first label in the area with the ID number of 2, three spaces to the east and four spaces to the north
moveMapLabel(0, 2, 3.0, 4.0)

-- move the first label in the area with the ID number of 2, one space to the west, note the final boolean argument is unneeded
moveMapLabel(0, 2, -1.0, 0.0, false)

-- move the second label in the area with the ID number of 2, three and a half spaces to the west, and two south **of the center of the current level it is on in the map**:
moveRoom(1, 2, -3.5, -2.0, true)

-- move the second label in the area with the ID number of 2, up three levels
moveRoom(1, 2, 0.0, 0.0, 3.0)

-- move the second label in the "Test 1" area one space to the west, note the last two arguments are unneeded
moveRoom("Test 1", 1, -1.0, 0.0, 0.0, false)

-- move the (top-left corner of the first) label with the text "Home" in the area with ID number 5 to the **center of the whole map**, note the last two arguments are required in this case:
moveRoom(5, "Home", 0.0, 0.0, 0.0, true)

-- all of the above will return the 'true'  boolean value assuming there are the indicated labels and areas

moveRoom, PR #6010 open

moveRoom(roomID, coordX/deltaX, coordY/deltaY[, coordZ/deltaZ][, absoluteNotRelativeMove])

Re-positions a room within an area, in the same manner as the "move to" context menu item for one or more rooms in the 2D mapper. Like that method this will also shift the entirety of any custom exit lines defined for the room concerned. This contrasts with the behavior of the setRoomCoordinates() which only moves the starting point of such custom exit lines so that they still emerge from the room to which they belong but otherwise remain pointing to the original place.

See also: setRoomCoordinates()
Mudlet VersionAvailable in Mudlet ?.??+

Note Note: pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6010

Parameters
  • roomID:
Room ID number to move.
  • coordX/deltaX:
The absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the X-axis.
  • coordY/deltaY:
The absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the Y-axis.
  • coordZ/deltaZ:
(Optional) the absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the Z-axis, if omitted the room is not moved in the z-axis at all.
  • absoluteNotRelativeMove:
(Optional) a boolean value (defaults to false if omitted) as to whether to move the room to the absolute coordinates (true) or the relative amount from its current location (false).
Returns
true on success or nil and an error message on failure, if successful it will also refresh the map display to show the result.
Example
-- move the first room one space to the east and two spaces to the north
moveRoom(1, 1, 2)

-- move the first room one space to the west, note the final boolean argument is unneeded
moveRoom(1, -1, 0, false)

-- move the first room three spaces to the west, and two south **of the center of the current level it is on in the map**:
moveRoom(1, -3, -2, true)

-- move the second room up three levels
moveRoom(2, 0, 0, 3)

-- move the second room one space to the west, note the last two arguments are unneeded
moveRoom(2, -1, 0, 0, false)

-- move the second room to the **center of the whole map**, note the last two arguments are required in this case:
moveRoom(2, 0, 0, 0, true)

-- all of the above will return the 'true'  boolean value assuming there are rooms with 1 and 2 as ID numbers

setupMapSymbolFont, PR #4038 closed

setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])
configures the font used for symbols in the (2D) map.
See also: mapSymbolFontInfo()

Note Note: pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/4038

Parameters
  • fontName one of:
  • - a string that is the family name of the font to use;
  • - the empty string "" to reset to the default {which is "Bitstream Vera Sans Mono"};
  • - a Lua nil as a placeholder to not change this parameter but still allow a following one to be modified.
  • onlyUseThisFont (optional) one of:
  • - a Lua boolean true to require Mudlet to use graphemes (character) only from the selected font. Should a requested grapheme not be included in the selected font then the font replacement character (�) might be used instead; note that under some circumstances it is possible that the OS (or Mudlet) provided color Emoji Font may still be used but that cannot be guaranteed across all OS platforms that Mudlet might be run on;
  • - a Lua boolean false to allow Mudlet to get a different glyph for a particular grapheme from the most suitable other font found in the system should there not be a glyph for it in the requested font. This is the default unless previously changed by this function or by the corresponding checkbox in the Profile Preferences dialogue for the profile concerned;
  • - a Lua nil as a placeholder to not change this parameter but still allow the following one to be modified.
  • scalingFactor (optional): a floating point value in the range 0.5 to 2.0 (default 1.0) that can be used to tweak the rectangular space that each different room symbol is scaled to fit inside; this might be useful should the range of characters used to make the room symbols be consistently under- or over-sized.
Returns
  • true on success
  • nil and an error message on failure. As the symbol font details are stored in the (binary) map file rather than the profile then this function will not work until a map is loaded (or initialised, by activating a map window).

Miscellaneous Functions

Miscellaneous functions.

compare, PR#7122 open

sameValue = compare(a, b)
This function takes two items, and compares their values. It will compare numbers, strings, but most importantly it will compare two tables by value, not reference. For instance, {} == {} is false, but compare({}, {}) is true
See also
table.complement(), table.n_union()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • a:
The first item to compare
  • b:
The second item to compare
Returns
  • Boolean true if the items have the same value, otherwise boolean false
Example
local tblA = { 255, 0, 0 }
local tblB = color_table.red
local same = compare(tblA, tblB)
display(same)
-- this will return true
display(tblA == tblB)
-- this will display false, as they are different tables
-- even though they have the same value
Additional development notes

This is just exposing the existing _comp function, which is currently the best way to compare two tables by value. --Demonnic (talk) 18:51, 7 February 2024 (UTC)

createVideoPlayer, PR #6439

createVideoPlayer([name of userwindow], x, y, width, height)
Creates a miniconsole window for the video player to render in, the with the given dimensions. One can only create one video player at a time (currently), and it is not currently possible to have a label on or under the video player - otherwise, clicks won't register.

Note Note: A video player may also be created through use of the Mud Client Media Protocol, the playVideoFile() API command, or adding a Geyser.VideoPlayer object to ones user interface such as the example below.

Note Note: The Main Toolbar will show a Video button to hide/show the video player, which is located in a userwindow generated through createVideoPlayer, embedded in a user interface, or a dock-able widget (that can be floated free to anywhere on the Desktop, it can be resized and does not have to even reside on the same monitor should there be multiple screens in your system). Further clicks on the Video button will toggle between showing and hiding the map whether it was created using the createVideo function or as a dock-able widget.

See also: loadSoundFile(), loadMusicFile(), loadVideoFile(), playSoundFile(), playMusicFile(), playVideoFile(), stopSounds(), stopMusic(), stopVideos(), purgeMediaCache(), Mud Client Media Protocol

Mudlet VersionAvailable in Mudlet4.??+
Example
-- Create a 300x300 video player in the top-left corner of Mudlet
createVideoPlayer(0,0,300,300)

-- Alternative examples using Geyser.VideoPlayer
GUI.VideoPlayer = GUI.VideoPlayer or Geyser.VideoPlayer:new({name="GUI.VideoPlayer", x = 0, y = 0, width = "25%", height = "25%"})
 
GUI.VideoPlayer = GUI.VideoPlayer or Geyser.VideoPlayer:new({
  name = "GUI.VideoPlayer",
  x = "70%", y = 0, -- edit here if you want to move it
  width = "30%", height = "50%"
}, GUI.Right)

loadVideoFile, PR #6439

loadVideoFile(settings table) or loadVideoFile(name, [url])
Loads video files from the Internet or the local file system to the "media" folder of the profile for later use with playVideoFile() and stopVideos(). Although files could be loaded or streamed directly at playing time from playVideoFile(), loadVideoFile() provides the advantage of loading files in advance.

Note Note: Video files consume drive space on your device. Consider using the streaming feature of playVideoFile() for large files.

Required Key Value Purpose
Yes name <file name>
  • Name of the media file.
  • May contain directory information (i.e. weather/maelstrom.mp4).
  • May be part of the profile (i.e. getMudletHomeDir().. "/congratulations.mp4")
  • May be on the local device (i.e. "C:/Users/YourNameHere/Movies/nevergoingtogiveyouup.mp4")
Maybe url <url>
  • Resource location where the media file may be downloaded.
  • Only required if file to load is not part of the profile or on the local file system.

See also: loadSoundFile(), loadMusicFile(), playSoundFile(), playMusicFile(), playVideoFile(), stopSounds(), stopMusic(), stopVideos(), createVideoPlayer(), purgeMediaCache(), Mud Client Media Protocol

Mudlet VersionAvailable in Mudlet4.??+
Example
---- Table Parameter Syntax ----

-- Download from the Internet
loadVideoFile({
    name = "TextInMotion-VideoSample-1080p.mp4"
    , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
})

-- OR download from the profile
loadVideoFile({name = getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4"})

-- OR download from the local file system
loadVideoFile({name = "C:/Users/Tamarindo/Movies/TextInMotion-VideoSample-1080p.mp4"})
---- Ordered Parameter Syntax of loadVideoFile(name[, url]) ----

-- Download from the Internet
loadVideoFile(
    "TextInMotion-VideoSample-1080p.mp4"
    , "https://d2qguwbxlx1sbt.cloudfront.net/"
)

-- OR download from the profile
loadVideoFile(getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4")

-- OR download from the local file system
loadVideoFile("C:/Users/Tamarindo/Movies/TextInMotion-VideoSample-1080p.mp4")

playVideoFile, PR #6439

playVideoFile(settings table)
Plays video files from the Internet or the local file system for later use with stopMusic(). Video files may be downloaded to the device and played, or streamed from the Internet when the value of the stream parameter is true.
Required Key Value Default Purpose
Yes name <file name>  
  • Name of the media file.
  • May contain directory information (i.e. weather/maelstrom.mp4).
  • May be part of the profile (i.e. getMudletHomeDir().. "/cow.mp4")
  • May be on the local device (i.e. "C:/Users/YourNameHere/Documents/nevergoingtogiveyouup.mp4")
  • Wildcards * and ? may be used within the name to randomize media files selection.
No volume 1 to 100 50
  • Relative to the volume set on the player's client.
No fadein <msec>
  • Volume increases, or fades in, ranged across a linear pattern from one to the volume set with the "volume" key.
  • Start position: Start of media.
  • End position: Start of media plus the number of milliseconds (msec) specified.
  • 1000 milliseconds = 1 second.
No fadeout <msec>
  • Volume decreases, or fades out, ranged across a linear pattern from the volume set with the "volume" key to one.
  • Start position: End of the media minus the number of milliseconds (msec) specified.
  • End position: End of the media.
  • 1000 milliseconds = 1 second.
No start <msec> 0
  • Begin play at the specified position in milliseconds.
No loops -1, or >= 1 1
  • Number of iterations that the media plays.
  • A value of -1 allows the media to loop indefinitely.
No key <key>  
  • Uniquely identifies media files with a "key" that is bound to their "name" or "url".
  • Halts the play of current media files with the same "key" that have a different "name" or "url" while this media plays.
No tag <tag>  
  • Helps categorize media.
No continue true or false true
  • Continues playing matching new video files when true.
  • Restarts matching new video files when false.
Maybe url <url>  
  • Resource location where the media file may be downloaded.
  • Only required if the file is to be downloaded remotely or for streaming from the Internet.
Maybe stream true or false false
  • Streams files from the Internet when true.
  • Download files when false (default).
  • Used in combination with the `url` key.

See also: loadSoundFile(), loadMusicFile(), loadVideoFile(), playSoundFile(), playMusicFile(), stopSounds(), stopMusic(), stopVideos(), createVideoPlayer(), purgeMediaCache(), Mud Client Media Protocol

Mudlet VersionAvailable in Mudlet4.??+
Example
---- Table Parameter Syntax ----

-- Stream a video file from the Internet and play it.
playVideoFile({
    name = "TextInMotion-VideoSample-1080p.mp4"
    , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
    , stream = true
})

-- Play a video file from the Internet, storing it in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media) so you don't need to download it over and over.  You could add ", stream = false" below, but that is the default and is not needed.

playVideoFile({
    name = "TextInMotion-VideoSample-1080p.mp4"
    , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
})

-- Play a video file stored in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media)
playVideoFile({
    name = "TextInMotion-VideoSample-1080p.mp4"
})

-- OR copy once from the game's profile, and play a video file stored in the profile's media directory
---- [volume] of 75 (1 to 100)
playVideoFile({
    name = getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4"
    , volume = 75
})

-- OR copy once from the local file system, and play a video file stored in the profile's media directory
---- [volume] of 75 (1 to 100)
playVideoFile({
    name = "C:/Users/Tamarindo/Movies/TextInMotion-VideoSample-1080p.mp4"
    , volume = 75
})

-- OR download once from the Internet, and play a video stored in the profile's media directory
---- [fadein] and increase the volume from 1 at the start position to default volume up until the position of 10 seconds
---- [fadeout] and decrease the volume from default volume to one, 15 seconds from the end of the video
---- [start] 5 seconds after position 0 (fadein scales its volume increase over a shorter duration, too)
---- [key] reference of "text" for stopping this unique video later
---- [tag] reference of "ambience" to stop any video later with the same tag
---- [continue] playing this video if another request for the same video comes in (false restarts it) 
---- [url] resource location where the file may be accessed on the Internet
---- [stream] download once from the Internet if the video does not exist in the profile's media directory when false (true streams from the Internet and will not download to the device) 
playVideoFile({
    name = "TextInMotion-VideoSample-1080p.mp4"
    , volume = nil -- nil lines are optional, no need to use
    , fadein = 10000
    , fadeout = 15000
    , start = 5000
    , loops = nil -- nil lines are optional, no need to use
    , key = "text"
    , tag = "ambience"
    , continue = true
    , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
    , stream = false
})
---- Ordered Parameter Syntax of playVideoFile(name[,volume][,fadein][,fadeout][,loops][,key][,tag][,continue][,url][,stream]) ----

-- Stream a video file from the Internet and play it.
playVideoFile(
    "TextInMotion-VideoSample-1080p.mp4"
    , nil -- volume
    , nil -- fadein
    , nil -- fadeout
    , nil -- start
    , nil -- loops
    , nil -- key
    , nil -- tag
    , true -- continue
    , "https://d2qguwbxlx1sbt.cloudfront.net/" -- url
    , false -- stream
)

-- Play a video file from the Internet, storing it in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media) so you don't need to download it over and over.
playVideoFile(
    "TextInMotion-VideoSample-1080p.mp4"
    , nil -- volume
    , nil -- fadein
    , nil -- fadeout
    , nil -- start
    , nil -- loops
    , nil -- key
    , nil -- tag
    , true -- continue
    , "https://d2qguwbxlx1sbt.cloudfront.net/" -- url
    , false -- stream
)

-- Play a video file stored in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media)
playVideoFile(
    "TextInMotion-VideoSample-1080p.mp4"  -- name
)

-- OR copy once from the game's profile, and play a video file stored in the profile's media directory
---- [volume] of 75 (1 to 100)
playVideoFile(
    getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4" -- name
    , 75 -- volume
)

-- OR copy once from the local file system, and play a video file stored in the profile's media directory
---- [volume] of 75 (1 to 100)
playVideoFile(
    "C:/Users/Tamarindo/Documents/TextInMotion-VideoSample-1080p.mp4" -- name
    , 75 -- volume
)

-- OR download once from the Internet, and play a video stored in the profile's media directory
---- [fadein] and increase the volume from 1 at the start position to default volume up until the position of 10 seconds
---- [fadeout] and decrease the volume from default volume to one, 15 seconds from the end of the video
---- [start] 5 seconds after position 0 (fadein scales its volume increase over a shorter duration, too)
---- [key] reference of "text" for stopping this unique video later
---- [tag] reference of "ambience" to stop any video later with the same tag
---- [continue] playing this video if another request for the same video comes in (false restarts it) 
---- [url] resource location where the file may be accessed on the Internet
---- [stream] download once from the Internet if the video does not exist in the profile's media directory when false (true streams from the Internet and will not download to the device) 
playVideoFile(
    "TextInMotion-VideoSample-1080p.mp4" -- name
    , nil -- volume
    , 10000 -- fadein
    , 15000 -- fadeout
    , 5000 -- start
    , nil -- loops
    , "text" -- key
    , "ambience" -- tag
    , true -- continue
    , "https://d2qguwbxlx1sbt.cloudfront.net/" -- url
    , false -- stream
)


stopVideos, PR #6439

stopVideos(settings table)
Stop all videos (no filter), or videos that meet a combination of filters (name, key, and tag) intended to be paired with playVideoFile().
Required Key Value Purpose
No name <file name>
  • Name of the media file.
No key <key>
  • Uniquely identifies media files with a "key" that is bound to their "name" or "url".
  • Halts the play of current media files with the same "key" that have a different "name" or "url" while this media plays.
No tag <tag>
  • Helps categorize media.

See also: loadSoundFile(), loadMusicFile(), loadVideoFile(), playSoundFile(), playMusicFile(), playVideoFile(), stopSounds(), stopMusic(), createVideoPlayer(), purgeMediaCache(), Mud Client Media Protocol

Mudlet VersionAvailable in Mudlet4.??+
Example
---- Table Parameter Syntax ----

-- Stop all playing video files for this profile associated with the API
stopVideos()

-- Stop playing the text mp4 by name
stopVideos({name = "TextInMotion-VideoSample-1080p.mp4"})

-- Stop playing the unique sound identified as "text"
stopVideos({
    name = nil  -- nil lines are optional, no need to use
    , key = "text" -- key
    , tag = nil  -- nil lines are optional, no need to use
})
---- Ordered Parameter Syntax of stopVideos([name][,key][,tag]) ----

-- Stop all playing video files for this profile associated with the API
stopVideos()

-- Stop playing the text mp4 by name
stopVideos("TextInMotion-VideoSample-1080p.mp4")

-- Stop playing the unique sound identified as "text"
stopVideos(
    nil -- name
    , "text" -- key
    , nil -- tag
)


getCustomLoginTextId, PR #3952 open

getCustomLoginTextId()

Returns the Id number of the custom login text setting from the profile's preferences. Returns 0 if the option is disabled or a number greater than that for the item in the table; note it is possible if using an old saved profile in the future that the number might be higher than expected. As a design policy decision it is not permitted for a script to change the setting, this function is intended to allow a script or package to check that the setting is what it expects.

Introduced along with four other functions to enable game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined doLogin() function, a replacement for which is shown below.

See also: getCharacterName(), sendCharacterName(), sendCustomLoginText(), sendPassword().

Note Note: Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952

Only one custom login text has been defined initially:

Predefined custom login texts
Id Custom text Introduced in Mudlet version
1 "connect {character name} {password}" TBD

The addition of further texts would be subject to negotiation with the Mudlet Makers.

Example
-- A replacement for the default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:
function doLogin()
  if getCustomLoginTextId() ~= 1 then
    -- We need this particular option but it is not permitted for a script to change the setting, it can only check what it is
    echo("\nUnable to login - please select the 'connect {character name} {password}` custom login option in the profile preferences.\n")
  else
    tempTime(2.0, [[sendCustomLoginText()]], 1)
  end
end

sendCharacterName, PR #3952 open

sendCharacterName()

Sends the name entered into the "Character name" field on the Connection Preferences form directly to the game server. Returns true unless there is nothing set in that entry in which case a nil and an error message will be returned instead.

Introduced along with four other functions to enable game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined doLogin() function that may be replaced for more sophisticated requirements.

See also: getCharacterName(), sendCharacterPassword(), sendCustomLoginText(), getCustomLoginTextId().

Note Note: Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952

sendCharacterPassword, PR #3952 open

sendCharacterPassword()

Sends the password entered into the "Password" field on the Connection Preferences form directly to the game server. Returns true unless there is nothing set in that entry or it is too long after (or before) a connection was successfully made in which case a nil and an error message will be returned instead.

Introduced along with four other functions to enable game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined doLogin() function, reproduced below, that may be replaced for more sophisticated requirements.

See also: getCharacterName(), sendCustomLoginText(), getCustomLoginTextId(), sendCharacterName().

Note Note: Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952

Example
-- The default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:
function doLogin()
  if getCharacterName() ~= "" then
    tempTime(2.0, [[sendCharacterName()]], 1)
    tempTime(3.0, [[sendCharacterPassword()]], 1)
  end
end

sendCustomLoginText, PR #3952 open

sendCustomLoginText()

Sends the custom login text (which does NOT depend on the user's choice of GUI language) selected in the preferences for this profile. The {password} (and {character name} if present) fields will be replaced with the values entered into the "Password" and "Character name" fields on the Connection Preferences form and then sent directly to the game server. Returns true unless there is nothing set in either of those entries (though only if required for the character name) or it is too long after (or before) a connection was successfully made or if the custom login feature is disabled, in which case a nil and an error message will be returned instead.

Introduced along with four other functions to enable game server log-in to be scripted with the simultaneous movement of that functionality from the Mudlet application core code to a predefined doLogin() function, a replacement for which is shown below.

See also: getCharacterName(), sendCharacterName(), sendPassword(), getCustomLoginTextId().

Note Note: Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952

Only one custom login text has been defined initially:

Predefined custom login texts
Id Custom text Introduced in Mudlet version
1 "connect {character name} {password}" TBD

The addition of further texts would be subject to negotiation with the Mudlet Makers.

Example
-- A replacement for the default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:
function doLogin()
  if getCustomLoginTextId() ~= 1 then
    -- We need this particular option but it is not permitted for a script to change the setting, it can only check what it is
    echo("\nUnable to login - please select the 'connect {character name} {password}` custom login option in the profile preferences.\n")
  else
    tempTime(2.0, [[sendCustomLoginText()]], 1)
  end
end

Mudlet Object Functions

A collection of functions that manipulate Mudlet's scripting objects - triggers, aliases, and so forth.

ancestors, new in PR #6726

ancestors(IDnumber, type)
You can use this function to find out about all the ancestors of something.
Returns a list as a table with the details of each successively distance ancestor (if any) of the given item; the details are in the form of a sub-table, within each containing specifically:
  • its IDnumber as a number
  • its name as a string
  • whether it is active as a boolean
  • its "node" (type) as a string, one of "item", "group" (folder) or "package" (module)
Returns nil and an error message if either parameter is not valid
Parameters
  • IDnumber:
The ID number of a single item, (which will be that returned by a temp* or perm* function to create such an item to identify the item).
  • type:
The type can be 'alias', 'button', 'trigger', 'timer', 'keybind', or 'script'.
See also: isAncestorsActive(...), isActive(...)
Example
-- To do

findItems, new in PR #6742

findItems("name", "type"[, exact[, case sensitive]])
You can use this function to determine the ID number or numbers of items of a particular type with a given name.
Returns a list as a table with ids of each Mudlet item that matched or nil and an error message should an incorrect type string be given.
Parameters
  • name:
The name (as a string) of the item, (which will be that returned by a temp* or perm* function to create such an item to identify the item).
  • type:
The type (as a string) can be 'alias', 'button', 'trigger', 'timer', 'keybind' , or 'script'.
  • exact:
(Optional) a boolean which if omitted or true specifies to match the given name against the whole of the names for items or only as a sub-string of them. As a side effect, if this is provided and is false and an empty string (i.e. "") is given as the first argument then the function will return the ID numbers of all items (both temporary and permanent) of the given type in existence at the time.
  • case sensitive:
(Optional) a boolean which if omitted or true specifies to match in a case-sensitive manner the given name against the names for items.
Example

Given a profile with just the default packages installed (automatically) - including the echo one:

View of standard aliases with focus on echo package.png
-- Should find just the package with the name:
lua findItems("echo", "alias")
{ 3 }

-- Should find both the package and the alias - as the latter contains "echo" with another character
lua findItems("echo", "alias", false)
{ 3, 4 }

-- Finds the ID numbers of all the aliases:
lua findItems("", "alias", false)
{ 1, 2, 3, 4, 5, 6, 7 }

-- Will still find the package with the name "echo" as we are not concerned with the casing now:
lua findItems("Echo", "alias", true, false)
{ 3 }

-- Won't find the package with the name "echo" now as we are concerned with the casing:
lua findItems("Echo", "alias", true, true)
{}

isActive, modified by PR #6726

isActive(name/IDnumber, type[, checkAncestors])
You can use this function to check if something, or somethings, are active.
Returns the number of active things - and 0 if none are active. Beware that all numbers are true in Lua, including zero.
Parameters
  • name:
The name (as a string) or, from Mudlet 4.17.0, the ID number of a single item, (which will be that returned by a temp* or perm* function to create such an item to identify the item).
  • type:
The type can be 'alias', 'button' (from Mudlet 4.10), 'trigger', 'timer', 'keybind' (from Mudlet 3.2), or 'script' (from Mudlet 3.17).
  • checkAncestors:
(Optional) If provided AND true (considered false if absent to reproduce behavior of previous versions of Mudlet) then this function will only count an item as active if it and all its parents (ancestors) are active (from Mudlet tbd).
See also: exists(...), isAncestorsActive(...), ancestors(...)
Example
echo("I have " .. isActive("my trigger", "trigger") .. " currently active trigger(s) called 'my trigger'!")

-- Can also be used to check if a specific item is enabled or not.
if isActive("spellname", "trigger") > 0 then
  -- the spellname trigger is active
else
  -- it is not active
end

Note Note: A positive ID number that does not exist will still return a 0 value, this is for constancy with the way the function behaves for a name that does not refer to any item either. If necessary the existence of an item should be confirmed with exists(...) first.

isAncestorsActive, new in PR #6726

isAncestorsActive(IDnumber, "type")
You can use this function to check if all the ancestors of something are active independent of whether it itself is, (for that use the two argument form of isActive(...)).
Returns true if all (if any) of the ancestors of the item with the specified ID number and type are active, if there are no such parents then it will also returns true; otherwise returns false. In the event that an invalid type string or item number is provided returns nil and an error message.
Parameters
  • IDnumber:
The ID number of a single item, (which will be that returned by a temp* or perm* function to create such an item to identify the item).
  • type:
The type can be 'alias', 'button', 'trigger', 'timer', 'keybind' or 'script' to define which item type is to be checked.
See also: exists(...)
Example
-- To do

Networking Functions

A collection of functions for managing networking.

sendSocket revised in PR #7066 (Open)

sendSocket(data)
Sends given binary data as-is (or with some predefined special tokens converted to byte values) to the game. You can use this to implement support for a new telnet protocol, simultronics login etc.
success = sendSocket("data")
See also
feedTelnet(), feedTriggers()

Note Note: Modified in Mudlet tbd to accept some tokens like "<NUL>" to include byte values that are not possible to insert with the standard Lua string escape "\###" form where ### is a three digit number between 000 and 255 inclusive or where the value is more easily provided via a mnemonic. For the table of the tokens that are known about, see the one in feedTelnet().

Note Note: The data (as bytes) once the tokens have been converted to their byte values is sent as is to the Game Server; any encoding to, say, a UTF-8 representation or to duplicate 0xff byte values so they are not considered to be Telnet <IAC> (Interpret As Command) bytes must be done to the data prior to calling this function.

Parameters
  • data:
String containing the bytes to send to the Game Server possibly containing some tokens that are to be converted to bytes as well.
Returns
  • (Only since Mudlet tbd) Boolean true if the whole data string (after token replacement) was sent to the Server, false if that failed for any reason (including if the Server has not been connected or is now disconnected). nil and an error message for any other defect.
Example
-- Tell the Server that we are now willing and able to process  to process Ask the Server to a comment explaining what is going on, if there is multiple functionalities (or optional parameters) the examples should start simple and progress in complexity if needed!
-- the examples should be small, but self-contained so new users can copy & paste immediately without going diving in lots other function examples first.
-- comments up top should introduce / explain what it does

local something = function(exampleValue)
if something then
  -- do something with something (assuming there is a meaningful return value)
end

-- maybe another example for the optional second case
local somethingElse = function(exampleValue, anotherValue)

-- lastly, include an example with error handling to give an idea of good practice
local ok, err = function()
if not ok then
  debugc(f"Error: unable to do <particular thing> because {err}\n")
  return
end
Additional development notes

-- This function is still being written up.

feedTelnet added in PR #7066 (Open)==

feedTelnet(data)
Sends given binary data with some predefined special tokens converted to byte values, to the internal telnet engine, as if it had been received from the game. This is primarily to enable testing when new Telnet sub-options/protocols are being developed. The data has to be injected into the system nearer to the point where the Game Server's data starts out than feedTriggers() and unlike the latter the data is not subject to any encoding so as to match the current profile's setting (which normally happens with feedTriggers()). Furthermore - to prevent this function from putting the telnet engine into a state which could damage the processing of real game data it will refuse to work unless the Profile is completely disconnected from the game server.
See also
feedTriggers(), sendSocket()
Mudlet VersionAvailable in Mudlettbd+

Note Note: This is not really intended for end-user's but might be useful in some circumstances.

Parameters
  • data
String containing the bytes to send to the internal telnet engine as if it had come from the Game Server, it can containing some tokens listed below that are to be converted to bytes as well.
Returns
  • Boolean true if the data string was sent to the internal telnet engine. nil and an error message otherwise, specifically the case when there is some traces of a connection or a complete connection to the socket that passes the data to and from the game server. Additionally, if the data is an empty string "" a second return value will be provided as an integer number representing a version for the table of tokens - which will be incremented each time a change is made to that table so that which tokens are valid can be determined. Note that unrecognised tokens should be passed through as is and not get replaced.
Token value table
Token Byte Version Notes
<00> \0x00 1 0 dec.
<O_BINARY> \0x00 1 Telnet option: Binary
<NUL> \0x00 1 ASCII control character: NULL
<01> \x01 1 1 dec.
<O_ECHO> \x01 1 Telnet option: Echo
<SOH> \x01 1 ASCII control character: Start of Heading
<02> \x02 1 2 dec. Telnet option: Reconnect
<STX> \x02 1 ASCII control character: Start of Text
<03> \x03 1 3 dec.
<O_SGA> \x03 1 Telnet option: Suppress Go Ahead
<ETX> \x03 1 ASCII control character: End of Text
<04> \x04 1 Telnet option: Approx Message Size Negotiation
<EOT> \x04 1 ASCII control character: End of Transmission
<05> \x05 1
<O_STATUS> \x05 1
<ENQ> \x05 1 ASCII control character: Enquiry
<06> \x06 1 Telnet option: Timing Mark
<ACK> \x06 1 ASCII control character: Acknowledge
<07> \x07 1 Telnet option: Remote Controlled Trans and Echo
<BELL> \x07 1 ASCII control character: Bell
<08> \x08 1 Telnet option: Output Line Width
<BS> \x08 1
<09> \x09 1 Telnet option: Output Page Size
<HTAB> \x09 1 ASCII control character: Horizontal Tab
<0A> \x0a 1 Telnet option: Output Carriage-Return Disposition
<LF> \x0a 1 ASCII control character: Line-Feed
<0B> \x0b 1 Telnet option: Output Horizontal Tab Stops
<VTAB> \x0b 1 ASCII control character: Vertical Tab
<0C> \x0c 1 Telnet option: Output Horizontal Tab Disposition
<FF> \x0c 1 ASCII control character: Form-Feed
<0D> \x0d 1 Telnet option: Output Form-feed Disposition
<CR> \x0d 1 ASCII control character: Carriage-Return
<0E> \x0e 1 Telnet option: Output Vertical Tab Stops
<SO> \x0e 1 ASCII control character: Shift-Out
<0F> \x0f 1 Telnet option: Output Vertical Tab Disposition
<SI> \x0f 1 ASCII control character: Shift-In
<10> \x10 1 Telnet option: Output Linefeed Disposition
<DLE> \x10 1 ASCII control character: Data Link Escape
<11> \x11 1 Telnet option: Extended ASCII
<DC1> \x11 1 ASCII control character: Device Control 1
<12> \x12 1 Telnet option: Logout
<DC2" \x12 1 ASCII control character: Device Control 2
<13> \x13 1 Telnet option: Byte Macro
<DC3> \x13 1 ASCII control character: Device Control 3
<14> \x14 1 Telnet option: Data Entry Terminal
<DC4> \x14 1 ASCII control character: Device Control 4
<15> \x15 1 Telnet option: SUPDUP
<NAK> \x15 1 ASCII control character: Negative Acknowledge
<16> \x16 1 Telnet option: SUPDUP Output
<SYN> \x16 1 ASCII control character: Synchronous Idle
<17> \x17 1 Telnet option: Send location
<ETB> \x17 1 ASCII control character: End of Transmission Block
<18> \x18 1
<O_TERM> \x18 1 Telnet option: Terminal Type
<CAN> \x18 1 ASCII control character: Cancel
<19> \x19 1
<O_EOR> \x19 1 Telnet option: End-of-Record
<EM> \x19 1 ASCII control character: End of Medium
<1A> \x1a 1 Telnet option: TACACS User Identification
<SUB> \x1a 1 ASCII control character: Substitute
<1B> \x1b 1 Telnet option: Output Marking
<ESC> \x1b 1 ASCII control character: Escape
<1C> \x1c 1 Telnet option: Terminal Location Number
<FS> \x1c 1 ASCII control character: File Separator
<1D> \x1d 1 Telnet option: Telnet 3270 Regime
<GS> \x1d 1 ASCII control character: Group Separator
<1E> \x1e 1 Telnet option: X.3 PAD
<RS> \x1e 1 ASCII control character: Record Separator
<1F> \x1f 1
<O_NAWS> \x1f 1 Telnet option: Negotiate About Window Size
<US> \x1f 1 ASCII control character: Unit Separator
<SP> \x20 1 32 dec. ASCII character: Space
<O_NENV> \x27 1 39 dec. Telnet option: New Environment (also MNES)
<O_CHARS> \x2a 1 42 dec. Telnet option: Character Set
<O_KERMIT> \x2f 1 47 dec. Telnet option: Kermit
<O_MSDP> \x45 1 69 dec. Telnet option: Mud Server Data Protocol
<O_MSSP> \x46 1 70 dec. Telnet option: Mud Server Status Protocol
<O_MCCP> \x55 1 85 dec
<O_MCCP2> \x56 1 86 dec
<O_MSP> \x5a 1 90 dec. Telnet option: Mud Sound Protocol
<O_MXP> \x5b 1 91 dec. Telnet option: Mud eXtension Protocol
<O_ZENITH> \x5d 1 93 dec. Telnet option: Zenith Mud Protocol
<O_AARDWULF> \x66 1 102 dec. Telnet option: Aardwuld Data Protocol
<DEL> \x7f 1 127 dec. ASCII control character: Delete
<O_ATCP> \xc8 1 200 dec
<O_GMCP> \xc9 1 201 dec
<T_EOR> \xef 1 239 dec
<F0> \xf0 1
<T_SE> \xf0 1
<F1> \xf1 1
<T_NOP> \xf1 1
<F2> \xf2 1
<T_DM> \xf2 1
<F3> \xf3 1
<T_BRK> \xf3 1
<F4> \xf4 1
<T_IP> \xf4 1
<F5> \xf5 1
<T_ABOP> \xf5 1
<F6> \xf6 1
<T_AYT> \xf6 1
<F7> \xf7 1
<T_EC> \xf7 1
<F8> \xf8 1
<T_EL> \xf8 1
<F9> \xf9 1
<T_GA> \xf9 1
<FA> \xfa 1
<T_SB> \xfa 1
<FB> \xfb 1
<T_WILL> \xfb 1
<FC> \xfc 1
<T_WONT> \xfc 1
<FD> \xfd 1
<T_DO> \xfd 1
<FE> \xfe 1
<T_DONT> \xfe 1
<FF> \xff 1
<T_IAC> \xff'
Example
-- a comment explaining what is going on, if there is multiple functionalities (or optional parameters) the examples should start simple and progress in complexity if needed!
-- the examples should be small, but self-contained so new users can copy & paste immediately without going diving in lots other function examples first.
-- comments up top should introduce / explain what it does

local something = feedTelnet(exampleValue)
if something then
  -- do something with something (assuming there is a meaningful return value)
end

-- maybe another example for the optional second case
local somethingElse = function(exampleValue, anotherValue)

-- lastly, include an example with error handling to give an idea of good practice
local ok, err = function()
if not ok then
  debugc(f"Error: unable to do <particular thing> because {err}\n")
  return
end
Additional development notes

-- This function is still being written up.

String Functions

These functions are used to manipulate strings.

Table Functions

These functions are used to manipulate tables. Through them you can add to tables, remove values, check if a value is present in the table, check the size of a table, and more.

Text to Speech Functions

These functions are used to create sound from written words. Check out our Text-To-Speech Manual for more detail on how this all works together.

UI Functions

These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation as well as displaying or formatting information on the screen.

cecho2decho PR#6849 merged

convertedString = cecho2decho(str)
Converts a cecho formatted string to a decho formatted one.
See also
decho2cecho(), cecho2html()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • str
string you wish to convert from cecho to decho
Returns
  • a string formatted for decho
Example
-- convert to a decho string and use decho to display it
local cechoString = "<red><b>!!ALERT!!:</b><orange> Something has gone wrong!\n"
decho(cecho2decho(cechoString))

cecho2hecho PR#6849 merged

convertedString = cecho2hecho(str)
Converts a cecho formatted string to an hecho formatted one.
See also
hecho2cecho(), cecho2html()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • str
string you wish to convert from cecho to decho
Returns
  • a string formatted for hecho
Example
-- convert to an hecho string and use hecho to display it
local cechoString = "<red><b>!!ALERT!!:</b><orange> Something has gone wrong!\n"
hecho(cecho2hecho(cechoString))

cecho2html PR#6849 merged

convertedString = cecho2html(str[, resetFormat])
Converts a cecho formatted string to an html formatted one.
See also
decho2cecho(), cecho2html()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • str
string you wish to convert from cecho to decho
  • resetFormat
optional table of default formatting options. As returned by getLabelFormat()
Returns
  • a string formatted for html
Example
-- create the base string
local cechoString = "<red><b>!!ALERT!!:</b><orange> Something has gone wrong!\n"

-- create a label to display the result onto
testLabel = Geyser.Label:new({name = "testLabel"})

-- convert the cecho string to an html one, using the default formatting of testLabel created above
local htmlString = cecho2html(cechoString, testLabel:getFormat())

-- and finally echo it to the label to see
-- I use rawEcho as that displays the html exactly as given.
testLabel:rawEcho(htmlString)

decho2cecho PR#6849 merged

convertedString = decho2cecho(str)
Converts a decho formatted string to a cecho formatted one.
See also
cecho2decho(), decho2html()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • str
string you wish to convert from decho to cecho
Returns
  • a string formatted for cecho
Example
-- convert to a decho string and use cecho to display it
local dechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n"
cecho(decho2cecho(dechoString))

decho2hecho PR#6849 merged

convertedString = decho2hecho(str)
Converts a decho formatted string to an hecho formatted one.
See also
hecho2decho(), decho2html()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • str
string you wish to convert from decho to decho
Returns
  • a string formatted for hecho
Example
-- convert to an hecho string and use hecho to display it
local dechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n"
hecho(decho2hecho(dechoString))

decho2html PR#6849 merged

convertedString = decho2html(str[, resetFormat])
Converts a decho formatted string to an html formatted one.
See also
cecho2decho(), decho2html()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • str
string you wish to convert from decho to decho
  • resetFormat
optional table of default formatting options. As returned by getLabelFormat()
Returns
  • a string formatted for html
Example
-- create the base string
local dechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n"

-- create a label to display the result onto
testLabel = Geyser.Label:new({name = "testLabel"})

-- convert the decho string to an html one, using the default formatting of testLabel created above
local htmlString = decho2html(dechoString, testLabel:getFormat())

-- and finally echo it to the label to see
-- I use rawEcho as that displays the html exactly as given.
testLabel:rawEcho(htmlString)

deleteMultiline PR #6779 merged

ok,err = deleteMultiline([triggerDelta])
Deletes all lines between when the multiline trigger fires and when the first trigger matched. Put another way, it deletes everything since the pattern in slot 1 matched.
See also
deleteLine(), replaceLine()
Mudlet VersionAvailable in Mudlet4.18+

Note Note: This deletes all the lines since the first match of the multiline trigger matched. Do not use this if you do not want to delete ALL of those lines.

Parameters
  • [optional]triggerDelta:
The line delta from the multiline trigger it is being called from. It is best to pass this in to ensure all lines are caught. If not given it will try to guess based on the number of patterns how many lines at most it might have to delete.
Returns
  • true if the function was able to run successfully, nil+error if something went wrong.
Example
-- if this trigger has a line delta of 3, you would call
deleteMultiline(3)

-- same thing, but with error handling
local ok,err = deleteMultiline(3)
if not ok then
  cecho("\n<firebrick>I could not delete the lines because: " .. err)
end
Additional development notes

echoPopup, revised in PR #6946

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; if there is one extra hint then the first one will be used as a (maybe containing Qt rich-text markup) tool-tip for the text otherwise the remaining hints will be concatenated, one-per-line, as a tool-tip when the text is hovered over by the pointer.
Parameters
  • windowName:
(optional) name of the window as a string to echo to. Use either main or omit for the main window, or the miniconsole's or user-window's name otherwise.
  • text:
the text string to display.
  • {commands}:
a table of lua code to do, in text strings or as functions (since Mudlet 4.11), i.e. {[[send("hello")]], function() echo("hi!") end}.
  • {hints}:
a table of strings which will be shown on the right-click menu and as a tool-tip for the text. If the number is the same as that of the commands table then they all will be used for the right-click menu and listed (one per line) as a plain text tooltip; alternatively if there is one extra in number than the commands table the first will be used purely for the tool tip and the remainder will be used for the right-click menu. This additional entry may be formatted as Qt style "rich-text" (in the same manner as labels elsewhere in the GUI).
  • If a particular position in the commands table is an empty string "" but there is something in the hints table then it will be listed in the right-click menu but as it does not do anything it will be shown greyed-out i.e. disabled and will not be clickable.
  • If a particular position in both the commands and the hints table are empty strings "" then this item will show as a separator (usually as a horizontal-line) in the right-click menu and it will not be clickable/do anything.
  • useCurrentFormatElseDefault:
(optional) a boolean value for using either the current formatting options (color, underline, italic and other effects) if true or the link default (blue underline) if false, if omitted the default format is used.
Example
-- Create some text as a clickable with a popup menu, a left click will ''send "sleep"'':
echoPopup("activities to do", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})

-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})

-- one can also provide helpful information

-- todo: an example with rich-text in the tool-tips(s) - not complete yet!
echoPopup("Fancy popup", {[[echo("Doing command 1 (default one)")]], "", "", [[echo("Doing command 3")]], [[echo("Doing another command (number 4)"]], [[echo("Doing another command (number 5)"]])}, {"<p>This tooltip has HTML type tags in/around it, and it will get word-wrapped automatically to fit into a reasonable rectangle.</p><p><b>Plus</b> it can have those HTML like <i>effects</i> and be easily formatted into more than one paragraph and with <span style=\"color:cyan\">bits</span> in <span style=\"color:lime\">different</span> colors!</p><p>This example also demonstrates how to produce disabled menu (right-click) items, how to insert separators and how it now will handle multiple items with the same hint (prior to PR 6945 such duplicates will all run the command associated with the last one!) If the first command/function is an empty string then clicking on the text will have no effect, but hovering the mouse over the text will still produce the tooltip, this could be useful to display extra information about the text without doing anything by default.</p>", "Command 1 (default)", "", "Command 2 (disabled)", "Command 3", "Another command", "Another command"}, true)
echo(" remaining text.\n")

hecho2cecho PR#6849 merged

convertedString = hecho2cecho(str)
Converts a hecho formatted string to a cecho formatted one.
See also
cecho2decho(), hecho2html()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • str
string you wish to convert from hecho to cecho
Returns
  • a string formatted for cecho
Example
-- convert to a hecho string and use cecho to display it
local hechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n""
cecho(hecho2cecho(hechoString))

hecho2decho PR#6849 merged

convertedString = hecho2decho(str)
Converts a hecho formatted string to a decho formatted one.
See also
decho2hecho(), hecho2html()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • str
string you wish to convert from hecho to decho
Returns
  • a string formatted for decho
Example
-- convert to a decho string and use decho to display it
local hechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n""
decho(hecho2decho(hechoString))

Discord Functions

All functions to customize the information Mudlet displays in Discord's rich presence interface. For an overview on how all of these functions tie in together, see our Discord scripting overview.

Mud Client Media Protocol

All GMCP functions to send sound and music events. For an overview on how all of these functions tie in together, see our MUD Client Media Protocol scripting overview.

Supported Protocols

Events

New or revised events that Mudlet can raise to inform a profile about changes. See Mudlet-raised events for the existing ones.

sysMapAreaChanged, PR #6615

Raised when the area being viewed in the mapper is changed, either by the player-room being set to a new area or the user selecting a different area in the area selection combo-box in the mapper controls area. Returns two additional arguments being the areaID of the area being switched to and then the one for the area that is being left.

Mudlet VersionAvailable in Mudlet ?.??+

Note Note: pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6615

sysMapWindowMousePressEvent, PR #6962

Raised when the mouse is left-clicked on the mapper window.

Mudlet VersionAvailable in Mudlet ?.??+

Note Note: pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6962

sysWindowOverflowEvent, PR #6872

Raised when the content in a mini-console/user window that has been set to be non-scrolling (see: enableScrolling(...) and disableScrolling(...)) overflows - i.e. fills the visible window and overflows off the bottom. Returns two additional arguments being the window's name as a string and the number of lines that have gone past that which can be shown on the current size of the window.

Mudlet VersionAvailable in Mudlet ?.??+

Note Note: pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6872 and https://github.com/Mudlet/Mudlet/pull/6848 for the Lua API functions (that also need documenting).