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 miscellaneous functions.}}
 
= Miscellaneous Functions =
 
  
==addFileWatch==
+
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.  
;addFileWatch(path)
 
:Adds file watch on directory or file. Every change in that file (or directory) will raise [[Manual:Event_Engine#sysPathChanged|sysPathChanged]] event.
 
  
:See also: [[#removeFileWatch|removeFileWatch()]]
+
Please use the [[Area_51/Template]] to add new entries in the sections below.
  
{{MudletVersion|4.12}}
+
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!
  
;Example
+
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.
<syntaxhighlight lang="lua">
 
herbs = {}
 
local herbsPath = getMudletHomeDir() .. "/herbs.lua"
 
function herbsChangedHandler(_, path)
 
  if path == herbsPath then
 
    table.load(herbsPath, herbs)
 
    removeFileWatch(herbsPath)
 
  end
 
end
 
 
 
addFileWatch(herbsPath)
 
registerAnonymousEventHandler("sysPathChanged", "herbsChangedHandler")
 
</syntaxhighlight>
 
 
 
==addSupportedTelnetOption==
 
;addSupportedTelnetOption(option)
 
:Adds a telnet option, which when queried by a game server, Mudlet will return DO (253) on. Use this to register the telnet option that you will be adding support for with Mudlet - see [[Manual:Supported_Protocols#Adding_support_for_a_telnet_protocol|additional protocols]] section for more.
 
 
 
;Example:
 
 
 
<syntaxhighlight lang="lua">
 
<event handlers that add support for MSDP... see http://www.mudbytes.net/forum/comment/63920/#c63920 for an example>
 
 
 
-- register with Mudlet that it should not decline the request of MSDP support
 
local TN_MSDP = 69
 
addSupportedTelnetOption(TN_MSDP)
 
</syntaxhighlight>
 
  
==alert==
 
;alert([seconds])
 
:alerts the user to something happening - makes Mudlet flash in the Windows window bar, bounce in the macOS dock, or flash on Linux.
 
  
{{MudletVersion|3.2}}
+
=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.
  
;Parameters
+
=Database Functions=
* ''seconds:''
+
:A collection of functions for helping deal with the database.
:(optional) number of seconds to have the alert for. If not provided, Mudlet will flash until the user opens Mudlet again.
 
  
;Example:
+
=Date/Time Functions=
 +
: A collection of functions for handling date & time.
  
<syntaxhighlight lang="lua">
+
=File System Functions=
-- flash indefinitely until Mudlet is open
+
: A collection of functions for interacting with the file system.
alert()
 
  
-- flash for just 3 seconds
+
=Mapper Functions=
alert(3)
+
: A collection of functions that manipulate the mapper and its related features.
</syntaxhighlight>
 
  
==cfeedTriggers==
+
==updateMap==
;cfeedTriggers(text)
+
;updateMap()
:Like feedTriggers, but you can add color information using color names, similar to cecho.
 
  
;Parameters
+
: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.
* ''text'': The string to feed to the trigger engine. Include colors by name as black,red,green,yellow,blue,magenta,cyan,white and light_* versions of same. You can also use a number to get the ansi color corresponding to that number.
 
:See also: [[#feedTriggers|feedTriggers]]
 
  
{{MudletVersion|4.10}}
+
: See also: [[#centerview|centerview()]]
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
cfeedTriggers("<green:red>green on red<r> reset <124:100> foreground of ANSI124 and background of ANSI100<r>\n")
+
-- delete a some room
 +
deleteRoom(500)
 +
-- now make the map show that it's gone
 +
updateMap()
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==closeMudlet==
 
;closeMudlet()
 
  
:Closes Mudlet and all profiles immediately.
+
==mapSymbolFontInfo, PR #4038 closed==
:See also: [[Manual:Lua_Functions#saveProfile|saveProfile()]]
+
;mapSymbolFontInfo()
 +
: See also: [[#setupMapSymbolFont|setupMapSymbolFont()]]
  
{{note}} Use with care. This potentially lead to data loss, if "save on close" is not activated and the user didn't save the profile manually as this will NOT ask for confirmation nor will the profile be saved. Also it does not consider if there are ''other'' profiles open if multi-playing: they '''all''' will be closed!
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/4038
  
{{MudletVersion|3.1}}
+
;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">
 
closeMudlet()
 
</syntaxhighlight>
 
 
 
==compare==
 
  
 +
==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|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).
  
; sameValue = compare(a, b)
+
:See also: [[Manual:Mapper_Functions#getMapLabels|getMapLabels()]], [[Manual:Mapper_Functions#getMapLabel|getMapLabel()]].
  
: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''
+
{{MudletVersion| ?.??}}
  
;See also: [[Manual:Lua_Functions#table.complement|table.complement()]], [[Manual:Lua_Functions#table.n_union|table.n_union()]]
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6014
 
 
{{MudletVersion|4.18}}
 
  
 
;Parameters
 
;Parameters
* ''a:''
+
* ''areaID/Name:''
: The first item to compare
+
: Area ID as number or AreaName as string containing the map label.
* ''b:''
 
: The second item to compare
 
  
;Returns
+
* ''labelID/Text:''
* Boolean true if the items have the same value, otherwise boolean false
+
: 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.
  
;Example
+
* ''coordX/deltaX:''
<syntaxhighlight lang="lua">
+
: 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.
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
 
</syntaxhighlight>
 
  
; Additional development notes
+
* ''coordY/deltaY:''
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)
+
: 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.
  
==createVideoPlayer==
+
* ''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.
  
;createVideoPlayer([name of userwindow], x, y, width, height)
+
* ''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'').
  
: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.
+
;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.
{{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.
 
 
 
{{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: [[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]]
 
 
 
{{MudletVersion|4.??}}
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- 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)
 
</syntaxhighlight>
 
 
 
==deleteAllNamedEventHandlers==
 
; deleteAllNamedEventHandlers(userName)
 
 
 
:Deletes all named event handlers for userName and prevents them from firing any more. Information is deleted and cannot be retrieved.
 
 
 
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#stopNamedEventHandler|stopNamedEventHandler()]]
 
 
 
{{MudletVersion|4.14}}
 
 
 
;Parameters
 
* ''userName:''
 
: The user name the event handler was registered under.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
deleteAllNamedEventHandlers("Demonnic") -- emergency stop or debugging situation, most likely.
+
-- move the first label in the area with the ID number of 2, three spaces to the east and four spaces to the north
</syntaxhighlight>
+
moveMapLabel(0, 2, 3.0, 4.0)
  
==deleteNamedEventHandler==
+
-- 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
; success = deleteNamedEventHandler(userName, handlerName)
+
moveMapLabel(0, 2, -1.0, 0.0, false)
  
:Deletes a named event handler with name handlerName and prevents it from firing any more. Information is deleted and cannot be retrieved.
+
-- 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)
  
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#stopNamedEventHandler|stopNamedEventHandler()]]
+
-- 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)
  
{{MudletVersion|4.14}}
+
-- 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)
  
;Parameters
+
-- 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:
* ''userName:''
+
moveRoom(5, "Home", 0.0, 0.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#registerNamedEventHandler|registerNamedEventHandler()]]
 
  
;Returns
+
-- all of the above will return the 'true' boolean value assuming there are the indicated labels and areas
* true if successful, false if it didn't exist
 
;Example
 
<syntaxhighlight lang="lua">
 
local deleted = deleteNamedEventHandler("Demonnic", "Vitals")
 
if deleted then
 
  cecho("Vitals deleted forever!!")
 
else
 
  cecho("Vitals doesn't exist and so could not be deleted.")
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==denyCurrentSend==
+
==moveRoom, PR #6010 open==
;denyCurrentSend()
+
;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 [[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.
  
:Cancels a [[Manual:Lua_Functions#send|send()]] or user-entered command, but only if used within a [[Manual:Event_Engine#sysDataSendRequest|sysDataSendRequest]] event.
+
:See also: [[Manual:Mapper_Functions#setRoomCoordinates|setRoomCoordinates()]]
  
;Example
+
{{MudletVersion| ?.??}}
<syntaxhighlight lang="lua">
 
-- cancels all "eat hambuger" commands
 
function cancelEatHamburger(event, command)
 
  if command == "eat hamburger" then
 
    denyCurrentSend()
 
    cecho("<red>Denied! Didn't let the command through.\n")
 
  end
 
end
 
 
 
registerAnonymousEventHandler("sysDataSendRequest", "cancelEatHamburger")
 
</syntaxhighlight>
 
  
==dfeedTriggers==
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6010
;dfeedTriggers(str)
 
:Like feedTriggers, but you can add color information using <r,g,b>, similar to decho.
 
  
 
;Parameters
 
;Parameters
* ''str'': The string to feed to the trigger engine. Include color information inside tags like decho.
+
* ''roomID:''
;See also: [[Manual:Lua_Functions#cfeedTriggers|cfeedTriggers]], [[Manual:Lua_Functions#decho|decho]]
+
: Room ID number to move.
  
{{MudletVersion|4.11}}
+
* ''coordX/deltaX:''
 +
: The absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the X-axis.
  
;Example
+
* ''coordY/deltaY:''
<syntaxhighlight lang="lua">
+
: The absolute coordinate or the relative amount as a number to move the room in "room coordinates" along the Y-axis.
dfeedTriggers("<0,128,0:128,0,0>green on red<r> reset\n")
 
</syntaxhighlight>
 
  
==disableModuleSync==
+
* ''coordZ/deltaZ:''
;disableModuleSync(name)
+
: (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.
: Stops syncing the given module.
 
  
;Parameter
+
* ''absoluteNotRelativeMove:''
* ''name'': name of the module.
+
: (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'').
 
 
:See also: [[Manual:Lua_Functions#enableModuleSync|enableModuleSync()]], [[Manual:Lua_Functions#getModuleSync|getModuleSync()]]
 
{{MudletVersion|4.8}}
 
 
 
==enableModuleSync==
 
;enableModuleSync(name)
 
: Enables the sync for the given module name - any changes done to it will be saved to disk and if the module is installed in any other profile(s), it'll be updated in them as well on profile save.
 
 
 
;Parameter
 
* ''name'': name of the module to enable sync on.
 
 
 
:See also: [[Manual:Lua_Functions#disableModuleSync|disableModuleSync()]], [[Manual:Lua_Functions#getModuleSync|getModuleSync()]]
 
{{MudletVersion|4.8}}
 
 
 
==expandAlias==
 
;expandAlias(command, [echoBackToBuffer])
 
:Runs the command as if it was from the command line - so aliases are checked and if none match, it's sent to the game unchanged.
 
 
 
;Parameters
 
* ''command''
 
: Text of the command you want to send to the game. Will be checked for aliases.
 
* ''echoBackToBuffer''
 
: (optional) If ''false'', the command will not be echoed back in your buffer. Defaults to ''true'' if omitted.
 
 
 
{{note}} Using expandAlias is not recommended anymore as it is not very robust and may lead to problems down the road. The recommendation is to use lua functions instead. See [[Manual:Functions_vs_expandAlias]] for details and examples.
 
 
 
{{note}} If you want to be using the ''matches'' table after calling ''expandAlias'', you should save it first, as, e.g. ''local oldmatches = matches'' before calling ''expandAlias'', since ''expandAlias'' will overwrite it after using it again.
 
 
 
{{note}} Since '''Mudlet 3.17.1''' the optional second argument to echo the command on screen will be ineffective whilst the game server has negotiated the telnet ECHO option to provide the echoing of text we ''send'' to him.
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
expandAlias("t rat")
 
 
 
-- don't echo the command
 
expandAlias("t rat", false)
 
</syntaxhighlight>
 
 
 
==feedTriggers==
 
;feedTriggers(text[, dataIsUtf8Encoded = true])
 
:This function will have Mudlet parse the given text as if it came from the game - one great application is trigger testing. The built-in '''`echo''' alias provides this functionality as well.
 
 
 
;Parameters
 
* ''text:''
 
:string which is sent to the trigger processing system almost as if it came from the game server. This string must be byte encoded in a manner to match the currently selected ''Server Encoding''. 
 
* ''dataIsUtf8Encoded'' (available in Mudlet 4.2+):
 
:Set this to false, if you need pre-Mudlet 4.0 behavior. Most players won't need this.
 
:(Before Mudlet 4.0 the text had to be encoded directly in whatever encoding the setting in the preferences was set to.
 
:(Encoding could involve using the Lua string character escaping mechanism of \ and a base 10 number for character codes from \1 up to \255 at maximum)
 
:Since Mudlet 4.0 it is assumed that the text is UTF-8 encoded. It will then be automatically converted to the currently selected game server encoding.
 
:Preventing the automatic conversion can be useful to Mudlet developers testing things, or possibly to those who are creating handlers for Telnet protocols within the Lua subsystem, who need to avoid the transcoding of individual protocol bytes, when they might otherwise be seen as extended ASCII characters.)
 
 
 
;Returns (available in Mudlet 4.2+):
 
* ''true'' on success, ''nil'' and an error message if the text contains characters that cannot be conveyed by the current Game Server encoding.
 
 
 
{{note}} It is important to ensure that in Mudlet 4.0.0 and beyond the text data only contains characters that can be encoded in the current Game Server encoding, from 4.2.0 the content is checked that it can successfully be converted from the UTF-8 that the Mudlet Lua subsystem uses internally into that particular encoding and if it cannot the function call will fail and not pass any of the data, this will be significant if the text component contains any characters that are not plain ASCII.
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- try using this on the command line
 
`echo This is a sample line from the game
 
 
 
-- You can use \n to represent a new line - you also want to use it before and after the text you’re testing, like so:
 
feedTriggers("\nYou sit yourself down.\n")
 
 
 
-- The function also accept ANSI color codes that are used in games. A sample table can be found http://codeworld.wikidot.com/ansicolorcodes
 
feedTriggers("\nThis is \27[1;32mgreen\27[0;37m, \27[1;31mred\27[0;37m, \27[46mcyan background\27[0;37m," ..
 
"\27[32;47mwhite background and green foreground\27[0;37m.\n")
 
</syntaxhighlight>
 
 
 
==getCharacterName==
 
;getCharacterName()
 
 
 
:Returns the name entered into the "Character name" field on the Connection Preferences form. Can be used to find out the name that might need to be handled specially in scripts or anything that needs to be personalized to the player. If there is nothing set in that entry will return an empty string.
 
 
 
:See also: [[#getProfileName|getProfileName()]]
 
 
 
{{MudletVersion|4.16}}
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- cast glamor on yourself
 
 
 
send("cast 'glamor' " .. getCharacterName())
 
</syntaxhighlight>
 
 
 
==getConfig ==
 
;getConfig([option])
 
 
 
: Returns configuration options similar to those that can be set with setConfig. One could use this to decide if a script should notify the user of suggested changes.
 
See also: [[Manual:Miscellaneous_Functions#setConfig|setConfig()]]
 
 
 
{{MudletVersion|4.17}}
 
 
 
;Parameters
 
*''option:''
 
:Particular option to retrieve - see list below for available ones. This may be a string or an array of strings.
 
 
 
{| class="wikitable sortable"
 
|+General options
 
|-
 
!Option!!Description!!Available in Mudlet
 
|-
 
|enableGMCP||Enable GMCP||4.17
 
|-
 
|enableMSDP||Enable MSDP||4.17
 
|-
 
|enableMSSP||Enable MSSP||4.17
 
|-
 
|enableMSP|| Enable MSP||4.17
 
|}
 
 
 
{| class="wikitable sortable"
 
|+Input line
 
|-
 
!Option!!Description!!Available in Mudlet
 
|-
 
|inputLineStrictUnixEndings||Workaround option to use strict UNIX line endings for sending commands||4.17
 
|-
 
|}
 
 
 
{| class="wikitable sortable"
 
|+Main display
 
|-
 
!Option!!Description!!Available in Mudlet
 
|-
 
|fixUnnecessaryLinebreaks||Remove extra linebreaks from output (mostly for IRE servers) || 4.17
 
|-
 
|}
 
 
 
{| class="wikitable sortable"
 
|+Mapper options
 
|-
 
!Option!!Description!!Available in Mudlet
 
|-
 
|mapRoomSize||Size of rooms on map||4.17
 
|-
 
|mapExitSize||Size of exits on map||4.17
 
|-
 
|mapRoundRooms||Draw rooms round or square||4.17
 
|-
 
|showRoomIdsOnMap||Show room IDs on all rooms||4.17
 
|-
 
|show3dMapView||Show map as 3D||4.17
 
|-
 
|mapperPanelVisible||Map controls at the bottom||4.17
 
|-
 
|mapShowRoomBorders|| Draw a thin border for every room||4.17
 
|}
 
 
 
{| class="wikitable sortable"
 
|+Special options
 
|-
 
!Option!!Description!!Available in Mudlet
 
|-
 
|specialForceCompressionOff|| Workaround option to disable MCCP compression, in case the game server is not working correctly||4.17
 
|-
 
|specialForceGAOff||Workaround option to disable Telnet Go-Ahead, in case the game server is not working correctly||4.17
 
|-
 
|specialForceCharsetNegotiationOff||Workaround option to disable automatically setting the correct encoding, in case the game server is not working correctly||4.17
 
|-
 
|specialForceMxpNegotiationOff|| Workaround option to disable MXP, in case the game server is not working correctly ||4.17
 
|-
 
|caretShortcut||For visually-impaired players - get the key to switch between input line and main window (can be "none", "tab", "ctrltab", "f6")|| 4.17
 
|-
 
|blankLinesBehaviour||For visually impaired players options for dealing with blank lines (can be "show", "hide", "replacewithspace")||4.17
 
|}
 
  
 
;Returns
 
;Returns
*It returns a table of options or the value of a single option requested. They are only the configuration options, for example "enableGMCP" means that the "Enable GMCP" box is checked and does not mean that it has been negotiated with the server.
+
: ''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
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
getConfig()
+
-- move the first room one space to the east and two spaces to the north
 +
moveRoom(1, 1, 2)
  
-- Suggest enabling GMCP if it is unchecked
+
-- move the first room one space to the west, note the final boolean argument is unneeded
if not getConfig("enableGMCP") then
+
moveRoom(1, -1, 0, false)
  echo("\nMy script works best with GMCP enabled. You may ")
 
  cechoLink("<red>click here", function() setConfig("enableGMCP",true) echo("GMCP enabled\n") end, "Enable GMCP", true)
 
  echo(" to enable it.\n")
 
end
 
</syntaxhighlight>
 
  
==getModulePath==
+
-- 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**:
;path = getModulePath(module name)
+
moveRoom(1, -3, -2, true)
  
:Returns the location of a module on the disk. If the given name does not correspond to an installed module, it'll return <code>nil</code>
+
-- move the second room up three levels
:See also: [[Manual:Lua_Functions#installModule|installModule()]]
+
moveRoom(2, 0, 0, 3)
  
{{MudletVersion|3.0}}
+
-- move the second room one space to the west, note the last two arguments are unneeded
 +
moveRoom(2, -1, 0, 0, false)
  
;Example
+
-- move the second room to the **center of the whole map**, note the last two arguments are required in this case:
<syntaxhighlight lang="lua">
+
moveRoom(2, 0, 0, 0, true)
getModulePath("mudlet-mapper")
 
</syntaxhighlight>
 
  
==getModulePriority==
+
-- all of the above will return the 'true' boolean value assuming there are rooms with 1 and 2 as ID numbers
;priority = getModulePriority(module name)
 
 
 
:Returns the priority of a module as an integer. This determines the order modules will be loaded in - default is 0. Useful if you have a module that depends on another module being loaded first, for example.
 
:Modules with priority <code>-1</code> will be loaded before scripts (Mudlet 4.11+).
 
 
 
:See also: [[Manual:Lua_Functions#setModulePriority|setModulePriority()]]
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
getModulePriority("mudlet-mapper")
 
</syntaxhighlight>
 
 
 
==getModules==
 
;getModules()
 
 
 
:Returns installed modules as table.
 
 
 
:See also: [[#getPackages|getPackages]]
 
 
 
{{MudletVersion|4.12}}
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
--Check if the module myTabChat is installed and if it isn't install it and enable sync on it
 
if not table.contains(getModules(),"myTabChat") then
 
  installModule(getMudletHomeDir().."/modules/myTabChat.xml")
 
  enableModuleSync("myTabChat")
 
end
 
 
 
</syntaxhighlight>
 
 
 
==getModuleInfo==
 
;getModuleInfo(moduleName, [info])
 
 
 
:Returns table with meta information for a package
 
 
 
;Parameters
 
* ''moduleName:''
 
:Name of the package
 
* ''info:''
 
:(optional) specific info wanted to get, if not given all available meta-info is returned
 
 
 
:See also: [[#getPackageInfo|getPackageInfo]], [[#setModuleInfo|setModuleInfo]]
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
getModuleInfo("myModule","author")
 
</syntaxhighlight>
 
 
 
{{MudletVersion|4.12}}
 
 
 
==getModuleSync==
 
;getModuleSync(name)
 
: returns false if module sync is not active, true if it is active and nil if module is not found.
 
 
 
;Parameter
 
* ''name'': name of the module
 
 
 
:See also: [[Manual:Lua_Functions#enableModuleSync|enableModuleSync()]], [[Manual:Lua_Functions#disableModuleSync|disableModuleSync()]]
 
{{MudletVersion|4.8}}
 
 
 
==getMudletHomeDir==
 
;getMudletHomeDir()
 
:Returns the current home directory of the current profile. This can be used to store data, save statistical information, or load resource files from packages.
 
 
 
{{note}} intentionally uses forward slashes <code>/</code> as separators on Windows since [[Manual:UI_Functions#setLabelStyleSheet|stylesheets]] require them.
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- save a table
 
table.save(getMudletHomeDir().."/myinfo.dat", myinfo)
 
 
 
-- or access package data. The forward slash works even on Windows fine
 
local path = getMudletHomeDir().."/mypackagename"
 
</syntaxhighlight>
 
 
 
==getMudletInfo==
 
;getMudletInfo()
 
:Prints debugging information about the Mudlet that you're running - this can come in handy for diagnostics.
 
 
 
Don't use this command in your scripts to find out if certain features are supported in Mudlet - there are better functions available for this.
 
 
 
{{MudletVersion|4.8}}
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
getMudletInfo()
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==getMudletVersion==
+
==setupMapSymbolFont, PR #4038 closed==
;getMudletVersion(style)
+
;setupMapSymbolFont(fontName[, onlyUseThisFont[, scalingFactor]])
:Returns the current Mudlet version. Note that you shouldn't hardcode against a specific Mudlet version if you'd like to see if a function is present - instead, check for the existence of the function itself. Otherwise, checking for the version can come in handy if you'd like to test for a broken function or so on.
+
:configures the font used for symbols in the (2D) map.
 +
: See also: [[#mapSymbolFontInfo|mapSymbolFontInfo()]]
  
See also: [[#mudletOlderThan|mudletOlderThan()]]
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/4038
 
 
{{MudletVersion|3.0}}
 
  
 
;Parameters
 
;Parameters
* ''style:''
+
* ''fontName'' one of:
:(optional) allows you to choose what you'd like returned. By default, if you don't specify it, a key-value table with all the values will be returned: major version, minor version, revision number and the optional build name.
+
:* - 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"'''};
;Values you can choose
+
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow a following one to be modified.
* ''"string"'':
+
* ''onlyUseThisFont'' (optional) one of:
:Returns the full Mudlet version as text.
+
:* - 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;
* ''"table"'':
+
:* - 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;
:Returns the full Mudlet version as four values (multi-return)
+
:* - a Lua ''nil'' as a placeholder to not change this parameter but still allow the following one to be modified.
* ''"major"'':
+
* ''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 the major version number (the first one).
 
* ''"minor"'':
 
:Returns the minor version number (the second one).
 
* ''"revision"'':
 
:Returns the revision version number (the third one).
 
* ''"build"'':
 
:Returns the build of Mudlet (the ending suffix, if any).
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- see the full Mudlet version as text:
 
getMudletVersion("string")
 
-- returns for example "3.0.0-alpha"
 
 
 
-- check that the major Mudlet version is at least 3:
 
if getMudletVersion("major") >= 3 then echo("You're running on Mudlet 3+!") end
 
-- but mudletOlderThan() is much better for this:
 
if mudletOlderThan(3) then echo("You're running on Mudlet 3+!") end
 
 
 
-- if you'd like to see if a function is available however, test for it explicitly instead:
 
if setAppStyleSheet then
 
  -- example credit to http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qscrollbar
 
  setAppStyleSheet[[
 
  QScrollBar:vertical {
 
      border: 2px solid grey;
 
      background: #32CC99;
 
      width: 15px;
 
      margin: 22px 0 22px 0;
 
  }
 
  QScrollBar::handle:vertical {
 
      background: white;
 
      min-height: 20px;
 
  }
 
  QScrollBar::add-line:vertical {
 
      border: 2px solid grey;
 
      background: #32CC99;
 
      height: 20px;
 
      subcontrol-position: bottom;
 
      subcontrol-origin: margin;
 
  }
 
  QScrollBar::sub-line:vertical {
 
      border: 2px solid grey;
 
      background: #32CC99;
 
      height: 20px;
 
      subcontrol-position: top;
 
      subcontrol-origin: margin;
 
  }
 
  QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical {
 
      border: 2px solid grey;
 
      width: 3px;
 
      height: 3px;
 
      background: white;
 
  }
 
  QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
 
      background: none;
 
  }
 
  ]]
 
end
 
</syntaxhighlight>
 
 
 
==getNewIDManager==
 
; getNewIDManager()
 
 
 
:Returns an IDManager object, for manager your own set of named events and timers isolated from the rest of the profile.
 
 
 
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
 
 
 
{{MudletVersion|4.14}}
 
 
 
{{note}} Full IDManager usage can be found at [[Manual:IDManager|IDManager]]
 
  
 
;Returns
 
;Returns
* an IDManager for managing your own named events and timers
+
* ''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).
  
;Example
+
=Miscellaneous Functions=
<syntaxhighlight lang="lua">
+
: Miscellaneous functions.
demonnic = demonnic or {}
 
demonnic.IDManager = getNewIDManager()
 
local idm = demonnic.IDManager
 
-- assumes you have defined demonnic.vitalsUpdate and demonnic.balanceChecker as functions
 
idm:registerEvent("DemonVitals", "gmcp.Char.Vitals", demonnic.vitalsUpdate)
 
idm:registerTimer("Balance Check", 1, demonnic.balanceChecker)
 
idm:stopEvent("DemonVitals")
 
</syntaxhighlight>
 
  
==getNamedEventHandlers==
+
==compare, PR#7122 open==
; handlers = getNamedEventHandlers(userName)
 
  
:Returns a list of all userName's named event handlers' names as a table.
+
; sameValue = compare(a, b)
  
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]]
+
: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''
  
{{MudletVersion|4.14}}
+
;See also: [[Manual:Lua_Functions#table.complement|table.complement()]], [[Manual:Lua_Functions#table.n_union|table.n_union()]]
 
 
;Parameters
 
* ''userName:''
 
: The user name the event handler was registered under.
 
 
 
;Returns
 
* a table of handler names. { "DemonVitals", "DemonInv" } for example. {} if none are registered
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
  local handlers = getNamedEventHandlers()
 
  display(handlers)
 
  -- {}
 
  registerNamedEventHandler("Test1", "testEvent", "testFunction")
 
  registerNamedEventHandler("Test2", "someOtherEvent", myHandlerFunction)
 
  handlers = getNamedEventHandlers()
 
  display(handlers)
 
  -- { "Test1", "Test2" }
 
</syntaxhighlight>
 
 
 
==getOS==
 
;getOS()
 
 
 
:Returns the name of the Operating System (OS). Useful for applying particular scripts only under particular operating systems, such as applying a stylesheet only when the OS is Windows.
 
:Returned text will be one of these: "windows", "mac", "linux", as well as "cygwin", "hurd", "freebsd", "kfreebsd", "openbsd", "netbsd", "bsd4", "unix" or "unknown" otherwise.
 
:Additionally returns the version of the OS, and if using Linux, the distribution in use (as of Mudlet 4.12+).
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
display(getOS())
 
 
 
if getOS() == "windows" then
 
  echo("\nWindows OS detected.\n")
 
else
 
  echo("\nDetected Operating system is NOT windows.\n")
 
end
 
 
 
if mudlet.supports.osVersion then
 
  local os, osversion = getOS()
 
  print(f"Running {os} {osversion}")
 
end
 
</syntaxhighlight>
 
 
 
==getPackages==
 
;getPackages()
 
 
 
:Returns installed packages as table.
 
 
 
:See also: [[#getModules|getModules]]
 
 
 
{{MudletVersion|4.12}}
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
--Check if the generic_mapper package is installed and if so uninstall it
 
if table.contains(getPackages(),"generic_mapper") then
 
  uninstallPackage("generic_mapper")
 
end
 
 
 
</syntaxhighlight>
 
 
 
==getPackageInfo==
 
;getPackageInfo(packageName, [info])
 
 
 
:Returns table with meta information for a package
 
 
 
;Parameters
 
* ''packageName:''
 
:Name of the package
 
* ''info:''
 
:(optional) specific info wanted to get, if not given all available meta-info is returned
 
 
 
:See also: [[#getModuleInfo|getModuleInfo]], [[#setPackageInfo|setPackageInfo]]
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
getPackageInfo("myPackage", "version")
 
</syntaxhighlight>
 
 
 
{{MudletVersion|4.12}}
 
 
 
==getPlayingMusic==
 
;getPlayingMusic(settings table)
 
:List all playing music (no filter), or playing music that meets a combination of filters (name, key, and tag) intended to be paired with [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]].
 
 
 
{| class="wikitable"
 
! Required
 
! Key
 
! Value
 
!Default
 
! style="text-align:left;"| Purpose
 
|-
 
| style="text-align:center;"| No
 
| 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".
 
|-
 
| style="text-align:center;"| No
 
| tag
 
| <tag>
 
|
 
| style="text-align:left;"|
 
* Helps categorize media.
 
|-
 
|}
 
 
 
See also: [[Manual:Miscellaneous_Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous_Functions#loadSoundFile|loadSoundFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]],  [[Manual:Miscellaneous_Functions#getPlayingSounds|getPlayingSounds()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
 
 
 
{{MudletVersion|4.18}}
 
 
 
;Example
 
 
 
<syntaxhighlight lang="lua">
 
---- Table Parameter Syntax ----
 
 
 
-- List all playing music files for this profile associated with the API
 
getPlayingMusic()
 
 
 
-- List all playing music matching the rugby mp3 name
 
getPlayingMusic({name = "167124__patricia-mcmillen__rugby-club-in-spain.mp3"})
 
 
 
-- List all playing music matching the unique key of "rugby"
 
getPlayingMusic({
 
    name = nil  -- nil lines are optional, no need to use
 
    , key = "rugby" -- key
 
    , tag = nil  -- nil lines are optional, no need to use
 
})
 
</syntaxhighlight>
 
<syntaxhighlight lang="lua">
 
---- Ordered Parameter Syntax of getPlayingMusic([name][,key][,tag]) ----
 
 
 
-- List all playing music files for this profile associated with the API
 
getPlayingMusic()
 
 
 
-- List all playing music matching the rugby mp3 name
 
getPlayingMusic("167124__patricia-mcmillen__rugby-club-in-spain.mp3")
 
 
 
-- List all playing music matching the unique key of "rugby"
 
getPlayingMusic(
 
    nil -- name
 
    , "rugby" -- key
 
    , nil -- tag
 
)
 
</syntaxhighlight>
 
 
 
==getPlayingSounds==
 
;getPlayingSounds(settings table)
 
:List all playing sounds (no filter), or playing sounds that meets a combination of filters (name, key, tag, and priority) intended to be paired with [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]].
 
 
 
{| class="wikitable"
 
! Required
 
! Key
 
! Value
 
!Default
 
! style="text-align:left;"| Purpose
 
|-
 
| style="text-align:center;"| No
 
| 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".
 
|-
 
| style="text-align:center;"| No
 
| tag
 
| <tag>
 
|
 
| style="text-align:left;"|
 
* Helps categorize media.
 
|-
 
| style="text-align:center;"| No
 
| priority
 
| <priority>
 
|
 
| style="text-align:left;"|
 
* Matches media files with equal or lower priority.
 
|-
 
|}
 
 
 
See also: [[Manual:Miscellaneous_Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous_Functions#loadSoundFile|loadSoundFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]],  [[Manual:Miscellaneous_Functions#getPlayingMusic|getPlayingMusic()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
 
  
 
{{MudletVersion|4.18}}
 
{{MudletVersion|4.18}}
 
;Example
 
 
<syntaxhighlight lang="lua">
 
---- Table Parameter Syntax ----
 
 
-- List all playing sounds for this profile associated with the API
 
getPlayingSounds()
 
 
-- List all playing sounds matching the rugby mp3 name
 
getPlayingSounds({name = "167124__patricia-mcmillen__rugby-club-in-spain.mp3"})
 
 
-- List the playing sound matching the unique key of "rugby"
 
getPlayingSounds({
 
    name = nil  -- nil lines are optional, no need to use
 
    , key = "rugby" -- key
 
    , tag = nil  -- nil lines are optional, no need to use
 
})
 
</syntaxhighlight>
 
<syntaxhighlight lang="lua">
 
---- Ordered Parameter Syntax of getPlayingSounds([name][,key][,tag][,priority]) ----
 
 
-- List all playing sounds for this profile associated with the API
 
getPlayingSounds()
 
 
-- List all playing sounds matching the rugby mp3 name
 
getPlayingSounds("167124__patricia-mcmillen__rugby-club-in-spain.mp3")
 
 
-- List the playing sound matching the unique key of "rugby"
 
getPlayingSounds(
 
    nil -- name
 
    , "rugby" -- key
 
    , nil -- tag
 
    , nil -- priority
 
)
 
</syntaxhighlight>
 
 
==getProfileName==
 
;getProfileName()
 
 
:Returns the name of the profile. Useful when combined with [[Manual:Mudlet_Object_Functions#raiseGlobalEvent|raiseGlobalEvent()]] to know which profile a global event came from.
 
 
{{MudletVersion|3.1}}
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- if connected to the Achaea profile, will print Achaea to the main console
 
echo(getProfileName())
 
</syntaxhighlight>
 
 
==getCommandSeparator==
 
;getCommandSeparator()
 
 
:Returns the command separator in use by the profile.
 
 
{{MudletVersion|3.18}}
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- if your command separator is ;;, the following would send("do thing 1;;do thing 2").
 
-- This way you can determine what it is set to and use that and share this script with
 
-- someone who has changed their command separator.
 
-- Note: This is not really the preferred way to send this, using sendAll("do thing 1", "do thing 2") is,
 
--      but this illustates the use case.
 
local s = getCommandSeparator()
 
expandAlias("do thing 1" .. s .. "do thing 2")
 
</syntaxhighlight>
 
 
==getServerEncoding==
 
;getServerEncoding()
 
:Returns the current server [https://www.w3.org/International/questions/qa-what-is-encoding data encoding] in use.
 
 
:See also: [[#setServerEncoding|setServerEncoding()]], [[#getServerEncodingsList|getServerEncodingsList()]]
 
 
;Example
 
<syntaxhighlight lang="lua">
 
getServerEncoding()
 
</syntaxhighlight>
 
 
==getServerEncodingsList==
 
;getServerEncodingsList()
 
:Returns an indexed list of the server [https://www.w3.org/International/questions/qa-what-is-encoding data encodings] that Mudlet knows. This is not the list of encodings the servers knows - there's unfortunately no agreed standard for checking that. See [[Manual:Unicode#Changing_encoding|encodings in Mudlet]] for the list of which encodings are available in which Mudlet version.
 
 
:See also: [[#setServerEncoding|setServerEncoding()]], [[#getServerEncoding|getServerEncoding()]]
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- check if UTF-8 is available:
 
if table.contains(getServerEncodingsList(), "UTF-8") then
 
  print("UTF-8 is available!")
 
end
 
</syntaxhighlight>
 
 
==getWindowsCodepage==
 
;getWindowsCodepage()
 
:Returns the current [https://docs.microsoft.com/en-us/windows/desktop/Intl/code-page-identifiers codepage] of your Windows system.
 
 
{{MudletVersion|3.22}}
 
{{Note}} This function only works on Windows - It is only needed internally in Mudlet to enable Lua to work with non-ASCII usernames (e.g. Iksiński, Jäger) for the purposes of IO. Linux and macOS work fine with with these out of the box.
 
 
;Example
 
<syntaxhighlight lang="lua">
 
print(getWindowsCodepage())
 
</syntaxhighlight>
 
 
==hfeedTriggers==
 
;hfeedTriggers(str)
 
:Like feedTriggers, but you can add color information using #RRGGBB in hex, similar to hecho.
 
  
 
;Parameters
 
;Parameters
* ''str'': The string to feed to the trigger engine. Include color information in the same manner as hecho.
+
* ''a:''
:See also: [[Manual:Lua_Functions#dfeedTriggers|dfeedTriggers]]
+
: The first item to compare
:See also: [[Manual:Lua_Functions#hecho|hecho]]
+
* ''b:''
 +
: The second item to compare
  
{{MudletVersion|4.11}}
+
;Returns
 +
* Boolean true if the items have the same value, otherwise boolean false
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
hfeedTriggers("#008000,800000green on red#r reset\n")
+
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
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==installModule==
+
; Additional development notes
;installModule(location)
+
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)
:Installs a Mudlet XML, zip, or mpackage as a module.
 
  
;Parameters
+
==createVideoPlayer, PR #6439==
* ''location:''
+
;createVideoPlayer([name of userwindow], x, y, width, height)
:Exact location of the file install.
 
  
:See also: [[#uninstallModule | uninstallModule()]], [[Manual:Event_Engine#sysLuaInstallModule | Event: sysLuaInstallModule]], [[#setModulePriority | setModulePriority()]]
+
: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.
  
;Example
+
{{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.
<syntaxhighlight lang="lua">
 
installModule([[C:\Documents and Settings\bub\Desktop\myalias.xml]])
 
</syntaxhighlight>
 
  
==installPackage==
+
{{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.
;installPackage(location or url)
 
:Installs a Mudlet XML or package. Since Mudlet 4.11+ returns <code>true</code> if it worked, or <code>false</code>.
 
  
;Parameters
+
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]]
* ''location:''
 
:Exact location of the xml or package to install.
 
Since Mudlet 4.11+ it is possible to pass download link to a package (must start with <code>http</code> or <code>https</code> and end with <code>.xml</code>, <code>.zip</code>, <code>.mpackage</code> or <code>.trigger</code>)
 
  
:See also: [[#uninstallPackage | uninstallPackage()]]
+
{{MudletVersion|4.??}}
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
installPackage([[C:\Documents and Settings\bub\Desktop\myalias.xml]])
+
-- Create a 300x300 video player in the top-left corner of Mudlet
</syntaxhighlight>
+
createVideoPlayer(0,0,300,300)
  
<syntaxhighlight lang="lua">
+
-- Alternative examples using Geyser.VideoPlayer
installPackage([[https://github.com/Mudlet/Mudlet/blob/development/src/run-lua-code-v4.xml]])
+
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>
  
==killAnonymousEventHandler==
+
==loadVideoFile, PR #6439==
;killAnonymousEventHandler(handler id)
+
;loadVideoFile(settings table) or loadVideoFile(name, [url])
:Disables and removes the given event handler.
+
: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.
 
 
;Parameters
 
* ''handler id''
 
:ID of the event handler to remove as returned by the [[ #registerAnonymousEventHandler | registerAnonymousEventHandler ]] function.
 
 
 
:See also: [[ #registerAnonymousEventHandler | registerAnonymousEventHandler ]]
 
 
 
{{MudletVersion|3.5}}
 
;Example
 
<syntaxhighlight lang="lua">
 
-- registers an event handler that prints the first 5 GMCP events and then terminates itself
 
 
 
local counter = 0
 
local handlerId = registerAnonymousEventHandler("gmcp", function(_, origEvent)
 
  print(origEvent)
 
  counter = counter + 1
 
  if counter == 5 then
 
    killAnonymousEventHandler(handlerId)
 
  end
 
end)
 
</syntaxhighlight>
 
  
==loadMusicFile==
+
{{note}} Video files consume drive space on your device. Consider using the streaming feature of [[Manual:Miscellaneous_Functions#playVideoFile|playVideoFile()]] for large files.
;loadMusicFile(settings table) or loadMusicFile(name, [url])
 
:Loads music files from the Internet or the local file system to the "media" folder of the profile for later use with [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]] and [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]]. Although files could be loaded directly at playing time from [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], loadMusicFile() provides the advantage of loading files in advance.  
 
  
 
{| class="wikitable"
 
{| class="wikitable"
! Required
+
!Required
! Key
+
!Key
! Value
+
!Value
! style="text-align:left;"| Purpose
+
! style="text-align:left;" |Purpose
 
|- style="color: green;"
 
|- style="color: green;"
| style="text-align:center;"| Yes
+
| style="text-align:center;" |Yes
| name
+
|name
| <file name>
+
|<file name>
| style="text-align:left;"|
+
| style="text-align:left;" |
* Name of the media file.
+
*Name of the media file.
* May contain directory information (i.e. weather/lightning.wav).
+
*May contain directory information (i.e. weather/maelstrom.mp4).
* May be part of the profile (i.e. getMudletHomeDir().. "/cow.mp3")
+
*May be part of the profile (i.e. getMudletHomeDir().. "/congratulations.mp4")
* May be on the local device (i.e. "C:/Users/YourNameHere/Documents/nevergoingtogiveyouup.mp3")
+
*May be on the local device (i.e. "C:/Users/YourNameHere/Movies/nevergoingtogiveyouup.mp4")
 
|- style="color: blue;"
 
|- style="color: blue;"
| style="text-align:center;"| Maybe
+
| style="text-align:center;" |Maybe
| url
+
|url
| <url>
+
|<url>
| style="text-align:left;"|
+
| style="text-align:left;" |
* Resource location where the media file may be downloaded.
+
*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.
+
*Only required if file to load is not part of the profile or on the local file system.
 
|-
 
|-
 
|}
 
|}
  
See also: [[Manual:Miscellaneous_Functions#playMusicFile|loadSoundFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]], [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
+
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]]
  
{{MudletVersion|4.15}}
+
{{MudletVersion|4.??}}
  
 
;Example
 
;Example
Line 1,052: Line 294:
  
 
-- Download from the Internet
 
-- Download from the Internet
loadMusicFile({
+
loadVideoFile({
     name = "167124__patricia-mcmillen__rugby-club-in-spain.mp3"
+
     name = "TextInMotion-VideoSample-1080p.mp4"
     , url = "https://raw.githubusercontent.com/StickMUD/StickMUDSounds/master/sounds/"
+
     , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
 
})
 
})
  
 
-- OR download from the profile
 
-- OR download from the profile
loadMusicFile({name = getMudletHomeDir().. "/167124__patricia-mcmillen__rugby-club-in-spain.mp3"})
+
loadVideoFile({name = getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4"})
  
 
-- OR download from the local file system
 
-- OR download from the local file system
loadMusicFile({name = "C:/Users/Tamarindo/Documents/167124__patricia-mcmillen__rugby-club-in-spain.mp3"})
+
loadVideoFile({name = "C:/Users/Tamarindo/Movies/TextInMotion-VideoSample-1080p.mp4"})
 
</syntaxhighlight>
 
</syntaxhighlight>
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
---- Ordered Parameter Syntax of loadMusicFile(name[, url]) ----
+
---- Ordered Parameter Syntax of loadVideoFile(name[, url]) ----
  
 
-- Download from the Internet
 
-- Download from the Internet
loadMusicFile(
+
loadVideoFile(
     "167124__patricia-mcmillen__rugby-club-in-spain.mp3"
+
     "TextInMotion-VideoSample-1080p.mp4"
     , "https://raw.githubusercontent.com/StickMUD/StickMUDSounds/master/sounds/"
+
     , "https://d2qguwbxlx1sbt.cloudfront.net/"
 
)
 
)
  
 
-- OR download from the profile
 
-- OR download from the profile
loadMusicFile(getMudletHomeDir().. "/167124__patricia-mcmillen__rugby-club-in-spain.mp3")
+
loadVideoFile(getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4")
  
 
-- OR download from the local file system
 
-- OR download from the local file system
loadMusicFile("C:/Users/Tamarindo/Documents/167124__patricia-mcmillen__rugby-club-in-spain.mp3")
+
loadVideoFile("C:/Users/Tamarindo/Movies/TextInMotion-VideoSample-1080p.mp4")
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==loadSoundFile==
+
==playVideoFile, PR #6439==
;loadSoundFile(settings table) or loadSoundFile(name, [url])
+
;playVideoFile(settings table)
:Loads sound files from the Internet or the local file system to the "media" folder of the profile for later use with [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]] and [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]]. Although files could be loaded directly at playing time from [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]], loadSoundFile() provides the advantage of loading files in advance.
+
: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>.
  
 
{| class="wikitable"
 
{| class="wikitable"
! Required
+
!Required
! Key
+
!Key
! Value
+
!Value
! style="text-align:left;"| Purpose
+
!Default
 +
! style="text-align:left;" |Purpose
 
|- style="color: green;"
 
|- style="color: green;"
| style="text-align:center;"| Yes
+
| style="text-align:center;" |Yes
| name
+
|name
| <file name>
+
|<file name>
| style="text-align:left;"|
+
|&nbsp;
* Name of the media file.
+
| style="text-align:left;" |
* May contain directory information (i.e. weather/lightning.wav).
+
*Name of the media file.
* May be part of the profile (i.e. getMudletHomeDir().. "/cow.mp3")
+
*May contain directory information (i.e. weather/maelstrom.mp4).
* May be on the local device (i.e. "C:/Users/YourNameHere/Documents/nevergoingtogiveyouup.mp3")
+
*May be part of the profile (i.e. getMudletHomeDir().. "/cow.mp4")
|- style="color: blue;"
+
* May be on the local device (i.e. "C:/Users/YourNameHere/Documents/nevergoingtogiveyouup.mp4")
| style="text-align:center;"| Maybe
+
*Wildcards ''*'' and ''?'' may be used within the name to randomize media files selection.
| 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.
 
 
|-
 
|-
|}
+
| style="text-align:center;" |No
 
 
See also: [[Manual:Miscellaneous_Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]], [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
 
 
 
{{MudletVersion|4.15}}
 
 
 
;Example
 
 
 
<syntaxhighlight lang="lua">
 
---- Table Parameter Syntax ----
 
 
 
-- Download from the Internet
 
loadSoundFile({
 
    name = "cow.wav"
 
    , url = "https://raw.githubusercontent.com/StickMUD/StickMUDSounds/master/sounds/"
 
})
 
 
 
-- OR download from the profile
 
loadSoundFile({name = getMudletHomeDir().. "/cow.wav"})
 
 
 
-- OR download from the local file system
 
loadSoundFile({name = "C:/Users/Tamarindo/Documents/cow.wav"})
 
</syntaxhighlight>
 
<syntaxhighlight lang="lua">
 
---- Ordered Parameter Syntax of loadSoundFile(name[,url]) ----
 
 
 
-- Download from the Internet
 
loadSoundFile("cow.wav", "https://raw.githubusercontent.com/StickMUD/StickMUDSounds/master/sounds/")
 
 
 
-- OR download from the profile
 
loadSoundFile(getMudletHomeDir().. "/cow.wav")
 
 
 
-- OR download from the local file system
 
loadSoundFile("C:/Users/Tamarindo/Documents/cow.wav")
 
</syntaxhighlight>
 
 
 
==mudletOlderThan==
 
;mudletOlderThan(major, [minor], [patch])
 
:Returns true if Mudlet is older than the given version to check. This is useful if you'd like to use a feature that you can't check for easily, such as coroutines support. However, if you'd like to check if a certain function exists, do not use this and use <code>if mudletfunction then</code> - it'll be much more readable and reliable.
 
 
 
See also: [[#getMudletVersion|getMudletVersion()]]
 
 
 
;Parameters
 
* ''major:''
 
:Mudlet major version to check. Given a Mudlet version 3.0.1, 3 is the major version, second 0 is the minor version, and third 1 is the patch version.
 
* ''minor:''
 
:(optional) minor version to check.
 
* ''patch:''
 
:(optional) patch version to check.
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
-- stop doing the script of Mudlet is older than 3.2
 
if mudletOlderThan(3,2) then return end
 
 
 
-- or older than 2.1.3
 
if mudletOlderThan(2, 1, 3) then return end
 
 
 
-- however, if you'd like to check that a certain function is available, like getMousePosition(), do this instead:
 
if not getMousePosition then return end
 
 
 
-- if you'd like to check that coroutines are supported, do this instead:
 
if not mudlet.supportscoroutines then return end
 
</syntaxhighlight>
 
 
 
==openWebPage==
 
;openWebPage(URL)
 
:Opens the browser to the given webpage.
 
 
 
;Parameters
 
* ''URL:''
 
:Exact URL to open.
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
openWebPage("http://google.com")
 
</syntaxhighlight>
 
 
 
Note: This function can be used to open a local file or file folder as well by using "file:///" and the file path instead of "http://".
 
 
 
;Example
 
<syntaxhighlight lang="lua">
 
openWebPage("file:///"..getMudletHomeDir().."file.txt")
 
</syntaxhighlight>
 
 
 
==playMusicFile==
 
;playMusicFile(settings table)
 
:Plays music files from the Internet or the local file system to the "media" folder of the profile for later use with [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]].
 
 
 
{| class="wikitable"
 
! Required
 
! 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/lightning.wav).
 
* May be part of the profile (i.e. getMudletHomeDir().. "/cow.mp3")
 
* May be on the local device (i.e. "C:/Users/YourNameHere/Documents/nevergoingtogiveyouup.mp3")
 
* Wildcards ''*'' and ''?'' may be used within the name to randomize media files selection.
 
|-
 
| style="text-align:center;"| No
 
 
| volume
 
| volume
| 1 to 100
+
|1 to 100
| 50
+
|50
| style="text-align:left;"|
+
| style="text-align:left;" |
* Relative to the volume set on the player's client.
+
*Relative to the volume set on the player's client.
 
|-
 
|-
| style="text-align:center;"| No
+
| style="text-align:center;" |No
| fadein
+
|fadein
 
|<msec>
 
|<msec>
 
|
 
|
Line 1,230: Line 361:
 
|-
 
|-
 
| style="text-align:center;" |No
 
| style="text-align:center;" |No
| fadeout
+
|fadeout
 
|<msec>
 
|<msec>
 
|
 
|
Line 1,239: Line 370:
 
*1000 milliseconds = 1 second.
 
*1000 milliseconds = 1 second.
 
|-
 
|-
| style="text-align:center;"| No
+
| style="text-align:center;" |No
| start
+
|start
| <msec>
+
|<msec>
 
| 0
 
| 0
| style="text-align:left;"|
+
| style="text-align:left;" |
* Begin play at the specified position in milliseconds.
+
*Begin play at the specified position in milliseconds.
|-
 
| style="text-align:center;"| No
 
| finish
 
| <msec>
 
|
 
| style="text-align:left;"|
 
*  End play at the specified position in milliseconds.
 
 
|-
 
|-
 
| style="text-align:center;" |No
 
| style="text-align:center;" |No
| loops
+
|loops
 
| -1, or >= 1
 
| -1, or >= 1
 
|1
 
|1
 
| style="text-align:left;" |
 
| style="text-align:left;" |
 
*Number of iterations that the media plays.
 
*Number of iterations that the media plays.
* A value of -1 allows the media to loop indefinitely.
+
*A value of -1 allows the media to loop indefinitely.
 
|-
 
|-
 
| style="text-align:center;" |No
 
| style="text-align:center;" |No
| key  
+
|key
 
|<key>
 
|<key>
 
|&nbsp;
 
|&nbsp;
Line 1,269: Line 393:
 
*Halts the play of current media files with the same "key" that have a different "name" or "url" while this media plays.
 
*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
+
| style="text-align:center;" |No
| tag
+
|tag
| <tag>
+
|<tag>
| &nbsp;
+
|&nbsp;
| style="text-align:left;"|
+
| style="text-align:left;" |
* Helps categorize media.
+
*Helps categorize media.
 
|-
 
|-
 
| style="text-align:center;" |No
 
| style="text-align:center;" |No
| continue  
+
|continue
| true or false
+
|true or false
| true
+
|true
 
| style="text-align:left;" |
 
| style="text-align:left;" |
*Continues playing matching new music files when true.
+
*Continues playing matching new video files when true.
*Restarts matching new music files when false.
+
*Restarts matching new video files when false.
 
|- style="color: blue;"
 
|- style="color: blue;"
| style="text-align:center;"| Maybe
+
| style="text-align:center;" |Maybe
| url
+
|url
| <url>
+
|<url>
| &nbsp;
+
|&nbsp;
| style="text-align:left;"|
+
| style="text-align:left;" |
* Resource location where the media file may be downloaded.
+
*Resource location where the media file may be downloaded.
* Only required if the file is to be downloaded remotely.
+
*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.
 
|-
 
|-
 
|}
 
|}
  
See also: [[Manual:Miscellaneous_Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous_Functions#loadSoundFile|loadSoundFile()]], [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]], [[Manual:Miscellaneous_Functions#getPlayingMusic|getPlayingMusic()]], [[Manual:Miscellaneous_Functions#getPlayingSounds|getPlayingSounds()]], [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
+
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]]
  
{{Note}} on Windows and certain files are not playing? Try installing the 3rd party [https://codecguide.com/download_k-lite_codec_pack_standard.htm K-lite codec pack].
+
{{MudletVersion|4.??}}
 
 
{{MudletVersion|4.15}}
 
  
 
;Example
 
;Example
Line 1,305: Line 436:
 
---- Table Parameter Syntax ----
 
---- Table Parameter Syntax ----
  
-- Play a music file stored in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media)
+
-- Stream a video file from the Internet and play it.
playMusicFile({
+
playVideoFile({
     name = "167124__patricia-mcmillen__rugby-club-in-spain.mp3"
+
    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 music file stored in the profile's media directory
+
-- 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)
 
---- [volume] of 75 (1 to 100)
playMusicFile({
+
playVideoFile({
     name = getMudletHomeDir().. "/167124__patricia-mcmillen__rugby-club-in-spain.mp3"
+
     name = getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4"
 
     , volume = 75
 
     , volume = 75
 
})
 
})
  
-- OR copy once from the local file system, and play a music file stored in the profile's media directory
+
-- 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)
 
---- [volume] of 75 (1 to 100)
playMusicFile({
+
playVideoFile({
     name = "C:/Users/Tamarindo/Documents/167124__patricia-mcmillen__rugby-club-in-spain.mp3"
+
     name = "C:/Users/Tamarindo/Movies/TextInMotion-VideoSample-1080p.mp4"
 
     , volume = 75
 
     , volume = 75
 
})
 
})
  
-- OR download once from the Internet, and play music stored in the profile's media directory
+
-- 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 20 seconds
+
---- [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, 53 seconds from the end of the music
+
---- [fadeout] and decrease the volume from default volume to one, 15 seconds from the end of the video
---- [start] 10 seconds after position 0 (fadein scales its volume increase over a shorter duration, too)
+
---- [start] 5 seconds after position 0 (fadein scales its volume increase over a shorter duration, too)
---- [finish] 110 seconds from the track start (fadeout scales its volume decrease over a shorter duration, too)
+
---- [key] reference of "text" for stopping this unique video later
---- [key] reference of "rugby" for stopping this unique music later
+
---- [tag] reference of "ambience" to stop any video later with the same tag
---- [tag] reference of "ambience" to stop and music later with the same tag
+
---- [continue] playing this video if another request for the same video comes in (false restarts it)  
---- [continue] playing this music if another request for the same music comes in (false restarts it)  
+
---- [url] resource location where the file may be accessed on the Internet
---- [url] to download once from the Internet if the music does not exist in the profile's media directory
+
---- [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)
playMusicFile({
+
playVideoFile({
     name = "167124__patricia-mcmillen__rugby-club-in-spain.mp3"
+
     name = "TextInMotion-VideoSample-1080p.mp4"
 
     , volume = nil -- nil lines are optional, no need to use
 
     , volume = nil -- nil lines are optional, no need to use
     , fadein = 20000
+
     , fadein = 10000
     , fadeout = 53000
+
     , fadeout = 15000
     , start = 10000
+
     , start = 5000
    , finish = 110000
 
 
     , loops = nil -- nil lines are optional, no need to use
 
     , loops = nil -- nil lines are optional, no need to use
     , key = "rugby"
+
     , key = "text"
 
     , tag = "ambience"
 
     , tag = "ambience"
 
     , continue = true
 
     , continue = true
     , url = "https://raw.githubusercontent.com/StickMUD/StickMUDSounds/master/sounds/"
+
     , url = "https://d2qguwbxlx1sbt.cloudfront.net/"
 +
    , stream = false
 
})
 
})
 
</syntaxhighlight>
 
</syntaxhighlight>
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
---- Ordered Parameter Syntax of playMusicFile(name[,volume][,fadein][,fadeout][,loops][,key][,tag][,continue][,url][,finish]) ----
+
---- 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 music file stored in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media)
+
-- Play a video file stored in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media)
playMusicFile(
+
playVideoFile(
     "167124__patricia-mcmillen__rugby-club-in-spain.mp3"  -- name
+
     "TextInMotion-VideoSample-1080p.mp4"  -- name
 
)
 
)
  
-- OR copy once from the game's profile, and play a music file stored in the profile's media directory
+
-- 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)
 
---- [volume] of 75 (1 to 100)
playMusicFile(
+
playVideoFile(
     getMudletHomeDir().. "/167124__patricia-mcmillen__rugby-club-in-spain.mp3" -- name
+
     getMudletHomeDir().. "/TextInMotion-VideoSample-1080p.mp4" -- name
 
     , 75 -- volume
 
     , 75 -- volume
 
)
 
)
  
-- OR copy once from the local file system, and play a music file stored in the profile's media directory
+
-- 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)
 
---- [volume] of 75 (1 to 100)
playMusicFile(
+
playVideoFile(
     "C:/Users/Tamarindo/Documents/167124__patricia-mcmillen__rugby-club-in-spain.mp3" -- name
+
     "C:/Users/Tamarindo/Documents/TextInMotion-VideoSample-1080p.mp4" -- name
 
     , 75 -- volume
 
     , 75 -- volume
 
)
 
)
  
-- OR download once from the Internet, and play music stored in the profile's media directory
+
-- 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 20 seconds
+
---- [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, 53 seconds from the end of the music
+
---- [fadeout] and decrease the volume from default volume to one, 15 seconds from the end of the video
---- [start] 10 seconds after position 0 (fadein scales its volume increase over a shorter duration, too)
+
---- [start] 5 seconds after position 0 (fadein scales its volume increase over a shorter duration, too)
---- [finish] 110 seconds from the track start (fadeout scales its volume decrease over a shorter duration, too)
+
---- [key] reference of "text" for stopping this unique video later
---- [key] reference of "rugby" for stopping this unique music later
+
---- [tag] reference of "ambience" to stop any video later with the same tag
---- [tag] reference of "ambience" to stop and music later with the same tag
+
---- [continue] playing this video if another request for the same video comes in (false restarts it)  
---- [continue] playing this music if another request for the same music comes in (false restarts it)  
+
---- [url] resource location where the file may be accessed on the Internet
---- [url] to download once from the Internet if the music does not exist in the profile's media directory
+
---- [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)
playMusicFile(
+
playVideoFile(
     "167124__patricia-mcmillen__rugby-club-in-spain.mp3" -- name
+
     "TextInMotion-VideoSample-1080p.mp4" -- name
 
     , nil -- volume
 
     , nil -- volume
     , 20000 -- fadein
+
     , 10000 -- fadein
     , 53000 -- fadeout
+
     , 15000 -- fadeout
     , 10000 -- start
+
     , 5000 -- start
 
     , nil -- loops
 
     , nil -- loops
     , "rugby" -- key  
+
     , "text" -- key
 
     , "ambience" -- tag
 
     , "ambience" -- tag
 
     , true -- continue
 
     , true -- continue
     , "https://raw.githubusercontent.com/StickMUD/StickMUDSounds/master/sounds/" -- url
+
     , "https://d2qguwbxlx1sbt.cloudfront.net/" -- url
     , 110000 -- finish
+
     , false -- stream
 
)
 
)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==playSoundFile==
+
 
;playSoundFile(settings table)
+
==stopVideos, PR #6439==
:Plays sound files from the Internet or the local file system to the "media" folder of the profile for later use with [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]].
+
;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 [[Manual:Miscellaneous_Functions#playVideoFile|playVideoFile()]].
  
 
{| class="wikitable"
 
{| class="wikitable"
! Required
+
!Required
! Key
+
!Key
! Value
+
!Value
! Default
+
! style="text-align:left;" |Purpose
! style="text-align:left;"| Purpose
+
|-
|- style="color: green;"
+
| style="text-align:center;" |No
| style="text-align:center;"| Yes
 
 
| name
 
| name
 
| <file name>
 
| <file name>
| &nbsp;
+
| style="text-align:left;" |
| style="text-align:left;"|
 
 
* Name of the media file.
 
* Name of the media file.
* May contain directory information (i.e. weather/lightning.wav).
 
* May be part of the profile (i.e. getMudletHomeDir().. "/cow.mp3")
 
* May be on the local device (i.e. "C:/Users/YourNameHere/Documents/nevergoingtogiveyouup.mp3")
 
* 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
 
| style="text-align:center;" |No
| fadeout
+
|key
|<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
 
| finish
 
| <msec>
 
|
 
| style="text-align:left;"|
 
*  Finish 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>
 
|<key>
|&nbsp;
 
 
| style="text-align:left;" |
 
| style="text-align:left;" |
 
*Uniquely identifies media files with a "key" that is bound to their "name" or "url".
 
*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.
 
*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
 
| style="text-align:center;" |No
| priority
+
|tag
| 1 to 100
+
|<tag>
|&nbsp;
 
 
| style="text-align:left;" |
 
| style="text-align:left;" |
*Halts the play of current or future played media files with a lower priority while this media plays.
+
*Helps categorize media.
|- 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.
 
 
|-
 
|-
 
|}
 
|}
  
See also: [[Manual:Miscellaneous_Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous_Functions#loadSoundFile|loadSoundFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous_Functions#getPlayingMusic|getPlayingMusic()]], [[Manual:Miscellaneous_Functions#getPlayingSounds|getPlayingSounds()]], [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
+
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]]
  
{{Note}} on Windows and certain files are not playing? Try installing the 3rd party [https://codecguide.com/download_k-lite_codec_pack_standard.htm K-lite codec pack].
+
{{MudletVersion|4.??}}
 
 
{{MudletVersion|4.15}}
 
  
 
;Example
 
;Example
Line 1,507: Line 609:
 
---- Table Parameter Syntax ----
 
---- Table Parameter Syntax ----
  
-- Play a sound file stored in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media)
+
-- Stop all playing video files for this profile associated with the API
playSoundFile({
+
stopVideos()
    name = "cow.wav"
 
})
 
  
-- OR copy once from the game's profile, and play a sound file stored in the profile's media directory
+
-- Stop playing the text mp4 by name
---- [volume] of 75 (1 to 100)
+
stopVideos({name = "TextInMotion-VideoSample-1080p.mp4"})
playSoundFile({
 
    name = getMudletHomeDir().. "/cow.wav"
 
    , volume = 75
 
})
 
  
-- OR copy once from the local file system, and play a sound file stored in the profile's media directory
+
-- Stop playing the unique sound identified as "text"
---- [volume] of 75 (1 to 100)
+
stopVideos({
playSoundFile({
+
     name = nil -- nil lines are optional, no need to use
    name = "C:/Users/Tamarindo/Documents/cow.wav"
+
     , key = "text" -- key
    , volume = 75
+
     , tag = nil -- nil lines are optional, no need to use
})
 
 
 
-- OR download once from the Internet, and play a sound stored in the profile's media directory
 
---- [volume] of 75
 
---- [loops] of 2 (-1 for indefinite repeats, 1+ for finite repeats)
 
---- [key] reference of "cow" for stopping this unique sound later
 
---- [tag] reference of "animals" to stop a group of sounds later with the same tag
 
---- [priority] of 25 (1 to 100, 50 default, a sound with a higher priority would stop this one)
 
---- [url] to download once from the Internet if the sound does not exist in the profile's media directory
 
playSoundFile({
 
     name = "cow.wav"
 
    , volume = 75
 
    , fadein = nil -- nil lines are optional, no need to use
 
     , fadeout = nil -- nil lines are optional, no need to use
 
     , start = nil -- nil lines are optional, no need to use
 
    , finish = nil -- nil lines are optional, no need to use
 
    , loops = 2
 
    , key = "cow"
 
    , tag = "animals"
 
    , priority = 25
 
    , url = "https://raw.githubusercontent.com/StickMUD/StickMUDSounds/master/sounds/"
 
 
})
 
})
 
</syntaxhighlight>
 
</syntaxhighlight>
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
---- Ordered Parameter Syntax of playSoundFile(name[,volume][,fadein][,fadeout][,loops][,key][,tag][,priority][,url][,finish]) ----
+
---- Ordered Parameter Syntax of stopVideos([name][,key][,tag]) ----
  
-- Play a sound file stored in the profile's media directory (i.e. /Users/Tamarindo/mudlet-data/profiles/StickMUD/media)
+
-- Stop all playing video files for this profile associated with the API
playSoundFile(
+
stopVideos()
    "cow.wav" -- name
 
)
 
  
-- OR copy once from the game's profile, and play a sound file stored in the profile's media directory
+
-- Stop playing the text mp4 by name
---- [volume] of 75 (1 to 100)
+
stopVideos("TextInMotion-VideoSample-1080p.mp4")
playSoundFile(
 
    getMudletHomeDir().. "/cow.wav" -- name
 
    , 75 -- volume
 
)
 
  
-- OR copy once from the local file system, and play a sound file stored in the profile's media directory
+
-- Stop playing the unique sound identified as "text"
---- [volume] of 75 (1 to 100)
+
stopVideos(
playSoundFile(
+
     nil -- name
    "C:/Users/Tamarindo/Documents/cow.wav" -- name
+
     , "text" -- key
    , 75 -- volume
+
     , nil -- tag
)
 
 
 
-- OR download once from the Internet, and play a sound stored in the profile's media directory
 
---- [volume] of 75
 
---- [loops] of 2 (-1 for indefinite repeats, 1+ for finite repeats)
 
---- [key] reference of "cow" for stopping this unique sound later
 
---- [tag] reference of "animals" to stop a group of sounds later with the same tag
 
---- [priority] of 25 (1 to 100, 50 default, a sound with a higher priority would stop this one)
 
---- [url] to download once from the Internet if the sound does not exist in the profile's media directory
 
playSoundFile(
 
     "cow.wav" -- name
 
    , 75 -- volume
 
    , nil -- fadein
 
    , nil -- fadeout
 
    , nil -- start
 
    , 2 -- loops
 
     , "cow" -- key  
 
     , "animals" -- tag
 
    , 25 -- priority
 
    , "https://raw.githubusercontent.com/StickMUD/StickMUDSounds/master/sounds/" -- url
 
    , nil -- finish
 
 
)
 
)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==purgeMediaCache==
 
;purgeMediaCache()
 
: Purge all media file stored in the media cache within a given Mudlet profile (media used with MCMP and MSP protocols). As game developers update the media files on their games, this enables the media folder inside the profile to be cleared so that the media files could be refreshed to the latest update(s).
 
  
;Guidance:
+
==getCustomLoginTextId, PR #3952 open==
 +
;getCustomLoginTextId()
  
* Instruct a player to type ''lua purgeMediaCache()'' on the command line, or
+
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.
* Distribute a trigger, button or other scriptable feature for the given profile to call ''purgeMediaCache()''
 
  
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]], [[Manual:Scripting#MUD_Client_Media_Protocol|Scripting MCMP]]
+
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()]].
  
==receiveMSP==
+
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952
;receiveMSP(command)
 
: Receives a well-formed Mud Sound Protocol (MSP) message to be processed by the Mudlet client. Reference the [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]] manual for more information on about what can be sent and example triggers.
 
  
: See also: [[Manual:Supported_Protocols#MSP|Supported Protocols MSP]]
+
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
 +
|}
 +
 
 +
The addition of further texts would be subject to negotiation with the Mudlet Makers.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
--Play a cow.wav media file stored in the media folder of the current profile. The sound would play twice at a normal volume.
+
-- A replacement for the default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:
receiveMSP("!!SOUND(cow.wav L=2 V=50)")
+
function doLogin()
 
+
  if getCustomLoginTextId() ~= 1 then
--Stop any SOUND media files playing stored in the media folder of the current profile.
+
    -- We need this particular option but it is not permitted for a script to change the setting, it can only check what it is
receiveMSP("!!SOUND(Off)")
+
    echo("\nUnable to login - please select the 'connect {character name} {password}` custom login option in the profile preferences.\n")
 
+
  else
--Play a city.mp3 media file stored in the media folder of the current profile. The music would play once at a low volume.
+
    tempTime(2.0, [[sendCustomLoginText()]], 1)
--The music would continue playing if it was triggered earlier by another room, perhaps in the same area.
+
  end
receiveMSP([[!!MUSIC(city.mp3 L=1 V=25 C=1)]])
+
end
 +
</syntaxhighlight>
  
--Stop any MUSIC media files playing stored in the media folder of the current profile.
+
==sendCharacterName, PR #3952 open==
receiveMSP("!!MUSIC(Off)")
+
;sendCharacterName()
</syntaxhighlight>
 
  
==registerAnonymousEventHandler==
+
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.
;registerAnonymousEventHandler(event name, functionReference, [one shot])
 
:Registers a function to an event handler, not requiring you to set one up via script. [[Manual:Event_Engine#Mudlet-raised_events|See here]] for a list of Mudlet-raised events. The function may be refered to either by name as a string containing a global function name, or with the lua function object itself.
 
  
:The optional <code>one shot</code> parameter allows you to automatically kill an event handler after it is done by giving a true value. If the event you waited for did not occur yet, return <code>true</code> from the function to keep it registered.
+
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()]].
  
:The function returns an ID that can be used in [[Manual:Lua_Functions#killAnonymousEventHandler|killAnonymousEventHandler()]] to unregister the handler again.
+
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952
  
:If you use an asterisk ''("*")'' as the event name, your code will capture all events. Useful for debugging, or integration with external programs.
+
==sendCharacterPassword, PR #3952 open==
 +
;sendCharacterPassword()
  
{{note}} The ability to refer lua functions directly, the <code>one shot</code> parameter and the returned ID are features of Mudlet 3.5 and above.
+
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.
  
{{note}} The ''"*"'' all-events capture was added in Mudlet 4.10.
+
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|getCharacterName()]], [[#sendCustomLoginText|sendCustomLoginText()]], [[#getCustomLoginTextId|getCustomLoginTextId()]], [[#sendCharacterName|sendCharacterName()]].
  
;See also
+
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952
:[[Manual:Lua_Functions#killAnonymousEventHandler|killAnonymousEventHandler()]], [[Manual:Lua_Functions#raiseEvent|raiseEvent()]], [[Manual:Event_Engine#Mudlet-raised_events|list of Mudlet-raised events]]
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- example taken from the God Wars 2 (http://godwars2.org) Mudlet UI - forces the window to keep to a certain size
+
-- The default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:
function keepStaticSize()
+
function doLogin()
   setMainWindowSize(1280,720)
+
   if getCharacterName() ~= "" then
end -- keepStaticSize
+
    tempTime(2.0, [[sendCharacterName()]], 1)
 
+
    tempTime(3.0, [[sendCharacterPassword()]], 1)
if keepStaticSizeEventHandlerID then killAnonymousEventHandler(keepStaticSizeEventHandlerID) end -- clean up any already registered handlers for this function
 
keepStatisSizeEventHandlerID = registerAnonymousEventHandler("sysWindowResizeEvent", "keepStaticSize") -- register the event handler and save the ID for later killing
 
</syntaxhighlight>
 
 
 
<syntaxhighlight lang="lua">
 
-- simple inventory tracker for GMCP enabled games. This version does not leak any of the methods
 
-- or tables into the global namespace. If you want to access it, you should export the inventory
 
-- table via an own namespace.
 
local inventory = {}
 
 
 
local function inventoryAdd()
 
  if gmcp.Char.Items.Add.location == "inv" then
 
    inventory[#inventory + 1] = table.deepcopy(gmcp.Char.Items.Add.item)
 
 
   end
 
   end
 
end
 
end
if inventoryAddHandlerID then killAnonymousEventHandler(inventoryAddHandlerID) end -- clean up any already registered handlers for this function
 
inventoryAddHandlerID = registerAnonymousEventHandler("gmcp.Char.Items.Add", inventoryAdd) -- register the event handler and save the ID for later killing
 
 
local function inventoryList()
 
  if gmcp.Char.Items.List.location == "inv" then
 
    inventory = table.deepcopy(gmcp.Char.Items.List.items)
 
  end
 
end
 
if inventoryListHandlerID then killAnonymousEventHandler(inventoryListHandlerID) end -- clean up any already registered handlers for this function
 
inventoryListHandlerID = registerAnonymousEventHandler("gmcp.Char.Items.List", inventoryList) -- register the event handler and save the ID for later killing
 
 
local function inventoryUpdate()
 
  if gmcp.Char.Items.Remove.location == "inv" then
 
    local found
 
    local updatedItem = gmcp.Char.Items.Update.item
 
    for index, item in ipairs(inventory) do
 
      if item.id == updatedItem.id then
 
        found = index
 
        break
 
      end
 
    end
 
    if found then
 
      inventory[found] = table.deepcopy(updatedItem)
 
    end
 
  end
 
end
 
if inventoryUpdateHandlerID then killAnonymousEventHandler(inventoryUpdateHandlerID) end -- clean up any already registered handlers for this function
 
inventoryUpdateHandlerID = registerAnonymousEventHandler("gmcp.Char.Items.Update", inventoryUpdate)
 
 
local function inventoryRemove()
 
  if gmcp.Char.Items.Remove.location == "inv" then
 
    local found
 
    local removedItem = gmcp.Char.Items.Remove.item
 
    for index, item in ipairs(inventory) do
 
      if item.id == removedItem.id then
 
        found = index
 
        break
 
      end
 
    end
 
    if found then
 
      table.remove(inventory, found)
 
    end
 
  end
 
end
 
if inventoryRemoveHandlerID then killAnonymousEventHandler(inventoryRemoveHandlerID) end -- clean up any already registered handlers for this function
 
inventoryRemoveHandlerID = registerAnonymousEventHandler("gmcp.Char.Items.Remove", inventoryRemove)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
<syntaxhighlight lang="lua">
+
==sendCustomLoginText, PR #3952 open ==
-- downloads a package from the internet and kills itself after it is installed.
+
;sendCustomLoginText()
local saveto = getMudletHomeDir().."/dark-theme-mudlet.zip"
 
local url = "http://www.mudlet.org/wp-content/files/dark-theme-mudlet.zip"
 
  
if myPackageInstallHandler then killAnonymousEventHandler(myPackageInstallHandler) end
+
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.
myPackageInstallHandler = registerAnonymousEventHandler(
 
  "sysDownloadDone",
 
  function(_, filename)
 
    if filename ~= saveto then
 
      return true -- keep the event handler since this was not our file
 
    end
 
    installPackage(saveto)
 
    os.remove(b)
 
  end,
 
  true
 
)
 
  
downloadFile(saveto, url)
+
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.
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")
+
:See also: [[#getCharacterName|getCharacterName()]], [[#sendCharacterName|sendCharacterName()]], [[#sendPassword|sendPassword()]], [[#getCustomLoginTextId|getCustomLoginTextId()]].
</syntaxhighlight>
 
  
==registerNamedEventHandler==
+
{{note}} Not available yet. See https://github.com/Mudlet/Mudlet/pull/3952
; success = registerNamedEventHandler(userName, handlerName, eventName, functionReference, [oneShot])
 
  
:Registers a named event handler with name handlerName. Named event handlers are protected from duplication and can be stopped and resumed, unlike anonymous event handlers. A separate list is kept per userName
+
Only one custom login text has been defined initially:
 
+
{| class="wikitable"
;See also: [[Manual:Lua_Functions#registerAnonymousEventHandler|registerAnonymousEventHandler()]], [[Manual:Lua_Functions#stopNamedEventHandler|stopNamedEventHandler()]], [[Manual:Lua_Functions#resumeNamedEventHandler|resumeNamedEventHandler()]], [[Manual:Lua_Functions#deleteNamedEventHandler|deleteNamedEventHandler()]], [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
+
|+Predefined custom login texts
 
+
|-
{{MudletVersion|4.14}}
+
!Id!!Custom text!!Introduced in Mudlet version
 
+
|-
;Parameters
+
|1||"connect {character name} {password}"||TBD
* ''userName:''
+
|}
: The user name the event handler was registered under.
 
* ''handlerName:''
 
: 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.
 
* ''eventName:''
 
: The name of the event the handler responds to. [[Manual:Event_Engine#Mudlet-raised_events|See here]] for a list of Mudlet-raised events.
 
* ''functionReference:''
 
: The function reference to run when the event comes in. Can be the name of a function, "handlerFuncion", or the lua function itself.
 
* ''oneShot:''
 
: (optional) if true, the event handler will only fire once when the event is raised. If you need to extend a one shot event handler for "one more check" you can have the handler return true, and it will keep firing until the function does not return true.
 
  
;Returns
+
The addition of further texts would be subject to negotiation with the Mudlet Makers.
* true if successful, otherwise errors.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- register a named event handler. Will call demonVitalsHandler(eventName, ...) when gmcp.Char.Vitals is raised.
+
-- A replacement for the default function placed into LuaGlobal.lua to reproduce the previous behavior of the Mudlet application:
local ok = registerNamedEventHandler("Demonnic", "DemonVitals", "gmcp.Char.Vitals", "demonVitalsHandler")
+
function doLogin()
if ok then
+
  if getCustomLoginTextId() ~= 1 then
  cecho("Vitals handler switched to demonVitalsHandler")
+
    -- 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
 
end
 +
</syntaxhighlight>
  
-- something changes later, and we want to handle vitals with another function, demonBlackoutHandler()
+
=Mudlet Object Functions=
-- note we do not use "" around demonBlackoutHandler but instead pass the function itself. Both work.
+
:A collection of functions that manipulate Mudlet's scripting objects - triggers, aliases, and so forth.
-- using the same handlerName ("DemonVitals") means it will automatically unregister the old handler
 
-- and reregister it using the new information.
 
local ok = registerNamedEventHandler("Demonnic", "DemonVitals", "gmcp.Char.Vitals", demonBlackoutHandler)
 
if ok then
 
  cecho("Vitals handler switched to demonBlackoutHandler")
 
end
 
  
-- Now you want to check your inventory, but you only want to do it once, so you pass the optional oneShot as true
+
==ancestors, new in PR #6726==
local function handleInv()
+
;ancestors(IDnumber, type)
  local list = gmcp.Char.Items.List
+
:You can use this function to find out about all the ancestors of something.
  if list.location ~= "inventory" then
 
    return true -- if list.location is, say "room" then we need to keep responding until it's "inventory"
 
  end
 
  display(list.items) -- you would probably store values and update displays or something, but here I'll just show the data as it comes in
 
end
 
  
-- you can ignore the response from registerNamedEventHandler if you want, it's always going to be true
+
: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:
-- unless there is an error, in which case it throws the error and halts execution anyway. The return is
+
:* its IDnumber as a number
-- in part for feedback when using the lua alias or other REPL window.
+
:* its name as a string
registerNamedEventHandler("Demonnic", "DemonInvCheck", "gmcp.Char.Items.List", handleInv, true)
+
:* whether it is active as a boolean
</syntaxhighlight>
+
:* 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
  
==reloadModule==
+
;Parameters
;reloadModule(module name)
+
* ''IDnumber:''
:Reload a module (by uninstalling and reinstalling).
+
: 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: [[#installModule|installModule()]], [[#uninstallModule|uninstallModule()]]
+
: See also: [[#isAncestorsActive|isAncestorsActive(...)]], [[#isActive|isActive(...)]]
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
reloadModule("3k-mapper")
+
-- To do
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
==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.
  
==removeFileWatch==
+
: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.
;removeFileWatch(path)
 
:Remove file watch on directory or file. Every change in that file will no longer raise [[Manual:Event_Engine#sysPathChanged|sysPathChanged]] event.
 
  
:See also: [[#addFileWatch|addFileWatch()]]
+
;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.
  
{{MudletVersion|4.12}}
+
;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=]]
  
;Example
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
herbs = {}
+
-- Should find just the package with the name:
local herbsPath = getMudletHomeDir() .. "/herbs.lua"
+
lua findItems("echo", "alias")
function herbsChangedHandler(_, path)
+
{ 3 }
  if path == herbsPath then
 
    table.load(herbsPath, herbs)
 
    removeFileWatch(herbsPath)
 
  end
 
end
 
  
addFileWatch(herbsPath)
+
-- Should find both the package and the alias - as the latter contains "echo" with another character
registerAnonymousEventHandler("sysPathChanged", "herbsChangedHandler")
+
lua findItems("echo", "alias", false)
</syntaxhighlight>
+
{ 3, 4 }
  
==resetProfile==
+
-- Finds the ID numbers of all the aliases:
;resetProfile()
+
lua findItems("", "alias", false)
 +
{ 1, 2, 3, 4, 5, 6, 7 }
  
:Reloads your entire Mudlet profile - as if you've just opened it. All UI elements will be cleared, so this useful when you're coding your UI.
+
-- 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 }
  
;Example
+
-- 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)
resetProfile()
+
{}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
The function used to require input from the game to work, but as of Mudlet 3.20 that is no longer the case.
+
==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|exists(...)]], [[#isAncestorsActive|isAncestorsActive(...)]], [[#ancestors|ancestors(...)]]
  
{{note}} Don't put resetProfile() in the a script-item in the script editor as the script will be reloaded by resetProfile() as well better use
+
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
lua resetProfile()
+
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
 
</syntaxhighlight>
 
</syntaxhighlight>
in your commandline or make an Alias containing resetProfile().
 
 
==resumeNamedEventHandler==
 
; success = resumeNamedEventHandler(userName, handlerName)
 
  
:Resumes a named event handler with name handlerName and causes it to start firing once more.
+
{{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.
  
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#stopNamedEventHandler|stopNamedEventHandler()]]
+
==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|isActive(...)]]).
  
{{MudletVersion|4.14}}
+
: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
 
;Parameters
* ''userName:''
+
* ''IDnumber:''
: The user name the event handler was registered under.
+
: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).
* ''handlerName:''
+
* ''type:''
: The name of the handler to resume. Same as used when you called [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]]
+
:The type can be 'alias', 'button', 'trigger', 'timer', 'keybind' or 'script' to define which item type is to be checked.
  
;Returns
+
:See also: [[#exists|exists(...)]]
* true if successful, false if it didn't exist.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
local resumed = resumeNamedEventHandler("Demonnic", "DemonVitals")
+
-- To do
if resumed then
 
  cecho("DemonVitals resumed!")
 
else
 
  cecho("DemonVitals doesn't exist, cannot resume it")
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==saveProfile==
+
=Networking Functions=
;saveProfile(location)
+
:A collection of functions for managing networking.
 +
==sendSocket revised in PR #7066 (Open)==
 +
 
 +
;sendSocket(data)
  
:Saves the current Mudlet profile to disk, which is equivalent to pressing the "Save Profile" button.
+
: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.
  
;Parameters
+
; success = sendSocket("data")
* ''location:''
 
:(optional) folder to save the profile to. If not given, the profile will go into the [[Mudlet_File_Locations|default location]].
 
  
;Example
+
;See also: [[Manual:Lua_Functions#feedTelnet|feedTelnet()]], [[Manual:Lua_Functions#feedTriggers|feedTriggers()]]
<syntaxhighlight lang="lua">
 
saveProfile()
 
  
-- save to the desktop on Windows:
+
{{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()]].
saveProfile([[C:\Users\yourusername\Desktop]])
 
</syntaxhighlight>
 
  
==sendSocket==
+
{{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.
;sendSocket(data)
 
  
:Sends given binary data as-is 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] or etcetera.
+
;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
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
TN_IAC = 255
+
-- 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!
TN_WILL = 251
+
-- the examples should be small, but self-contained so new users can copy & paste immediately without going diving in lots other function examples first.
TN_DO = 253
+
-- comments up top should introduce / explain what it does
TN_SB = 250
 
TN_SE = 240
 
TN_MSDP = 69
 
  
MSDP_VAL = 1
+
local something = function(exampleValue)
MSDP_VAR = 2
+
if something then
 +
  -- do something with something (assuming there is a meaningful return value)
 +
end
  
sendSocket( string.char( TN_IAC, TN_DO, TN_MSDP ) ) -- sends IAC DO MSDP
+
-- maybe another example for the optional second case
 +
local somethingElse = function(exampleValue, anotherValue)
  
--sends: IAC  SB MSDP MSDP_VAR "LIST" MSDP_VAL "COMMANDS" IAC SE
+
-- lastly, include an example with error handling to give an idea of good practice
local msg = string.char( TN_IAC, TN_SB, TN_MSDP, MSDP_VAR ) .. " LIST " ..string.char( MSDP_VAL ) .. " COMMANDS " .. string.char( TN_IAC, TN_SE )
+
local ok, err = function()
sendSocket( msg )
+
if not ok then
 +
  debugc(f"Error: unable to do <particular thing> because {err}\n")
 +
  return
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{Note}} Remember that should it be necessary to send the byte value of 255 as a ''data'' byte and not as the Telnet '''IAC''' value it is required to repeat it for Telnet to ignore it and not treat it as the latter.
+
; Additional development notes
 +
-- This function is still being written up.
  
==setConfig==
+
==feedTelnet added in PR #7066 (Open)====
; setConfig(option, value)
 
  
:Sets a Mudlet option to a certain value. This comes in handy for scripts that want to customise Mudlet settings to their preferences - for example, setting up mapper room and exit size to one that works for a certain map, or enabling MSDP for a certain game. For transparency reasons, the Debug window (when open) will show which options were modified by scripts.
+
; feedTelnet(data)
:To set many options at once, pass in a table of options. More options will be added over time / per request.
 
  
;See also: [[Manual:Lua_Functions#enableMapInfo|enableMapInfo()]], [[Manual:Lua_Functions#disableMapInfo|disableMapInfo()]]
+
: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.
  
{{MudletVersion|4.16}}
+
;See also: [[Manual:Lua_Functions#feedTriggers|feedTriggers()]], [[Manual:Lua_Functions#sendSocket|sendSocket()]]
 +
 
 +
{{MudletVersion|tbd}}
 +
 
 +
{{note}} This is not really intended for end-user's but might be useful in some circumstances.
  
 
;Parameters
 
;Parameters
* ''option:''
+
* ''data''
: Particular option to change - see list below for available ones.
+
: 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.
* ''value:''
+
 
: Value to set - can be a boolean, number, or text depending on the option.
+
;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.
  
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
|+ General options
+
|+ 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
 +
|-
 +
|| <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 ||
 
|-
 
|-
! Option !! Default !! Description !! Available in Mudlet
+
|| <T_NOP> || \xf1 || 1 ||
 
|-
 
|-
| enableGMCP || true || Enable GMCP (Reconnect after changing) || 4.16
+
|| <F2> || \xf2 || 1 ||
 
|-
 
|-
| enableMSDP || false || Enable MSDP (Reconnect after changing) || 4.16
+
|| <T_DM> || \xf2 || 1 ||
 
|-
 
|-
| enableMSSP || true || Enable MSSP (Reconnect after changing) || 4.16
+
|| <F3> || \xf3 || 1 ||
 
|-
 
|-
| enableMSP || true || Enable MSP (Reconnect after changing) || 4.16
+
|| <T_BRK> || \xf3 || 1 ||
 
|-
 
|-
| compactInputLine || false || Hide search, timestamp, other buttons and labels bottom-right of input line || 4.17
+
|| <F4> || \xf4 || 1 ||
|}
 
 
 
{| class="wikitable sortable"
 
|+ Input line
 
 
|-
 
|-
! Option !! Default !! Description !! Available in Mudlet
+
|| <T_IP> || \xf4 || 1 ||
 
|-
 
|-
| inputLineStrictUnixEndings || false || Workaround option to use strict UNIX line endings for sending commands || 4.16
+
|| <F5> || \xf5 || 1 ||
 
|-
 
|-
|}
+
|| <T_ABOP> || \xf5 || 1 ||
 
 
{| class="wikitable sortable"
 
|+ Main display
 
 
|-
 
|-
! Option !! Default !! Description !! Available in Mudlet
+
|| <F6> || \xf6 || 1 ||
 
|-
 
|-
| fixUnnecessaryLinebreaks || false || Remove extra linebreaks from output (mostly for IRE servers) || 4.16
+
|| <T_AYT> || \xf6 || 1 ||
 
|-
 
|-
|}
+
|| <F7> || \xf7 || 1 ||
 
 
{| class="wikitable sortable"
 
|+ Mapper options
 
 
|-
 
|-
! Option !! Default !! Description !! Available in Mudlet
+
|| <T_EC> || \xf7 || 1 ||
 
|-
 
|-
| mapRoomSize  || 5 || Size of rooms on map (a good value is 5) || 4.16
+
|| <F8> || \xf8 || 1 ||
 
|-
 
|-
| mapExitSize  || 10 || Size of exits on map (a good value is 10) || 4.16
+
|| <T_EL> || \xf8 || 1 ||
 
|-
 
|-
| mapRoundRooms || false || Draw rooms round or square || 4.16
+
|| <F9> || \xf9 || 1 ||
 
|-
 
|-
| showRoomIdsOnMap || false || Show room IDs on all rooms (if zoom permits) || 4.16
+
|| <T_GA> || \xf9 || 1 ||
 
|-
 
|-
| showMapInfo || - || Map overlay text ('Full', 'Short', or any custom made. Map can show multiple at once) || 4.16
+
|| <FA> || \xfa || 1 ||
 
|-
 
|-
| hideMapInfo || - || Map overlay text ('Full', 'Short', or any custom made. Hide each info separately to hide all) || 4.16
+
|| <T_SB> || \xfa || 1 ||
 
|-
 
|-
| show3dMapView || false || Show map as 3D || 4.16
+
|| <FB> || \xfb || 1 ||
 
|-
 
|-
| mapperPanelVisible || true || Map controls at the bottom || 4.16
+
|| <T_WILL> || \xfb || 1 ||
 
|-
 
|-
| mapShowRoomBorders || true || Draw a thin border for every room || 4.16
+
|| <FC> || \xfc || 1 ||
|}
 
 
 
{| class="wikitable sortable"
 
|+ Special options
 
 
|-
 
|-
! Option !! Default !! Description !! Available in Mudlet
+
|| <T_WONT> || \xfc || 1 ||
 
|-
 
|-
| specialForceCompressionOff || false || Workaround option to disable MCCP compression, in case the game server is not working correctly || 4.16
+
|| <FD> || \xfd || 1 ||
 
|-
 
|-
| specialForceGAOff || false || Workaround option to disable Telnet Go-Ahead, in case the game server is not working correctly || 4.16
+
|| <T_DO> || \xfd || 1 ||
 
|-
 
|-
| specialForceCharsetNegotiationOff || false || Workaround option to disable automatically setting the correct encoding, in case the game server is not working correctly || 4.16
+
|| <FE> || \xfe || 1 ||
 
|-
 
|-
| specialForceMxpNegotiationOff || false || Workaround option to disable MXP, in case the game server is not working correctly || 4.16
+
|| <T_DONT> || \xfe || 1 ||
 
|-
 
|-
| caretShortcut || "none" || For visually-impaired players - set the key to switch between input line and main window (can be "none", "tab", "ctrltab", "f6") || 4.17
+
|| <FF> || \xff || 1 ||
 
|-
 
|-
| blankLinesBehaviour || "show" || For visually impaired players options for dealing with blank lines (can be "show", "hide", "replacewithspace") || 4.17
+
|| <T_IAC> || \xff'
 
|}
 
|}
 
;Returns
 
* true if successful, or nil+msg if the option doesn't exist. Setting mapper options requires the mapper being open first.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
setConfig("mapRoomSize", 5)
+
-- 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
  
setConfig({mapRoomSize = 6, mapExitSize = 12})
+
local something = feedTelnet(exampleValue)
</syntaxhighlight>
+
if something then
 +
  -- do something with something (assuming there is a meaningful return value)
 +
end
  
==setMergeTables==
+
-- maybe another example for the optional second case
;setMergeTables(module)
+
local somethingElse = function(exampleValue, anotherValue)
:Makes Mudlet merge the table of the given GMCP or MSDP module instead of overwriting the data. This is useful if the game sends only partial updates which need combining for the full data. By default "Char.Status" is the only merged module.
 
  
;Parameters
+
-- lastly, include an example with error handling to give an idea of good practice
* ''module:''
+
local ok, err = function()
:Name(s) of the GMCP or MSDP module(s) that should be merged as a string - this will add it to the existing list.
+
if not ok then
 
+
  debugc(f"Error: unable to do <particular thing> because {err}\n")
;Example
+
  return
<syntaxhighlight lang="lua">
+
end
setMergeTables("Char.Skills", "Char.Vitals")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==setModuleInfo==
+
; Additional development notes
;setModuleInfo(moduleName, info, value)
+
-- This function is still being written up.
  
:Sets a specific meta info value for a module
+
=String Functions=
 +
:These functions are used to manipulate strings.
  
;Parameters
+
=Table Functions=
* ''moduleName:''
+
: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.
:Name of the module
 
* ''info:''
 
: specific info to set (for example "version")
 
* ''value:''
 
: specific value to set (for example "1.0")
 
  
:See also: [[#getModuleInfo|getModuleInfo]], [[#setPackageInfo|getPackageInfo]]
+
=Text to Speech Functions=
 +
: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.
  
;Example
+
=UI Functions=
<syntaxhighlight lang="lua">
+
: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.
setModuleInfo("myModule", "version", "1.0")
 
</syntaxhighlight>
 
  
{{MudletVersion|4.12}}
+
==cecho2decho PR#6849 merged==
 +
; convertedString = cecho2decho(str)
  
==setModulePriority==
+
:Converts a cecho formatted string to a decho formatted one.
;setModulePriority(moduleName, priority)
+
;See also: [[Manual:Lua_Functions#decho2cecho|decho2cecho()]], [[Manual:Lua_Functions#cecho2html|cecho2html()]]
  
:Sets the module priority on a given module as a number - the module priority determines the order modules are loaded in, which can be helpful if you have ones dependent on each other. This can also be set from the module manager window.
+
{{MudletVersion|4.18}}
: Modules with priority <code>-1</code> will be loaded before scripts (Mudlet 4.11+).
 
 
 
: See also: [[#getModulePriority|getModulePriority()]]
 
 
 
<syntaxhighlight lang="lua">
 
setModulePriority("mudlet-mapper", 1)
 
</syntaxhighlight>
 
 
 
==setPackageInfo==
 
;setPackageInfo(packageName, info, value)
 
 
 
:Sets a specific meta info value for a package
 
  
 
;Parameters
 
;Parameters
* ''packageName:''
+
* ''str''
:Name of the module
+
: string you wish to convert from cecho to decho
* ''info:''
+
;Returns
: specific info to set (for example "version")
+
* a string formatted for decho
* ''value:''
 
: specific value to set (for example "1.0")
 
 
 
:See also: [[#getPackageInfo|getPackageInfo]], [[#setModuleInfo|setModuleInfo]]
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
setPackageInfo("myPackage", "title", "This is my test package")
+
-- 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))
 
</syntaxhighlight>
 
</syntaxhighlight>
  
{{MudletVersion|4.12}}
+
==cecho2hecho PR#6849 merged==
 +
; convertedString = cecho2hecho(str)
 +
 
 +
:Converts a cecho formatted string to an hecho formatted one.
 +
;See also: [[Manual:Lua_Functions#hecho2cecho|hecho2cecho()]], [[Manual:Lua_Functions#cecho2html|cecho2html()]]
  
==setServerEncoding==
+
{{MudletVersion|4.18}}
;setServerEncoding(encoding)
 
:Makes Mudlet use the specified [https://www.w3.org/International/questions/qa-what-is-encoding encoding] for communicating with the game.
 
  
 
;Parameters
 
;Parameters
* ''encoding:''
+
* ''str''
:Encoding to use.
+
: string you wish to convert from cecho to decho
 
+
;Returns
:See also: [[#getServerEncodingsList|getServerEncodingsList()]], [[#getServerEncoding|getServerEncoding()]]
+
* a string formatted for hecho
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- use UTF-8 if Mudlet knows it. Unfortunately there's no way to check if the game's server knows it too.
+
-- convert to an hecho string and use hecho to display it
if table.contains(getServerEncodingsList(), "UTF-8") then
+
local cechoString = "<red><b>!!ALERT!!:</b><orange> Something has gone wrong!\n"
  setServerEncoding("UTF-8")
+
hecho(cecho2hecho(cechoString))
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==showNotification==
+
==cecho2html PR#6849 merged==
;showNotification(title, [content], [expiryTimeInSeconds])
+
; convertedString = cecho2html(str[, resetFormat])
  
:Shows a native (system) notification.
+
:Converts a cecho formatted string to an html formatted one.
 +
;See also: [[Manual:Lua_Functions#decho2cecho|decho2cecho()]], [[Manual:Lua_Functions#decho2html|cecho2html()]]
  
{{MudletVersion|4.11}}
+
{{MudletVersion|4.18}}
 
 
{{Note}} This might not work on all systems, this depends on the system.
 
  
 
;Parameters
 
;Parameters
* ''title'' - plain text notification title
+
* ''str''
* ''content'' - optional argument, plain text notification content, if omitted title argument will be used as content as well
+
: string you wish to convert from cecho to decho
* ''expiryTimeInSeconds'' - optional argument, sets expiration time in seconds for notification, very often ignored by OS
+
* ''resetFormat''
 +
: optional table of default formatting options. As returned by [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]
 +
;Returns
 +
* a string formatted for html
  
 +
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
showNotification("Notification title", "Notification content", 5)
+
-- create the base string
</syntaxhighlight>
+
local cechoString = "<red><b>!!ALERT!!:</b><orange> Something has gone wrong!\n"
  
==spawn==
+
-- create a label to display the result onto
;spawn(readFunction, processToSpawn[, ...arguments])
+
testLabel = Geyser.Label:new({name = "testLabel"})
  
:Spawns a process and opens a communicatable link with it - ''read function'' is the function you'd like to use for reading output from the process, and ''t'' is a table containing functions specific to this connection - ''send(data)'', ''true/false = isRunning()'', and ''close()''.
+
-- convert the cecho string to an html one, using the default formatting of testLabel created above
 +
local htmlString = cecho2html(cechoString, testLabel:getFormat())
  
:This allows you to setup RPC communication with another process.
+
-- and finally echo it to the label to see
 +
-- I use rawEcho as that displays the html exactly as given.
 +
testLabel:rawEcho(htmlString)
 +
</syntaxhighlight>
  
;Examples
+
==decho2cecho PR#6849 merged==
<syntaxhighlight lang="lua">
+
; convertedString = decho2cecho(str)
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function
 
local f = spawn(display, "ls")
 
display(f.isRunning())
 
f.close()
 
</syntaxhighlight>
 
<syntaxhighlight lang="lua">
 
local f = spawn(display, "ls", "-la")
 
display(f.isRunning())
 
f.close()
 
</syntaxhighlight>
 
  
==startLogging==
+
:Converts a decho formatted string to a cecho formatted one.
;startLogging(state)
+
;See also: [[Manual:Lua_Functions#cecho2decho|cecho2decho()]], [[Manual:Lua_Functions#decho2html|decho2html()]]
  
:Control logging of the main console text as text or HTML (as specified by the "Save log files in HTML format instead of plain text" setting on the "General" tab of the "Profile preferences" or "Settings" dialog).  Despite being called startLogging it can also stop the process and correctly close the file being created. The file will have an extension of type ".txt" or ".html" as appropriate and the name will be in the form of a date/time "yyyy-MM-dd#hh-mm-ss" using the time/date of when logging started.  Note that this control parallels the corresponding icon in the "bottom buttons" for the profile and that button can also start and stop the same logging process and will reflect the state as well.
+
{{MudletVersion|4.18}}
  
 
;Parameters
 
;Parameters
* ''state:''
+
* ''str''
:Required: logging state. Passed as a boolean
+
: string you wish to convert from decho to cecho
 
+
;Returns  
;Returns (4 values)
+
* a string formatted for cecho
* ''successful (bool)''
 
:''true'' if the logging state actually changed; if, for instance, logging was already active and ''true'' was supplied then no change in logging state actually occurred and ''nil'' will be returned (and logging will continue).
 
* ''message (string)''
 
:A displayable message given one of four messages depending on the current and previous logging states, this will include the file name except for the case when logging was not taking place and the supplied argument was also ''false''.
 
* ''fileName (string)''
 
:The log will be/is being written to the path/file name returned.
 
* ''code (number)''
 
:A value indicating the response to the system to this instruction:
 
  *  0 = logging has just stopped
 
  *  1 = logging has just started
 
  * -1 = logging was already in progress so no change in logging state
 
  * -2 = logging was already not in progress so no change in logging state
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- start logging
+
-- convert to a decho string and use cecho to display it
local success, message, filename, code = startLogging(true)
+
local dechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n"
if code == 1 or code == -1 then print(f"Started logging to {filename}") end
+
cecho(decho2cecho(dechoString))
 
 
-- stop logging
 
startLogging(false)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==stopAllNamedEventHandlers==
+
==decho2hecho PR#6849 merged==
; stopAllNamedEventHandlers(userName)
+
; convertedString = decho2hecho(str)
  
:Stops all named event handlers and prevents them from firing any more. Information is retained and handlers can be resumed.
+
:Converts a decho formatted string to an hecho formatted one.  
 +
;See also: [[Manual:Lua_Functions#hecho2decho|hecho2decho()]], [[Manual:Lua_Functions#decho2html|decho2html()]]
  
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#stopNamedEventHandler|stopNamedEventHandler()]], [[Manual:Lua_Functions#resumeNamedEventHandler|resumeNamedEventHandler()]]
+
{{MudletVersion|4.18}}
  
{{MudletVersion|4.14}}
+
;Parameters
 
+
* ''str''
;Parameter
+
: string you wish to convert from decho to decho
* ''userName:''
+
;Returns
: The user name the event handler was registered under.
+
* a string formatted for hecho
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
stopAllNamedEventHandlers() -- 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>
  
==stopMusic==
+
==decho2html PR#6849 merged==
;stopMusic(settings table)
+
; convertedString = decho2html(str[, resetFormat])
:Stop all music (no filter), or music that meets a combination of filters (name, key, and tag) intended to be paired with [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]].
 
  
{| class="wikitable"
+
:Converts a decho formatted string to an html formatted one.  
! Required
+
;See also: [[Manual:Lua_Functions#cecho2decho|cecho2decho()]], [[Manual:Lua_Functions#decho2html|decho2html()]]
! Key
 
! Value
 
!Default
 
! style="text-align:left;"| Purpose
 
|-
 
| style="text-align:center;"| No
 
| 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.
 
|-
 
| style="text-align:center;"| No
 
| fadeaway
 
| true or false
 
|false
 
| style="text-align:left;" |
 
* Decrease volume from the current position for a given duration, then stops the track.
 
* Given duration is the lesser of the remaining track duration or the fadeout specified in playMusicFile().
 
* If fadeout was not specified in playMusicFile(), then the optional fadeout parameter from stopMusic() or a default of 5000 milliseconds will be applied.
 
|-
 
| style="text-align:center;"| No
 
| fadeout
 
|
 
|5000
 
| style="text-align:left;" |
 
* Default duration in milliseconds to decrease volume to the end of the track.
 
* Only used if fadeout was not defined in playMusicFile().
 
|-
 
|}
 
  
See also: [[Manual:Miscellaneous_Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous_Functions#loadSoundFile|loadSoundFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]], [[Manual:Miscellaneous_Functions#getPlayingMusic|getPlayingMusic()]], [[Manual:Miscellaneous_Functions#getPlayingSounds|getPlayingSounds()]], [[Manual:Miscellaneous_Functions#stopSounds|stopSounds()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
+
{{MudletVersion|4.18}}
  
{{MudletVersion|4.15}}
+
;Parameters
 +
* ''str''
 +
: string you wish to convert from decho to decho
 +
* ''resetFormat''
 +
: optional table of default formatting options. As returned by [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]
 +
;Returns
 +
* a string formatted for html
  
 
;Example
 
;Example
 
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
---- Table Parameter Syntax ----
+
-- create the base string
 +
local dechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n"
  
-- Stop all playing music files for this profile associated with the API
+
-- create a label to display the result onto
stopMusic()
+
testLabel = Geyser.Label:new({name = "testLabel"})
  
-- Stop playing the rugby mp3 by name
+
-- convert the decho string to an html one, using the default formatting of testLabel created above
stopMusic({name = "167124__patricia-mcmillen__rugby-club-in-spain.mp3"})
+
local htmlString = decho2html(dechoString, testLabel:getFormat())
  
-- Stop playing the unique sound identified as "rugby"
+
-- and finally echo it to the label to see
stopMusic({
+
-- I use rawEcho as that displays the html exactly as given.
    name = nil  -- nil lines are optional, no need to use
+
testLabel:rawEcho(htmlString)
    , key = "rugby" -- key
 
    , tag = nil  -- nil lines are optional, no need to use
 
})
 
 
 
-- Decrease volume for 5 seconds and then stop all playing music files for this profile associated with the API
 
stopMusic({
 
    fadeaway = true
 
})
 
 
 
-- Decrease volume for 10 seconds (or apply the duration of fadeout set in playMusicFile()) and then stop all playing music files for this profile associated with the API
 
stopMusic({
 
    fadeaway = true
 
    , fadeout = 10000
 
})
 
 
 
-- Decrease volume for 5 seconds and then stop all the unique "rugby" music for this profile associated with the API
 
stopMusic({
 
    key = "rugby"
 
    , fadeaway = true
 
})
 
 
</syntaxhighlight>
 
</syntaxhighlight>
<syntaxhighlight lang="lua">
 
---- Ordered Parameter Syntax of stopMusic([name][,key][,tag][,fadeaway][,fadeout]) ----
 
  
-- Stop all playing music files for this profile associated with the API
+
==deleteMultiline PR #6779 merged==
stopMusic()
 
  
-- Stop playing the rugby mp3 by name
+
; ok,err = deleteMultiline([triggerDelta])
stopMusic("167124__patricia-mcmillen__rugby-club-in-spain.mp3")
 
  
-- Stop playing the unique sound identified as "rugby"
+
: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.
stopMusic(
+
;See also: [[Manual:Lua_Functions#deleteLine|deleteLine()]], [[Manual:Lua_Functions#replaceLine|replaceLine()]]
    nil -- name
 
    , "rugby" -- key
 
    , nil -- tag
 
)
 
  
-- Decrease the volume for 10 seconds then stop playing the unique sound identified as "rugby"
+
{{MudletVersion|4.18}}
stopMusic(
 
    nil -- name
 
    , "rugby" -- key
 
    , nil -- tag
 
    , true -- fadeaway
 
    , 10000 -- fadeout
 
)
 
</syntaxhighlight>
 
 
 
==stopNamedEventHandler==
 
; success = stopNamedEventHandler(userName, handlerName)
 
 
 
:Stops a named event handler 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#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#resumeNamedEventHandler|resumeNamedEventHandler()]]
 
  
{{MudletVersion|4.14}}
+
{{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
 
;Parameters
* ''userName:''
+
* ''[optional]triggerDelta:''
: The user name the event handler was registered under.
+
: 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.
* ''handlerName:''
 
: The name of the handler to stop. Same as used when you called [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]]
 
  
 
;Returns  
 
;Returns  
* true if successful, false if it didn't exist or was already stopped
+
* true if the function was able to run successfully, nil+error if something went wrong.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
local stopped = stopNamedEventHandler("DemonVitals")
+
-- if this trigger has a line delta of 3, you would call
if stopped then
+
deleteMultiline(3)
   cecho("DemonVitals stopped!")
+
 
else
+
-- same thing, but with error handling
  cecho("DemonVitals doesn't exist or already stopped; either way it won't fire any more.")
+
local ok,err = deleteMultiline(3)
 +
if not ok then
 +
   cecho("\n<firebrick>I could not delete the lines because: " .. err)
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==stopSounds==
+
; Additional development notes
;stopSounds(settings table)
 
:Stop all sounds (no filter), or sounds that meets a combination of filters (name, key, tag, and priority) intended to be paired with [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]].
 
  
{| class="wikitable"
+
==echoPopup, revised in PR #6946==
! Required
+
;echoPopup([windowName,] text, {commands}, {hints}[, useCurrentFormatElseDefault])
! Key
+
: 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.
! Value
 
! Default
 
! style="text-align:left;"| Purpose
 
|-
 
| style="text-align:center;"| No
 
| 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.
 
|-
 
| style="text-align:center;" |No
 
| priority
 
| 1 to 100
 
|
 
| style="text-align:left;" |
 
*Halts the play of current or future played media files with a matching or lower priority.
 
|-
 
| style="text-align:center;"| No
 
| fadeaway
 
| true or false
 
|false
 
| style="text-align:left;" |
 
* Decrease volume from the current position for a given duration, then stops the track.
 
* Given duration is the lesser of the remaining track duration or the fadeout specified in playSoundFile().
 
* If fadeout was not specified in playSoundFile(), then the optional fadeout parameter from stopSounds() or a default of 5000 milliseconds will be applied.
 
|-
 
| style="text-align:center;"| No
 
| fadeout
 
|
 
|5000
 
| style="text-align:left;" |
 
* Default duration in milliseconds to decrease volume to the end of the track.
 
* Only used if fadeout was not defined in playSoundFile().
 
|-
 
|}
 
  
See also: [[Manual:Miscellaneous_Functions#loadMusicFile|loadMusicFile()]], [[Manual:Miscellaneous_Functions#loadSoundFile|loadSoundFile()]], [[Manual:Miscellaneous_Functions#playMusicFile|playMusicFile()]], [[Manual:Miscellaneous_Functions#playSoundFile|playSoundFile()]], [[Manual:Miscellaneous_Functions#getPlayingMusic|getPlayingMusic()]], [[Manual:Miscellaneous_Functions#getPlayingSounds|getPlayingSounds()]], [[Manual:Miscellaneous_Functions#stopMusic|stopMusic()]], [[Manual:Miscellaneous_Functions#purgeMediaCache|purgeMediaCache()]], [[Manual:Scripting#MUD_Client_Media_Protocol|Mud Client Media Protocol]]
+
; Parameters
 
+
* ''windowName:''
{{MudletVersion|4.15}}
+
: (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. <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">
---- Table Parameter Syntax ----
+
-- 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"})
  
-- Stop all playing sound files for this profile associated with the API
+
-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)
stopSounds()
+
echoPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})
  
-- Stop playing the cow sound
+
-- one can also provide helpful information
stopSounds({name = "cow.wav"})
 
  
-- Stop playing any sounds tagged as "animals" with a priority less than or equal to 50
+
-- todo: an example with rich-text in the tool-tips(s) - not complete yet!
---- This would not stop sounds tagged as "animals" greater than priority 50.  This is an "AND" and not an "OR".
+
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)
stopSounds({
+
echo(" remaining text.\n")
    name = nil -- nil lines are optional, no need to use
 
    , key = nil -- nil lines are optional, no need to use
 
    , tag = "animals"
 
    , priority = 50
 
})
 
  
-- Decrease volume for 5 seconds and then stop all playing sound files for this profile associated with the API
+
</syntaxhighlight>
stopSounds({
 
    fadeaway = true
 
})
 
  
-- Decrease volume for 10 seconds (or apply the duration of fadeout set in playSoundFile()) and then stop all playing music files for this profile associated with the API
+
==hecho2cecho PR#6849 merged==
stopSounds({
+
; convertedString = hecho2cecho(str)
    fadeaway = true
 
    , fadeout = 10000
 
})
 
  
-- Decrease volume for 3 seconds and then stop all the tagged "animals" music for this profile associated with the API
+
:Converts a hecho formatted string to a cecho formatted one.
stopSounds({
+
;See also: [[Manual:Lua_Functions#cecho2decho|cecho2decho()]], [[Manual:Lua_Functions#hecho2html|hecho2html()]]
    tag = "animals"
 
    , fadeaway = true
 
    , fadeout = 3000
 
})
 
</syntaxhighlight>
 
<syntaxhighlight lang="lua">
 
---- Ordered Parameter Syntax of stopSounds([name][,key][,tag][,priority][,fadeaway][,fadeout]) ----
 
  
-- Stop all playing sound files for this profile associated with the API
+
{{MudletVersion|4.18}}
stopSounds()
 
  
-- Stop playing the cow sound
+
;Parameters
stopSounds("cow.wav")
+
* ''str''
 +
: string you wish to convert from hecho to cecho
 +
;Returns
 +
* a string formatted for cecho
  
-- Stop playing any sounds tagged as "animals" with a priority less than or equal to 50
+
;Example
---- This would not stop sounds tagged as "animals" greater than priority 50.  This is an "AND" and not an "OR".
+
<syntaxhighlight lang="lua">
stopSounds(
+
-- convert to a hecho string and use cecho to display it
    nil -- name
+
local hechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n""
    , nil -- key
+
cecho(hecho2cecho(hechoString))
    , "animals" -- tag
 
    , 50 -- priority
 
)
 
 
 
-- Decrease the volume for 7 seconds and then stop playing sounds
 
stopSounds(
 
    nil -- name
 
    , nil -- key
 
    , nil -- tag
 
    , nil -- priority
 
    , true -- fadeaway
 
    , 7000 -- fadeout
 
)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==timeframe==
+
==hecho2decho PR#6849 merged==
;timeframe(vname, true_time, nil_time, ...)
+
; convertedString = hecho2decho(str)
  
:A utility function that helps you change and track variable states without using a lot of tempTimers.
+
:Converts a hecho formatted string to a decho formatted one.  
 +
;See also: [[Manual:Lua_Functions#decho2hecho|decho2hecho()]], [[Manual:Lua_Functions#hecho2html|hecho2html()]]
  
{{MudletVersion|3.6}}
+
{{MudletVersion|4.18}}
  
 
;Parameters
 
;Parameters
* ''vname:''
+
* ''str''
:A string or function to use as the variable placeholder.
+
: string you wish to convert from hecho to decho
* ''true_time:''
+
;Returns
:Time before setting the variable to true. Can be a number or a table in the format: <code>{time, value}</code>
+
* a string formatted for decho
* ''nil_time:''
 
:(optional) Number of seconds until <code>vname</code> is set back to nil. Leaving it undefined will leave it at whatever it was set to last. Can be a number of a table in the format: <code>{time, value}</code>
 
* ''...:''
 
:(optional) Further list of times and values to set the variable to, in the following format: <code>{time, value}</code>
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- sets the global 'limiter' variable to true immediately (see the 0) and back to nil in one second (that's the 1).
+
-- convert to a decho string and use decho to display it
timeframe("limiter", 0, 1)
+
local hechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n""
 
+
decho(hecho2decho(hechoString))
-- An angry variable 'giant' immediately set to "fee", followed every second after by "fi", "fo", and "fum" before being reset to nil at four seconds.
 
timeframe("giant", {0, "fee"}, 4, {1, "fi"}, {2, "fo"}, {3, "fum"})
 
 
 
-- sets the local 'width' variable to true immediately and back to nil in one second.
 
local width
 
timeframe(function(value) width = value end, 0, 1)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==translateTable==
+
==hecho2html PR#6849 merged==
;translateTable(directions, [languagecode])
+
; convertedString = hecho2html(str[, resetFormat])
  
:Given a table of directions (such as <code>speedWalkDir</code>), translates directions to another language for you. Right now, it can only translate it into the language of Mudlet's user interface - but [https://github.com/Mudlet/Mudlet/issues/new let us know if you need more].
+
:Converts a hecho formatted string to an html formatted one.
 +
;See also: [[Manual:Lua_Functions#cecho2hecho|cecho2hecho()]], [[Manual:Lua_Functions#hecho2html|hecho2html()]]
  
{{MudletVersion|3.22}}
+
{{MudletVersion|4.18}}
  
 
;Parameters
 
;Parameters
* ''directions:''
+
* ''str''
:An indexed table of directions (eg. <code>{"sw", "w", "nw", "s"}</code>).
+
: string you wish to convert from hecho to hecho
* ''languagecode:''
+
* ''resetFormat''
:(optional) Language code (eg <code>ru_RU</code> or <code>it_IT</code>) - by default, <code>mudlet.translations.interfacelanguage</code> is used.
+
: optional table of default formatting options. As returned by [[Manual:Lua_Functions#getLabelFormat|getLabelFormat()]]
 +
;Returns
 +
* a string formatted for html
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- get the path from room 2 to room 5 and translate directions
+
-- create the base string
if getPath(2, 5) then
+
local hechoString = "#ff0000#b!!ALERT!!:#/b#ffa500 Something has gone wrong!\n""
speedWalkDir = translateTable(speedWalkDir)
+
 
print("Translated directions:")
+
-- create a label to display the result onto
display(speedWalkDir)
+
testLabel = Geyser.Label:new({name = "testLabel"})
 +
 
 +
-- convert the hecho string to an html one, using the default formatting of testLabel created above
 +
local htmlString = hecho2html(hechoString, 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)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==uninstallModule==
+
==insertPopup, revised in PR #6925==
;uninstallModule(name)
+
;insertPopup([windowName], text, {commands}, {hints}[{, tool-tips}][, 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 a tool-tips table is not provided the same hints will also be listed one-per-line as a tool-tip but if a matching number of tool-tips are provided they will be concatenated to provide a tool-tip when the text is hovered over by the pointer - these tool-tips can be ''rich-text'' to produce information formatted with additional content in the same manner as labels.
  
:Uninstalls a Mudlet module with the given name.
+
; 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. <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 popup if no {tool-tips} table is provided). If a particular position in both the commands and hints table are both the empty string ''""'' but there is something in the tool-tips table, no entry for that position will be made in the context menu but the tool-tip can still display something which can include images or text.
 +
* ''{tool-tips}:''
 +
: (optional) a table of possibly ''rich-text'' strings which will be shown on the popup if provided.
 +
* ''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.
  
:See also: [[#installModule | installModule()]], [[Manual:Event_Engine#sysLuaUninstallModule | Event: sysLuaUninstallModule]]
+
{{note}} Mudlet will distinguish between the optional tool-tips and the flag to switch between the standard link and the current text format by examining the type of the argument, as such this pair of arguments can be in either order.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
uninstallModule("myalias")
+
-- Create some text as a clickable with a popup menu, a left click will ''send "sleep"'':
</syntaxhighlight>
+
insertPopup("activities to do", {function() send "sleep" end, function() send "sit" end, function() send "stand" end}, {"sleep", "sit", "stand"})
  
==uninstallPackage==
+
-- alternatively, put commands as text (in [[ and ]] to use quotation marks inside)
;uninstallPackage(name)
+
insertPopup("activities to do", {[[send "sleep"]], [[send "sit"]], [[send "stand"]]}, {"sleep", "sit", "stand"})
  
:Uninstalls a Mudlet package with the given name.
+
-- one can also provide helpful information
  
:See also: [[#installPackage | installPackage()]]
+
-- todo: an example with rich-text in the tool-tips(s)
  
;Example
 
<syntaxhighlight lang="lua">
 
uninstallPackage("myalias")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==unzipAsync==
+
=Discord Functions=
;unzipAsync(path, location)
+
: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]].
  
:Unzips the zip file at path, extracting the contents to the location provided. Returns true if it is able to start unzipping, or nil+message if it cannot.
+
=Mud Client Media Protocol=
Raises the <code>sysUnzipDone</code> event with the zip file location and location unzipped to as arguments if unzipping is successful, and <code>sysUnzipError</code> with the same arguments if it is not.
+
: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]].
  
Do not use the <code>unzip()</code> function as it is synchronous and will impact Mudlet's performance (ie, freeze Mudlet while unzipping).
+
=Supported Protocols=
  
{{MudletVersion|4.6}}
+
=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.
  
;Example
+
===sysMapAreaChanged, PR #6615===
<syntaxhighlight lang="lua">
+
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.
function handleUnzipEvents(event, ...)
 
  local args = {...}
 
  local zipName = args[1]
 
  local unzipLocation = args[2]
 
  if event == "sysUnzipDone" then
 
    cecho(string.format("<green>Unzip successful! Unzipped %s to %s\n", zipName, unzipLocation))
 
  elseif event == "sysUnzipError" then
 
    cecho(string.format("<firebrick>Unzip failed! Tried to unzip %s to %s\n", zipName, unzipLocation))
 
  end
 
end
 
if unzipSuccessHandler then killAnonymousEventHandler(unzipSuccessHandler) end
 
if unzipFailureHandler then killAnonymousEventHandler(unzipFailureHandler) end
 
unzipSuccessHandler = registerAnonymousEventHandler("sysUnzipDone", "handleUnzipEvents")
 
unzipFailureHandler = registerAnonymousEventHandler("sysUnzipError", "handleUnzipEvents")
 
--use the path to your zip file for this, not mine
 
local zipFileLocation = "/home/demonnic/Downloads/Junkyard_Orc.zip"
 
--directory to unzip to, it does not need to exist but you do need to be able to create it
 
local unzipLocation = "/home/demonnic/Downloads/Junkyard_Orcs"
 
unzipAsync(zipFileLocation, unzipLocation) -- this will work
 
unzipAsync(zipFileLocation .. "s", unzipLocation) --demonstrate error, will happen first because unzipping takes time</syntaxhighlight>
 
  
==yajl.to_string==
+
{{MudletVersion| ?.??}}
;yajl.to_string(data)
 
  
:Encodes a Lua table into JSON data and returns it as a string. This function is very efficient - if you need to encode into JSON, use this.
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6615
  
;Example
+
===sysMapWindowMousePressEvent, PR #6962===
<syntaxhighlight lang="lua">
+
Raised when the mouse is left-clicked on the mapper window.
-- on IRE MUD games, you can send a GMCP request to request the skills in a particular skillset. Here's an example:
 
sendGMCP("Char.Skills.Get "..yajl.to_string{group = "combat"})
 
 
 
-- you can also use it to convert a Lua table into a string, so you can, for example, store it as room's userdata
 
local toserialize = yajl.to_string(continents)
 
setRoomUserData(1, "areaContinents", toserialize)
 
</syntaxhighlight>
 
  
 +
{{MudletVersion| ?.??}}
  
==yajl.to_value==
+
{{note}} pending, not yet available. See https://github.com/Mudlet/Mudlet/pull/6962
;yajl.to_value(data)
 
  
:Decodes JSON data (as a string) into a Lua table. This function is very efficient - if you need to dencode into JSON, use this.
+
===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.
  
;Example
+
{{MudletVersion| ?.??}}
<syntaxhighlight lang="lua">
 
-- given the serialization example above with yajl.to_string, you can deserialize room userdata back into a table
 
local tmp = getRoomUserData(1, "areaContinents")
 
if tmp == "" then return end
 
 
 
local continents = yajl.to_value(tmp)
 
display(continents)
 
</syntaxhighlight>
 
  
[[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]]
 

Revision as of 07:07, 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))

hecho2html PR#6849 merged

convertedString = hecho2html(str[, resetFormat])
Converts a hecho formatted string to an html formatted one.
See also
cecho2hecho(), hecho2html()
Mudlet VersionAvailable in Mudlet4.18+
Parameters
  • str
string you wish to convert from hecho to hecho
  • resetFormat
optional table of default formatting options. As returned by getLabelFormat()
Returns
  • a string formatted for html
Example
-- create the base string
local hechoString = "#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 hecho string to an html one, using the default formatting of testLabel created above
local htmlString = hecho2html(hechoString, 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)

insertPopup, revised in PR #6925

insertPopup([windowName], text, {commands}, {hints}[{, tool-tips}][, 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 a tool-tips table is not provided the same hints will also be listed one-per-line as a tool-tip but if a matching number of tool-tips are provided they will be concatenated to provide a tool-tip when the text is hovered over by the pointer - these tool-tips can be rich-text to produce information formatted with additional content in the same manner as labels.
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 popup if no {tool-tips} table is provided). If a particular position in both the commands and hints table are both the empty string "" but there is something in the tool-tips table, no entry for that position will be made in the context menu but the tool-tip can still display something which can include images or text.
  • {tool-tips}:
(optional) a table of possibly rich-text strings which will be shown on the popup if provided.
  • 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.

Note Note: Mudlet will distinguish between the optional tool-tips and the flag to switch between the standard link and the current text format by examining the type of the argument, as such this pair of arguments can be in either order.

Example
-- Create some text as a clickable with a popup menu, a left click will ''send "sleep"'':
insertPopup("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)
insertPopup("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)

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