Difference between revisions of "Manual:Miscellaneous Functions"

From Mudlet
Jump to navigation Jump to search
Line 1: Line 1:
 
{{TOC right}}
 
{{TOC right}}
 
== Miscellaneous Functions ==
 
== Miscellaneous Functions ==
 
===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. 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:
 
<lua>
 
feedTriggers("\nYou sit yourself down.\n")
 
</lua>
 
:The function also accept ANSI color codes that are used in MUDs. A sample table can be found [http://codeworld.wikidot.com/ansicolorcodes here].
 
;Example:
 
<lua>
 
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")
 
</lua>
 
  
 
===expandAlias===
 
===expandAlias===
Line 40: Line 27:
 
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>
 +
 +
===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: [[Manual:Lua_Functions#setModulePriority|setModulePriority()]]
 +
 +
;Example
 +
<lua>
 +
getModulePriority("mudlet-mapper")
 
</lua>
 
</lua>
  
Line 55: Line 53:
 
</lua>
 
</lua>
  
 +
===installPackage===
 +
;installPackage(location)
 +
: Installs a Mudlet XML or package.
 +
 +
* ''location:''
 +
: Exact location of the xml or package to install.
 +
 +
: See also: [[#uninstallPackage | uninstallPackage()]]
 +
 +
;Example
 +
<lua>
 +
installPackage([[C:\Documents and Settings\bub\Desktop\myalias.xml]])
 +
</lua>
  
 
===playSoundFile===
 
===playSoundFile===
Line 104: Line 115:
 
display(f.isRunning())
 
display(f.isRunning())
 
f.close()
 
f.close()
</lua>
 
 
===installPackage===
 
;installPackage(location)
 
: Installs a Mudlet XML or package.
 
 
* ''location:''
 
: Exact location of the xml or package to install.
 
 
: See also: [[#uninstallPackage | uninstallPackage()]]
 
 
;Example
 
<lua>
 
installPackage([[C:\Documents and Settings\bub\Desktop\myalias.xml]])
 
 
</lua>
 
</lua>
  

Revision as of 02:36, 6 January 2013

Miscellaneous Functions

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

<lua> expandAlias("t rat")

-- don't echo the command expandAlias("t rat", false) </lua>

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

<lua> feedTriggers("\nYou sit yourself down.\n") </lua>

The function also accept ANSI color codes that are used in MUDs. A sample table can be found here.
Example

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

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

<lua> getModulePriority("mudlet-mapper") </lua>

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

<lua> -- save a table table.save(getMudletHomeDir().."/myinfo.dat", myinfo)

-- or access package data. The forward slash works even on Windows fine local path = getMudletHomeDir().."/mypackagename" </lua>

installPackage

installPackage(location)
Installs a Mudlet XML or package.
  • location:
Exact location of the xml or package to install.
See also: uninstallPackage()
Example

<lua> installPackage(C:\Documents and Settings\bub\Desktop\myalias.xml) </lua>

playSoundFile

playSoundFile(fileName)
This function plays a sound file. On 2.0, it can play most sound formats and up to 4 sounds simulaneously.
Parameters
  • fileName:
Exact path of the sound file.
Example

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

registerAnonymousEventHandler

registerAnonymousEventHandler(event name, function name)
Registers a function to an event handler, not requiring you to set one up via s cript.
At the moment, it's not possible to use handlers inside namespaces, or unregister them.
Example

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


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

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

uninstallPackage

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

<lua> uninstallPackage("myalias") </lua>