Difference between revisions of "Area 51"

From Mudlet
Jump to navigation Jump to search
(10 intermediate revisions by 3 users not shown)
Line 11: Line 11:
 
:These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.
 
: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=
+
==printDebug==
:A collection of functions for helping deal with the database.
+
; printDebug(msg, [showStackTrace])
 +
 
 +
:Prints a debug message in green to the error console in the script editor only. Does not echo to the debug window or the main console. Includes stack trace if showStackTrace is included and not nil or false.
 +
 
 +
;See also: [[Manual:Lua_Functions#printError|printError]], [[Manual:Lua_Functions#debugc|debugc]]
 +
 
 +
{{MudletVersion|4.14}}
 +
 
 +
{{note}} This will not be echoed to the main console even if the option to echo Lua errors to the main console is turned on. Does not echo to the debug window. As such you can use it for debugging information without fear it will be shown unless someone goes looking for errors.
  
=Date/Time Functions=
+
;Parameters
: A collection of functions for handling date & time.
+
* ''msg:''
 +
: string to echo to the error console
 +
* ''showStackTrace:''
 +
: (optional) boolean true if you want to include the stack trace, leave off if you do not.
  
=File System Functions=
+
;Example
: A collection of functions for interacting with the file system.
+
<syntaxhighlight lang="lua">
 +
-- print a debug message to the error console for troubleshooting purposes, when you don't want to echo the information to the main screen.
 +
-- the only difference between this and debugc is this includes information on the script/alias/trigger/etc and line it was called from, whereas debugc does not.
 +
printDebug("Switching to chaos mode")
  
=Mapper Functions=
+
-- Want to record that something occurred, and include stacktrace so you can see what path the code was taking, but you don't want to halt execution or have it show up in main screen or in scary red.
: A collection of functions that manipulate the mapper and its related features.
+
printDebug("Something unexpected occurred but we can recover from it. Still, we want to be able to notice and troubleshoot it with extra information.", true)
 +
</syntaxhighlight>
  
==createMapLabel==
+
==printError==
;labelID = createMapLabel(areaID, text, posX, posY, posZ, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue, zoom, fontSize, showOnTop, noScaling, fontName, foregroundTransparency, backgroundTransparency)
+
; printError(msg, [showStackTrace], [haltExecution])
  
:Creates a text label on the map at given coordinates, with the given background and foreground colors. It can go above or below the rooms, scale with zoom or stay a static size. It returns a label ID that you can use later for deleting it.
+
:Prints an error message in red to the error console in the script editor. Can optionally include stacktrace information and halt execution.
  
:The coordinates 0,0 are in the middle of the map, and are in sync with the room coordinates - so using the x,y values of [[#getRoomCoordinates|getRoomCoordinates()]] will place the label near that room.
+
;See also: [[Manual:Lua_Functions#printDebug|printDebug]], [[Manual:Lua_Functions#debugc|debugc]]
  
: See also: [[#getMapLabel|getMapLabel()]], [[#getMapLabels|getMapLabels()]], [[#deleteMapLabel|deleteMapLabel]]
+
{{MudletVersion|4.14}}
  
{{MudletVersion|4.13}}
+
{{note}} This WILL be echoed to the main console if the option to echo Lua errors to the main console is turned on. You should not use this for idle debugging information, but actual errors that may put big red error lines in the main window.
  
 
;Parameters
 
;Parameters
* ''areaID:''
+
* ''msg:''
: Area ID where to put the label.
+
: string to echo to the error console
* ''text:''
+
* ''showStackTrace:''
: The text to put into the label. To get a multiline text label add a '\n' between the lines.
+
: (optional) true if you want to include the stack trace, leave off if you do not.
* ''posX, posY, posZ:''
+
* ''haltExecution:''
: Position of the label in room coordinates.
+
: (optional) true if you want to halt execution. You must pass a value for showStackTrace in order to halt execution.
* ''fgRed, fgGreen, fgBlue:''
 
: Foreground color or text color of the label.
 
* ''bgRed, bgGreen, bgBlue:''
 
: Background color of the label.
 
* ''zoom:''
 
: Zoom factor of the label if noScaling is false. Higher zoom will give higher resolution of the text and smaller size of the label. Default is 30.0.
 
* ''fontSize:''
 
: Size of the font of the text. Default is 50.
 
* ''showOnTop:''
 
: If true the label will be drawn on top of the rooms and if it is false the label will be drawn as a background.
 
* ''noScaling:''
 
: If true the label will have the same size when you zoom in and out in the mapper. If it is false the label will scale when you zoom the mapper.  
 
* ''fontName:''
 
: (optional) font name to use.
 
* ''foregroundTransparency''
 
: (optional) transparency of the text on the label.
 
* ''backgroundTransparency''
 
: (optional) transparency of the label background itself.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- the first 50 is some area id, the next three 0,0,0 are coordinates - middle of the area
+
-- print an error message but do not include extra stack information or halt execution.
-- 255,0,0 would be the foreground in RGB, 23,0,0 would be the background RGB
+
-- this is similar to debugc except it include more information on the place it was called from
-- zoom is only relevant when when you're using a label of a static size, so we use 0
+
-- and will show up in red and echo to the main console if the option for errors to echo there is selected.
-- and we use a font size of 20 for our label, which is a small medium compared to the map
+
printError("Your maxhp is below your currenthp and our game doesn't allow for that. HAX?!")
local labelid = createMapLabel( 50, "my map label", 0,0,0, 255,0,0, 23,0,0, 0,20)
 
  
-- to create a multi line text label we add '\n' between lines
+
-- Something bad happened, for sure, but your script can recover.
-- the position is placed somewhat to the northeast of the center of the map
+
-- Make sure this is something important enough it might make it to the main window as a big red error.
-- this label will be scaled as you zoom the map.
+
-- but we are not halting execution, since we can carry on in some capacity
local labelid = createMapLabel( 50, "1. Row One\n2. Row 2", .5,5.5,0, 255,0,0, 23,0,0, 30,50, true,false)
+
printError("gmcp values for this thing went missing, will carry on using defaults but you should tell somebody about this.", true)
 +
 
 +
-- print an error message to the error console for troubleshooting purposes.  
 +
-- Prints stack trace for troubleshooting and halts execution (because you cannot continue without the configuration, presumably)
 +
-- similar to using error(msg) but includes the stacktrace information.
 +
printError("Our entire configuration seems to have gone missing!", true, true)
  
createMapLabel(getRoomArea(getPlayerRoom()), "my map label", -1,-6,1, 255,0,0, 23,0,0, 0,20, true, true, "Ubuntu", 255, 0)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=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.
  
 
==mapSymbolFontInfo==
 
==mapSymbolFontInfo==
Line 91: Line 103:
 
::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).
 
::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).
  
==pauseSpeedwalk==
 
;pauseSpeedwalk()
 
 
:Pauses a speedwalk started using [[#speedwalk|speedwalk()]]
 
 
: See also: [[#speedwalk|speedwalk()]], [[#stopSpeedwalk|stopSpeedwalk()]], [[#resumeSpeedwalk|resumeSpeedwalk()]]
 
 
{{MudletVersion|4.13}}
 
 
==resumeSpeedwalk==
 
;resumeSpeedwalk()
 
 
:Continues a speedwalk paused using [[#pauseSpeedwalk|pauseSpeedwalk()]]
 
: See also: [[#speedwalk|speedwalk()]], [[#pauseSpeedwalk|pauseSpeedwalk()]], [[#stopSpeedwalk|stopSpeedwalk()]]
 
 
{{MudletVersion|4.13}}
 
  
 
==setupMapSymbolFont==
 
==setupMapSymbolFont==
Line 130: Line 126:
 
* ''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).
 
* ''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).
  
==stopSpeedwalk==
+
=Miscellaneous Functions=
;stopSpeedwalk()
+
: Miscellaneous functions.
 +
 
 +
==deleteAllNamedEventHandlers==
 +
; deleteAllNamedEventHandlers(handlerName)
 +
 
 +
:Deletes all named event handlers 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}}
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
deleteAllNamedEventHandlers() -- emergency stop or debugging situation, most likely.
 +
</syntaxhighlight>
 +
 
 +
==deleteNamedEventHandler==
 +
; success = deleteNamedEventHandler(handlerName)
 +
 
 +
:Deletes a named event handler with name handlerName and prevents it from firing any more. Information is deleted and cannot be retrieved.
 +
 
 +
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#stopNamedEventHandler|stopNamedEventHandler()]]
  
:Stops a speedwalk started using [[#speedwalk|speedwalk()]]
+
{{MudletVersion|4.14}}
: See also: [[#pauseSpeedwalk|pauseSpeedwalk()]], [[#resumeSpeedwalk|resumeSpeedwalk()]], [[#speedwalk|speedwalk()]]
 
  
{{MudletVersion|4.13}}
+
;Parameters
 +
* ''handlerName:''
 +
: The name of the handler to stop. Same as used when you called [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]]
  
=Miscellaneous Functions=
+
;Returns
: Miscellaneous functions.
+
* true if successful, false if it didn't exist
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
local deleted = deletedNamedEventHandler("DemonVitals")
 +
if deleted then
 +
  cecho("DemonVitals deleted forever!!")
 +
else
 +
  cecho("DemonVitals doesn't exist and so could not be deleted.")
 +
end
 +
</syntaxhighlight>
  
 
==getCharacterName==
 
==getCharacterName==
Line 199: Line 226:
 
</syntaxhighlight>
 
</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}}
 +
 +
;Returns
 +
* an IDManager for managing your own named events and timers
 +
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
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==
 +
; handlers = getNamedEventHandlers()
 +
 +
:Returns a list of all the named event handlers' names as a table.
 +
 +
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]]
 +
 +
{{MudletVersion|4.14}}
 +
 +
;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>
 +
 +
==registerNamedEventHandler==
 +
; success = registerNamedEventHandler(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.
 +
 +
;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()]]
 +
 +
{{MudletVersion|4.14}}
 +
 +
;Parameters
 +
* ''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
 +
* true if successful, otherwise errors.
 +
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
-- register a named event handler. Will call demonVitalsHandler(eventName, ...) when gmcp.Char.Vitals is raised.
 +
local ok = registerNamedEventHandler("DemonVitals", "gmcp.Char.Vitals", "demonVitalsHandler")
 +
if ok then
 +
  cecho("Vitals handler switched to demonVitalsHandler")
 +
end
 +
 +
-- something changes later, and we want to handle vitals with another function, demonBlackoutHandler()
 +
-- note we do not use "" around demonBlackoutHandler but instead pass the function itself. Both work.
 +
-- using the same handlerName ("DemonVitals") means it will automatically unregister the old handler
 +
-- and reregister it using the new information.
 +
local ok = registerNamedEventHandler("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
 +
local function handleInv()
 +
  local list = gmcp.Char.Items.List
 +
  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
 +
-- unless there is an error, in which case it throws the error and halts execution anyway. The return is
 +
-- in part for feedback when using the lua alias or other REPL window.
 +
registerNamedEventHandler("DemonInvCheck", "gmcp.Char.Items.List", handleInv, true)
 +
</syntaxhighlight>
 +
 +
==resumeNamedEventHandler==
 +
; success = resumeNamedEventHandler(handlerName)
 +
 +
:Resumes a named event handler with name handlerName and causes it to start firing once more
 +
 +
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#stopNamedEventHandler|stopNamedEventHandler()]]
 +
 +
{{MudletVersion|4.14}}
 +
 +
;Parameters
 +
* ''handlerName:''
 +
: The name of the handler to resume. Same as used when you called [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]]
 +
 +
;Returns
 +
* true if successful, false if it didn't exist.
 +
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
local resumed = resumeNamedEventHandler("DemonVitals")
 +
if resumed then
 +
  cecho("DemonVitals resumed!")
 +
else
 +
  cecho("DemonVitals doesn't exist, cannot resume it")
 +
end
 +
</syntaxhighlight>
  
 
==sendCharacterName==
 
==sendCharacterName==
Line 267: Line 420:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=Scripting Object Functions=
+
==stopAllNamedEventHandlers==
: A collection of functions that manipulate Mudlets scripting objects - triggers, aliases, and so forth.
+
; stopAllNamedEventHandlers(handlerName)
 +
 
 +
:Stops all named event handlers and prevents them from firing any more. Information is retained and handlers can be resumed.
 +
 
 +
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#stopNamedEventHandler|stopNamedEventHandler()]], [[Manual:Lua_Functions#resumeNamedEventHandler|resumeNamedEventHandler()]]
 +
 
 +
{{MudletVersion|4.14}}
 +
 
 +
;Example
 +
<syntaxhighlight lang="lua">
 +
stopAllNamedEventHandlers() -- emergency stop situation, most likely.
 +
</syntaxhighlight>
 +
 
 +
==stopNamedEventHandler==
 +
; success = stopNamedEventHandler(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.
  
==getButtonState==
+
;See also: [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]], [[Manual:Lua_Functions#resumeNamedEventHandler|resumeNamedEventHandler()]]
;getButtonState([ButtonNameOrID])
 
:This function can be used within checkbox button scripts (2-state buttons) to determine the current state of the checkbox.
 
  
: See also: [[#setButtonState|setButtonState()]].
+
{{MudletVersion|4.14}}
{{note}} Function can be used in any Mudlet script outside of a button's own script with parameter ButtonNameOrID available from Mudlet version 4.13.0+
 
  
 
;Parameters
 
;Parameters
* ''ButtonNameOrID:''
+
* ''handlerName:''
: a numerical ID or string name to identify the checkbox button.
+
: The name of the handler to stop. Same as used when you called [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]]
  
 
;Returns  
 
;Returns  
* ''2'' if the button has "checked" state, or ''1'' if the button is not checked. (or a ''nil'' and an error message if ButtonNameOrID did not identify a check-able button)
+
* true if successful, false if it didn't exist or was already stopped
  
;Example  
+
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- check from within the script of a check-able button:
+
local stopped = stopNamedEventHandler("DemonVitals")
local checked = getButtonState()
+
if stopped then
if checked == 1 then
+
  cecho("DemonVitals stopped!")
    hideExits()
 
 
else
 
else
    showExits()
+
  cecho("DemonVitals doesn't exist or already stopped; either way it won't fire any more.")
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
=Scripting Object Functions=
 +
: A collection of functions that manipulate Mudlets scripting objects - triggers, aliases, and so forth.
 +
 +
==deleteAllNamedTimers==
 +
; deleteAllNamedTimers(handlerName)
 +
 +
:Deletes all named timers and prevents them from firing any more. Information is deleted and cannot be retrieved.
 +
 +
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]]
 +
 +
{{MudletVersion|4.14}}
 +
 +
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- check from anywhere in another Lua script of the same profile (available from Mudlet 4.13.0)
+
deleteAllNamedTimers() -- emergency stop or debugging situation, most likely.
local checked, errMsg = getButtonState("Sleep")
 
if checked then
 
    shouldBeMounted = shouldBeMounted or false
 
    sendAll("wake", "stand")
 
    if shouldBeMounted then
 
        send("mount horse")
 
    end
 
else
 
    -- Global used to record if we were on a horse before our nap:
 
    shouldBeMounted = mounted or false
 
    if shouldBeMounted then
 
        send("dismount")
 
    end
 
    sendAll("sit", "sleep")
 
end
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==setButtonState==
+
==deleteNamedTimer==
;setButtonState(ButtonNameOrID, checked)
+
; success = deleteNamedTimer(handlerName)
:Sets the state of a check-able ("push-down") type button from any Mudlet item's script - but does not cause the script or one of the commands associated with that button to be run/sent.
+
 
{{MudletVersion|4.13}}
+
:Deletes a named timer with name handlerName and prevents it from firing any more. Information is deleted and cannot be retrieved.
 +
 
 +
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]]
 +
 
 +
{{MudletVersion|4.14}}
  
 
;Parameters
 
;Parameters
* ''ButtonNameOrID:''
+
* ''handlerName:''
: The name of the button as a string or a unique ID (positive) integer number {for a name only one matching one will be affected - it will be the same one that the matching [[#getButtonState|getButtonState()]] reports upon}.
+
: The name of the handler to stop. Same as used when you called [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
* ''checked:''
 
: boolean value that indicated whether the state required is down (''true'') or up (''false'').
 
 
 
;Returns:
 
* A boolean value indicating ''true'' if the visible state was actually changed, i.e. had any effect. This function will return a ''nil'' and a suitable error message if the identifying name or ID was not found or was not a check-able (push-down) button item (i.e. was a non-checkable button or a menu or a toolbar instead).
 
  
 +
;Returns
 +
* true if successful, false if it didn't exist
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- inside, for example, an initialization script for a GUI package:
+
local deleted = deletedNamedTimer("DemonVitals")
setButtonState("Sleep", false)
+
if deleted then
setButtonState("Sit", false)
+
  cecho("DemonVitals deleted forever!!")
-- these are going to be used as "radio" buttons where setting one
+
else
-- of them will unset all the others, they will each need something
+
  cecho("DemonVitals doesn't exist and so could not be deleted.")
-- similar in their own scripts to unset all the others in the set
 
-- and also something to prevent them from being unset by clicking
 
-- on themselves:
 
setButtonState("Wimpy", true)
 
setButtonState("Defensive", false)
 
setButtonState("Normal", false)
 
setButtonState("Brave", false)
 
if character.type == "Warrior" then
 
    -- Only one type has this mode - and it can only be reset by
 
    -- something dying (though that could be us!)
 
    setButtonState("Beserk!!!", false)
 
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=Networking Functions=
+
==getNamedTimers==
: A collection of functions for managing networking.
+
; timers = getNamedTimers()
 +
 
 +
:Returns a list of all the named timers' names as a table.
  
=String Functions=
+
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
: These functions are used to manipulate strings.
 
  
=Table Functions=
+
{{MudletVersion|4.14}}
: 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=
+
;Returns
: 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.
+
* a table of handler names. { "DemonVitals", "DemonInv" } for example. {} if none are registered
  
=UI Functions=
+
;Example
: These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation as well as displaying or formatting information on the screen.
+
<syntaxhighlight lang="lua">
 +
  local timers = getNamedTimers()
 +
  display(timers)
 +
  -- {}
 +
  registerNamedTimer("Test1", "testEvent", "testFunction")
 +
  registerNamedTimer("Test2", "someOtherEvent", myHandlerFunction)
 +
  timers = getNamedTimers()
 +
  display(timers)
 +
  -- { "Test1", "Test2" }
 +
</syntaxhighlight>
  
==addMouseEvent==
+
==registerNamedTimer==
; addMouseEvent(uniqueName, eventName, [displayName, tooltipText])
+
; success = registerNamedTimer(handlerName, eventName, functionReference, [repeating])
  
:Registers a new context menu option when right-clicked on a console window. Will return ''True'' if the event was added successfully, otherwise a warning will be thrown. If the ''displayName'' isn't set, ''uniqueName'' will be used for the menu label. ''eventName'' should be a Mudlet event that will handle the click data that includes ''event'', ''unique name'', ''window name'', selection upper left ''column'' and ''row'' and selection bottom right ''column'' and ''row'' in that order. This is intended to be used with available cursor functions for any selection or processing needs.
+
:Registers a named timer with name handlerName. Named timers are protected from duplication and can be stopped and resumed, unlike normal tempTimers.
  
{{MudletVersion|4.13}}
+
;See also: [[Manual:Lua_Functions#tempTimer|tempTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]], [[Manual:Lua_Functions#resumeNamedTimer|resumeNamedTimer()]], [[Manual:Lua_Functions#deleteNamedTimer|deleteNamedTimer()]], [[Manual:Lua_Functions#registerNamedEventHandler|registerNamedEventHandler()]]
  
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#moveCursor|moveCursor()]]
+
{{MudletVersion|4.14}}
  
 
;Parameters
 
;Parameters
* ''uniqueName:''
+
* ''handlerName:''
: A unique identifier for the mouse event.
+
: 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:''
 
* ''eventName:''
: Name of the Mudlet event that will handle the data.
+
: The name of the event the handler responds to. [[Manual:Event_Engine#Mudlet-raised_events|See here]] for a list of Mudlet-raised events.
* ''displayName:''
+
* ''functionReference:''
: (optional) Label text for the mouse context menu. If not set, the label defaults to ''uniqueName''.
+
: The function reference to run when the event comes in. Can be the name of a function, "handlerFuncion", or the lua function itself.
* ''tooltipText:''
+
* ''repeating:''
: (optional) Tooltip text when mouse is hovered on the option. If not set, no tooltip will be visible.
+
: (optional) if true, the timer continue to fire until the stop it using [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]]
 
 
 
;Returns  
 
;Returns  
* Returns ''True'' If the mouse event was added successfully.
+
* true if successful, otherwise errors.
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
-- An example showing implementing a hecho-friendly copy option:
+
-- establish a named timer called "Check balance" which runs balanceChecker() after 1 second
 +
-- it is started automatically when registered, and fires only once despite being run twice
 +
-- you wouldn't do this intentionally, but illustrates the duplicate protection
 +
registerNamedTimer("Check Balance", 1, balanceChecker)
 +
registerNamedTimer("Check Balance", 1, balanceChecker)
 +
 
 +
-- then the next time you want to make/use the same timer, you can shortcut it with
 +
resumeNamedTimer("Check Balance")
 +
</syntaxhighlight>
 +
 
 +
==resumeNamedTimer==
 +
; success = resumeNamedTimer(handlerName)
 +
 
 +
:Resumes a named timer with name handlerName and causes it to fire again. One time unless it was registered as repeating.
 +
 
 +
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]]
 +
 
 +
{{MudletVersion|4.14}}
  
addMouseEvent("hecho copy", "onMouseCopyExample")
+
;Parameters
 +
* ''handlerName:''
 +
: The name of the handler to resume. Same as used when you called [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
  
function rgbToHex(r,g,b)
+
;Returns
    local rgb = (r * 0x10000) + (g * 0x100) + b
+
* true if successful, false if it didn't exist. If the timer is waiting to fire it will be restarted at 0.
    return string.format("#%x", rgb)
 
end
 
  
function onMouseCopyExample(event, menu, window, startCol, startRow, endCol, endRow)
+
;Example
  -- Check whether there's an actual selection
+
<syntaxhighlight lang="lua">
  if startCol == endCol and startRow == endRow then return end
+
local resumed = resumeNamedTimer("DemonVitals")
  local parsed = ""
+
if resumed then
  local lastColor = nil
+
  cecho("DemonVitals resumed!")
  -- Loop through each symbol within the range
+
else
  for l = startRow, endRow do
+
  cecho("DemonVitals doesn't exist, so cannot resume it.")
    local cStart = l == startRow and startCol or 0
 
    moveCursor(window, cStart, l)
 
    local cEnd = l == endRow and endCol or #getCurrentLine() - 1
 
    for c = cStart, cEnd do
 
      selectSection(window, c, 1)
 
      local symbol = getSelection(window) or ""
 
      -- Convert the foreground color to a hex format, suitable for hecho
 
      local color = rgbToHex(getFgColor(window))
 
      -- Don't repeat the color if previous one was the same
 
      if color == lastColor then
 
        parsed = parsed .. symbol
 
      else
 
        lastColor = color
 
        parsed = parsed .. color .. symbol
 
      end
 
    end
 
    if l ~= endRow then parsed = parsed .. "\n" end
 
  end
 
  setClipboardText(parsed)
 
 
end
 
end
 
registerAnonymousEventHandler("onMouseCopyExample", "onMouseCopyExample")
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==closestColor==
+
==stopAllNamedTimers==
; closestColor(coloR[,G,B])
+
; stopAllNamedTimers(handlerName)
 
 
:Returns the closest color from the color_table to the one provided for use in cecho and associated functions.
 
  
{{MudletVersion|4.13}}
+
:Stops all named timers and prevents them from firing any more. Information is retained and timers can be resumed.
  
;Parameters
+
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#stopNamedTimer|stopNamedTimer()]], [[Manual:Lua_Functions#resumeNamedTimer|resumeNamedTimer()]]
* ''coloR:''
 
: Either the string representation of a color from decho or hecho (IE "#ff0077" or "<255,0,128>"), a table of color values (IE {255,0,18}), or the Red component of RGB
 
* ''G:''
 
: The Green component of RGB coordinates. Only needed if first parameter sent as the Red component only
 
* ''B:''
 
: The Blue component of RGB coordinates. Only needed if first parameter sent as the Red component only
 
  
;Returns
+
{{MudletVersion|4.14}}
* The closest color name from the color_table to the one supplied on success
 
* nil + error if it cannot parse the parameters into a color.
 
  
 
;Example
 
;Example
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
local colorName = closestColor(255, 0, 0) -- "ansi_light_red"
+
stopAllNamedTimers() -- emergency stop situation, most likely.
local colorName = closestColor({127, 255, 127}) -- "ansi_120"
 
local colorName = closestColor("<127, 127, 127>") -- "ansi_008"
 
local colorName = closestColor("#a020e6") -- "purple"
 
local colorName = closestColor("blue") -- "blue" (you wouldn't necessarily do this on purpose, but during automated color conversions this might occur)
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==removeMouseEvent==
+
==stopNamedTimer==
; removeMouseEvent(uniqueName)
+
; success = stopNamedTimer(handlerName)
  
:Removes an existing mouse event. Returns ''True'' If the event exists and was removed successfully, throws a warning if the event doesn't exist.
+
:Stops a named timer with name handlerName and prevents it from firing any more. Information is stored so it can be resumed later if desired.
  
{{MudletVersion|4.13}}
+
;See also: [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]], [[Manual:Lua_Functions#resumeNamedTimer|resumeNamedTimer()]]
  
;See also: [[Manual:Lua_Functions#getMouseEvents|getMouseEvents()]], [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]]
+
{{MudletVersion|4.14}}
  
 
;Parameters
 
;Parameters
* ''uniqueName:''
+
* ''handlerName:''
: A unique identifier that the mouse event was registered under.
+
: The name of the handler to stop. Same as used when you called [[Manual:Lua_Functions#registerNamedTimer|registerNamedTimer()]]
  
 
;Returns  
 
;Returns  
* Returns ''True'' If the mouse event was removed successfully.
+
* true if successful, false if it didn't exist or was already stopped
  
==getMouseEvents==
+
;Example
; events = getMouseEvents()
+
<syntaxhighlight lang="lua">
 +
local stopped = stopNamedTimer("DemonVitals")
 +
if stopped then
 +
  cecho("DemonVitals stopped!")
 +
else
 +
  cecho("DemonVitals doesn't exist or already stopped; either way it won't fire any more.")
 +
end
 +
</syntaxhighlight>
  
:Returns a table of registered mouse events, including any of the additional arguments they may have.
+
=Networking Functions=
 +
: A collection of functions for managing networking.
  
{{MudletVersion|4.13}}
+
=String Functions=
 +
: These functions are used to manipulate strings.
  
;See also: [[Manual:Lua_Functions#addMouseEvent|addMouseEvent()]], [[Manual:Lua_Functions#removeMouseEvent|removeMouseEvent()]]
+
=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.
  
;Returns
+
=Text to Speech Functions=
* Returns a table with mouse event ''uniqueName'' as indexes, containing all the creation arguments as the sub-table members.
+
: 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.
 +
 
 +
=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.

Revision as of 00:30, 17 October 2021

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.

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.

printDebug

printDebug(msg, [showStackTrace])
Prints a debug message in green to the error console in the script editor only. Does not echo to the debug window or the main console. Includes stack trace if showStackTrace is included and not nil or false.
See also
printError, debugc
Mudlet VersionAvailable in Mudlet4.14+

Note Note: This will not be echoed to the main console even if the option to echo Lua errors to the main console is turned on. Does not echo to the debug window. As such you can use it for debugging information without fear it will be shown unless someone goes looking for errors.

Parameters
  • msg:
string to echo to the error console
  • showStackTrace:
(optional) boolean true if you want to include the stack trace, leave off if you do not.
Example
-- print a debug message to the error console for troubleshooting purposes, when you don't want to echo the information to the main screen.
-- the only difference between this and debugc is this includes information on the script/alias/trigger/etc and line it was called from, whereas debugc does not.
printDebug("Switching to chaos mode")

-- Want to record that something occurred, and include stacktrace so you can see what path the code was taking, but you don't want to halt execution or have it show up in main screen or in scary red.
printDebug("Something unexpected occurred but we can recover from it. Still, we want to be able to notice and troubleshoot it with extra information.", true)

printError

printError(msg, [showStackTrace], [haltExecution])
Prints an error message in red to the error console in the script editor. Can optionally include stacktrace information and halt execution.
See also
printDebug, debugc
Mudlet VersionAvailable in Mudlet4.14+

Note Note: This WILL be echoed to the main console if the option to echo Lua errors to the main console is turned on. You should not use this for idle debugging information, but actual errors that may put big red error lines in the main window.

Parameters
  • msg:
string to echo to the error console
  • showStackTrace:
(optional) true if you want to include the stack trace, leave off if you do not.
  • haltExecution:
(optional) true if you want to halt execution. You must pass a value for showStackTrace in order to halt execution.
Example
-- print an error message but do not include extra stack information or halt execution.
-- this is similar to debugc except it include more information on the place it was called from
-- and will show up in red and echo to the main console if the option for errors to echo there is selected.
printError("Your maxhp is below your currenthp and our game doesn't allow for that. HAX?!")

-- Something bad happened, for sure, but your script can recover.
-- Make sure this is something important enough it might make it to the main window as a big red error.
-- but we are not halting execution, since we can carry on in some capacity
printError("gmcp values for this thing went missing, will carry on using defaults but you should tell somebody about this.", true)

-- print an error message to the error console for troubleshooting purposes. 
-- Prints stack trace for troubleshooting and halts execution (because you cannot continue without the configuration, presumably)
-- similar to using error(msg) but includes the stacktrace information.
printError("Our entire configuration seems to have gone missing!", true, true)

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.

mapSymbolFontInfo

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


setupMapSymbolFont

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.

deleteAllNamedEventHandlers

deleteAllNamedEventHandlers(handlerName)
Deletes all named event handlers and prevents them from firing any more. Information is deleted and cannot be retrieved.
See also
registerNamedEventHandler(), stopNamedEventHandler()
Mudlet VersionAvailable in Mudlet4.14+
Example
deleteAllNamedEventHandlers() -- emergency stop or debugging situation, most likely.

deleteNamedEventHandler

success = deleteNamedEventHandler(handlerName)
Deletes a named event handler with name handlerName and prevents it from firing any more. Information is deleted and cannot be retrieved.
See also
registerNamedEventHandler(), stopNamedEventHandler()
Mudlet VersionAvailable in Mudlet4.14+
Parameters
  • handlerName:
The name of the handler to stop. Same as used when you called registerNamedEventHandler()
Returns
  • true if successful, false if it didn't exist
Example
local deleted = deletedNamedEventHandler("DemonVitals")
if deleted then
  cecho("DemonVitals deleted forever!!")
else
  cecho("DemonVitals doesn't exist and so could not be deleted.")
end

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.

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: sendCharacterName(), sendCharacterPassword(), sendCustomLoginText(), getCustomLoginTextId().

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

Example
lua send("cast 'glamor' " .. getCharacterName())

You get a warm feeling passing from your core to the tips of your hands, feet and other body parts.
A small twittering bird settles on your shoulder and starts to look adoringly at you.
A light brown faun gambles around you and then nuzzles your hand.
A tawny long-haired cat saunters over and start to rub itself against your ankles.
A small twittering bird settles on your shoulder and starts to look adoringly at you.
A light brown faun gambles around you and then nuzzles your hand.
A small twittering bird settles on your shoulder and starts to look adoringly at you.
A mangy dog trots up to you and proceeds to mark the bottom of your leggings.

getCustomLoginTextId

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

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
registerNamedEventHandler(), registerNamedTimer()
Mudlet VersionAvailable in Mudlet4.14+
Returns
  • an IDManager for managing your own named events and timers
Example
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")

getNamedEventHandlers

handlers = getNamedEventHandlers()
Returns a list of all the named event handlers' names as a table.
See also
registerNamedEventHandler()
Mudlet VersionAvailable in Mudlet4.14+
Returns
  • a table of handler names. { "DemonVitals", "DemonInv" } for example. {} if none are registered
Example
  local handlers = getNamedEventHandlers()
  display(handlers)
  -- {}
  registerNamedEventHandler("Test1", "testEvent", "testFunction")
  registerNamedEventHandler("Test2", "someOtherEvent", myHandlerFunction)
  handlers = getNamedEventHandlers()
  display(handlers)
  -- { "Test1", "Test2" }

registerNamedEventHandler

success = registerNamedEventHandler(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.
See also
registerAnonymousEventHandler(), stopNamedEventHandler(), resumeNamedEventHandler(), deleteNamedEventHandler(), registerNamedTimer()
Mudlet VersionAvailable in Mudlet4.14+
Parameters
  • 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. 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
  • true if successful, otherwise errors.
Example
-- register a named event handler. Will call demonVitalsHandler(eventName, ...) when gmcp.Char.Vitals is raised.
local ok = registerNamedEventHandler("DemonVitals", "gmcp.Char.Vitals", "demonVitalsHandler")
if ok then
  cecho("Vitals handler switched to demonVitalsHandler")
end

-- something changes later, and we want to handle vitals with another function, demonBlackoutHandler()
-- note we do not use "" around demonBlackoutHandler but instead pass the function itself. Both work.
-- using the same handlerName ("DemonVitals") means it will automatically unregister the old handler
-- and reregister it using the new information.
local ok = registerNamedEventHandler("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
local function handleInv()
  local list = gmcp.Char.Items.List
  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
-- unless there is an error, in which case it throws the error and halts execution anyway. The return is
-- in part for feedback when using the lua alias or other REPL window.
registerNamedEventHandler("DemonInvCheck", "gmcp.Char.Items.List", handleInv, true)

resumeNamedEventHandler

success = resumeNamedEventHandler(handlerName)
Resumes a named event handler with name handlerName and causes it to start firing once more
See also
registerNamedEventHandler(), stopNamedEventHandler()
Mudlet VersionAvailable in Mudlet4.14+
Parameters
  • handlerName:
The name of the handler to resume. Same as used when you called registerNamedEventHandler()
Returns
  • true if successful, false if it didn't exist.
Example
local resumed = resumeNamedEventHandler("DemonVitals")
if resumed then
  cecho("DemonVitals resumed!")
else
  cecho("DemonVitals doesn't exist, cannot resume it")
end

sendCharacterName

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

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

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

stopAllNamedEventHandlers

stopAllNamedEventHandlers(handlerName)
Stops all named event handlers and prevents them from firing any more. Information is retained and handlers can be resumed.
See also
registerNamedEventHandler(), stopNamedEventHandler(), resumeNamedEventHandler()
Mudlet VersionAvailable in Mudlet4.14+
Example
stopAllNamedEventHandlers() -- emergency stop situation, most likely.

stopNamedEventHandler

success = stopNamedEventHandler(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
registerNamedEventHandler(), resumeNamedEventHandler()
Mudlet VersionAvailable in Mudlet4.14+
Parameters
  • handlerName:
The name of the handler to stop. Same as used when you called registerNamedEventHandler()
Returns
  • true if successful, false if it didn't exist or was already stopped
Example
local stopped = stopNamedEventHandler("DemonVitals")
if stopped then
  cecho("DemonVitals stopped!")
else
  cecho("DemonVitals doesn't exist or already stopped; either way it won't fire any more.")
end

Scripting Object Functions

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

deleteAllNamedTimers

deleteAllNamedTimers(handlerName)
Deletes all named timers and prevents them from firing any more. Information is deleted and cannot be retrieved.
See also
registerNamedTimer(), stopNamedTimer()
Mudlet VersionAvailable in Mudlet4.14+
Example
deleteAllNamedTimers() -- emergency stop or debugging situation, most likely.

deleteNamedTimer

success = deleteNamedTimer(handlerName)
Deletes a named timer with name handlerName and prevents it from firing any more. Information is deleted and cannot be retrieved.
See also
registerNamedTimer(), stopNamedTimer()
Mudlet VersionAvailable in Mudlet4.14+
Parameters
  • handlerName:
The name of the handler to stop. Same as used when you called registerNamedTimer()
Returns
  • true if successful, false if it didn't exist
Example
local deleted = deletedNamedTimer("DemonVitals")
if deleted then
  cecho("DemonVitals deleted forever!!")
else
  cecho("DemonVitals doesn't exist and so could not be deleted.")
end

getNamedTimers

timers = getNamedTimers()
Returns a list of all the named timers' names as a table.
See also
registerNamedTimer()
Mudlet VersionAvailable in Mudlet4.14+
Returns
  • a table of handler names. { "DemonVitals", "DemonInv" } for example. {} if none are registered
Example
  local timers = getNamedTimers()
  display(timers)
  -- {}
  registerNamedTimer("Test1", "testEvent", "testFunction")
  registerNamedTimer("Test2", "someOtherEvent", myHandlerFunction)
  timers = getNamedTimers()
  display(timers)
  -- { "Test1", "Test2" }

registerNamedTimer

success = registerNamedTimer(handlerName, eventName, functionReference, [repeating])
Registers a named timer with name handlerName. Named timers are protected from duplication and can be stopped and resumed, unlike normal tempTimers.
See also
tempTimer(), stopNamedTimer(), resumeNamedTimer(), deleteNamedTimer(), registerNamedEventHandler()
Mudlet VersionAvailable in Mudlet4.14+
Parameters
  • 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. 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.
  • repeating:
(optional) if true, the timer continue to fire until the stop it using stopNamedTimer()
Returns
  • true if successful, otherwise errors.
Example
-- establish a named timer called "Check balance" which runs balanceChecker() after 1 second
-- it is started automatically when registered, and fires only once despite being run twice
-- you wouldn't do this intentionally, but illustrates the duplicate protection
registerNamedTimer("Check Balance", 1, balanceChecker)
registerNamedTimer("Check Balance", 1, balanceChecker)

-- then the next time you want to make/use the same timer, you can shortcut it with
resumeNamedTimer("Check Balance")

resumeNamedTimer

success = resumeNamedTimer(handlerName)
Resumes a named timer with name handlerName and causes it to fire again. One time unless it was registered as repeating.
See also
registerNamedTimer(), stopNamedTimer()
Mudlet VersionAvailable in Mudlet4.14+
Parameters
  • handlerName:
The name of the handler to resume. Same as used when you called registerNamedTimer()
Returns
  • true if successful, false if it didn't exist. If the timer is waiting to fire it will be restarted at 0.
Example
local resumed = resumeNamedTimer("DemonVitals")
if resumed then
  cecho("DemonVitals resumed!")
else
  cecho("DemonVitals doesn't exist, so cannot resume it.")
end

stopAllNamedTimers

stopAllNamedTimers(handlerName)
Stops all named timers and prevents them from firing any more. Information is retained and timers can be resumed.
See also
registerNamedTimer(), stopNamedTimer(), resumeNamedTimer()
Mudlet VersionAvailable in Mudlet4.14+
Example
stopAllNamedTimers() -- emergency stop situation, most likely.

stopNamedTimer

success = stopNamedTimer(handlerName)
Stops a named timer with name handlerName and prevents it from firing any more. Information is stored so it can be resumed later if desired.
See also
registerNamedTimer(), resumeNamedTimer()
Mudlet VersionAvailable in Mudlet4.14+
Parameters
  • handlerName:
The name of the handler to stop. Same as used when you called registerNamedTimer()
Returns
  • true if successful, false if it didn't exist or was already stopped
Example
local stopped = stopNamedTimer("DemonVitals")
if stopped then
  cecho("DemonVitals stopped!")
else
  cecho("DemonVitals doesn't exist or already stopped; either way it won't fire any more.")
end

Networking Functions

A collection of functions for managing networking.

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.