Difference between revisions of "Manual:Miscellaneous Functions"

From Mudlet
Jump to navigation Jump to search
(added mudletOlderThan())
(→‎Miscellaneous Functions: updated syntax highlighting)
Line 8: Line 8:
 
;Example:
 
;Example:
  
<lua>
+
<syntaxhighlight lang="lua">
 
<event handlers that add support for MSDP... see http://www.mudbytes.net/forum/comment/63920/#c63920 for an example>
 
<event handlers that add support for MSDP... see http://www.mudbytes.net/forum/comment/63920/#c63920 for an example>
  
Line 14: Line 14:
 
local TN_MSDP = 69
 
local TN_MSDP = 69
 
addSupportedTelnetOption(TN_MSDP)
 
addSupportedTelnetOption(TN_MSDP)
</lua>
+
</syntaxhighlight>
  
 
===alert===
 
===alert===
Line 28: Line 28:
 
;Example:
 
;Example:
  
<lua>
+
<syntaxhighlight lang="lua">
 
-- flash indefinitely until Mudlet is open
 
-- flash indefinitely until Mudlet is open
 
alert()
 
alert()
Line 34: Line 34:
 
-- flash for just 3 seconds
 
-- flash for just 3 seconds
 
alert(3)
 
alert(3)
</lua>
+
</syntaxhighlight>
  
 
===closeMudlet===
 
===closeMudlet===
Line 47: Line 47:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
closeMudlet()
 
closeMudlet()
</lua>
+
</syntaxhighlight>
  
 
===denyCurrentSend===
 
===denyCurrentSend===
Line 57: Line 57:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- cancels all "eat hambuger" commands
 
-- cancels all "eat hambuger" commands
 
function cancelEatHamburger(event, command)
 
function cancelEatHamburger(event, command)
Line 67: Line 67:
  
 
registerAnonymousEventHandler("sysDataSendRequest", "cancelEatHamburger")
 
registerAnonymousEventHandler("sysDataSendRequest", "cancelEatHamburger")
</lua>
+
</syntaxhighlight>
  
 
===expandAlias===
 
===expandAlias===
Line 74: Line 74:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
expandAlias("t rat")
 
expandAlias("t rat")
  
 
-- don't echo the command
 
-- don't echo the command
 
expandAlias("t rat", false)
 
expandAlias("t rat", false)
</lua>
+
</syntaxhighlight>
  
 
{{note}} If you want to be using the ''matches'' table after calling ''expandAlias'', you should save it first as ''local oldmatches = matches'' before calling ''expandAlias'', since ''expandAlias'' will overwrite it after using it again.
 
{{note}} If you want to be using the ''matches'' table after calling ''expandAlias'', you should save it first as ''local oldmatches = matches'' before calling ''expandAlias'', since ''expandAlias'' will overwrite it after using it again.
Line 88: Line 88:
  
 
;Example:
 
;Example:
<lua>
+
<syntaxhighlight lang="lua">
 
-- try using this on the command line
 
-- try using this on the command line
 
`echo This is a sample line from the game
 
`echo This is a sample line from the game
Line 98: Line 98:
 
feedTriggers("\nThis is \27[1;32mgreen\27[0;37m, \27[1;31mred\27[0;37m, \27[46mcyan background\27[0;37m," ..
 
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")
 
"\27[32;47mwhite background and green foreground\27[0;37m.\n")
</lua>
+
</syntaxhighlight>
  
 
===getModulePath===
 
===getModulePath===
Line 109: Line 109:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
getModulePath("mudlet-mapper")
 
getModulePath("mudlet-mapper")
</lua>
+
</syntaxhighlight>
  
 
===getModulePriority===
 
===getModulePriority===
Line 120: Line 120:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
getModulePriority("mudlet-mapper")
 
getModulePriority("mudlet-mapper")
</lua>
+
</syntaxhighlight>
  
 
===getMudletHomeDir===
 
===getMudletHomeDir===
Line 129: Line 129:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- save a table
 
-- save a table
 
table.save(getMudletHomeDir().."/myinfo.dat", myinfo)
 
table.save(getMudletHomeDir().."/myinfo.dat", myinfo)
Line 135: Line 135:
 
-- or access package data. The forward slash works even on Windows fine
 
-- or access package data. The forward slash works even on Windows fine
 
local path = getMudletHomeDir().."/mypackagename"
 
local path = getMudletHomeDir().."/mypackagename"
</lua>
+
</syntaxhighlight>
  
 
===getMudletLuaDefaultPath===
 
===getMudletLuaDefaultPath===
Line 176: Line 176:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- see the full Mudlet version as text:
 
-- see the full Mudlet version as text:
 
getMudletVersion("string")
 
getMudletVersion("string")
Line 222: Line 222:
 
   ]]
 
   ]]
 
end
 
end
</lua>
+
</syntaxhighlight>
  
 
===getProfileName===
 
===getProfileName===
Line 232: Line 232:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- if connected to the Achaea profile, will print Achaea to the main console
 
-- if connected to the Achaea profile, will print Achaea to the main console
 
echo(getProfileName())
 
echo(getProfileName())
</lua>
+
</syntaxhighlight>
  
 
===getServerEncoding===
 
===getServerEncoding===
Line 244: Line 244:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
getServerEncoding()
 
getServerEncoding()
</lua>
+
</syntaxhighlight>
  
 
===getServerEncodingsList===
 
===getServerEncodingsList===
Line 255: Line 255:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- check if UTF-8 is available:
 
-- check if UTF-8 is available:
 
if table.contains(getServerEncodingsList(), "UTF-8") then
 
if table.contains(getServerEncodingsList(), "UTF-8") then
 
   print("UTF-8 is available!")
 
   print("UTF-8 is available!")
 
end
 
end
</lua>
+
</syntaxhighlight>
  
 
===installModule===
 
===installModule===
Line 273: Line 273:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
installModule([[C:\Documents and Settings\bub\Desktop\myalias.xml]])
 
installModule([[C:\Documents and Settings\bub\Desktop\myalias.xml]])
</lua>
+
</syntaxhighlight>
  
 
===installPackage===
 
===installPackage===
Line 288: Line 288:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
installPackage([[C:\Documents and Settings\bub\Desktop\myalias.xml]])
 
installPackage([[C:\Documents and Settings\bub\Desktop\myalias.xml]])
</lua>
+
</syntaxhighlight>
  
 
===loadWindowLayout===
 
===loadWindowLayout===
Line 301: Line 301:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
loadWindowLayout()
 
loadWindowLayout()
</lua>
+
</syntaxhighlight>
  
 
===mudletOlderThan===
 
===mudletOlderThan===
Line 318: Line 318:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- stop doing the script of Mudlet is older than 3.2
 
-- stop doing the script of Mudlet is older than 3.2
 
if mudletOlderThan(3,2) then return end
 
if mudletOlderThan(3,2) then return end
Line 330: Line 330:
 
-- if you'd like to check that coroutines are supported, do this instead:
 
-- if you'd like to check that coroutines are supported, do this instead:
 
if not mudlet.supportscoroutines then return end
 
if not mudlet.supportscoroutines then return end
</lua>
+
</syntaxhighlight>
  
 
===openWebPage===
 
===openWebPage===
Line 341: Line 341:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
openWebPage("http://google.com")
 
openWebPage("http://google.com")
</lua>
+
</syntaxhighlight>
  
 
===playSoundFile===
 
===playSoundFile===
Line 356: Line 356:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- play a sound in Windows
 
-- play a sound in Windows
 
playSoundFile([[C:\My folder\boing.wav]])
 
playSoundFile([[C:\My folder\boing.wav]])
Line 365: Line 365:
 
-- play a sound from a package
 
-- play a sound from a package
 
playSoundFile(getMudletHomeDir().. [[/mypackage/boingboing.wav]])
 
playSoundFile(getMudletHomeDir().. [[/mypackage/boingboing.wav]])
</lua>
+
</syntaxhighlight>
  
 
===registerAnonymousEventHandler===
 
===registerAnonymousEventHandler===
Line 374: Line 374:
  
 
;Example
 
;Example
<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
 
-- example taken from the God Wars 2 (http://godwars2.org) Mudlet UI - forces the window to keep to a certain size
 
function keepStaticSize()
 
function keepStaticSize()
Line 381: Line 381:
 
   
 
   
 
registerAnonymousEventHandler("sysWindowResizeEvent", "keepStaticSize")
 
registerAnonymousEventHandler("sysWindowResizeEvent", "keepStaticSize")
</lua>
+
</syntaxhighlight>
  
 
===reloadModule===
 
===reloadModule===
Line 390: Line 390:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
reloadModule("3k-mapper")
 
reloadModule("3k-mapper")
</lua>
+
</syntaxhighlight>
  
 
===resetProfile===
 
===resetProfile===
Line 405: Line 405:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
saveProfile()
 
saveProfile()
</lua>
+
</syntaxhighlight>
  
 
===saveWindowLayout===
 
===saveWindowLayout===
Line 418: Line 418:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
saveWindowLayout()
 
saveWindowLayout()
</lua>
+
</syntaxhighlight>
  
 
===sendSocket===
 
===sendSocket===
Line 428: Line 428:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
TN_IAC = 255
 
TN_IAC = 255
 
TN_WILL = 251
 
TN_WILL = 251
Line 444: Line 444:
 
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 msg = string.char( TN_IAC, TN_SB, TN_MSDP, MSDP_VAR ) .. " LIST " ..string.char( MSDP_VAL ) .. " COMMANDS " .. string.char( TN_IAC, TN_SE )
 
sendSocket( msg )
 
sendSocket( msg )
</lua>
+
</syntaxhighlight>
  
 
===setServerEncoding===
 
===setServerEncoding===
Line 457: Line 457:
  
 
;Example
 
;Example
<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.
 
-- use UTF-8 if Mudlet knows it. Unfortunately there's no way to check if the game's server knows it too.
 
if table.contains(getServerEncodingsList(), "UTF-8") then
 
if table.contains(getServerEncodingsList(), "UTF-8") then
 
   setServerEncoding("UTF-8")
 
   setServerEncoding("UTF-8")
 
end
 
end
</lua>
+
</syntaxhighlight>
  
 
===spawn===
 
===spawn===
Line 470: Line 470:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function
 
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function
 
local f = spawn(display, "ls")
 
local f = spawn(display, "ls")
 
display(f.isRunning())
 
display(f.isRunning())
 
f.close()
 
f.close()
</lua>
+
</syntaxhighlight>
  
 
===startLogging===
 
===startLogging===
Line 510: Line 510:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
stopSounds()
 
stopSounds()
</lua>
+
</syntaxhighlight>
  
 
===uninstallModule===
 
===uninstallModule===
Line 522: Line 522:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
uninstallModule("myalias")
 
uninstallModule("myalias")
</lua>
+
</syntaxhighlight>
  
 
===uninstallPackage===
 
===uninstallPackage===
Line 534: Line 534:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
uninstallPackage("myalias")
 
uninstallPackage("myalias")
</lua>
+
</syntaxhighlight>
  
 
===yajl.to_string===
 
===yajl.to_string===
Line 544: Line 544:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- on IRE MUDs, you can send a GMCP request to request the skills in a particular skillset. Here's an example:
 
-- on IRE MUDs, 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"})
 
sendGMCP("Char.Skills.Get "..yajl.to_string{group = "combat"})
Line 551: Line 551:
 
local toserialize = yajl.to_string(continents)
 
local toserialize = yajl.to_string(continents)
 
setRoomUserData(1, "areaContinents", toserialize)
 
setRoomUserData(1, "areaContinents", toserialize)
</lua>
+
</syntaxhighlight>
  
  
Line 560: Line 560:
  
 
;Example
 
;Example
<lua>
+
<syntaxhighlight lang="lua">
 
-- given the serialization example above with yajl.to_string, you can deserialize room userdata back into a table
 
-- given the serialization example above with yajl.to_string, you can deserialize room userdata back into a table
 
local tmp = getRoomUserData(1, "areaContinents")
 
local tmp = getRoomUserData(1, "areaContinents")
Line 567: Line 567:
 
local continents = yajl.to_value(tmp)
 
local continents = yajl.to_value(tmp)
 
display(continents)
 
display(continents)
</lua>
+
</syntaxhighlight>
  
 
[[Category:Mudlet Manual]]
 
[[Category:Mudlet Manual]]
 
[[Category:Mudlet API]]
 
[[Category:Mudlet API]]

Revision as of 04:10, 29 June 2017

Miscellaneous Functions

addSupportedTelnetOption

addSupportedTelnetOption(option)
Adds a telnet option, which when queried by a MUD server, Mudlet will return DO (253) on. Use this to register the telnet option that you will be adding support for with Mudlet - see additional protocols section for more.
Example
<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)

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.

Note Note: Available in Mudlet 3.2+

Parameters
  • seconds:
(optional) number of seconds to have the alert for. If not provided, Mudlet will flash until the user opens Mudlet again.
Example
-- flash indefinitely until Mudlet is open
alert()

-- flash for just 3 seconds
alert(3)

closeMudlet

closeMudlet()
Closes Mudlet and subsequently all profiles immediately.
See also: saveProfile()

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

Note Note: Available in Mudlet 3.1+

Example
closeMudlet()

denyCurrentSend

denyCurrentSend()
Cancels a send() or user-entered command, but only if used within a sysDataSendRequest event.
Example
-- 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")

expandAlias

expandAlias(command, true/false)
Runs the command as if it was from the command line - so aliases are checked and if none match, it's sent to the the game. If the second argument is false, it will hide the command from being echoed back in your buffer. Defaults to true.
Example
expandAlias("t rat")

-- don't echo the command
expandAlias("t rat", false)

Note Note: If you want to be using the matches table after calling expandAlias, you should save it first as local oldmatches = matches before calling expandAlias, since expandAlias will overwrite it after using it again.

feedTriggers

feedTriggers(text)
This function will have Mudlet parse the given text as if it came from the MUD - one great application is trigger testing. The built-in `echo alias provides this functionality as well.
Example
-- 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 MUDs. 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")

getModulePath

path = getModulePath(module name)
Returns the location of a module on the disk.
See also: installModule()

Note Note: Available in Mudlet 3.0+

Example
getModulePath("mudlet-mapper")

getModulePriority

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.
See also: setModulePriority()
Example
getModulePriority("mudlet-mapper")

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

getMudletLuaDefaultPath

getMudletLuaDefaultPath()
Returns the compiled in default location that this version of Mudlet tries as the last ditch attempt to find the luaGlobal.lua Lua script. luaGlobal.lua is the "loader" for all the Mudlet (and included Geyser but NOT Vyzor GUI management system packages) - failure to find this when a profile is loaded will be associated with a:

[ ERROR ] - LuaGlobal.lua compile error - please report!

message in the main console, instead of the expected:

[ OK ] - Mudlet-lua API & Geyser Layout manager loaded.

Note Note: This command is initially for *nix (but NOT MacOs) versions that need to support having shared, read-only copies of non-executable files used by an application in a directory that is not directly associated with that executable; for MacOs and Windows version it will not return a useful result either an empty string "" or a single slash "/". It is currently present only in the development branch of code in the GitHub repository and will not be included in the 3.0.0 release or it's previews.

getMudletVersion

getMudletVersion(style)
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 functions existence itself. Otherwise, checking for the version can come in handy if you'd like to test for a broken function or so on.

Note Note: Available since Mudlet 3.0.0-alpha.

Parameters
  • style:
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.
Values you can choose
  • "string":
Returns the full Mudlet version as text.
  • "table":
Returns the full Mudlet version as four values (multi-return)
  • "major":
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
-- see the full Mudlet version as text:
getMudletVersion("string")

-- check that the major Mudlet version is at least 3:
if getMudletVersion("major") >= 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

getProfileName

name = getProfileName()
Returns the name of the profile. Useful when combined with raiseGlobalEvent() to know which profile a global event came from.

Note Note: Available in Mudlet 3.1+

Example
-- if connected to the Achaea profile, will print Achaea to the main console
echo(getProfileName())

getServerEncoding

getServerEncoding()
Returns the current server data encoding in use.
See also: setServerEncoding(), getServerEncodingsList()
Example
getServerEncoding()

getServerEncodingsList

getServerEncodingsList()
Returns an indexed list of the server 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 encodings in Mudlet for the list of which encodings are available in which Mudlet version.
See also: setServerEncoding(), getServerEncoding()
Example
-- check if UTF-8 is available:
if table.contains(getServerEncodingsList(), "UTF-8") then
  print("UTF-8 is available!")
end

installModule

installModule(location)
Installs a Mudlet XML or zip as a module.
Parameters
  • location:
Exact location of the file install.
See also: uninstallModule()
Example
installModule([[C:\Documents and Settings\bub\Desktop\myalias.xml]])

installPackage

installPackage(location)
Installs a Mudlet XML or package.
Parameters
  • location:
Exact location of the xml or package to install.
See also: uninstallPackage()
Example
installPackage([[C:\Documents and Settings\bub\Desktop\myalias.xml]])

loadWindowLayout

loadWindowLayout
Resets the layout of userwindows (floating miniconsoles) to the last saved state.
See also: saveWindowLayout()

Note Note: Available in Mudlet 3.2+

Example
loadWindowLayout()

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 if mudletfunction then - it'll be much more readable and reliable.
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
-- 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,3,1) 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

openWebPage

openWebPage(URL)
Opens the browser to the given webpage.
Parameters
  • URL:
Exact URL to open.
Example
openWebPage("http://google.com")

playSoundFile

playSoundFile(fileName)
This function plays a sound file. On 2.0, it can play most sound formats and up to 4 sounds simulaneously and an there's no limit on simultaneous sounds since 3.0.
Parameters
  • fileName:
Exact path of the sound file.

See also: stopSounds()

Example
-- play a sound in Windows
playSoundFile([[C:\My folder\boing.wav]])

-- play a sound in Linux
playSoundFile([[/home/myname/Desktop/boingboing.wav]])

-- play a sound from a package
playSoundFile(getMudletHomeDir().. [[/mypackage/boingboing.wav]])

registerAnonymousEventHandler

registerAnonymousEventHandler(event name, function name)
Registers a function to an event handler, not requiring you to set one up via script.
At the moment, it's not possible to use handlers inside namespaces, or unregister them.
Example
-- example taken from the God Wars 2 (http://godwars2.org) Mudlet UI - forces the window to keep to a certain size
function keepStaticSize()
  setMainWindowSize(1280,720)
end -- keepStaticSize
 
registerAnonymousEventHandler("sysWindowResizeEvent", "keepStaticSize")

reloadModule

reloadModule(module name)
Reload a module (by uninstalling and reinstalling).
See also: installModule(), uninstallModule()
Example
reloadModule("3k-mapper")

resetProfile

resetProfile()
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. To use this function, call it and then receive input from the game - that will trigger Mudlet to do the reset.

saveProfile

saveProfile()
Saves the current Mudlet profile to disk, which is equivalent to pressing the "Save Profile" button.
Example
saveProfile()

saveWindowLayout

saveWindowLayout
Saves the layout of userwindows (floating miniconsoles), in case you'd like to load them again later.
See also: loadWindowLayout()

Note Note: Available in Mudlet 3.2+

Example
saveWindowLayout()

sendSocket

sendSocket(data)
Sends given binary data as-is to the MUD. You can use this to implement support for a new telnet protocol, simultronics login or etcetera.
Example
TN_IAC = 255
TN_WILL = 251
TN_DO = 253
TN_SB = 250
TN_SE = 240
TN_MSDP = 69

MSDP_VAL = 1
MSDP_VAR = 2

sendSocket( string.char( TN_IAC, TN_DO, TN_MSDP ) ) -- sends IAC DO MSDP

--sends: IAC  SB MSDP MSDP_VAR "LIST" MSDP_VAL "COMMANDS" IAC SE
local msg = string.char( TN_IAC, TN_SB, TN_MSDP, MSDP_VAR ) .. " LIST " ..string.char( MSDP_VAL ) .. " COMMANDS " .. string.char( TN_IAC, TN_SE )
sendSocket( msg )

setServerEncoding

setServerEncoding(encoding)
Makes Mudlet use the specified encoding for communicating with the game.
Parameters
  • encoding:
Encoding to use.
See also: getServerEncodingsList(), getServerEncoding()
Example
-- use UTF-8 if Mudlet knows it. Unfortunately there's no way to check if the game's server knows it too.
if table.contains(getServerEncodingsList(), "UTF-8") then
  setServerEncoding("UTF-8")
end

spawn

spawn(read function, process to spawn)
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().
Example
-- 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()

startLogging

startLogging(state)
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.
Parameters
  • state:
Required: logging state. Passed as a boolean
Returns (4 values)
  • 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).
  • fileName (string)
The log will be/is being written to the path/file name returned.
  • 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.
  • 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

stopSounds

stopSounds()
Stops all currently playing sounds.

Note Note: Available in Mudlet 3.0.

See also: playSoundFile()
Example
stopSounds()

uninstallModule

uninstallModule(name)
Uninstalls a Mudlet module with the given name.
See also: installModule()
Example
uninstallModule("myalias")

uninstallPackage

uninstallPackage(name)
Uninstalls a Mudlet package with the given name.
See also: installPackage()
Example
uninstallPackage("myalias")

yajl.to_string

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.
Example
-- on IRE MUDs, 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)


yajl.to_value

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