https://wiki.mudlet.org/api.php?action=feedcontributions&user=Rayth&feedformat=atomMudlet - User contributions [en]2024-03-29T12:07:27ZUser contributionsMediaWiki 1.35.0https://wiki.mudlet.org/index.php?title=Manual:Trigger_Engine&diff=2303Manual:Trigger Engine2014-06-14T20:29:15Z<p>Rayth: /* Multi-Line Triggers and Multi-Condition Triggers */</p>
<hr />
<div>=Trigger Engine=<br />
<br />
Unlike alias that define patterns that match on user input, triggers define patterns that match on MUD output. In other words, triggers react to text that has been sent by the MUD, whereas alias react to user commands that have been typed into the command line.<br />
<br />
==Simple Trigger Matching==<br />
[[File:Simple-trigger.png]]<br />
<br />
<br />
{{note}} QUICKSTART: Here is a simple '''[http://www.youtube.com/watch?v=URbwW41LBcQ&hd=1 video tutorial]''' on how to make basic triggers in Mudlet.<br />
<br />
<br />
To begin with, click on the "Add" button to create a new trigger. Then put the text pattern that you’d like to trigger on into the trigger conditions table on the right side of the screen above the script editor. Afterwards, chose the correct pattern type of your trigger pattern in the drop down list on the right side of the trigger pattern i.e. in the second column of the trigger pattern table. If you define multiple patterns in the same trigger, your trigger will run whenever any one of these patterns matches unless you chose the AND-trigger option, in which case the trigger will only fire if all patterns match within a specified amount of lines from the MUD. For more advanced information on AND and OR trigger see the corresponding AND/OR trigger section below. The next step is to define what should happen when the trigger matches. Usually, this will be done by a Lua script in the Lua editor below the table with the pattern list. In the beginning, you can simply chose the "highlight trigger" option to make your trigger highlight the text that it has triggered on or send a clear text command to the MUD whenever the trigger fires until you have learned enough Lua to more meaningful scripts. Clear text command can be defined in the "send plain text" input box next to the trigger name above the pattern table. Finally, you need to save the new trigger and then activate it with the padlock icon button. By default, new triggers are deactivated and thus will do nothing unless you explicitly activate them. Activated triggers show a green tick in the little blue box on the left side of the trigger name in the trigger tree on the left side of the script editor dialog. There is three ways to save your changes. 1. click on the save icon 2. adding a new trigger 3. clicking on another trigger item. Triggers that have not been saved yet cannot be activated. If you see a bug icon instead of an activation box, there is some error that prevents to activate your trigger. Check the error message above the pattern table.<br />
<br />
<blockquote>Example: You want to trigger on the word "pond" in a line such as: "The frog swims in the pond. Plop." All you need to do is add "pond" as a pattern and chose "substring" as a pattern type. Then enter the command you like to send to the MUD if the trigger matches. For example enter "drink water" into the "send plain text" input box and activate your new trigger. Your new trigger will send the command "drink water" to the MUD any time it sees the word "pond" somewhere in the MUD output.</blockquote><br />
<br />
==Simple Highlighter Triggers==<br />
<br />
'''<span style="color:blue">Beginners should use Mudlets automated highlight triggers in the beginning to get the hang of the different trigger and pattern types quicker. Click on the "highlight trigger" option and pick a foreground and a background color. When the trigger matches it automatically highlights its pattern. This is the most used form of triggers in mudding as it is a quick way of highlighting words that are important to you at the moment. This helps you spot things at a single glance instead of reading the entire text. You don’t have to know anything about scripting, regular expressions etc. to use highlight triggers. Just type in the word you like to be highlighted, select appropriate colors, save the new trigger and activate it.</span>'''<br />
<br />
More advanced users will often want to do custom highlighting from within scripts. This is how it works: If you want to highlight the word "pond" in the above example you have to add the following little Lua script to the script editor on the lower right side of the Script Editor window:<br />
<lua><br />
selectString( "pond", 1 )<br />
fg( "red " )<br />
bg( "blue" )<br />
resetFormat()<br />
</lua><br />
<br />
=="AND" and "OR" Condition Triggers==<br />
<br />
AND -Triggers execute their respective command or script only if all conditions in their respective conditions expression list are fulfilled. OR-Triggers execute when any one of their conditions is true. To make OR-Triggers you simply have to add a few conditions to the conditions list e.g. in our example: "pond", "frog", "Plop". The trigger will now also execute on lines like this: "A frog is green" or "You hear a loud Plop!" However, it will not execute on "With a loud plop the frog dived into the water." because "plop" in the line is in lower case letters and your condition specified a "P" in upper case. The simplest form of AND-Triggers in Mudlet are Trigger Chains or Filter Chains, whatever you’d like to call it.<br />
<br />
==Trigger Chains & Filter Chains==<br />
<br />
"Chains" and "filters" are different trigger group entities in Mudlet and serve completely different ends.<br />
<br />
===Chains===<br />
<br />
A chain is defined in Mudlet by making a trigger group and adding a trigger pattern to the group. A group without a pattern is a simple trigger group that serves no other purposes than adding structure to your trigger system in order to organize your triggers better. Such a normal trigger group will always grant access to its children unless it has been explicitly disabled (= all access to itself or any of its children is locked) either manually or by a script.<br />
<br />
A trigger group with a defined trigger pattern, however, will behave like a normal trigger and match if the pattern matches. Such a trigger group is called "chain head". A chain head will only grant access to its children if the trigger pattern has matched and the chain has been enabled. Thus, chains can be looked at as a mechanism to automatically enable and disable triggers or groups of triggers when a certain condition has been met i. e. the trigger pattern of the chain head has been matched. (However, technically this is not correct as disabled child triggers will not be invoked if the chain head matches. In other words, in chains you can still have enabled/disabled elements. The idea of a chain can better be described by necessary and sufficient condition - both of which need to be met before a child trigger is being run.)<br />
<br />
Adding child triggers to this group will add elements to the trigger chain. These chain elements will only be activated if the chain head has matched before and thus opened the trigger chain. The chain stays open until the "keep chain open for x lines" value has been reached. The default is 0 which means that the chain only stays open for the current line. When access to the chain has been granted all child triggers will be tested against the content of the current line. Consequently, trigger chains are a means to automatically enable/disable trigger groups without the hassle of enabling and disabling trigger groups manually. This has 2 important advantages: Chains are faster than conventional solutions and chains reduce the complexity of your scripts and greatly reduce the usual system bugs that inevitably go along with enable/disable trigger xy function calls as it’s very difficult and error prone to enable and disable your triggers correctly in large complex trigger systems. This is one of the most powerful features in Mudlet and should be used whenever possible.<br />
<br />
Let’s look at a practical example for a trigger chain:<br />
<br />
My newbie prompt on Achaea looks like this <code>500h, 500m ex-</code> when I have balance and <code>500h, 500m e-</code> when I have lost balance. We are going to develop a prompt detection trigger that raises the event gotPrompt and sets the variables <code>myBalance=true</code> or <code>myBalance=false</code> To begin with, we add a new trigger group and add the Perl regex pattern to detect the prompt:<br />
<br />
<code>^(\d+)h, (\d+)m</code><br />
<br />
The pattern reads in plain English: At the beginning of a prompt line there are is a number directly followed by the letter h, a comma, a space and another number followed by the letter h. Whenever this pattern matches the trigger will fire and we’ll know that we have a prompt line. We use the 2 numbers that we captured in our pattern to update our health and mana stats.<br />
<br />
Detecting balance is more difficult as balance is indicated by the letters ex- on the same line after the prompt and imbalance is indicated by the letters e-. As we have set a pattern in a trigger group (folder), the folder is turned into a trigger chain head. It will now only let data through to its children when its own pattern is matched. In other words, the child triggers of the trigger chain will only receive data on prompt lines. We are going to take advantage of this by adding two simple substring triggers to detect balance and imbalance. The balance trigger pattern is ex- and the imbalance detector pattern is e-.<br />
<br />
In the two balance detection triggers we now write <code>myBalance=false</code> and <code>myBalance=true</code> respectively plus a little echo on the screen that shows our current balance status.<br />
<br />
We could now add a call <code>deleteLine()</code> to the prompt detection trigger to erase the prompt from the screen if we don’t want to see it as we have computed all relevant information.<br />
<br />
===Filters===<br />
<br />
You can turn a trigger chain head into a filter by checking the "filter" option. This changes the content of what is forwarded as trigger text to the children triggers in the chain. Chains forward the content of the current line as trigger text whereas filters forward the matched pattern instead of the current line. In other words, the text of the current line is filtered according to the pattern of the filter. For example: You want to know the exits in the current room. The simplest solution is a simple filter on <code>You see exits to: (.*)</code> Then you simply add triggers to the filter chain such as <code>north</code>, <code>south</code>, <code>west</code>, <code>east</code> etc. The direction triggers will only be called if the filter head has matched.<br />
<br />
Imagine the following scenario: You want to collect some berries. You know that the room contains some berries if the room description contains the words "You are inside a forest. There are some strawberries." or "You are inside a forest. There are some blackberries." and there are always only one kind of berry in the room. You make a new substring trigger for this line, but instead of choosing a regular trigger, you chose to add a new trigger group. Now you add <code>You are inside a forest\. There are some (\w+)\.</code> as an Regular Expression to the expression list of the trigger group. '''<span style="color:blue">When adding conditions to a trigger group, the trigger group turns from an organizational unit into a filter unit, if the "filter" option is checked.</span>''' From now on this folder is a filter and will only let its matches pass through. In our case this is exactly what we want, because we don’t want to collect all sorts of berries, but we only want 2 particular kinds, namely, strawberries and blackberries, and we know that these berries can only be trusted if they are picked inside a forest as other areas may contain contaminated berries. Now you add two regular triggers to our berry-in-the-forest filter - one containing the condition: <code>strawberries</code> and the other one <code>blackberries</code>. Then we add the commands to pick the particular kind of berry to both triggers (send field). Now what happens is that as soon as a room description reads "You are inside a forest. There are some strawberries/blackberries." the filter will let the kind of berry pass through to our two berry triggers and they will issue commands to pick berries, if there are such berries. However, in any other situation the words "strawberries" and "blackberries" will NOT trigger a pick - only in the above scenario when the filter parent’s condition is met. This is a very nice way to solve complicated problems with a few easy filter chains. This example is trivial, but using filter chains will rapidly show you how formerly complicated things that could only be solved with very complicated regular expressions can be solved easily now with a couple of filter chains.<br />
<br />
==Multi-Line Triggers and Multi-Condition Triggers==<br />
<br />
Multi Condition Triggers are the most advanced feature of Mudlets trigger engine. Like trigger chains or filter chains they are a form of AND-Triggers. All conditions in the list must have matched within the specified margin of lines (delta), in order to trigger the script. Normal triggers fire and run the script as soon as one of the conditions in the regex list is met i.e. if one of the regex/string matches match - or the Lua function condition returns true, the trigger script is run. In multiline triggers, however, each single regex/string/Lua function condition in the list has to have matched within the specified margin of lines at least once to trigger the script. The sequence of the conditions is binding. This means that if the 10th regex on the regex list would be matched on the eleventh line after the match of the first line happened, the trigger will NOT run unless the margin of lines is set to 11. If condition #3 is true but currently #2 is waiting to be true, condition #3 is ignored and must be true again after condition #2 has been true. Conditions can also be Lua Functions or plain Lua code that returns a boolean truth value. You can mix all types of conditions to build complex multi-condition triggers that only fire if all conditions are met. This is a very powerful feature as it reduces the amount of scripting to a minimum or even takes away with the need to script formerly complex processes completely. Multicondition triggers are multi-line triggers, i. e. the conditions can all be met in a single line or many lines after the first condition has been fulfilled. This effectively reduces the amount of complexity as you have all the important conditions placed into a single trigger and all the tedious bookkeeping, variable and condition state accounting is being done by Mudlets trigger engine. The result of this is that the amount of manual condition checking via many different trigger scripts and legions of if condition1 == true then check condition2 can be forgotten about. All you have to do is to define the conditions and the final action that is taken if the trigger fires.<br />
<br />
{{note}} to retrieve wildcards in multi-line or multi-condition triggers, use the '''multimatches[line][match]''' table instead of matches[].<br />
<br />
[[File:Trigger-engine-diagram.png|left|text-bottom]] <br />
<!-- Add a bunch of spaces here to align the text to the middle of the image--><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<!-- End Add Spacing --><br />
{{Note}} This diagram shows what steps are involved in the process of problem solving with Mudlets trigger engine. The main question is: How do we arrive at a solution to our problem, and how can we simplify the problem as much as possible?<br />
<br style="clear: both" /><br />
Example: Let’s go back to our pond & frog example. We have explained the difference between AND-triggers and OR-triggers. If you have a room description consisting of 3 lines:<br />
<div style="width:100%; background:#F0F0F0; margin-top:1.2em; border:1px solid #ccc; color:#0000FF;"><br />
# You see a pond<br />
# You see a frog.<br />
# The frog sits on a stong.<br />
</div><br />
<br />
Every single one of these 3 lines will be fed into the trigger engine one after another. If we define an OR-trigger with a condition list consisting of 3 condition patterns:<br />
<br />
condition #1 pattern = pond condition #2 pattern = frog condition #3 pattern = stone<br />
<br />
Whether or not a condition is found to be true also depends on another property, namely the type of the condition. The condition type can be among others:<br />
<br />
<div style="width:100%; background:#F0F0F0; border:1px solid #ccc; color:#000;"><br />
# substring matching → the condition is true if the condition pattern is a substring of the output line from the MUD. In other words: If the pattern "pond" is contained in any line of output, the condition is true.<br />
# begin of line matching → the condition is only true if the condition pattern can be found at the beginning of a line from the MUD.<br />
# Perl regular expression → the condition is true if the Perl regex pattern is matched. You’ll find more information on Perl regex below.<br />
# Lua code that returns a truth value e.g. a call to a function check() that return either true or false depending on the condition<br />
</div><br />
In our example we chose condition type "substring" for all three conditions. Consequently, the trigger will fire the command or script 3 times i. e. the trigger will do on each line it is matched against because in every line at least one condition evaluates to true because the pattern is a substring of the line.<br />
<br />
<div style="width:100%; background:#F0F0F0; border:1px solid #ccc; color:#000;"><br />
in line #1 we get: pond = true.<br />
in line #2 we get frog = true and<br />
in line #3 two conditions are true i.e. frog=true and stone = true<br />
</div><br />
<br />
Because an OR-trigger fires on the first condition that is true and ignores the rest the trigger will only execute 3 times on these 3 lines although 4 conditions are true.<br />
<br />
{{note}} <span style="color:#0000FF;">'''CAUTION:''' The multi line condition switch must be turned off to get an OR-trigger! If the multi-line condition switch is turned on the trigger becomes an AND trigger which means that the trigger only fires if all conditions are true and fulfilled in the correct sequence. With OR-triggers the sequence is irrelevant.</span><br />
<br />
To complicate matters, however, you don’t want your trigger to fire 3 commands, because you want to use this room description as a whole to fire your trigger e. g. this pond is the only kind of ponds in the entire world that doesn’t have poisoned water. So you want to make sure that you only drink water from a pond of this kind and from no other pond. Your solution is to use Multi Condition Triggers (MCT). If you check the MCT checkbox this trigger will fire only once from now on - and only if all conditions are met i e. when you can guarantee that you only drink water from a good pond because your drinking trigger is matching on the entire room description despite that this room description my be spread over a number of lines. (NOTE: If you have word wrap turned off in your MUD chances are that the entire room description will be contained in a single line, but we are trying to keep the examples as easy as possible.)<br />
<br />
Sadly, there are many unfriendly people in this world and somebody goes around and poisons your good ponds. Consequently, you would want to examine the frog and find out if it is poisoned before drinking water from the pond. This is difficult because the villain is a mean magician who used illusion spells to make everything look like the good pond. To solve the problem you can now resort to Lua function conditions in the trigger condition list that perform certain check ups to put the current room description into a wider context e. g. check if you have been here before etc. This adds yet another level of complexity to your problem but this is a very powerful means to use the full potential of Mudlets MCTs.<br />
<br />
You can combine all forms of conditions with trigger chains, filters and Lua functions. Mudlet gives you relatively easy to use tools that require no programming background. However, these tools can evolve into complex powerful problem solving mechanisms if they are combined with each other thus enabling non-programmer users to solve problems that would need a profound programming background in other MUD clients. However, unlocking the full potential of Mudlet requires you do learn some Lua basics. In this manual we’ll try to be as easy on you as we can in this respect, but it’s highly recommended that you dig deeper into Lua after a while. It’s one of the easiest fully fledged scripting languages available, easy to learn and the fastest of them all, and this is why it has been chosen by us. You don’t need to become a programmer to be able to use Mudlet effectively. All you have to know is how to work with variables and how to do if conditions and maybe a few loops. But knowing more won’t harm you and it will make your systems more effective.<br />
<br />
==Lua Code Conditions & Variable Triggers - Expression Triggers==<br />
<br />
In a Lua Code/Function Condition (LFC) you can run Lua code inside the trigger engine directly, as a trigger pattern. If the trigger pattern returns anything Lua considers true (false in Lua is only ''nil'' and the boolean ''false'' value, everything else is true), then the pattern will be considered to have matched. The easiest example would be a simple variable trigger: add a new trigger and chose pattern type '''Lua function'''. Then define this pattern: <code>if health ⇐ 100 then escape() end</code>. If your health is lower than 100, and your escape function with more logic inside it returns true, the pattern will match. Another formulation of the same would be: <code>checkHealth()</code>. For the last formulation to work you have defined a Lua function <code>checkHealth()</code>. Open the script editor, add a new script "health care" and add this code to the new script-script.<br />
<lua><br />
function checkHealth()<br />
if health <= 100 then<br />
echo( "WARNING: Low health! I have to run away!\n" )<br />
startEscape()<br />
return true<br />
else<br />
return false<br />
end<br />
end<br />
</lua><br />
<br />
{note} Mudlet used to only allow the boolean ''true'' value as the return value to consider the pattern to have been a match. It has since been improved to allow any value Lua would consider true - but if you see any LFCs making use of ''and true or false'' at the end, that'd be why.<br />
<br />
'''Lua Syntax Primer: Expressions'''<br />
<lua><br />
if A == B then (...) ----> if A equals B<br />
if A ~= B then (...) ----> if A *NOT* equals B<br />
if A <= B then (...) ----> if A is smaller or equal to B<br />
if A >= B then (...) ----> if A is greater or equal to B<br />
if A < B then (...) ----> if A is smaller than B<br />
if A > B then (...) ----> if A is greater than B<br />
</lua><br />
The operators ''and'' and ''or'' behave differently in Lua than in most other programming languages as they are not guaranteed to return a boolean value.[http://hisham.hm/2011/05/04/luas-and-or-as-a-ternary-operator/]<br />
<br />
Lua function conditions effectively means that you run the Lua code they represent on every single line that is received from the MUD, unless the LFCs are part of a multi-condition trigger, in which case the LFCs would only be run when they would be the current test-condition of their respective trigger state. LFCs are implemented in such a way that the trigger engine only calls the compiled byte code, but running as few scripts as possible is always the best idea. LFCs are nice and handy, and for most people the performance aspect will not be relevant at all.<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Mudlet_Packages&diff=2275Manual:Mudlet Packages2014-03-03T21:53:58Z<p>Rayth: Undo revision 2262 by Domtheo (talk)</p>
<hr />
<div>{{TOC right}}<br />
= What is a Mudlet package =<br />
It's a archive file that ends with ''.mpackage'' or ''.zip'' that contains xml files to import along with any resources a package might have (images, sounds and etc). Packages can be installed / uninstalled via a window in Mudlet.<br />
<br />
The system is backwards-compatible and existing ''.xml'' files will also be recognized as packages.<br />
<br />
You'll see packages represented in brown in the script editor everywhere - triggers, aliases, etc. All items of a package have to go into a package folder that they belong in - so the user can know which package do items belong to, and modify the package for their needs (if it didn't have a folder, then you wouldn't be able to 'add' anything to a package).<br />
<br />
Mudlet Packages were introduced to Mudlet in the '''2.0''' release.<br />
<br />
= How to install a Mudlet package =<br />
== manually ==<br />
Toolbox→Package Manager will open the window where you can 'Install' to install a package.<br />
<br />
(xmls installed via ''Import'' will be converted to packages too, but do not ''Import'' packages.)<br />
<br />
== from the MUD ==<br />
<br />
Packages can also be auto-installed from the MUD server via ATCP or GMCP - see [[Manual:ATCP_Extensions|ATCP extensions]] or [[Manual:GMCP_Extensions|GMCP extensions]] for more.<br />
<br />
= How to create a Mudlet package =<br />
Create a zip file that ends with either ''.mpackage'' (preferred) or ''.zip''. Include all xml's that you'd like to be installed in the top level folder of the package (that is, don't have them within a folder in the archive - just have them be upfront).<br />
<br />
== Naming the package ==<br />
Add a file at the top level of the package (so not inside any folders in the package) called '''config.lua''' that has the following line to name your package:<br />
<br />
<lua><br />
mpackage = "<name of your package>"<br />
</lua><br />
<br />
That's it. If you don't include config.lua, Mudlet will then deduce the package name from the file name.<br />
<br />
== Including images, sounds, and other files ==<br />
If you'd like to include other folders or files in the package, you can - they will be copied into ''getMudletHomeDir().."/"..packagename'' upon installation, so your scripts can use them. For example, if your package is called "sipper" and you have health.png as an image in it, you can place on a label like so:<br />
<br />
<lua><br />
-- you don't have to worry about \ versus / for file paths - use / everywhere, Lua will make it work on Windows fine<br />
<br />
setBackgroundImage("my health label", getMudletHomeDir().."/sipper/health.png")<br />
</lua><br />
<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Contents&diff=2274Manual:Contents2014-03-03T21:53:39Z<p>Rayth: Undo revision 2261 by Domtheo (talk)</p>
<hr />
<div><!--{{Hubs|banner|dev=y|admin=y}}--><br />
[[File:Mudlet-Manual.png|right|175px|Mudlet documentation]]<br />
This is a '''technical manual for the Mudlet software'''. It contains information for '''developers''' and '''end users''' on '''using''' and '''developing''' for the Mudlet software.<br />
<br />
<!--This manual is '''not for end users''' of MediaWiki. If you are looking for '''documentation to help you use MediaWiki, read the [[Help:Contents|MediaWiki Handbook]].'''--><br />
<br />
==Main sections==<br />
{| class="MainPageBG" style="width:100%; border:1px solid #c9c07f; background:#fdf7bb; vertical-align:top; color:#000;" |<br />
!- style="width:50%; vertical-align:top; padding-left:2px border:none" |<br />
==For End Users==<br />
!- style="width:50%; vertical-align:top; padding-left:2px border:none" |<br />
==For Developers==<br />
|-<br />
| style="width:50%; vertical-align:top; border:none" |<br />
; Guide to using Mudlet client.<br />
[[Manual:Introduction|Introduction to Mudlet]] | [[Manual:Technical Manual|Technical Manual]] | [[Manual:Migrating|Migrating to Mudlet]]<br />
; Enhancing your Mudlet experience.<br />
[[Manual:Scripting|Scripting]] | [[Manual:Lua Functions | Lua API and Reference]] | [[VyzorGuide|Vyzor Guide]] | [[Manual:Geyser| Geyser Guide]]<br />
| style="width:50%; vertical-align:top; border:none" |<br />
; Architecture<br />
: An overview of the key parts of Mudlet's source code.<br />
: [[Manual:Code|Code]] | [[Manual:Global object variables|Global object variables]] | [[Compiling Mudlet | Compiling Mudlet]]<br />
|}<br />
<br />
=== Others ===<br />
; [[FAQ|Mudlet FAQ]]<br />
: Frequently asked questions about Mudlet.<br />
<br />
== Browsing the manual ==<br />
There are multiple ways to browse through the documentation. Readers having trouble finding a particular topic in the section above or the [[#Categories|category]] list may find the following ways of browsing to be helpful.<br />
* [[Special:Allpages/Manual:]] - An automatically generated list of all pages in the Manual: namespace.<br />
* [[:Category:Mudlet Manual]] - the top-level Manual category<br />
<br />
== Improving the manual ==<br />
* There are still a lot of holes in this manual! See the [[Manual:To do|'to do' page]] for details.<br />
* There is still content on [http://mudlet.git.sourceforge.net/git/gitweb.cgi?p=mudlet/mudlet;a=blob_plain;f=src/mudlet_documentation.html;hb=HEAD The Mudlet Manual] which may need to be migrated. If you can't find information on a particular issue in this documentation, please visit [http://mudlet.org/forums The Mudlet Forum] and ask your question there and someone will help you.<br />
* '''[[Project:Manual]]''' is a place to discuss and co-ordinate the development of the Manual: namespace.<br />
* See also [[Project:Current issues]].<br />
<!--<br />
{{Languages}}<br />
<br />
{{Categories}}<br />
<br />
{{Mudlet Manual list}}<br />
--><br />
[[Category: Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Contents&diff=2273Manual:Contents2014-03-03T21:53:26Z<p>Rayth: Undo revision 2264 by Domtheo (talk)</p>
<hr />
<div><!--{{Hubs|banner|dev=y|admin=y}}--><br />
[[File:Mudlet-Manual.png|right|175px|Mudlet documentation]]<br />
This is a '''technical manual for the Mudlet software'''. It contains information for '''developers''' and '''end users''' on '''using''' and '''developing''' for the Mudlet software.<br />
<br />
<!--This manual is '''not for end users''' of MediaWiki. If you are looking for '''documentation to help you use MediaWiki, read the [[Help:Contents|MediaWiki Handbook]].'''--><br />
<br />
==Main sections==<br />
{| class="MainPageBG" style="width:100%; border:1px solid #c9c07f; background:#fdf7bb; vertical-align:top; color:#000;" |<br />
!- style="width:50%; vertical-align:top; padding-left:2px border:none" |<br />
==For End Users==<br />
!- style="width:50%; vertical-align:top; padding-left:2px border:none" |<br />
==For Developers==<br />
|-<br />
| style="width:50%; vertical-align:top; border:none" |<br />
; Guide to using Mudlet client.<br />
[[Manual:Introduction|Introduction to Mudlet]] | [[Manual:Technical Manual|Technical Manual]] | [[Manual:Migrating|Migrating to Mudlet]]<br />
; Enhancing your Mudlet experience.<br />
[[Manual:Scripting|Scripting]] | [[Manual:Lua Functions | Lua API and Reference]] | [[VyzorGuide|Vyzor Guide]] | [[Manual:Geyser| Geyser Guide]]<br />
| style="width:50%; vertical-align:top; border:none" |<br />
; Architecture<br />
: An overview of the key parts of Mudlet's source code.<br />
: [[Manual:Code|Code]] | [[Manual:Global object variables|Global object variables]] | [[Compiling Mudlet | Compiling Mudlet]]<br />
|}<br />
<br />
=== Others ===<br />
; [[FAQ|Mudlet FAQ]]<br />
: Frequently asked questions about Mudlet.<br />
<br />
== Browsing the manual ==<br />
There are multiple ways to browse through the documentation. Readers having trouble finding a particular topic in the section above or the [[#Categories|category]] list may find the following ways of browsing to be helpful [http://www.grosir-kosmetik.com/62-glutera.html Glutera].<br />
* [[Special:Allpages/Manual:]] - An automatically generated list of all pages in the Manual: namespace.<br />
* [[:Category:Mudlet Manual]] - the top-level Manual category<br />
<br />
== Improving the manual ==<br />
* There are still a lot of holes in this manual! See the [[Manual:To do|'to do' page]] for details.<br />
* There is still content on [http://www.awanirentcar.com/pricelist Sewa mobil jakarta] which may need to be migrated. If you can't find information on a particular issue in this documentation, please visit [http://www.tokobungasabana.com Toko bunga jakarta] and ask your question there and someone will help you.<br />
* '''[[Project:Manual]]''' is a place to discuss and co-ordinate the development of the Manual: namespace.<br />
* See also [[Project:Current issues]].<br />
<!--<br />
{{Languages}}<br />
<br />
{{Categories}}<br />
<br />
{{Mudlet Manual list}}<br />
--><br />
[[Category: Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Supported_Protocols&diff=2272Manual:Supported Protocols2014-03-03T21:52:18Z<p>Rayth: Undo revision 2269 by Domtheo (talk)</p>
<hr />
<div>{{TOC right}}<br />
= Supported Protocols =<br />
<br />
Mudlet supports GMCP, ATCP, Aardwolfs 102 and and the MXP Protocol. MXP, ATCP and 102 are enabled by default, while GMCP can be [http://wiki.mudlet.org/images/e/e7/Enable_gmcp.png enabled in settings].<br />
<br />
==GMCP==<br />
GMCP is a protocol for MUD servers to communicate information with MUD clients in a separate channel from the one which carries all of the text that makes up the game itself. Mudlet can be configured to use GMCP by clicking on the Settings button (or Options->Preferences in the menu, or <alt>p). The option is on the General tab. <br />
Once GMCP is enabled, you will need to reconnect to the MUD so that Mudlet can inform the server it is ready to receive GMCP information. Mudlet will automatically enable some GMCP modules for you once GMCP has been enabled. To get an idea of what information is available, you can use<br />
<lua><br />
display(gmcp)<br />
</lua><br />
<br />
When working with GMCP on IRE games, their [http://ironrealms.com/gmcp-doc GMCP reference] is a useful tool.<br />
<br />
===Using GMCP===<br />
====Receiving GMCP Data====<br />
To "trigger" on GMCP messages, you'll need to create [[Manual:Technical_Manual#Event_System|an event handler]] - Mudlet will call it for you whenever relevant GMCP data is received.<br />
<br />
As an example, create a new script and give it a name of the function you'd like to be called when the relevant GMCP message is received. Then, add the GMCP event you'd like the function to fire on under the registered event handlers left. Lastly, define the function - either in this or any other script - and you'll be done. The GMCP data received will be stored in the corresponding field of the ''gmcp'' table, which your function will read from.<br />
<br />
Example:<br />
<br />
[[File:using_gmcp.png]]<br />
<br />
The ''test_gmcp()'' function will be called whenever ''Char.Vitals'' is received from the game, and it'll echo the latest data on the screen.<br />
<br />
====Sending GMCP Data====<br />
Certain modules will only send data when a request is made by your client. In Mudlet, you can make such a request using the command '''sendGMCP("command")'''. Read your MUD's relevant documentation, such as the [http://www.ironrealms.com/gmcp-doc IRE document on GMCP], for information about specific modules.<br />
<br />
:See Also: [[Manual:Miscellaneous Functions#sendGMCP | sendGMCP]]<br />
<br />
===Managing GMCP Modules===<br />
While some GMCP modules are enabled by Mudlet by default when you connect with a GMCP enabled MUD, others may not be 'standard' modules and are instead specific to the MUD itself. In order to provide a way to manage GMCP modules without scripts causing modules in use by other scripts to be disabled.<br />
{{note}} The gmod lua module has been included with Mudlet (rc2.0+). <br />
<br />
====Registering User====<br />
While this step is no longer strictly required, you can register your 'user' with gmod using<br />
<lua><br />
gmod.registerUser("MyUser")<br />
</lua><br />
Where ''MyUser'' is your plugin/addon/whatever name. However, your user will be automatically registered if you enable or disable any modules using it. Which leads us to...<br />
<br />
====Enabling Modules====<br />
Enabling a GMCP module is as easy as:<br />
<lua><br />
gmod.enableModule("MyUser", "Module.Name")<br />
</lua><br />
<br />
If MyUser has not been registered previously, then they will be automatically registered when you call this function. An example of a module which would need to be enabled this way is the IRE.Rift module provided by IRE MUDs. <br />
<lua><br />
-- add this to a login trigger, or anything that will get done just once per login<br />
gmod.enableModule("<character name>", "IRE.Rift")<br />
</lua><br />
<br />
Another example would be the Combat module in Lithmeria, which isn't enabled by default:<br />
<lua><br />
-- add this to a login trigger, or anything that will get done just once per login<br />
gmod.enableModule("<character name>", "Combat")<br />
</lua><br />
<br />
====Disabling Modules====<br />
Disabling a GMCP module is just as easy as enabling it:<br />
<lua><br />
gmod.disableModule("MyUser", "Module.Name")<br />
</lua><br />
The main difference being that the module will be turned on as soon as you enable it if it is not already enabled. If you disable it, it will not be disabled with the server until every user of that module has disabled it. This prevents script A from disabling modules that script B may still be using.<br />
<br />
===Through GMCP tutorial===<br />
A good GMCP tutorial that walks you through receiving and sending GMCP data is [http://www.mudlet.org/wp-content/uploads/2011/10/GMCPtutorial.pdf available here] - take a read!<br />
<br />
==ATCP==<br />
<br />
Since version 1.0.6, Mudlet includes support for ATCP. This is primarily available on IRE-based MUDs, but Mudlets impelementation is generic enough such that any it should work on others.<br />
<br />
The latest ATCP data is stored in the atcp table. Whenever new data arrives, the previous is overwritten. An event is also raised for each ATCP message that arrives. To find out the available messages available in the atcp table and the event names, you can use display(atcp).<br />
<br />
Note that while the typical message comes in the format of Module.Submodule, ie Char.Vitals or Room.Exits, in Mudlet the dot is removed - so it becomes CharVitals and RoomExits. <br />
;Example<br />
<lua><br />
room_number = tonumber(atcp.RoomNum)<br />
echo(room_number)<br />
</lua><br />
<br />
===Triggering on ATCP events===<br />
<br />
If you’d like to trigger on ATCP messages, then you need to create scripts to attach handlers to the ATCP messages. The ATCP handler names follow the same format as the atcp table - RoomNum, RoomExits, CharVitals and so on.<br />
<br />
While the concept of handlers for events is to be explained elsewhere in the manual, the quick rundown is this - place the event name you’d like your script to listen to into the Add User Defined Event Handler: field and press the + button to register it. Next, because scripts in Mudlet can have multiple functions, you need to tell Mudlet which function should it call for you when your handler receives a message. You do that by setting the Script name: to the function name in the script you’d like to be called.<br />
<br />
For example, if you’d like to listen to the RoomExits event and have it call the process_exits() function - register RoomExits as the event handler, make the script name be process_exits, and use this in the script:<br />
<br />
<lua><br />
function process_exits(event, args)<br />
echo("Called event: " .. event .. "\nWith args: " .. args)<br />
end<br />
</lua><br />
<br />
Feel free to experiment with this to achieve the desired results. A ATCP demo package is also available on the forums for using event handlers and parsing its messages into Lua datastructures.<br />
<br />
=== Mudlet-specific ATCP ===<br />
See [[Manual:ATCP_Extensions|ATCP Extensions]] for ATCP extensions that have been added to Mudlet.<br />
<br />
==Aardwolf’s 102 subchannel==<br />
<br />
Similar to ATCP, Aardwolf includes a hidden channel of information that you can access in Mudlet since 1.1.1. Mudlet deals with it in the same way as with ATCP, so for full usage instructions see the ATCP section. All data is stored in the channel102 table, such that you can do:<br />
<br />
<lua><br />
display(channel102)<br />
</lua><br />
<br />
... to see all the latest information that has been received. The event to create handlers on is titled '''channel102Message''', and you can use the [[Manual:Lua_Functions#sendTelnetChannel102|sendTelnetChannel102(msg)]] function to send text via the 102 channel back to Aardwolf.<br />
<br />
<lua><br />
-- Function for detecting AFK status on Aardwolf mud.<br />
function amIafk()<br />
for k,v in pairs(channel102) do<br />
if k==100 and v==4 then<br />
return true<br />
end<br />
end<br />
return false<br />
end<br />
</lua><br />
<br />
==MXP==<br />
MXP is based loosely on the HTML and XML standards supported by modern web browsers. It is only "loosely" based upon these standards because MUDs require dynamic, streaming text, rather than the page-oriented view of web browsers. Also, the existing standards are needlessly verbose for use on a MUD where text efficiency is important.<br />
<br />
In addition, there are additional security concerns to worry about with MXP. While support for HTML tags within a line is desired, players on a MUD can exploit this power and cause problems. Certain HTML functions need to be restricted so that MUD players cannot abuse them. For example, while it might be desirable to allow players to change the font or color of their chat messages, you would not want to allow them to display a large graphics image, or execute script commands on the client of other users. MXP handles this by grouping the various tags and commands into secure and open categories, and preventing the secure tags from being used by MUD players.<br />
<br />
Mudlet implements a subset of MXP features - the most popular ones that are actually in use. Mudlet supports MXP links (including send to prompt), pop-up menus, creation of custom elements, line modes, and fg/bg coloring (including bold, italics and underline) - see [http://forums.mudlet.org/viewtopic.php?f=5&t=92&start=240#p11835 here] for background.<br />
<br />
==Adding support for a telnet protocol==<br />
In addition to supporting ATCP, GMCP, Aardwolf's 102 and MXP, Mudlet has open telnet support - meaning that for any telnet protocol it doesn't support, it has the tools you can use to build the support for. This does not mean Mudlet supports other protocols "out of the box" - you will either have to get code that adds the support, or you could create it yourself.<br />
<br />
The basic tools that you need are [[Manual:Miscellaneous_Functions#addSupportedTelnetOption|addSupportedTelnetOption()]], [[Manual:Miscellaneous_Functions#sendSocket|sendSocket()]] and the [[Manual:Event_Engine#sysTelnetEvent|sysTelnetEvent]].<br />
<br />
Create [[Manual:Event_Engine#Registering_an_event_from_a_script|an event handler]] that goes off on [[Manual:Event_Engine#sysTelnetEvent|sysTelnetEvent]] - which is raised whenever an unsupported telnet option is encountered. Your logic handling will start in this event handler. Once you decide what you'd like to send to the MUD, use [[Manual:Miscellaneous_Functions#sendSocket|sendSocket()]] to send raw data as-is. Finally, when your logic is done, use [[Manual:Miscellaneous_Functions#addSupportedTelnetOption|addSupportedTelnetOption()]] to register your telnet option with Mudlet, so it will respond with telnet DO on a query from the MUD server. See [http://www.mudbytes.net/index.php?a=topic&t=4104&p=63920#p63920 this MSDP snippet] for a barebones example.<br />
<br />
===API philosophy===<br />
Adding a support for a new telnet protocol will involve adding the user-facing API. It best for users if it was in the same style as Mudlets handling of other protocols. To see how it's done exactly, check out GMCP, ATCP or Aardwolf 102 examples - but the gist of it is provided below.<br />
<br />
Mudlet has a built-in event system, which is used to broadcast messages in an independent way. With it, people can "trigger" on 102, ATCP or GMCP events with Lua functions that get called whenever an event they're interested in is raised. '''Use the event system to provide your users with a way to react to new protocol data'''.<br />
<br />
Events have names, and optionally, any amount of data with them. For protocol support, Mudlet prefixes the relevant message received name with the protocol name in lowercase. For example, an ATCP Char.Vitals getting updated would raise an event titled "atcp.Char.Vitals". A GMCP Room.Info message would raise a "gmcp.Room.Info" message. <br />
<br />
Additionally, Mudlet also allows catch-all event - in case the user wants to use one event handler for a variety of sub-events (it's not uncommon for MUDs to use ''Main.Sub.Add'', ''Main.Sub.Remove'', ''Main.Sub.List'' to keep track of a list, for example, while conserving data). To accomplish this, it raises events for every relevant namespace - that is, a Main.Sub.Add event will raise ''protocol.Main.Sub'' and ''protocol.Main.Sub.Add events''. While it is entirely possible for one event handler to react to multiple events, this is provided for convenience.<br />
<br />
For storing protocol data, Mudlet uses an aptly named global table - '''gmcp''' for GMCP data, '''atcp''' for ATCP data. Data is stored in the same way it is received and the event is raised for - so a Char.Vitals message's contents will be stored in gmcp.Char.Vitals, a Room.Info's contents in gmcp.Room.Info. If there were was any nested data within the message, it is stored as a table within the proper namespace - ie, a "details" JSON array of a GMCP Room.Info message would be stored in gmcp.Room.Info.details. '''Use a global table with the protocol name in lowerspace for storing permanent data''' that your users will read from.<br />
<br />
That's it! If you'll need any Mudlet-related help, feel free to [http://forums.mudlet.org/viewforum.php?f=9 post on our forums]. Once you're done, [[Mudlet_Packages|package your work]] for distribution which you can optionally post in the [http://forums.mudlet.org/viewforum.php?f=6 finished scripts] section.<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Event_Engine&diff=2271Manual:Event Engine2014-03-03T21:51:13Z<p>Rayth: Undo revision 2260 by Domtheo (talk)</p>
<hr />
<div>{{TOC right}}<br />
=Event System=<br />
<br />
Events in Mudlet allow a paradigm of system-building that is easy to maintain (because if you’d like to restructure something, you’d have to do less work), enables interoperability (making a collection of scripts that work with each other is easier) and enables an event-based way of programming.<br />
<br />
The essentials of it are as such: you use Scripts to define which events should a function to listen to, and when the event is raised, the said function(s) will be called. Events can also have function parameters with them, which’ll be passed onto the receiving functions.<br />
<br />
== Registering an event handler via UI ==<br />
Registering an event handler means that you’ll be telling Mudlet what function should it call for you when an event is raised, so it’s a two step process - you need to tell it both what function you’d like to be called, and on what event should it be called.<br />
<br />
To tell it what function should be called, create a new script, and give the script the name of the function you’d like to be called. This is the only time where an items name matters in Mudlet. You can define the function right inside the script as well, if you’d like.<br />
<br />
Next, we tell it what event or events should this function be called on - you can add multiple ones. To do that, enter the events name in the Add User Defined Event Handler: field, press enter, and it’ll go into the list - and that is all.<br />
<br />
== Registering an event from a script ==<br />
You can also register your event with the ''[[Manual:Miscellaneous_Functions#registerAnonymousEventHandler|registerAnonymousEventHandler(event name, function name)]]'' function inside your scripts:<br />
<br />
<lua><br />
-- example taken from the God Wars 2 (http://godwars2.org) Mudlet UI - forces the window to keep to a certain size<br />
function keepStaticSize()<br />
setMainWindowSize(1280,720)<br />
end -- keepStaticSize<br />
<br />
registerAnonymousEventHandler("sysWindowResizeEvent", "keepStaticSize")<br />
</lua><br />
<br />
{{note}} Mudlet also uses the event system in-game protocols (like ATCP, GMCP and others).<br />
<br />
{{note}} Event handler functions can now also be in namespaces (tables).<br />
<br />
== Raising an event== <br />
To raise an event, you’d use the raiseEvent function:<br />
<br />
<lua>raiseEvent(name, [arguments...])</lua><br />
<br />
It takes an event name as the first argument, and then any amount of arguments after it which will be passed onto the receiving functions.<br />
<br />
;Mini-tutorial<br />
As an example, our prompt trigger could raise an ''onPrompt'' event if you want to attach 2 functions to it. In your prompt trigger, all you’d need to do is ''raiseEvent("onPrompt")''. Now we go about creating functions that attach to the event - lets say the first one is ''check_health_stuff()'' and the other is ''check_salve_stuff()''. We would like these to be executed when the event is raised. So create a script and give it a name of ''check_health_stuff''. In the '''Add user defined event handler''', type ''onPrompt'', and press enter to add it to the list. In the script box, create: <br />
<br />
<lua><br />
function check_health_stuff()<br />
echo("I work!\n")<br />
end<br />
</lua><br />
<br />
When the onPrompt event comes along, that script catches it, and runs ''check_health_stuff()'' for you.<br />
<br />
[[Link title]]<br />
==Mudlet-raised events==<br />
Mudlet itself also creates events for your scripts to hook on. The following events are generated currently:<br />
<br />
===mapOpenEvent===<br />
<br />
Raised when the mapper is opened - either the floating dock or the in-Mudlet widget.<br />
<br />
===sysWindowResizeEvent===<br />
<br />
Raised when the main window is resized, with the new height and width coordinates passed to the event. A common usecase for this event is to move/resize your UI elements according to the new dimensions.<br />
Example<br />
<br />
This sample code will echo whenever a resize happened with the new dimensions:<br />
<br />
<lua><br />
function resizeEvent( event, x, y )<br />
echo("RESIZE EVENT: event="..event.." x="..x.." y="..y.."\n")<br />
end<br />
</lua><br />
<br />
===sysWindowMousePressEvent===<br />
<br />
Raised when a mouse button is pressed down anywhere on the main window (note that a click is composed of a mouse press and mouse release). The button number and the x,y coordinates of the click are reported.<br />
Example<br />
<br />
<lua><br />
function onClickHandler( event, button, x, y )<br />
echo("CLICK event:"..event.." button="..button.." x="..x.." y="..y.."\n")<br />
end<br />
</lua><br />
<br />
===sysWindowMouseReleaseEvent===<br />
<br />
Raised when a mouse button is released after being pressed down anywhere on the main window (note that a click is composed of a mouse press and mouse release). See sysWindowMousePressEvent for example use.<br />
<br />
===sysLoadEvent===<br />
<br />
Raised when Mudlet is loading the profile. Note that when it does so, it also compiles and runs all scripts - which could be a good idea to initialize everything at, but beware - scripts are also run when saved. Hence, hooking only on the sysLoadEvent would prevent multiple re-loads as you’re editing the script.<br />
<br />
===sysExitEvent===<br />
<br />
Raised when Mudlet is shutting down the profile - a good event to hook onto for saving all of your data.<br />
<br />
===sysDownloadDone===<br />
<br />
Raised when Mudlet is finished downloading a file successfully - the location of the downloaded file is passed as a second argument. For a practical example, see the [[Manual:Lua_Functions#downloadFile|downloadFile()]] function.<br />
<br />
===sysDownloadError===<br />
<br />
Raised when downloading a file failed - the second argument contains the error message. Starting with Mudlet 2.0-test5+, it specifies the original URL that was going to be downloaded.<br />
<br />
===sysIrcMessage===<br />
<br />
Raised when you see or receive an IRC message. The speakers name, channel and their message will follow as arguments.<br />
<br />
<lua><br />
function onIrcMessage(_, person, channel, message)<br />
echo(string.format('(%s) %s says, "%s"\n', channel, person, message))<br />
end<br />
</lua><br />
<br />
<sub>Added to Mudlet in an unreleased 2.0rc8</sub><br />
<br />
===sysDataSendRequest===<br />
Raised right before a command from the send() function or the command line is sent to the game - useful for keeping track of what your last command was, or even denying the command to be sent if necessary with ''denyCurrentSend()''.<br />
<br />
Note: if you'll be making use of denyCurrentSend(), you ''really should'' notify the user that you denied their command - unexperienced ones might conclude that your script or Mudlet is buggy if they don't see visual feedback. Do not mis-use this and use it as [http://en.wikipedia.org/wiki/Keylogger keylogger] either.<br />
<br />
<lua><br />
function onNetworkOutput(_, command)<br />
if math.random(2) == 1 then<br />
echo("Hello! Sending "..command.." to the game.\n")<br />
else<br />
echo("Not your day! Denying "..command..".\n")<br />
end<br />
end<br />
</lua><br />
<br />
===sysConnectionEvent===<br />
Raised when the profile becomes connected to a MUD - available in 2.0-test5+.<br />
<br />
===sysDisconnectionEvent===<br />
Raised when the profile becomes disconnected, either manually or by the game - available in 2.0-test5+.<br />
<br />
===sysTelnetEvent===<br />
Raised whenever an unsupported telnet option is encountered, allowing you to handle it yourself. The arguments that get passed with the event are type, telnet option, and the message. Available in 2.1+<br />
<br />
===sysMapDownloadEvent===<br />
Raised whenever an MMP map (currently only supported by IRE games) is downloaded and loaded in.<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Event_Engine&diff=2270Manual:Event Engine2014-03-03T21:50:48Z<p>Rayth: Undo revision 2265 by Domtheo (talk)</p>
<hr />
<div>{{TOC right}}<br />
=Event System=<br />
<br />
Events in Mudlet allow a paradigm of system-building that is easy to maintain (because if you’d like to restructure something, you’d have to do less work), enables interoperability (making a collection of scripts that work with each other is easier) and enables an event-based way of programming.<br />
<br />
The essentials of it are as such: you use Scripts to define which events should a function to listen to, and when the event is raised, the said function(s) will be called. Events can also have function parameters with them, which’ll be passed onto the receiving functions.<br />
<br />
== Registering an event handler via UI ==<br />
Registering an event handler means that you’ll be telling Mudlet what function should it call for you when an event is raised, so it’s a two step process - you need to tell it both what function you’d like to be called, and on what event should it be called.<br />
<br />
To tell it what function should be called, create a new script, and give the script the name of the function you’d like to be called. This is the only time where an items name matters in Mudlet. You can define the function right inside the script as well, if you’d like.<br />
<br />
Next, we tell it what event or events should this function be called on - you can add multiple ones. To do that, enter the events name in the Add User Defined Event Handler: field, press enter, and it’ll go into the list - and that is all.<br />
[http://www.awanirentcar.com/pricelist Sewa mobil jakarta], [http://www.grosir-kosmetik.com/62-glutera.html Glutera], [http://www.tokobungasabana.com Toko bunga jakarta], [http://vamostech.com/gps-tracking Gps tracking]<br />
<br />
== Registering an event from a script ==<br />
You can also register your event with the ''[[Manual:Miscellaneous_Functions#registerAnonymousEventHandler|registerAnonymousEventHandler(event name, function name)]]'' function inside your scripts:<br />
<br />
<lua><br />
-- example taken from the God Wars 2 (http://godwars2.org) Mudlet UI - forces the window to keep to a certain size<br />
function keepStaticSize()<br />
setMainWindowSize(1280,720)<br />
end -- keepStaticSize<br />
<br />
registerAnonymousEventHandler("sysWindowResizeEvent", "keepStaticSize")<br />
</lua><br />
<br />
{{note}} Mudlet also uses the event system in-game protocols (like ATCP, GMCP and others).<br />
<br />
{{note}} Event handler functions can now also be in namespaces (tables).<br />
<br />
== Raising an event== <br />
To raise an event, you’d use the raiseEvent function:<br />
<br />
<lua>raiseEvent(name, [arguments...])</lua><br />
<br />
It takes an event name as the first argument, and then any amount of arguments after it which will be passed onto the receiving functions.<br />
<br />
;Mini-tutorial<br />
As an example, our prompt trigger could raise an ''onPrompt'' event if you want to attach 2 functions to it. In your prompt trigger, all you’d need to do is ''raiseEvent("onPrompt")''. Now we go about creating functions that attach to the event - lets say the first one is ''check_health_stuff()'' and the other is ''check_salve_stuff()''. We would like these to be executed when the event is raised. So create a script and give it a name of ''check_health_stuff''. In the '''Add user defined event handler''', type ''onPrompt'', and press enter to add it to the list. In the script box, create: <br />
<br />
<lua><br />
function check_health_stuff()<br />
echo("I work!\n")<br />
end<br />
</lua><br />
<br />
When the onPrompt event comes along, that script catches it, and runs ''check_health_stuff()'' for you.<br />
<br />
[[Link title]]<br />
==Mudlet-raised events==<br />
Mudlet itself also creates events for your scripts to hook on. The following events are generated currently:<br />
<br />
===mapOpenEvent===<br />
<br />
Raised when the mapper is opened - either the floating dock or the in-Mudlet widget.<br />
<br />
===sysWindowResizeEvent===<br />
<br />
Raised when the main window is resized, with the new height and width coordinates passed to the event. A common usecase for this event is to move/resize your UI elements according to the new dimensions.<br />
Example<br />
<br />
This sample code will echo whenever a resize happened with the new dimensions:<br />
<br />
<lua><br />
function resizeEvent( event, x, y )<br />
echo("RESIZE EVENT: event="..event.." x="..x.." y="..y.."\n")<br />
end<br />
</lua><br />
<br />
===sysWindowMousePressEvent===<br />
<br />
Raised when a mouse button is pressed down anywhere on the main window (note that a click is composed of a mouse press and mouse release). The button number and the x,y coordinates of the click are reported.<br />
Example<br />
<br />
<lua><br />
function onClickHandler( event, button, x, y )<br />
echo("CLICK event:"..event.." button="..button.." x="..x.." y="..y.."\n")<br />
end<br />
</lua><br />
<br />
===sysWindowMouseReleaseEvent===<br />
<br />
Raised when a mouse button is released after being pressed down anywhere on the main window (note that a click is composed of a mouse press and mouse release). See sysWindowMousePressEvent for example use.<br />
<br />
===sysLoadEvent===<br />
<br />
Raised when Mudlet is loading the profile. Note that when it does so, it also compiles and runs all scripts - which could be a good idea to initialize everything at, but beware - scripts are also run when saved. Hence, hooking only on the sysLoadEvent would prevent multiple re-loads as you’re editing the script.<br />
<br />
===sysExitEvent===<br />
<br />
Raised when Mudlet is shutting down the profile - a good event to hook onto for saving all of your data.<br />
<br />
===sysDownloadDone===<br />
<br />
Raised when Mudlet is finished downloading a file successfully - the location of the downloaded file is passed as a second argument. For a practical example, see the [[Manual:Lua_Functions#downloadFile|downloadFile()]] function.<br />
<br />
===sysDownloadError===<br />
<br />
Raised when downloading a file failed - the second argument contains the error message. Starting with Mudlet 2.0-test5+, it specifies the original URL that was going to be downloaded.<br />
<br />
===sysIrcMessage===<br />
<br />
Raised when you see or receive an IRC message. The speakers name, channel and their message will follow as arguments.<br />
<br />
<lua><br />
function onIrcMessage(_, person, channel, message)<br />
echo(string.format('(%s) %s says, "%s"\n', channel, person, message))<br />
end<br />
</lua><br />
<br />
<sub>Added to Mudlet in an unreleased 2.0rc8</sub><br />
<br />
===sysDataSendRequest===<br />
Raised right before a command from the send() function or the command line is sent to the game - useful for keeping track of what your last command was, or even denying the command to be sent if necessary with ''denyCurrentSend()''.<br />
<br />
Note: if you'll be making use of denyCurrentSend(), you ''really should'' notify the user that you denied their command - unexperienced ones might conclude that your script or Mudlet is buggy if they don't see visual feedback. Do not mis-use this and use it as [http://en.wikipedia.org/wiki/Keylogger keylogger] either.<br />
<br />
<lua><br />
function onNetworkOutput(_, command)<br />
if math.random(2) == 1 then<br />
echo("Hello! Sending "..command.." to the game.\n")<br />
else<br />
echo("Not your day! Denying "..command..".\n")<br />
end<br />
end<br />
</lua><br />
<br />
===sysConnectionEvent===<br />
Raised when the profile becomes connected to a MUD - available in 2.0-test5+.<br />
<br />
===sysDisconnectionEvent===<br />
Raised when the profile becomes disconnected, either manually or by the game - available in 2.0-test5+.<br />
<br />
===sysTelnetEvent===<br />
Raised whenever an unsupported telnet option is encountered, allowing you to handle it yourself. The arguments that get passed with the event are type, telnet option, and the message. Available in 2.1+<br />
<br />
===sysMapDownloadEvent===<br />
Raised whenever an MMP map (currently only supported by IRE games) is downloaded and loaded in.<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Mudlet_Object_Functions&diff=2032Manual:Mudlet Object Functions2013-03-07T19:02:29Z<p>Rayth: /* setConsoleBufferSize */</p>
<hr />
<div>{{TOC right}}<br />
== Mudlet Object Functions ==<br />
<br />
===appendCmdLine===<br />
;appendCmdLine()<br />
: Appends text to the main input line.<br />
<br />
;Example<br />
<lua><br />
-- adds the text "55 backpacks" to whatever is currently in the input line<br />
appendCmdLine("55 backpacks")<br />
<br />
-- makes a link, that when clicked, will add "55 backpacks" to the input line<br />
echoLink("press me", "appendCmdLine'55 backpack'", "Press me!")<br />
</lua><br />
<br />
===clearCmdLine===<br />
:clearCmdLine()<br />
: Clears the input line of any text that's been entered.<br />
<br />
;Example<br />
<lua><br />
-- don't be evil with this!<br />
clearCmdLine()<br />
</lua><br />
<br />
===createStopWatch===<br />
;createStopWatch()<br />
: This function creates a stop watch. It is high resolution time measurement tool. Stop watches can be started, stopped, reset and asked how much time has passed since the stop watch has been started.<br />
{{note}} it's best to re-use stopwatch IDs if you can - Mudlet at the moment does not delete them, so creating more and more would use more memory.<br />
<br />
: Returns: The ID of a high resolution clock with milliseconds to measure time more accurately.<br />
<br />
;Example<br />
:In a global script you create all stop watches that you need in your system and store the respective stopWatch-IDs in global variables:<br />
<lua><br />
fightStopWatch = createStopWatch() -- you store the watchID in a global variable to access it from anywhere<br />
</lua><br />
:Then you can start the stop watch in some trigger/alias/script with:<br />
<lua><br />
startStopWatch( fightStopWatch )<br />
</lua><br />
:To stop the watch and measure its time in e.g. a trigger script you can write:<br />
<lua><br />
fightTime = stopStopWatch( fightStopWatch )<br />
echo( "The fight lasted for " .. fightTime .. " seconds." )<br />
resetStopWatch( fightStopWatch )<br />
</lua><br />
:You can also measure the elapsed time without having to stop the stop watch with getStopWatchTime.<br />
<br />
===disableAlias===<br />
;disableAlias(name)<br />
:Disables/deactivates the alias by it’s name. If several aliases have this name, they’ll all be disabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the alias. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--Disables the alias called 'my alias'<br />
disableAlias("my alias")<br />
</lua><br />
<br />
===disableKey===<br />
;disableKey(name)<br />
:Disables key a key (macro) or a key group. When you disable a key group, all keys within the group will be implicitly disabled as well.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the key or group to identify what you'd like to disable.<br />
<br />
;Examples<br />
<br />
<lua><br />
-- you could set multiple keys on the F1 key and swap their use as you wish by disabling and enabling them<br />
disableKey("attack macro")<br />
disableKey("jump macro")<br />
enableKey("greet macro")<br />
</lua><br />
<br />
===disableTimer===<br />
;disableTimer(name)<br />
:Disables a timer from running it’s script when it fires - so the timer cycles will still be happening, just no action on them. If you’d like to permanently delete it, use [[Manual:Lua_Functions#killTrigger|killTrigger]] instead.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<br />
;Example<br />
<lua><br />
--Disables the timer called 'my timer'<br />
disableTimer("my timer")<br />
</lua><br />
<br />
===disableTrigger===<br />
;disableTrigger(name)<br />
:Disables a trigger that was previously enabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.<br />
<br />
;Example<br />
<lua><br />
-- Disables the trigger called 'my trigger'<br />
disableTrigger("my trigger")<br />
</lua><br />
<br />
===enableAlias===<br />
;enableAlias(name)<br />
:Enables/activates the alias by it’s name. If several aliases have this name, they’ll all be enabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the alias ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] on creation of the alias or the name of the alias in case of a GUI alias.<br />
<br />
;Example<br />
<lua><br />
--Enables the alias called 'my alias'<br />
enableAlias("my alias")<br />
</lua><br />
<br />
===enableKey===<br />
;enableKey(name)<br />
:Enables a key (macro) or a group of keys (and thus all keys within it that aren't explicitly deactivated).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the group that identifies the key.<br />
<br />
<lua><br />
-- you could use this to disable one key set for the numpad and activate another<br />
disableKey("fighting keys")<br />
enableKey("walking keys")<br />
</lua><br />
<br />
===enableTimer===<br />
;enableTimer(name)<br />
:Enables or activates a timer that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<lua><br />
-- enable the timer called 'my timer' that you created in Mudlets timers section<br />
enableTimer("my timer")<br />
</lua><br />
<br />
<lua><br />
-- or disable & enable a tempTimer you've made<br />
timerID = tempTimer(10, [[echo("hi!")]])<br />
<br />
-- it won't go off now<br />
disableTimer(timerID)<br />
-- it will continue going off again<br />
enableTimer(timerID)<br />
</lua><br />
<br />
===enableTrigger===<br />
;enableTrigger(name)<br />
:Enables or activates a trigger that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] or by any other temp*Trigger variants, or the name of the trigger in case of a GUI trigger.<br />
<lua><br />
-- enable the trigger called 'my trigger' that you created in Mudlets triggers section<br />
enableTrigger("my trigger")<br />
</lua><br />
<br />
<lua><br />
-- or disable & enable a tempTrigger you've made<br />
triggerID = tempTrigger("some text that will match in a line", [[echo("hi!")]])<br />
<br />
-- it won't go off now when a line with matching text comes by<br />
disableTrigger(triggerID)<br />
<br />
-- and now it will continue going off again<br />
enableTrigger(triggerID)<br />
</lua><br />
<br />
===exists===<br />
;exists(name, type)<br />
:Tells you how many things of the given type exist. <br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', or 'timer'.<br />
<br />
;Example<br />
<lua><br />
echo("I have " .. exists("my trigger", "trigger") .. " triggers called 'my trigger'!")<br />
</lua><br />
<br />
: You can also use this alias to avoid creating duplicate things, for example:<br />
<lua><br />
-- this code doesn't check if an alias already exists and will keep creating new aliases<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
<br />
-- while this code will make sure that such an alias doesn't exist first<br />
-- we do == 0 instead of 'not exists' because 0 is considered true in Lua<br />
if exists("Attack", "alias") == 0 then<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
end<br />
</lua><br />
<br />
===getButtonState===<br />
;getButtonState()<br />
:This function can only be used inside a toggle button script <br />
<br />
:Returns ''2'' if button is checked, and ''1'' if it's not.<br />
<br />
;Example<br />
<lua><br />
checked = getButtonState();<br />
if checked == 1 then<br />
hideExits()<br />
else<br />
showExits()<br />
end;<br />
</lua><br />
<br />
===invokeFileDialog===<br />
;invokeFileDialog(fileOrFolder, dialogTitle)<br />
:Opens a file chooser dialog, allowing the user to select a file or a folder visually. The function returns the selected path or "" if there was none chosen.<br />
<br />
;Parameters<br />
* ''fileOrFolder:'' ''true'' for file selection, ''false'' for folder selection.<br />
* ''dialogTitle'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
function whereisit()<br />
local path = invokeFileDialog(false, "Where should we save the file? Select a folder and click Open")<br />
<br />
if path == "" then return nil else return path end<br />
end<br />
</lua><br />
<br />
===isActive===<br />
;isActive(name, type)<br />
:You can use this function to check if something, or somethings, are active. <br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', or 'timer'.<br />
<br />
;Example<br />
<lua><br />
echo("I have " .. isActive("my trigger", "trigger") .. " currently active trigger(s) called 'my trigger'!")<br />
</lua><br />
<br />
===isPrompt===<br />
;isPrompt()<br />
:Returns true or false depending on if the current line being processed is a prompt. This infallible feature is available for MUDs that supply GA events (to check if yours is one, look to bottom-right of the main window - if it doesn’t say <No GA>, then it supplies them).<br />
<br />
:Example use could be as a Lua function, making closing gates on a prompt real easy.<br />
<br />
;Example<br />
<lua><br />
-- make a trigger pattern with 'Lua function', and this will trigger on every prompt!<br />
return isPrompt()<br />
</lua><br />
<br />
===killAlias===<br />
;killAlias(name)<br />
:Deletes an alias with the given name. If several aliases have this name, they'll all be deleted.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the alias.<br />
<br />
<lua><br />
--Deletes the alias called 'my alias'<br />
killAlias("my alias")<br />
</lua><br />
<br />
===killTimer===<br />
;killTimer(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
{{note}} Non-temporary timers that you have set up in the GUI cannot be deleted with this function. Use [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#enableTimer|enableTimer()]] to turn them on or off.<br />
<br />
;Parameters<br />
* ''id:'' the ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
: Returns true on success and false if the timer id doesn’t exist anymore (timer has already fired) or the timer is not a temp timer.<br />
<br />
;Example<br />
<lua><br />
-- create the timer and remember the timer ID<br />
timerID = tempTimer(10, [[echo("hello!")]])<br />
<br />
-- delete the timer<br />
if killTimer(timerID) then echo("deleted the timer") else echo("timer is already deleted") end<br />
</lua><br />
<br />
===killTrigger===<br />
;killTrigger(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTrigger]].<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the trigger id doesn’t exist anymore (trigger has already fired) or the trigger is not a temp trigger.<br />
<br />
===permAlias===<br />
;permAlias(name, parent, regex, lua code)<br />
<br />
:Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name you’d like the alias to have.<br />
* ''parent:'' <br />
: The name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''regex:''<br />
: The pattern that you’d like the alias to use.<br />
* ''lua code:'' <br />
: The script the alias will do when it matches.<br />
;Example<br />
<lua><br />
-- creates an alias called "new alias" in a group called "my group"<br />
permAlias("new alias", "my group", "^test$", [[echo ("say it works! This alias will show up in the script editor too.")]])<br />
</lua><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permAlias with the same name will keep creating new aliases. You can check if an alias already exists with the [[Manual:Lua_Functions#exists|exists]] function.<br />
<br />
===permGroup===<br />
;permGroup(name, itemtype)<br />
<br />
:Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts. <br />
;Parameters<br />
* ''name:''<br />
: The name of the new group you want to create.<br />
* ''itemtype:''<br />
: The name of the timer, trigger, or alias.<br />
<br />
{{note}} Added to Mudlet in the 2.0 final release.<br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
===permRegexTrigger===<br />
;permRegexTrigger(name, parent, pattern, lua code)<br />
:Creates a persistent trigger with a ''regex'' pattern that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<lua><br />
-- Create a regex trigger that will match on the prompt to record your status<br />
permRegexTrigger("Prompt", "", {"^(\d+)h, (\d+)m"}, [[health = tonumber(matches[2]; mana = tonumber(matches[3])]]<br />
</lua><br />
{{note}} Mudlet by design allows duplicate names - so calling permRegexTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
===permSubstringTrigger===<br />
;permSubstringTrigger( name, parent, pattern, lua code )<br />
:Creates a persistent trigger with a substring pattern that stays after Mudlet is restarted and shows up in the Script Editor.<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<lua><br />
-- Create a trigger to highlight the word "pixie" for us<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie"},<br />
[[selectString(line, 1) bg("yellow") resetFormat()]])<br />
<br />
-- Or another trigger to highlight several different things<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie", "cat", "dog", "rabbit"},<br />
[[selectString(line, 1) fg ("blue") bg("yellow") resetFormat()]])<br />
</lua><br />
{{note}} Mudlet by design allows duplicate names - so calling permSubstringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
===permTimer===<br />
;permTimer(name, parent, seconds, lua code)<br />
: Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:Is the name of the timer.<br />
* ''parent'' <br />
:Is the name of the timer group you want the timer to go in..<br />
* ''seconds'' <br />
:Is a number specifying a delay after which the timer will do the lua code you give it as a string.<br />
* ''lua code'' is the code with string you are doing this to.<br />
<br />
;Example:<br />
<lua><br />
permTimer("my timer", "first timer group", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
</lua><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permTimer with the same name will keep creating new timers. You can check if a timer already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
===printCmdLine===<br />
;printCmdLine(text)<br />
<br />
: Replaces the current text in the input line, and sets it to the given text.<br />
<br />
<lua><br />
printCmdLine("say I'd like to buy ")<br />
</lua><br />
<br />
===raiseEvent===<br />
;raiseEvent(event_name, arg-1, … arg-n)<br />
<br />
: Raises the event event_name. The event system will call the main function (the one that is called exactly like the script name) of all such scripts that have registered event handlers. If an event is raised, but no event handler scripts have been registered with the event system, the event is ignored and nothing happens. This is convenient as you can raise events in your triggers, timers, scripts etc. without having to care if the actual event handling has been implemented yet - or more specifically how it is implemented. Your triggers raise an event to tell the system that they have detected a certain condition to be true or that a certain event has happened. How - and if - the system is going to respond to this event is up to the system and your trigger scripts don’t have to care about such details. For small systems it will be more convenient to use regular function calls instead of events, however, the more complicated your system will get, the more important events will become because they help reduce complexity very much.<br />
<br />
:The corresponding event handlers that listen to the events raised with raiseEvent() need to use the script name as function name and take the correct number of arguments. <br />
<br />
<!-- Hm... what is this?<br />
{{note}} If you raise an event with 5 arguments but your event handlers functions only take 2,10 or 0 arguments, the functions will not be called. --><br />
<br />
;Example:<br />
<br />
:raiseEvent("fight") a correct event handler function would be: myScript( event_name ). In this example raiseEvent uses minimal arguments, name the event name. There can only be one event handler function per script, but a script can still handle multiple events as the first argument is always the event name. So you can call your own special handlers for individual events. The reason behind this is that you should rather use many individual scripts instead of one huge script that has all your function code etc. Scripts can be organized very well in trees and thus help reduce complexity on large systems.<br />
<br />
===remember===<br />
;remember("variable")<br />
;This function flags a variable to be saved by Mudlet's variable persistence system.<br />
<br />
;Parameters<br />
* ''variable''<br />
: Variable that you are saving. Can be a table or regular variable. Name must be passed as a string.<br />
<br />
;Example<br />
<lua>remember("table_Weapons")<br />
remember("var_EnemyHeight")<br />
</lua><br />
Variables are automatically unpacked into the global namespace when the profile is loaded.<br><br />
They are saved to "SavedVariables.lua" when the profile is closed or saved.<br />
<br />
===resetStopWatch===<br />
;resetStopWatch(watchID)<br />
:This function resets the time to 0:0:0.0, but does not start the stop watch. You can start it with [[Manual:Lua_Functions#startStopWatch | startStopWatch]] → [[Manual:Lua_Functions#createStopWatch | createStopWatch]]<br />
<br />
===setConsoleBufferSize===<br />
;setConsoleBufferSize( consoleName, linesLimit, sizeOfBatchDeletion )<br />
:Sets the maximum number of lines a buffer (main window or a miniconsole) can hold.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of the window<br />
* ''linesLimit:''<br />
: Sets the amount of lines the buffer should have. <br />
{{note}} Mudlet performs extremely efficiently with even huge numbers, so your only limitation is your computers memory (RAM).<br />
* ''sizeOfBatchDeletion:''<br />
: Specifies how many lines should Mudlet delete at once when you go over the limit - it does it in bulk because it's efficient to do so.<br />
<br />
;Example<br />
<lua><br />
-- sets the main windows size to 5 million lines maximum - which is more than enough!<br />
setConsoleBufferSize("main", 5000000, 1000)<br />
</lua><br />
<br />
===setTriggerStayOpen===<br />
;setTriggerStayOpen(name, number)<br />
:Sets for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched - so this allows you to extend or shorten the ''fire length'' of a trigger. The main use of this function is to close a chain when a certain condition has been met.<br />
<br />
;Parameters<br />
* ''name:'' The name of the trigger which has a fire length set (and which opens the chain).<br />
* ''number'': 0 to close the chain, or a positive number to keep the chain open that much longer.<br />
<br />
;Examples<br />
<lua><br />
-- if you have a trigger that opens a chain (has some fire length) and you'd like it to be closed <br />
-- on the next prompt, you could make a trigger inside the chain with a Lua function pattern of:<br />
return isPrompt()<br />
-- and a script of:<br />
setTriggerStayOpen("''Parent trigger name''", 0)<br />
-- to close it on the prompt!<br />
</lua><br />
<br />
===startStopWatch===<br />
;startStopWatch( watchID )<br />
:Starts the stop watch. → [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
<br />
===stopStopWatch===<br />
;stopStopWatch( watchID )<br />
:Stops the stop watch and returns the elapsed time in milliseconds in form of 0.001. → [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
: Returns time as a number<br />
<br />
===tempAlias===<br />
;aliasID = tempAlias(regex, code to do)<br />
:Creates a temporary alias - temporary in the sense that it won't be saved when Mudlet restarts (unless you re-create it). The alias will go off as many times as it matches, it is not a one-shot alias. The function returns an ID for subsequent [[Manual:Lua_Functions#enableAlias|enableAlias()]], [[Manual:Lua_Functions#disableAlias|disableAlias()]] and [[Manual:Lua_Functions#killAlias|killAlias()]] calls.<br />
<br />
;Parameters<br />
* ''regex:'' Alias pattern in regex.<br />
* ''code to do:'' The code to do when the alias fires - wrap it in [[ ]].<br />
<br />
;Examples<br />
<lua><br />
myaliasID = tempAlias("^hi$", [[send ("hi") echo ("we said hi!")]])<br />
<br />
-- you can also delete the alias later with:<br />
killAlias(myaliasID)<br />
</lua><br />
<br />
===tempBeginOfLineTrigger===<br />
;tempBeginOfLineTrigger(part of line, code to do)<br />
:Creates a trigger that will go off whenever the part of line it's provided with matches the line right from the start (doesn't matter what the line ends with). This trigger isn't temporary in the sense that it'll go off only once (it'll go off as often as it matches), but rather it won't be saved when Mudlet is closed. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger will go off multiple times until you disable or destroy it.<br />
<br />
;Parameters<br />
* ''part of line:'' Start of the line that you'd like to match.<br />
* ''code to do:'' The code to do when the trigger fires - wrap it in [[ ]].<br />
<br />
;Examples<br />
<lua><br />
mytriggerID = tempBeginOfLineTrigger("Hello", [[echo("We matched!")]])<br />
<br />
--[[ now this trigger will match on any of these lines:<br />
Hello<br />
Hello!<br />
Hello, Bob!<br />
<br />
but not on:<br />
Oh, Hello<br />
Oh, Hello!<br />
]]<br />
</lua><br />
<br />
===tempColorTrigger===<br />
;tempColorTrigger(foregroundColor, backgroundColor, code)<br />
:Makes a color trigger that triggers on the specified foreground and background color. Both colors need to be supplied in form of these simplified ANSI 16 color mode codes. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger will go off multiple times until you disable or destroy it.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code'': The code you'd like the trigger to run, as a string.<br />
<br />
;Color codes<br />
<lua><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</lua><br />
<br />
;Examples<br />
<lua><br />
-- This script will re-highlight all text in blue foreground colors on a black background with a red foreground color<br />
-- on a blue background color until another color in the current line is being met. temporary color triggers do not <br />
-- offer match_all or filter options like the GUI color triggers because this is rarely necessary for scripting. <br />
-- A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempColorTrigger(9,2,[[selectString(matches[1],1); fg("red"); bg("blue");]] );<br />
</lua><br />
<br />
===tempExactMatchTrigger===<br />
;tempExactMatchTrigger(exact line, code to do)<br />
:Creates a trigger that will go off whenever the line from the game matches the provided line exactly (ends the same, starts the same, and looks the same). You don't need to use any of the regex symbols here (^ and $). This trigger isn't temporary in the sense that it'll go off only once (it'll go off as often as it matches), but rather it won't be saved when Mudlet is closed. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger will go off multiple times until you disable or destroy it.<br />
<br />
;Parameters<br />
* ''exact line:'' Exact line you'd like to match.<br />
* ''code to do:'' The code to do when the trigger fires - wrap it in [[ ]].<br />
<br />
;Examples<br />
<lua><br />
mytriggerID = tempExactMatchTrigger("You have recovered balance on all limbs.", [[echo("We matched!")]])<br />
</lua><br />
<br />
===tempLineTrigger===<br />
;tempLineTrigger( from, howMany, LuaCode )<br />
:Temporary trigger that will fire on ''n'' consecutive lines following the current line. This is useful to parse output that is known to arrive in a certain line margin or to delete unwanted output from the MUD - the trigger does not require any patterns to match on. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger will go off multiple times until you disable or destroy it.<br />
<br />
:Returns trigger ID as a string.<br />
{{note}} You can use this ID to enable/disable or kill this trigger later on.<br />
;Example: <br />
<lua><br />
--Will fire 3 times with the line from the MUD.<br />
tempLineTrigger( 1, 3, ) <br />
<br />
--Will fire 20 lines after the current line and fire twice on 2 consecutive lines.<br />
tempLineTrigger( 20, 2, )<br />
</lua><br />
<br />
===tempRegexTrigger===<br />
;tempRegexTrigger(regex, code to do)<br />
:Creates a temporary regex trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger will go off multiple times until you disable or destroy it.<br />
<br />
;Parameters:<br />
* ''regex:'' The regular expression that lines will be matched on.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]].<br />
<br />
;Examples:<br />
<lua><br />
-- create a non-duplicate trigger that matches on any line and calls a function<br />
html5log = html5log or {}<br />
if html5log.trig then killTrigger(html5log.trig) end<br />
html5log.trig = tempRegexTrigger("^", "html5log.recordline()")<br />
</lua><br />
<br />
===tempTimer===<br />
;tempTimer(time, code to do)<br />
:Creates a temporary one-shot timer and returns the timer ID, which you can use with [[Manual:Lua_Functions#enableTimer|enableTimer()]], [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#killTimer|killTimer()]] functions. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and destroyed, so it will only go off once. See [[Manual:Introduction#Timers|here]] for a more detailed introduction to tempTimer.<br />
<br />
;Parameters<br />
* ''time:'' The time in seconds for which to set the timer for - you can use decimals here for precision. The timer will go off ''x'' given seconds after you make it.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
{{note}} Double brackets, e.g: [[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
<br />
{{note}} Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
<br />
-- tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
===tempTrigger===<br />
;tempTrigger(substring, code to do)<br />
:Creates a temporary substring trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls. The trigger will go off multiple times until you disable or destroy it.<br />
<br />
;Parameters:<br />
* ''substring:'': The substring to look for - this means a part of the line. If your provided text matches anywhere within the line from the game, the trigger will go off.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]].<br />
<br />
Example:<br />
<lua><br />
-- this example will highlight the contents of the "target" variable.<br />
-- It will also delete the previous trigger it made when you call it again, so you're only ever highlighting one name<br />
if id then killTrigger(id) end<br />
id = tempTrigger(target, [[selectString("]] .. target .. [[", 1) fg("gold") resetFormat()]])<br />
</lua><br />
<br />
<lua><br />
-- a simpler trigger to replace "hi" with "bye" whenever you see it<br />
tempTrigger("hi", [[selectString("hi", 1) replace("bye")]])<br />
</lua><br />
<br />
===tempButton===<br />
;tempButton(group name, button text, orientation)<br />
:Creates a temporary button.<br />
<br />
;Parameters:<br />
* ''group name:'': The toolbar to place the button into.<br />
* ''button text'': The text to place on the button.<br />
* ''orientation'': a number, 0 - horizontal orientation for the button, or 1 - vertical orientation for the button.<br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Category:Mudlet_Package_Listing&diff=2031Category:Mudlet Package Listing2013-02-28T15:23:39Z<p>Rayth: </p>
<hr />
<div>{{TOC right}}<br />
=Mudlet Packages=<br />
==Current MUDs with listed packages==<br />
* Achaea<br />
* Aetolia<br />
* God Wars II<br />
* Imperian<br />
* Lusternia<br />
* Midkemia Online<br />
<br />
=Package listing by MUD=<br />
==Achaea==<br />
# [[RiftTracker|Rift Tracker]]<br />
# [[Enemy_Highlighter|Enemy Highlighter]]<br />
# [[ShardCounter| Shard Counter]]<br />
# [[Sacrificer| simplified corpse handling]]<br />
# [[Refiller| Automatic concoctions refiller]]<br />
# [[Harvester| Automatic herb harvester]]<br />
<br />
==Aetolia==<br />
==God Wars II==<br />
==Discworld MUD==<br />
# [[DiscworldUI|Discworld MUD UI for Mudlet]]<br />
==Imperian==<br />
==Lusternia==<br />
==Midkemia Online==<br />
<br />
==Non-specific Packages==<br />
# [[IRE mapping script|IRE Mapping Script]]<br />
# [[Misc Scripts]]<br />
<br />
===GUI Packages===<br />
# [[Vyzor|Vyzor, UI Manager for Mudlet]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Mudlet_Object_Functions&diff=1509Manual:Mudlet Object Functions2012-05-14T16:37:59Z<p>Rayth: /* remember */</p>
<hr />
<div>== Mudlet Object Functions ==<br />
<br />
===appendCmdLine===<br />
;appendCmdLine()<br />
: Appends text to the main input line.<br />
<br />
;Example<br />
<lua><br />
-- adds the text "55 backpacks" to whatever is currently in the input line<br />
appendCmdLine("55 backpacks")<br />
<br />
-- makes a link, that when clicked, will add "55 backpacks" to the input line<br />
echoLink("press me", "appendCmdLine'55 backpack'", "Press me!")<br />
</lua><br />
<br />
===clearCmdLine===<br />
:clearCmdLine()<br />
: Clears the input line of any text that's been entered.<br />
<br />
;Example<br />
<lua><br />
-- don't be evil with this!<br />
clearCmdLine()<br />
</lua><br />
<br />
===createStopWatch===<br />
;createStopWatch()<br />
: This function creates a stop watch. It is high resolution time measurement tool. Stop watches can be started, stopped, reset and asked how much time has passed since the stop watch has been started.<br />
: Returns: The ID of a high resolution clock with milliseconds to measure time more accurately.<br />
<br />
;Example<br />
:In a global script you create all stop watches that you need in your system and store the respective stopWatch-IDs in global variables:<br />
<lua><br />
fightStopWatch = createStopWatch(); -- you store the watchID in a global variable to access it from anywhere<br />
</lua><br />
:Then you can start the stop watch in some trigger/alias/script with:<br />
<lua><br />
startStopWatch( fightStopWatch );<br />
</lua><br />
:To stop the watch and measure its time in e.g. a trigger script you can write:<br />
<lua><br />
fightTime = stopStopWatch( fightStopWatch )<br />
echo( "The fight lasted for " .. fightTime .. " seconds." )<br />
resetStopWatch( fightStopWatch );<br />
</lua><br />
:You can also measure the elapsed time without having to stop the stop watch with getStopWatchTime<br />
<br />
===disableAlias===<br />
;disableAlias(name)<br />
:Disables/deactivates the alias by it’s name. If several aliases have this name, they’ll all be disabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the alias. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--Disables the alias called 'my alias'<br />
disableAlias("my alias")<br />
</lua><br />
<br />
===disableKey===<br />
;disableKey(name)<br />
:Disable key or key group "name" (hot keys or action keys).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the key or group name that you want to disable.<br />
<br />
;Examples<br />
<br />
''Need example use''<br />
<br />
===disableTimer===<br />
;disableTimer(name)<br />
:Disables a timer from running it’s script when it fires - so the timer cycles will still be happening, just no action on them. If you’d like to permanently delete it, use [[Manual:Lua_Functions#killTrigger|killTrigger]] instead.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<br />
;Example<br />
<lua><br />
--Disables the timer called 'my timer'<br />
disableTimer("my timer")<br />
</lua><br />
<br />
===disableTrigger===<br />
;disableTrigger(name)<br />
:Disables a trigger that was previously enabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] on creation of the timer or the name of the timer in case of a GUI trigger.<br />
<br />
;Example<br />
<lua><br />
-- Disables the trigger called 'my trigger'<br />
disableTrigger("my trigger")<br />
</lua><br />
<br />
===enableAlias===<br />
;enableAlias(name)<br />
:Enables/activates the alias by it’s name. If several aliases have this name, they’ll all be enabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the alias ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] on creation of the alias or the name of the alias in case of a GUI alias.<br />
<br />
;Example<br />
<lua><br />
--Enables the alias called 'my alias'<br />
enableAlias("my alias")<br />
</lua><br />
<br />
===enableKey===<br />
;enableKey(name)<br />
:Enable key or key group "name" (hot keys or action keys).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the key or group name that you want to enable.<br />
<br />
===enableTimer===<br />
;enableTimer(name)<br />
:Enables or activates a timer that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<lua><br />
--Enables the timer called 'my timer'<br />
enableTimer("my timer")<br />
</lua><br />
<br />
===enableTrigger===<br />
;enableTrigger(name)<br />
:Enables a Trigger. see [[Manual:Lua_Functions#enableTimer|enableTimer]] for more details.<br />
<lua><br />
enableTrigger("my trigger")<br />
</lua><br />
<br />
===exists===<br />
;exists(name, type)<br />
:Tells you how many things of the given type exist. <br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', or 'timer'.<br />
<br />
;Example<br />
<lua><br />
echo("I have " .. exists("my trigger", "trigger") .. " triggers called 'my trigger'!")<br />
</lua><br />
<br />
: You can also use this alias to avoid creating duplicate things, for example:<br />
<lua><br />
-- this code doesn't check if an alias already exists and will keep creating new aliases<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
<br />
-- while this code will make sure that such an alias doesn't exist first<br />
-- we do == 0 instead of 'not exists' because 0 is considered true in Lua<br />
if exists("Attack", "alias") == 0 then<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
end<br />
</lua><br />
<br />
===getButtonState===<br />
;getButtonState()<br />
:This function can only be used inside a toggle button script <br />
<br />
:Returns ''2'' if button is checked, and ''1'' if it's not.<br />
<br />
;Example<br />
<lua><br />
checked = getButtonState();<br />
if checked == 1 then<br />
hideExits()<br />
else<br />
showExits()<br />
end;<br />
</lua><br />
<br />
===invokeFileDialog===<br />
;invokeFileDialog(fileOrFolder, dialogTitle)<br />
:Opens a file chooser dialog, allowing the user to select a file or a folder visually. The function returns the selected path or "" if there was none chosen.<br />
<br />
;Parameters<br />
* ''fileOrFolder:'' ''true'' for file selection, ''false'' for folder selection.<br />
* ''dialogTitle'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
function whereisit()<br />
local path = invokeFileDialog(false, "Where should we save the file? Select a folder and click Open")<br />
<br />
if path == "" then return nil else return path end<br />
end<br />
</lua><br />
<br />
===isActive===<br />
;isActive(name, type)<br />
:You can use this function to check if something, or somethings, are active. <br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', or 'timer'.<br />
<br />
;Example<br />
<lua><br />
echo("I have " .. isActive("my trigger", "trigger") .. " currently active trigger(s) called 'my trigger'!")<br />
</lua><br />
<br />
===isPrompt===<br />
;isPrompt()<br />
:Returns true or false depending on if the current line being processed is a prompt. This infallible feature is available for MUDs that supply GA events (to check if yours is one, look to bottom-right of the main window - if it doesn’t say <No GA>, then it supplies them).<br />
<br />
:Example use could be as a Lua function, making closing gates on a prompt real easy.<br />
<br />
;Example<br />
<lua><br />
-- make a trigger pattern with 'Lua function', and this will trigger on every prompt!<br />
return isPrompt()<br />
</lua><br />
<br />
===killAlias===<br />
;killAlias(name)<br />
:Deletes an alias with the given name. If several aliases have this name, they'll all be deleted.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the alias.<br />
<br />
<lua><br />
--Deletes the alias called 'my alias'<br />
killAlias("my alias")<br />
</lua><br />
<br />
===killTimer===<br />
;killTimer(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
{{note}} Non-temporary timers that you have set up in the GUI cannot be deleted with this function. Use [[Manual:Lua_Functions#disableTimer|disableTimer]] to turn them on or off.<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the timer id doesn’t exist anymore (timer has already fired) or the timer is not a temp timer.<br />
<br />
===killTrigger===<br />
;killTrigger(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTrigger]].<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the trigger id doesn’t exist anymore (trigger has already fired) or the trigger is not a temp trigger.<br />
<br />
===permAlias===<br />
;permAlias(name, parent, regex, lua code)<br />
<br />
:Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name you’d like the alias to have.<br />
* ''parent:'' <br />
: The name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''regex:''<br />
: The pattern that you’d like the alias to use.<br />
* ''lua code:'' <br />
: The script the alias will do when it matches.<br />
;Example<br />
<lua><br />
-- creates an alias called "new alias" in a group called "my group"<br />
permAlias("new alias", "my group", "^test$", [[echo ("say it works! This alias will show up in the script editor too.")]])<br />
</lua><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permAlias with the same name will keep creating new aliases. You can check if an alias already exists with the [[Manual:Lua_Functions#exists|exists]] function.<br />
<br />
===permGroup===<br />
;permGroup(name, itemtype)<br />
<br />
:Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts. <br />
;Parameters<br />
* ''name:''<br />
: The name of the new group you want to create.<br />
* ''itemtype:''<br />
: The name of the timer, trigger, or alias.<br />
<br />
{{note}} Added to Mudlet in the 2.0 final release.<br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
===permRegexTrigger===<br />
;permRegexTrigger(name, parent, pattern, lua code)<br />
:Creates a persistent trigger with a ''regex'' pattern that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<lua><br />
-- Create a regex trigger that will match on the prompt to record your status<br />
permRegexTrigger("Prompt", "", {"^(\d+)h, (\d+)m"}, [[health = tonumber(matches[2]; mana = tonumber(matches[3])]]<br />
</lua><br />
{{note}} Mudlet by design allows duplicate names - so calling permRegexTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
===permSubstringTrigger===<br />
;permSubstringTrigger( name, parent, pattern, lua code )<br />
:Creates a persistent trigger with a substring pattern that stays after Mudlet is restarted and shows up in the Script Editor.<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<lua><br />
-- Create a trigger to highlight the word "pixie" for us<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie"},<br />
[[selectString(line, 1) bg("yellow") resetFormat()]])<br />
<br />
-- Or another trigger to highlight several different things<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie", "cat", "dog", "rabbit"},<br />
[[selectString(line, 1) fg ("blue") bg("yellow") resetFormat()]])<br />
</lua><br />
{{note}} Mudlet by design allows duplicate names - so calling permSubstringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
===permTimer===<br />
;permTimer(name, parent, seconds, lua code)<br />
: Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:Is the name of the timer.<br />
* ''parent'' <br />
:Is the name of the timer group you want the timer to go in..<br />
* ''seconds'' <br />
:Is a number specifying a delay after which the timer will do the lua code you give it as a string.<br />
* ''lua code'' is the code with string you are doing this to.<br />
<br />
;Example:<br />
<lua><br />
permTimer("my timer", "first timer group", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
</lua><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permTimer with the same name will keep creating new timers. You can check if a timer already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
===printCmdLine===<br />
;printCmdLine(text)<br />
<br />
: Replaces the current text in the input line, and sets it to the given text.<br />
<br />
<lua><br />
printCmdLine("say I'd like to buy ")<br />
</lua><br />
<br />
===raiseEvent===<br />
;raiseEvent(event_name, arg-1, … arg-n)<br />
<br />
: Raises the event event_name. The event system will call the main function (the one that is called exactly like the script name) of all such scripts that have registered event handlers. If an event is raised, but no event handler scripts have been registered with the event system, the event is ignored and nothing happens. This is convenient as you can raise events in your triggers, timers, scripts etc. without having to care if the actual event handling has been implemented yet - or more specifically how it is implemented. Your triggers raise an event to tell the system that they have detected a certain condition to be true or that a certain event has happened. How - and if - the system is going to respond to this event is up to the system and your trigger scripts don’t have to care about such details. For small systems it will be more convenient to use regular function calls instead of events, however, the more complicated your system will get, the more important events will become because they help reduce complexity very much.<br />
<br />
:The corresponding event handlers that listen to the events raised with raiseEvent() need to use the script name as function name and take the correct number of arguments. <br />
<br />
<!-- Hm... what is this?<br />
{{note}} If you raise an event with 5 arguments but your event handlers functions only take 2,10 or 0 arguments, the functions will not be called. --><br />
<br />
;Example:<br />
<br />
:raiseEvent("fight") a correct event handler function would be: myScript( event_name ). In this example raiseEvent uses minimal arguments, name the event name. There can only be one event handler function per script, but a script can still handle multiple events as the first argument is always the event name. So you can call your own special handlers for individual events. The reason behind this is that you should rather use many individual scripts instead of one huge script that has all your function code etc. Scripts can be organized very well in trees and thus help reduce complexity on large systems.<br />
<br />
===remember===<br />
;remember("variable")<br />
;This function flags a variable to be saved by Mudlet's variable persistence system.<br />
<br />
;Parameters<br />
* ''variable''<br />
: Variable that you are saving. Can be a table or regular variable. Name must be passed as a string.<br />
<br />
;Example<br />
<lua>remember("table_Weapons")<br />
remember("var_EnemyHeight")<br />
</lua><br />
Variables are automatically unpacked into the global namespace when the profile is loaded.<br><br />
They are saved to "SavedVariables.lua" when the profile is closed or saved.<br />
<br />
===resetStopWatch===<br />
;resetStopWatch(watchID)<br />
:This function resets the time to 0:0:0.0, but does not start the stop watch. You can start it with [[Manual:Lua_Functions#startStopWatch | startStopWatch]] → [[Manual:Lua_Functions#createStopWatch | createStopWatch]]<br />
<br />
===setConsoleBufferSize===<br />
;setConsoleBufferSize( consoleName, linesLimit, sizeOfBatchDeletion )<br />
:Sets the maximum number of lines can a buffer (main window or a miniconsole) can hold.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of the window<br />
* ''linesLimit:''<br />
: Sets the amount of lines the buffer should have. <br />
{{note}} Mudlet performs extremely efficiently with even huge numbers, so your only limitation is your computers memory (RAM).<br />
* ''sizeOfBatchDeletion:''<br />
: Specifies how many lines should Mudlet delete at once when you go over the limit - it does it in bulk because it's efficient to do so.<br />
<br />
;Example<br />
<lua><br />
-- sets the main windows size to 5 million lines maximum - which is more than enough!<br />
setConsoleBufferSize("main", 5000000, 1000)<br />
</lua><br />
<br />
===setTriggerStayOpen===<br />
;setTriggerStayOpen(name, number)<br />
:Sets for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched - so this allows you to extend or shorten the ''fire length'' of a trigger. The main use of this function is to close a chain when a certain condition has been met.<br />
<br />
;Parameters<br />
* ''name:'' The name of the trigger which has a fire length set (and which opens the chain).<br />
* ''number'': 0 to close the chain, or a positive number to keep the chain open that much longer.<br />
<br />
;Examples<br />
<lua><br />
-- if you have a trigger that opens a chain (has some fire length) and you'd like it to be closed <br />
-- on the next prompt, you could make a trigger inside the chain with a Lua function pattern of:<br />
return isPrompt()<br />
-- and a script of:<br />
setTriggerStayOpen("''Parent trigger name''", 0)<br />
-- to close it on the prompt!<br />
</lua><br />
<br />
===startStopWatch===<br />
;startStopWatch( watchID )<br />
:Starts the stop watch. → [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
<br />
===stopStopWatch===<br />
;stopStopWatch( watchID )<br />
:Stops the stop watch and returns the elapsed time in milliseconds in form of 0.001. → [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
: Returns time as a number<br />
<br />
===tempAlias===<br />
;tempAlias(regex, code to do)<br />
:Creates a temporary alias - it'll won't be saved when Mudlet restarts and thus wiped.<br />
<br />
;Parameters<br />
* ''regex:'' Alias pattern in regex.<br />
* ''code to do:'':The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
;Examples<br />
<lua><br />
tempAlias("^hi$", [[send ("hi") echo ("we said hi!")]]<br />
</lua><br />
<br />
===tempColorTrigger===<br />
;tempColorTrigger(foregroundColor, backgroundColor, code)<br />
:Makes a color trigger that triggers on the specified foreground and background color. Both colors need to be supplied in form of these simplified ANSI 16 color mode codes.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code'': The code you'd like the trigger to run, as a string.<br />
<br />
;Color codes<br />
<lua><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</lua><br />
<br />
;Examples<br />
<lua><br />
-- This script will re-highlight all text in blue foreground colors on a black background with a red foreground color<br />
on a blue background color until another color in the current line is being met. temporary color triggers do not <br />
offer match_all or filter options like the GUI color triggers because this is rarely necessary for scripting. <br />
A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempColorTrigger(9,2,[[selectString(matches[1],1); fg("red"); bg("blue");]] );<br />
</lua><br />
<br />
===tempLineTrigger===<br />
;tempLineTrigger( from, howMany, LuaCode )<br />
:Temporary trigger that will fire on n consecutive lines following the current line. This is useful to parse output that is known to arrive in a certain line margin or to delete unwanted output from the MUD. <br />
<br />
:Returns trigger ID, ID is a string and not a number.<br />
{{note}} You can use this ID to enable/disable or kill this trigger later on.<br />
;Example: <br />
<lua><br />
--Will fire 3 times with the line from the MUD.<br />
tempLineTrigger( 1, 3, ) <br />
<br />
--Will fire 20 lines after the current line and fire twice on 2 consecutive lines.<br />
tempLineTrigger( 20, 2, )<br />
</lua><br />
<br />
===tempRegexTrigger===<br />
;tempRegexTrigger(regex, code to do)<br />
:Creates a temporary regex trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
<br />
: Returns trigger ID<br />
<br />
;Parameters:<br />
* ''regex:'' The regex to look for.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
{{note}} You can use this ID to enable/disable or kill this trigger later on. → [[Manual: Lua Functions#tempTrigger | tempTimer()]]<br />
<br />
===tempTimer===<br />
;tempTimer(time, code to do)<br />
:Creates a temporary single shot timer and returns the timer ID for subsequent [[Manual:Lua_Functions#enableTimer|enableTimer()]], [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#killTimer|killTimer()<br />
]] calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed. <br />
<br />
;Parameters<br />
* ''time:'' The time in seconds for which to set the timer for.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
{{note}} Double Brackets, e.g: [[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
===tempTrigger===<br />
;tempTrigger(substring, code to do)<br />
:Creates a temporary substring trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
;Parameters:<br />
* ''substring:'' The substring to look for.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Mudlet_Object_Functions&diff=1508Manual:Mudlet Object Functions2012-05-14T16:37:05Z<p>Rayth: /* remember */</p>
<hr />
<div>== Mudlet Object Functions ==<br />
<br />
===appendCmdLine===<br />
;appendCmdLine()<br />
: Appends text to the main input line.<br />
<br />
;Example<br />
<lua><br />
-- adds the text "55 backpacks" to whatever is currently in the input line<br />
appendCmdLine("55 backpacks")<br />
<br />
-- makes a link, that when clicked, will add "55 backpacks" to the input line<br />
echoLink("press me", "appendCmdLine'55 backpack'", "Press me!")<br />
</lua><br />
<br />
===clearCmdLine===<br />
:clearCmdLine()<br />
: Clears the input line of any text that's been entered.<br />
<br />
;Example<br />
<lua><br />
-- don't be evil with this!<br />
clearCmdLine()<br />
</lua><br />
<br />
===createStopWatch===<br />
;createStopWatch()<br />
: This function creates a stop watch. It is high resolution time measurement tool. Stop watches can be started, stopped, reset and asked how much time has passed since the stop watch has been started.<br />
: Returns: The ID of a high resolution clock with milliseconds to measure time more accurately.<br />
<br />
;Example<br />
:In a global script you create all stop watches that you need in your system and store the respective stopWatch-IDs in global variables:<br />
<lua><br />
fightStopWatch = createStopWatch(); -- you store the watchID in a global variable to access it from anywhere<br />
</lua><br />
:Then you can start the stop watch in some trigger/alias/script with:<br />
<lua><br />
startStopWatch( fightStopWatch );<br />
</lua><br />
:To stop the watch and measure its time in e.g. a trigger script you can write:<br />
<lua><br />
fightTime = stopStopWatch( fightStopWatch )<br />
echo( "The fight lasted for " .. fightTime .. " seconds." )<br />
resetStopWatch( fightStopWatch );<br />
</lua><br />
:You can also measure the elapsed time without having to stop the stop watch with getStopWatchTime<br />
<br />
===disableAlias===<br />
;disableAlias(name)<br />
:Disables/deactivates the alias by it’s name. If several aliases have this name, they’ll all be disabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the alias. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--Disables the alias called 'my alias'<br />
disableAlias("my alias")<br />
</lua><br />
<br />
===disableKey===<br />
;disableKey(name)<br />
:Disable key or key group "name" (hot keys or action keys).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the key or group name that you want to disable.<br />
<br />
;Examples<br />
<br />
''Need example use''<br />
<br />
===disableTimer===<br />
;disableTimer(name)<br />
:Disables a timer from running it’s script when it fires - so the timer cycles will still be happening, just no action on them. If you’d like to permanently delete it, use [[Manual:Lua_Functions#killTrigger|killTrigger]] instead.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<br />
;Example<br />
<lua><br />
--Disables the timer called 'my timer'<br />
disableTimer("my timer")<br />
</lua><br />
<br />
===disableTrigger===<br />
;disableTrigger(name)<br />
:Disables a trigger that was previously enabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] on creation of the timer or the name of the timer in case of a GUI trigger.<br />
<br />
;Example<br />
<lua><br />
-- Disables the trigger called 'my trigger'<br />
disableTrigger("my trigger")<br />
</lua><br />
<br />
===enableAlias===<br />
;enableAlias(name)<br />
:Enables/activates the alias by it’s name. If several aliases have this name, they’ll all be enabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the alias ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] on creation of the alias or the name of the alias in case of a GUI alias.<br />
<br />
;Example<br />
<lua><br />
--Enables the alias called 'my alias'<br />
enableAlias("my alias")<br />
</lua><br />
<br />
===enableKey===<br />
;enableKey(name)<br />
:Enable key or key group "name" (hot keys or action keys).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the key or group name that you want to enable.<br />
<br />
===enableTimer===<br />
;enableTimer(name)<br />
:Enables or activates a timer that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<lua><br />
--Enables the timer called 'my timer'<br />
enableTimer("my timer")<br />
</lua><br />
<br />
===enableTrigger===<br />
;enableTrigger(name)<br />
:Enables a Trigger. see [[Manual:Lua_Functions#enableTimer|enableTimer]] for more details.<br />
<lua><br />
enableTrigger("my trigger")<br />
</lua><br />
<br />
===exists===<br />
;exists(name, type)<br />
:Tells you how many things of the given type exist. <br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', or 'timer'.<br />
<br />
;Example<br />
<lua><br />
echo("I have " .. exists("my trigger", "trigger") .. " triggers called 'my trigger'!")<br />
</lua><br />
<br />
: You can also use this alias to avoid creating duplicate things, for example:<br />
<lua><br />
-- this code doesn't check if an alias already exists and will keep creating new aliases<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
<br />
-- while this code will make sure that such an alias doesn't exist first<br />
-- we do == 0 instead of 'not exists' because 0 is considered true in Lua<br />
if exists("Attack", "alias") == 0 then<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
end<br />
</lua><br />
<br />
===getButtonState===<br />
;getButtonState()<br />
:This function can only be used inside a toggle button script <br />
<br />
:Returns ''2'' if button is checked, and ''1'' if it's not.<br />
<br />
;Example<br />
<lua><br />
checked = getButtonState();<br />
if checked == 1 then<br />
hideExits()<br />
else<br />
showExits()<br />
end;<br />
</lua><br />
<br />
===invokeFileDialog===<br />
;invokeFileDialog(fileOrFolder, dialogTitle)<br />
:Opens a file chooser dialog, allowing the user to select a file or a folder visually. The function returns the selected path or "" if there was none chosen.<br />
<br />
;Parameters<br />
* ''fileOrFolder:'' ''true'' for file selection, ''false'' for folder selection.<br />
* ''dialogTitle'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
function whereisit()<br />
local path = invokeFileDialog(false, "Where should we save the file? Select a folder and click Open")<br />
<br />
if path == "" then return nil else return path end<br />
end<br />
</lua><br />
<br />
===isActive===<br />
;isActive(name, type)<br />
:You can use this function to check if something, or somethings, are active. <br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', or 'timer'.<br />
<br />
;Example<br />
<lua><br />
echo("I have " .. isActive("my trigger", "trigger") .. " currently active trigger(s) called 'my trigger'!")<br />
</lua><br />
<br />
===isPrompt===<br />
;isPrompt()<br />
:Returns true or false depending on if the current line being processed is a prompt. This infallible feature is available for MUDs that supply GA events (to check if yours is one, look to bottom-right of the main window - if it doesn’t say <No GA>, then it supplies them).<br />
<br />
:Example use could be as a Lua function, making closing gates on a prompt real easy.<br />
<br />
;Example<br />
<lua><br />
-- make a trigger pattern with 'Lua function', and this will trigger on every prompt!<br />
return isPrompt()<br />
</lua><br />
<br />
===killAlias===<br />
;killAlias(name)<br />
:Deletes an alias with the given name. If several aliases have this name, they'll all be deleted.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the alias.<br />
<br />
<lua><br />
--Deletes the alias called 'my alias'<br />
killAlias("my alias")<br />
</lua><br />
<br />
===killTimer===<br />
;killTimer(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
{{note}} Non-temporary timers that you have set up in the GUI cannot be deleted with this function. Use [[Manual:Lua_Functions#disableTimer|disableTimer]] to turn them on or off.<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the timer id doesn’t exist anymore (timer has already fired) or the timer is not a temp timer.<br />
<br />
===killTrigger===<br />
;killTrigger(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTrigger]].<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the trigger id doesn’t exist anymore (trigger has already fired) or the trigger is not a temp trigger.<br />
<br />
===permAlias===<br />
;permAlias(name, parent, regex, lua code)<br />
<br />
:Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name you’d like the alias to have.<br />
* ''parent:'' <br />
: The name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''regex:''<br />
: The pattern that you’d like the alias to use.<br />
* ''lua code:'' <br />
: The script the alias will do when it matches.<br />
;Example<br />
<lua><br />
-- creates an alias called "new alias" in a group called "my group"<br />
permAlias("new alias", "my group", "^test$", [[echo ("say it works! This alias will show up in the script editor too.")]])<br />
</lua><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permAlias with the same name will keep creating new aliases. You can check if an alias already exists with the [[Manual:Lua_Functions#exists|exists]] function.<br />
<br />
===permGroup===<br />
;permGroup(name, itemtype)<br />
<br />
:Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts. <br />
;Parameters<br />
* ''name:''<br />
: The name of the new group you want to create.<br />
* ''itemtype:''<br />
: The name of the timer, trigger, or alias.<br />
<br />
{{note}} Added to Mudlet in the 2.0 final release.<br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
===permRegexTrigger===<br />
;permRegexTrigger(name, parent, pattern, lua code)<br />
:Creates a persistent trigger with a ''regex'' pattern that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<lua><br />
-- Create a regex trigger that will match on the prompt to record your status<br />
permRegexTrigger("Prompt", "", {"^(\d+)h, (\d+)m"}, [[health = tonumber(matches[2]; mana = tonumber(matches[3])]]<br />
</lua><br />
{{note}} Mudlet by design allows duplicate names - so calling permRegexTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
===permSubstringTrigger===<br />
;permSubstringTrigger( name, parent, pattern, lua code )<br />
:Creates a persistent trigger with a substring pattern that stays after Mudlet is restarted and shows up in the Script Editor.<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<lua><br />
-- Create a trigger to highlight the word "pixie" for us<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie"},<br />
[[selectString(line, 1) bg("yellow") resetFormat()]])<br />
<br />
-- Or another trigger to highlight several different things<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie", "cat", "dog", "rabbit"},<br />
[[selectString(line, 1) fg ("blue") bg("yellow") resetFormat()]])<br />
</lua><br />
{{note}} Mudlet by design allows duplicate names - so calling permSubstringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
===permTimer===<br />
;permTimer(name, parent, seconds, lua code)<br />
: Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:Is the name of the timer.<br />
* ''parent'' <br />
:Is the name of the timer group you want the timer to go in..<br />
* ''seconds'' <br />
:Is a number specifying a delay after which the timer will do the lua code you give it as a string.<br />
* ''lua code'' is the code with string you are doing this to.<br />
<br />
;Example:<br />
<lua><br />
permTimer("my timer", "first timer group", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
</lua><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permTimer with the same name will keep creating new timers. You can check if a timer already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
===printCmdLine===<br />
;printCmdLine(text)<br />
<br />
: Replaces the current text in the input line, and sets it to the given text.<br />
<br />
<lua><br />
printCmdLine("say I'd like to buy ")<br />
</lua><br />
<br />
===raiseEvent===<br />
;raiseEvent(event_name, arg-1, … arg-n)<br />
<br />
: Raises the event event_name. The event system will call the main function (the one that is called exactly like the script name) of all such scripts that have registered event handlers. If an event is raised, but no event handler scripts have been registered with the event system, the event is ignored and nothing happens. This is convenient as you can raise events in your triggers, timers, scripts etc. without having to care if the actual event handling has been implemented yet - or more specifically how it is implemented. Your triggers raise an event to tell the system that they have detected a certain condition to be true or that a certain event has happened. How - and if - the system is going to respond to this event is up to the system and your trigger scripts don’t have to care about such details. For small systems it will be more convenient to use regular function calls instead of events, however, the more complicated your system will get, the more important events will become because they help reduce complexity very much.<br />
<br />
:The corresponding event handlers that listen to the events raised with raiseEvent() need to use the script name as function name and take the correct number of arguments. <br />
<br />
<!-- Hm... what is this?<br />
{{note}} If you raise an event with 5 arguments but your event handlers functions only take 2,10 or 0 arguments, the functions will not be called. --><br />
<br />
;Example:<br />
<br />
:raiseEvent("fight") a correct event handler function would be: myScript( event_name ). In this example raiseEvent uses minimal arguments, name the event name. There can only be one event handler function per script, but a script can still handle multiple events as the first argument is always the event name. So you can call your own special handlers for individual events. The reason behind this is that you should rather use many individual scripts instead of one huge script that has all your function code etc. Scripts can be organized very well in trees and thus help reduce complexity on large systems.<br />
<br />
===remember===<br />
;remember("variable")<br />
;This function flags a variable to be saved by Mudlet's variable persistence system.<br />
<br />
;Parameters<br />
* ''variable''<br />
: Variable that you are saving. Can be a table or regular variable. Name must be passed as a string.<br />
<br />
;Example<br />
<lua> remember("table_Weapons")<br />
remember("var_EnemyHeight")<br />
</lua><br />
Variables are automatically unpacked into the global namespace when the profile is loaded.<br><br />
They are saved to "SavedVariables.lua" when the profile is closed or saved.<br />
<br />
===resetStopWatch===<br />
;resetStopWatch(watchID)<br />
:This function resets the time to 0:0:0.0, but does not start the stop watch. You can start it with [[Manual:Lua_Functions#startStopWatch | startStopWatch]] → [[Manual:Lua_Functions#createStopWatch | createStopWatch]]<br />
<br />
===setConsoleBufferSize===<br />
;setConsoleBufferSize( consoleName, linesLimit, sizeOfBatchDeletion )<br />
:Sets the maximum number of lines can a buffer (main window or a miniconsole) can hold.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of the window<br />
* ''linesLimit:''<br />
: Sets the amount of lines the buffer should have. <br />
{{note}} Mudlet performs extremely efficiently with even huge numbers, so your only limitation is your computers memory (RAM).<br />
* ''sizeOfBatchDeletion:''<br />
: Specifies how many lines should Mudlet delete at once when you go over the limit - it does it in bulk because it's efficient to do so.<br />
<br />
;Example<br />
<lua><br />
-- sets the main windows size to 5 million lines maximum - which is more than enough!<br />
setConsoleBufferSize("main", 5000000, 1000)<br />
</lua><br />
<br />
===setTriggerStayOpen===<br />
;setTriggerStayOpen(name, number)<br />
:Sets for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched - so this allows you to extend or shorten the ''fire length'' of a trigger. The main use of this function is to close a chain when a certain condition has been met.<br />
<br />
;Parameters<br />
* ''name:'' The name of the trigger which has a fire length set (and which opens the chain).<br />
* ''number'': 0 to close the chain, or a positive number to keep the chain open that much longer.<br />
<br />
;Examples<br />
<lua><br />
-- if you have a trigger that opens a chain (has some fire length) and you'd like it to be closed <br />
-- on the next prompt, you could make a trigger inside the chain with a Lua function pattern of:<br />
return isPrompt()<br />
-- and a script of:<br />
setTriggerStayOpen("''Parent trigger name''", 0)<br />
-- to close it on the prompt!<br />
</lua><br />
<br />
===startStopWatch===<br />
;startStopWatch( watchID )<br />
:Starts the stop watch. → [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
<br />
===stopStopWatch===<br />
;stopStopWatch( watchID )<br />
:Stops the stop watch and returns the elapsed time in milliseconds in form of 0.001. → [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
: Returns time as a number<br />
<br />
===tempAlias===<br />
;tempAlias(regex, code to do)<br />
:Creates a temporary alias - it'll won't be saved when Mudlet restarts and thus wiped.<br />
<br />
;Parameters<br />
* ''regex:'' Alias pattern in regex.<br />
* ''code to do:'':The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
;Examples<br />
<lua><br />
tempAlias("^hi$", [[send ("hi") echo ("we said hi!")]]<br />
</lua><br />
<br />
===tempColorTrigger===<br />
;tempColorTrigger(foregroundColor, backgroundColor, code)<br />
:Makes a color trigger that triggers on the specified foreground and background color. Both colors need to be supplied in form of these simplified ANSI 16 color mode codes.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code'': The code you'd like the trigger to run, as a string.<br />
<br />
;Color codes<br />
<lua><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</lua><br />
<br />
;Examples<br />
<lua><br />
-- This script will re-highlight all text in blue foreground colors on a black background with a red foreground color<br />
on a blue background color until another color in the current line is being met. temporary color triggers do not <br />
offer match_all or filter options like the GUI color triggers because this is rarely necessary for scripting. <br />
A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempColorTrigger(9,2,[[selectString(matches[1],1); fg("red"); bg("blue");]] );<br />
</lua><br />
<br />
===tempLineTrigger===<br />
;tempLineTrigger( from, howMany, LuaCode )<br />
:Temporary trigger that will fire on n consecutive lines following the current line. This is useful to parse output that is known to arrive in a certain line margin or to delete unwanted output from the MUD. <br />
<br />
:Returns trigger ID, ID is a string and not a number.<br />
{{note}} You can use this ID to enable/disable or kill this trigger later on.<br />
;Example: <br />
<lua><br />
--Will fire 3 times with the line from the MUD.<br />
tempLineTrigger( 1, 3, ) <br />
<br />
--Will fire 20 lines after the current line and fire twice on 2 consecutive lines.<br />
tempLineTrigger( 20, 2, )<br />
</lua><br />
<br />
===tempRegexTrigger===<br />
;tempRegexTrigger(regex, code to do)<br />
:Creates a temporary regex trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
<br />
: Returns trigger ID<br />
<br />
;Parameters:<br />
* ''regex:'' The regex to look for.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
{{note}} You can use this ID to enable/disable or kill this trigger later on. → [[Manual: Lua Functions#tempTrigger | tempTimer()]]<br />
<br />
===tempTimer===<br />
;tempTimer(time, code to do)<br />
:Creates a temporary single shot timer and returns the timer ID for subsequent [[Manual:Lua_Functions#enableTimer|enableTimer()]], [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#killTimer|killTimer()<br />
]] calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed. <br />
<br />
;Parameters<br />
* ''time:'' The time in seconds for which to set the timer for.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
{{note}} Double Brackets, e.g: [[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
===tempTrigger===<br />
;tempTrigger(substring, code to do)<br />
:Creates a temporary substring trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
;Parameters:<br />
* ''substring:'' The substring to look for.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Mudlet_Object_Functions&diff=1507Manual:Mudlet Object Functions2012-05-14T16:32:41Z<p>Rayth: /* Mudlet Object Functions */</p>
<hr />
<div>== Mudlet Object Functions ==<br />
<br />
===appendCmdLine===<br />
;appendCmdLine()<br />
: Appends text to the main input line.<br />
<br />
;Example<br />
<lua><br />
-- adds the text "55 backpacks" to whatever is currently in the input line<br />
appendCmdLine("55 backpacks")<br />
<br />
-- makes a link, that when clicked, will add "55 backpacks" to the input line<br />
echoLink("press me", "appendCmdLine'55 backpack'", "Press me!")<br />
</lua><br />
<br />
===clearCmdLine===<br />
:clearCmdLine()<br />
: Clears the input line of any text that's been entered.<br />
<br />
;Example<br />
<lua><br />
-- don't be evil with this!<br />
clearCmdLine()<br />
</lua><br />
<br />
===createStopWatch===<br />
;createStopWatch()<br />
: This function creates a stop watch. It is high resolution time measurement tool. Stop watches can be started, stopped, reset and asked how much time has passed since the stop watch has been started.<br />
: Returns: The ID of a high resolution clock with milliseconds to measure time more accurately.<br />
<br />
;Example<br />
:In a global script you create all stop watches that you need in your system and store the respective stopWatch-IDs in global variables:<br />
<lua><br />
fightStopWatch = createStopWatch(); -- you store the watchID in a global variable to access it from anywhere<br />
</lua><br />
:Then you can start the stop watch in some trigger/alias/script with:<br />
<lua><br />
startStopWatch( fightStopWatch );<br />
</lua><br />
:To stop the watch and measure its time in e.g. a trigger script you can write:<br />
<lua><br />
fightTime = stopStopWatch( fightStopWatch )<br />
echo( "The fight lasted for " .. fightTime .. " seconds." )<br />
resetStopWatch( fightStopWatch );<br />
</lua><br />
:You can also measure the elapsed time without having to stop the stop watch with getStopWatchTime<br />
<br />
===disableAlias===<br />
;disableAlias(name)<br />
:Disables/deactivates the alias by it’s name. If several aliases have this name, they’ll all be disabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the alias. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--Disables the alias called 'my alias'<br />
disableAlias("my alias")<br />
</lua><br />
<br />
===disableKey===<br />
;disableKey(name)<br />
:Disable key or key group "name" (hot keys or action keys).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the key or group name that you want to disable.<br />
<br />
;Examples<br />
<br />
''Need example use''<br />
<br />
===disableTimer===<br />
;disableTimer(name)<br />
:Disables a timer from running it’s script when it fires - so the timer cycles will still be happening, just no action on them. If you’d like to permanently delete it, use [[Manual:Lua_Functions#killTrigger|killTrigger]] instead.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<br />
;Example<br />
<lua><br />
--Disables the timer called 'my timer'<br />
disableTimer("my timer")<br />
</lua><br />
<br />
===disableTrigger===<br />
;disableTrigger(name)<br />
:Disables a trigger that was previously enabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the trigger ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] on creation of the timer or the name of the timer in case of a GUI trigger.<br />
<br />
;Example<br />
<lua><br />
-- Disables the trigger called 'my trigger'<br />
disableTrigger("my trigger")<br />
</lua><br />
<br />
===enableAlias===<br />
;enableAlias(name)<br />
:Enables/activates the alias by it’s name. If several aliases have this name, they’ll all be enabled.<br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the alias ID that was returned by [[Manual:Lua_Functions#tempTrigger|tempTrigger]] on creation of the alias or the name of the alias in case of a GUI alias.<br />
<br />
;Example<br />
<lua><br />
--Enables the alias called 'my alias'<br />
enableAlias("my alias")<br />
</lua><br />
<br />
===enableKey===<br />
;enableKey(name)<br />
:Enable key or key group "name" (hot keys or action keys).<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the key or group name that you want to enable.<br />
<br />
===enableTimer===<br />
;enableTimer(name)<br />
:Enables or activates a timer that was previously disabled. <br />
<br />
;Parameters<br />
* ''name:''<br />
: Expects the timer ID that was returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] on creation of the timer or the name of the timer in case of a GUI timer.<br />
<lua><br />
--Enables the timer called 'my timer'<br />
enableTimer("my timer")<br />
</lua><br />
<br />
===enableTrigger===<br />
;enableTrigger(name)<br />
:Enables a Trigger. see [[Manual:Lua_Functions#enableTimer|enableTimer]] for more details.<br />
<lua><br />
enableTrigger("my trigger")<br />
</lua><br />
<br />
===exists===<br />
;exists(name, type)<br />
:Tells you how many things of the given type exist. <br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', or 'timer'.<br />
<br />
;Example<br />
<lua><br />
echo("I have " .. exists("my trigger", "trigger") .. " triggers called 'my trigger'!")<br />
</lua><br />
<br />
: You can also use this alias to avoid creating duplicate things, for example:<br />
<lua><br />
-- this code doesn't check if an alias already exists and will keep creating new aliases<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
<br />
-- while this code will make sure that such an alias doesn't exist first<br />
-- we do == 0 instead of 'not exists' because 0 is considered true in Lua<br />
if exists("Attack", "alias") == 0 then<br />
permAlias("Attack", "General", "^aa$", [[send ("kick rat")]])<br />
end<br />
</lua><br />
<br />
===getButtonState===<br />
;getButtonState()<br />
:This function can only be used inside a toggle button script <br />
<br />
:Returns ''2'' if button is checked, and ''1'' if it's not.<br />
<br />
;Example<br />
<lua><br />
checked = getButtonState();<br />
if checked == 1 then<br />
hideExits()<br />
else<br />
showExits()<br />
end;<br />
</lua><br />
<br />
===invokeFileDialog===<br />
;invokeFileDialog(fileOrFolder, dialogTitle)<br />
:Opens a file chooser dialog, allowing the user to select a file or a folder visually. The function returns the selected path or "" if there was none chosen.<br />
<br />
;Parameters<br />
* ''fileOrFolder:'' ''true'' for file selection, ''false'' for folder selection.<br />
* ''dialogTitle'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
function whereisit()<br />
local path = invokeFileDialog(false, "Where should we save the file? Select a folder and click Open")<br />
<br />
if path == "" then return nil else return path end<br />
end<br />
</lua><br />
<br />
===isActive===<br />
;isActive(name, type)<br />
:You can use this function to check if something, or somethings, are active. <br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item.<br />
* ''type:''<br />
: The type can be 'alias', 'trigger', or 'timer'.<br />
<br />
;Example<br />
<lua><br />
echo("I have " .. isActive("my trigger", "trigger") .. " currently active trigger(s) called 'my trigger'!")<br />
</lua><br />
<br />
===isPrompt===<br />
;isPrompt()<br />
:Returns true or false depending on if the current line being processed is a prompt. This infallible feature is available for MUDs that supply GA events (to check if yours is one, look to bottom-right of the main window - if it doesn’t say <No GA>, then it supplies them).<br />
<br />
:Example use could be as a Lua function, making closing gates on a prompt real easy.<br />
<br />
;Example<br />
<lua><br />
-- make a trigger pattern with 'Lua function', and this will trigger on every prompt!<br />
return isPrompt()<br />
</lua><br />
<br />
===killAlias===<br />
;killAlias(name)<br />
:Deletes an alias with the given name. If several aliases have this name, they'll all be deleted.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name or the id returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the alias.<br />
<br />
<lua><br />
--Deletes the alias called 'my alias'<br />
killAlias("my alias")<br />
</lua><br />
<br />
===killTimer===<br />
;killTimer(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTimer]].<br />
<br />
{{note}} Non-temporary timers that you have set up in the GUI cannot be deleted with this function. Use [[Manual:Lua_Functions#disableTimer|disableTimer]] to turn them on or off.<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the timer id doesn’t exist anymore (timer has already fired) or the timer is not a temp timer.<br />
<br />
===killTrigger===<br />
;killTrigger(id)<br />
:Deletes a [[Manual:Lua_Functions#tempTimer|tempTrigger]].<br />
<br />
;Parameters<br />
* ''id:''<br />
: The ID returned by [[Manual:Lua_Functions#tempTimer|tempTimer]] to identify the item. ID is a string and not a number.<br />
<br />
:Returns true on success and false if the trigger id doesn’t exist anymore (trigger has already fired) or the trigger is not a temp trigger.<br />
<br />
===permAlias===<br />
;permAlias(name, parent, regex, lua code)<br />
<br />
:Creates a persistent alias that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name you’d like the alias to have.<br />
* ''parent:'' <br />
: The name of the group, or another alias you want the trigger to go in - however if such a group/alias doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''regex:''<br />
: The pattern that you’d like the alias to use.<br />
* ''lua code:'' <br />
: The script the alias will do when it matches.<br />
;Example<br />
<lua><br />
-- creates an alias called "new alias" in a group called "my group"<br />
permAlias("new alias", "my group", "^test$", [[echo ("say it works! This alias will show up in the script editor too.")]])<br />
</lua><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permAlias with the same name will keep creating new aliases. You can check if an alias already exists with the [[Manual:Lua_Functions#exists|exists]] function.<br />
<br />
===permGroup===<br />
;permGroup(name, itemtype)<br />
<br />
:Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts. <br />
;Parameters<br />
* ''name:''<br />
: The name of the new group you want to create.<br />
* ''itemtype:''<br />
: The name of the timer, trigger, or alias.<br />
<br />
{{note}} Added to Mudlet in the 2.0 final release.<br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
===permRegexTrigger===<br />
;permRegexTrigger(name, parent, pattern, lua code)<br />
:Creates a persistent trigger with a ''regex'' pattern that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<lua><br />
-- Create a regex trigger that will match on the prompt to record your status<br />
permRegexTrigger("Prompt", "", {"^(\d+)h, (\d+)m"}, [[health = tonumber(matches[2]; mana = tonumber(matches[3])]]<br />
</lua><br />
{{note}} Mudlet by design allows duplicate names - so calling permRegexTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
===permSubstringTrigger===<br />
;permSubstringTrigger( name, parent, pattern, lua code )<br />
:Creates a persistent trigger with a substring pattern that stays after Mudlet is restarted and shows up in the Script Editor.<br />
;Parameters<br />
* ''name'' is the name you’d like the trigger to have.<br />
* ''parent'' is the name of the group, or another trigger you want the trigger to go in - however if such a group/trigger doesn’t exist, it won’t do anything. Use "" to make it not go into any groups.<br />
* ''pattern table'' is a table of patterns that you’d like the trigger to use - it can be one or many.<br />
* ''lua code'' is the script the trigger will do when it matches.<br />
;Example<br />
<lua><br />
-- Create a trigger to highlight the word "pixie" for us<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie"},<br />
[[selectString(line, 1) bg("yellow") resetFormat()]])<br />
<br />
-- Or another trigger to highlight several different things<br />
permSubstringTrigger("Highlight stuff", "General", {"pixie", "cat", "dog", "rabbit"},<br />
[[selectString(line, 1) fg ("blue") bg("yellow") resetFormat()]])<br />
</lua><br />
{{note}} Mudlet by design allows duplicate names - so calling permSubstringTrigger with the same name will keep creating new triggers. You can check if a trigger already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
===permTimer===<br />
;permTimer(name, parent, seconds, lua code)<br />
: Creates a persistent timer that stays after Mudlet is restarted and shows up in the Script Editor.<br />
<br />
;Parameters<br />
* ''name'' <br />
:Is the name of the timer.<br />
* ''parent'' <br />
:Is the name of the timer group you want the timer to go in..<br />
* ''seconds'' <br />
:Is a number specifying a delay after which the timer will do the lua code you give it as a string.<br />
* ''lua code'' is the code with string you are doing this to.<br />
<br />
;Example:<br />
<lua><br />
permTimer("my timer", "first timer group", 4.5, [[send ("my timer that's in my first timer group fired!")]])<br />
</lua><br />
<br />
{{note}} Mudlet by design allows duplicate names - so calling permTimer with the same name will keep creating new timers. You can check if a timer already exists with the [[Manual:Lua_Functions#exists|exists()]] function.<br />
<br />
===printCmdLine===<br />
;printCmdLine(text)<br />
<br />
: Replaces the current text in the input line, and sets it to the given text.<br />
<br />
<lua><br />
printCmdLine("say I'd like to buy ")<br />
</lua><br />
<br />
===raiseEvent===<br />
;raiseEvent(event_name, arg-1, … arg-n)<br />
<br />
: Raises the event event_name. The event system will call the main function (the one that is called exactly like the script name) of all such scripts that have registered event handlers. If an event is raised, but no event handler scripts have been registered with the event system, the event is ignored and nothing happens. This is convenient as you can raise events in your triggers, timers, scripts etc. without having to care if the actual event handling has been implemented yet - or more specifically how it is implemented. Your triggers raise an event to tell the system that they have detected a certain condition to be true or that a certain event has happened. How - and if - the system is going to respond to this event is up to the system and your trigger scripts don’t have to care about such details. For small systems it will be more convenient to use regular function calls instead of events, however, the more complicated your system will get, the more important events will become because they help reduce complexity very much.<br />
<br />
:The corresponding event handlers that listen to the events raised with raiseEvent() need to use the script name as function name and take the correct number of arguments. <br />
<br />
<!-- Hm... what is this?<br />
{{note}} If you raise an event with 5 arguments but your event handlers functions only take 2,10 or 0 arguments, the functions will not be called. --><br />
<br />
;Example:<br />
<br />
:raiseEvent("fight") a correct event handler function would be: myScript( event_name ). In this example raiseEvent uses minimal arguments, name the event name. There can only be one event handler function per script, but a script can still handle multiple events as the first argument is always the event name. So you can call your own special handlers for individual events. The reason behind this is that you should rather use many individual scripts instead of one huge script that has all your function code etc. Scripts can be organized very well in trees and thus help reduce complexity on large systems.<br />
<br />
===remember===<br />
This function flags a variable to be saved by Mudlet's variable persistence system.<br />
Usage: remember("varName")<br />
Example: remember("table_Weapons")<br />
Example: remember("var_EnemyHeight")<br />
Variables are automatically unpacked into the global namespace when the profile is loaded.<br />
They are saved to "SavedVariables.lua" when the profile is closed or saved.<br />
<br />
===resetStopWatch===<br />
;resetStopWatch(watchID)<br />
:This function resets the time to 0:0:0.0, but does not start the stop watch. You can start it with [[Manual:Lua_Functions#startStopWatch | startStopWatch]] → [[Manual:Lua_Functions#createStopWatch | createStopWatch]]<br />
<br />
===setConsoleBufferSize===<br />
;setConsoleBufferSize( consoleName, linesLimit, sizeOfBatchDeletion )<br />
:Sets the maximum number of lines can a buffer (main window or a miniconsole) can hold.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of the window<br />
* ''linesLimit:''<br />
: Sets the amount of lines the buffer should have. <br />
{{note}} Mudlet performs extremely efficiently with even huge numbers, so your only limitation is your computers memory (RAM).<br />
* ''sizeOfBatchDeletion:''<br />
: Specifies how many lines should Mudlet delete at once when you go over the limit - it does it in bulk because it's efficient to do so.<br />
<br />
;Example<br />
<lua><br />
-- sets the main windows size to 5 million lines maximum - which is more than enough!<br />
setConsoleBufferSize("main", 5000000, 1000)<br />
</lua><br />
<br />
===setTriggerStayOpen===<br />
;setTriggerStayOpen(name, number)<br />
:Sets for how many more lines a trigger script should fire or a chain should stay open after the trigger has matched - so this allows you to extend or shorten the ''fire length'' of a trigger. The main use of this function is to close a chain when a certain condition has been met.<br />
<br />
;Parameters<br />
* ''name:'' The name of the trigger which has a fire length set (and which opens the chain).<br />
* ''number'': 0 to close the chain, or a positive number to keep the chain open that much longer.<br />
<br />
;Examples<br />
<lua><br />
-- if you have a trigger that opens a chain (has some fire length) and you'd like it to be closed <br />
-- on the next prompt, you could make a trigger inside the chain with a Lua function pattern of:<br />
return isPrompt()<br />
-- and a script of:<br />
setTriggerStayOpen("''Parent trigger name''", 0)<br />
-- to close it on the prompt!<br />
</lua><br />
<br />
===startStopWatch===<br />
;startStopWatch( watchID )<br />
:Starts the stop watch. → [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
<br />
===stopStopWatch===<br />
;stopStopWatch( watchID )<br />
:Stops the stop watch and returns the elapsed time in milliseconds in form of 0.001. → [[Manual:Lua_Functions#createStopWatch|createStopWatch()]]<br />
: Returns time as a number<br />
<br />
===tempAlias===<br />
;tempAlias(regex, code to do)<br />
:Creates a temporary alias - it'll won't be saved when Mudlet restarts and thus wiped.<br />
<br />
;Parameters<br />
* ''regex:'' Alias pattern in regex.<br />
* ''code to do:'':The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
;Examples<br />
<lua><br />
tempAlias("^hi$", [[send ("hi") echo ("we said hi!")]]<br />
</lua><br />
<br />
===tempColorTrigger===<br />
;tempColorTrigger(foregroundColor, backgroundColor, code)<br />
:Makes a color trigger that triggers on the specified foreground and background color. Both colors need to be supplied in form of these simplified ANSI 16 color mode codes.<br />
<br />
;Parameters<br />
* ''foregroundColor:'' The foreground color you'd like to trigger on.<br />
* ''backgroundColor'': The background color you'd like to trigger on.<br />
* ''code'': The code you'd like the trigger to run, as a string.<br />
<br />
;Color codes<br />
<lua><br />
0 = default text color<br />
1 = light black<br />
2 = dark black<br />
3 = light red<br />
4 = dark red<br />
5 = light green<br />
6 = dark green<br />
7 = light yellow<br />
8 = dark yellow<br />
9 = light blue<br />
10 = dark blue<br />
11 = light magenta<br />
12 = dark magenta<br />
13 = light cyan<br />
14 = dark cyan<br />
15 = light white<br />
16 = dark white<br />
</lua><br />
<br />
;Examples<br />
<lua><br />
-- This script will re-highlight all text in blue foreground colors on a black background with a red foreground color<br />
on a blue background color until another color in the current line is being met. temporary color triggers do not <br />
offer match_all or filter options like the GUI color triggers because this is rarely necessary for scripting. <br />
A common usage for temporary color triggers is to schedule actions on the basis of forthcoming text colors in a particular context.<br />
tempColorTrigger(9,2,[[selectString(matches[1],1); fg("red"); bg("blue");]] );<br />
</lua><br />
<br />
===tempLineTrigger===<br />
;tempLineTrigger( from, howMany, LuaCode )<br />
:Temporary trigger that will fire on n consecutive lines following the current line. This is useful to parse output that is known to arrive in a certain line margin or to delete unwanted output from the MUD. <br />
<br />
:Returns trigger ID, ID is a string and not a number.<br />
{{note}} You can use this ID to enable/disable or kill this trigger later on.<br />
;Example: <br />
<lua><br />
--Will fire 3 times with the line from the MUD.<br />
tempLineTrigger( 1, 3, ) <br />
<br />
--Will fire 20 lines after the current line and fire twice on 2 consecutive lines.<br />
tempLineTrigger( 20, 2, )<br />
</lua><br />
<br />
===tempRegexTrigger===<br />
;tempRegexTrigger(regex, code to do)<br />
:Creates a temporary regex trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
<br />
: Returns trigger ID<br />
<br />
;Parameters:<br />
* ''regex:'' The regex to look for.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
{{note}} You can use this ID to enable/disable or kill this trigger later on. → [[Manual: Lua Functions#tempTrigger | tempTimer()]]<br />
<br />
===tempTimer===<br />
;tempTimer(time, code to do)<br />
:Creates a temporary single shot timer and returns the timer ID for subsequent [[Manual:Lua_Functions#enableTimer|enableTimer()]], [[Manual:Lua_Functions#disableTimer|disableTimer()]] and [[Manual:Lua_Functions#killTimer|killTimer()<br />
]] calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed. <br />
<br />
;Parameters<br />
* ''time:'' The time in seconds for which to set the timer for.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
{{note}} Double Brackets, e.g: [[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
===tempTrigger===<br />
;tempTrigger(substring, code to do)<br />
:Creates a temporary substring trigger that executes the code whenever it matches. The function returns the trigger ID for subsequent [[Manual:Lua_Functions#enableTrigger|enableTrigger()]], [[Manual:Lua_Functions#disableTrigger|disableTrigger()]] and [[Manual:Lua_Functions#killTrigger|killTrigger()]] calls.<br />
;Parameters:<br />
* ''substring:'' The substring to look for.<br />
* ''code to do'': The code to do when the timer is up - wrap it in [[ ]], or provide a Lua function.<br />
<br />
[[Category:Mudlet Manual]]<br />
[[Category:Mudlet API]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Mapper&diff=1506Manual:Mapper2012-05-14T16:28:25Z<p>Rayth: </p>
<hr />
<div>=Mapper=<br />
== Maps and Autowalking==<br />
Maps are implemented as directed graphs of connected nodes (rooms). Nodes are connected by edges (exits). Nodes are referenced by unique integer IDs. Edges fall into 2 categories: Standard exits with a visual representation on the map (e. g. north, south) and "special exits" without a calculated visual representation on the map e. g. the command "jump cliff" is a special exit that connects to a room without a clear spatial orientation. However, special exits can be visually represented if the user provides custom exit line strips. Standard exits are referenced by their respective node and a directional integer value. Special exits are referenced by their respective nodes and strings that hold the exit commands. Both nodes and individual exits can seperately be locked and thus excluded from speed walk path finding graphs. Path finding uses the fast A* search algorithm. Mudlet choses a path with the fastest travel time (-> room weights) as opposed to the shortest path.<br />
<br />
Maps are divided into areas or zones where the area/room relationship is unique, i. e. rooms cannot be in more than 1 area. <br />
<br />
{{note}}Areas help make do with the typical geographical irregularities of MUD maps where an entire city with hundrets of rooms makes up a single room on a wilderness map. In other words, if you can't make a place look geographically correctly, create (sub) areas to deal with the problem.<br />
<br />
There are 2 forms of visual representations of maps. Standard mode shows exits and custom exit lines whereas "grid mode" hides exit details and sizes rooms to form a perfect grid without any empty space in between rooms. Grid maps can be made to look exactly like ASCII color text maps with character symbols to keep the look and feel of the MUD. Technically, grid maps are a special optimized representation of the typically very large LPC MUD style wilderness maps where every room has 8 direct neighbors in a n*m grid of rooms with relatively few holes. The grid map implementation uses pre image caching and fast gfx hardware render support and can thus render very large grid maps in less than 1ms that would take much longer if the map were to be displayed in regular mode. Changing the zoom level of maps in grid mode can take a significant amount of time if the maps are very large, because the pre cached images of the map need to be recreated at the new zoom level. Areas remember their particular zoom level so this is no hindering issue in actual gameplay.<br />
<br />
Any map can be displayed in both modes, but the visual map editor only works in regular mode. Consequently, grid map mode need to be turned off before editing the map. Grid mode is an area property.<br />
<br />
[[File:Ashar-city.png|250px|frameless|regular mode]] ''regular mode''<br />
[[File:GridMapExample.PNG|250px|frameless|grid mode]] ''grid mode.''<br />
<br />
=== Areas ===<br />
Areas are defined by a unique integer number ID and a unique area name. Mudlet builds an internal numerical area ID table on the basis of the rooms that belong to the respective areas. Mudlet keeps a seperate lookup table to retrieve the area name on the basis of the area IDs. This name lookup table is not guaranteed to be correct because it may be imported invalid information if the map has been downloaded by the game server as an xml map description file on the basis of the MMP protocol. <ref>MMP allows for an area ID/area names table to be defined, but Mudlet has no means to verify which definition is the correct one if 2 different area names relate to the same area ID.</ref> However, if the map has been created with Mudlet directly, there will be no such problems as the area name lookup table API is made to enforce uniqueness.<br />
<br />
==== Area Properties ====<br />
* area map display mode (-> regular map display mode or grid mode)<br />
* area name<br />
<br />
=== Rooms ===<br />
Rooms are invisible on the map unless the required properties have been set.<br />
==== Room Properties ====<br />
*Room object need following required properties in order to be shown on the respective area map:<br />
** unique room ID in form of an integer value <br />
** area ID in form of an integer value (To which area does this room belong - or in other words, which area map displays this room)<br />
** x, y and z coordinates as integer values which relate to its paricular area map coordinate system<br />
<br />
*Optional room properties:<br />
** regular exits with or without respective exit locks<br />
** special exits with or without respecitve special exit locks<br />
** room lock<br />
** exit stubs (draw exit directions even though the exit rooms have not yet been defined)<br />
** custom exit lines (user defined line strips of various formats to visualize special exits or redefine regular exit lines)<br />
** searchable room name that can be used for bookmarks, annotations etc. <br />
** room weight (How long does it travel through this node. A high room weight makes it less likely that this room will be chosen for pathfinding e. g. a safe road should have a low weight, whereas a dangerous place should have a high weight<br />
** room color<br />
** room character e. g. the symbol $ to symbolize a bank or H for a hotel.<br />
<br />
== Advanced Map Features ==<br />
=== Map Labels ===<br />
Maps can be embellised with images and text labels. Map labels can be either used as background (default) or as the top most foreground e. g. for player name location scripts. Labels are defined by position and size according to the map coordinate system and keep their position and size relative to the rest of the map when the map is zoomed or moved.<br />
Contrary to rooms which work on the basis of integer (natural numbers) coordinates, labels are described (with respect to both position & size) by real numbers in order to allow for more advanced placement and label sizes within the map coordinate system. Map labels are stored in form of png images directly in the map file and are thus a direct part of the map. As these images are being scaled to fit the label creation size, the image quality will depend on the initial size of the label (the large the better the quality, but the more memory will be used).<br />
<br />
[[File:MapTextLabelDemo.PNG|250px|frameless|misc label types]]<br />
[[File:MalLabelsScaled.PNG|250px|frameless|zoomed]]<br />
[[File:MapBackgroundImageLabel.PNG|250px|frameless|label as background image]]<br />
<br />
(The desert and dragon images used in this example are licensed under the Creative Commons Attribution 2.0 Generic license and can be found here: http://en.wikipedia.org/wiki/File:Ninedragonwallpic1.jpg and http://en.wikipedia.org/wiki/File:Siwa_sand_dunes2009a.jpg)<br />
<br />
=== Custom Exit Line Definitions ===<br />
The mapper supports user defined visual exit lines on the basis of a sequence of line points in the map coordinate system. Custom lines as well as labels work on real numbers to allow for fine grained placement. User defined lines can be solid, dotted, dashed etc. line types with or without ending arrows. The line color can be freely selected. By default the regular exit color is being used.<br />
<br />
[[File:CustomExitSelection.PNG|500px|frameless|custom exit line demo]]<br />
<br />
The above example shows 3 different types of user defined exit lines, where the orange one on the left has been selected by the user in order to be edited.<br />
<br />
Custom exit lines are purely visual tools and have no effect on the pathfinding, but each custom line must be linked to a valid room exit - either standard or special exit.<br />
<br />
==Visual Map Editor==<br />
Maps can be comfortably edited by using the visual map editor or by scripts. The editor behaves like the usual WYSIWYG editors. Select objects with a left click and then right click to open a context menus and do actions on the selected objects.<br />
===Object selection===<br />
<br />
* left click = select element<br />
* left click + drag = sizing group selection box choosing all rooms in the box on the current z-level<br />
* left click + shift + drag = sizing group selection box choosing all rooms in the box on all z-levels<br />
* left click + alt (or the mapper menu move map buttons) = move map<br />
* left click + control = add a room to current group selection or remove it<br />
<br />
if multiple rooms are being selected a room id selection list box is being shown where you can fine tune the current room selection via the usual ''left click + control'' or ''left click + shift''. The box disappears if the number of rooms in group selection is zero.<br />
<br />
===Moving Objects===<br />
Move selected objects either by right click and select "move" or with following handy short cut:<br />
<br />
* left button down on custom line point + drag = move custom line point<br />
* left button down + drag usually moves the item directly (as a handy shortcut) if only one element has been selected<br />
* '''or''' hold left button down + control + drag if multiple rooms have been selected<br />
<br />
== Mapping Tutorial ==<br />
<br />
<br />
== Notes ==<br />
<references /><br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Mapper&diff=1505Manual:Mapper2012-05-14T16:19:22Z<p>Rayth: </p>
<hr />
<div>=Mapper=<br />
== Maps and Autowalking==<br />
Maps are implemented as directed graphs of connected nodes (rooms). Nodes are connected by edges (exits). Nodes are referenced by unique integer IDs. Edges fall into 2 categories: Standard exits with a visual representation on the map (e. g. north, south) and "special exits" without a calculated visual representation on the map e. g. the command "jump cliff" is a special exit that connects to a room without a clear spatial orientation. However, special exits can be visually represented if the user provides custom exit line strips. Standard exits are referenced by their respective node and a directional integer value. Special exits are referenced by their respective nodes and strings that hold the exit commands. Both nodes and individual exits can seperately be locked and thus excluded from speed walk path finding graphs. Path finding uses the fast A* search algorithm. Mudlet choses a path with the fastest travel time (-> room weights) as opposed to the shortest path.<br />
<br />
Maps are divided into areas or zones where the area/room relationship is unique, i. e. rooms cannot be in more than 1 area. <br />
<br />
{{note}}Areas help make do with the typical geographical irregularities of MUD maps where an entire city with hundrets of rooms makes up a single room on a wilderness map. In other words, if you can't make a place look geographically correctly, create (sub) areas to deal with the problem.<br />
<br />
There are 2 forms of visual representations of maps. Standard mode shows exits and custom exit lines whereas "grid mode" hides exit details and sizes rooms to form a perfect grid without any empty space in between rooms. Grid maps can be made to look exactly like ASCII color text maps with character symbols to keep the look and feel of the MUD. Technically, grid maps are a special optimized representation of the typically very large LPC MUD style wilderness maps where every room has 8 direct neighbors in a n*m grid of rooms with relatively few holes. The grid map implementation uses pre image caching and fast gfx hardware render support and can thus render very large grid maps in less than 1ms that would take much longer if the map were to be displayed in regular mode. Changing the zoom level of maps in grid mode can take a significant amount of time if the maps are very large, because the pre cached images of the map need to be recreated at the new zoom level. Areas remember their particular zoom level so this is no hindering issue in actual gameplay.<br />
<br />
Any map can be displayed in both modes, but the visual map editor only works in regular mode. Consequently, grid map mode need to be turned off before editing the map. Grid mode is an area property.<br />
<br />
[[File:Ashar-city.png|250px|frameless|regular mode]] ''regular mode''<br />
[[File:GridMapExample.PNG|250px|frameless|grid mode]] ''grid mode.''<br />
<br />
=== Areas ===<br />
Areas are defined by a unique integer number ID and a unique area name. Mudlet builds an internal numerical area ID table on the basis of the rooms that belong to the respective areas. Mudlet keeps a seperate lookup table to retrieve the area name on the basis of the area IDs. This name lookup table is not guaranteed to be correct because it may be imported invalid information if the map has been downloaded by the game server as an xml map description file on the basis of the MMP protocol. <ref>MMP allows for an area ID/area names table to be defined, but Mudlet has no means to verify which definition is the correct one if 2 different area names relate to the same area ID.</ref> However, if the map has been created with Mudlet directly, there will be no such problems as the area name lookup table API is made to enforce uniqueness.<br />
<br />
==== Area Properties ====<br />
* area map display mode (-> regular map display mode or grid mode)<br />
* area name<br />
<br />
=== Rooms ===<br />
Rooms are invisible on the map unless the required properties have been set.<br />
==== Room Properties ====<br />
*Room object need following required properties in order to be shown on the respective area map:<br />
** unique room ID in form of an integer value <br />
** area ID in form of an integer value (To which area does this room belong - or in other words, which area map displays this room)<br />
** x, y and z coordinates as integer values which relate to its paricular area map coordinate system<br />
<br />
*Optional room properties:<br />
** regular exits with or without respective exit locks<br />
** special exits with or without respecitve special exit locks<br />
** room lock<br />
** exit stubs (draw exit directions even though the exit rooms have not yet been defined)<br />
** custom exit lines (user defined line strips of various formats to visualize special exits or redefine regular exit lines)<br />
** searchable room name that can be used for bookmarks, annotations etc. <br />
** room weight (How long does it travel through this node. A high room weight makes it less likely that this room will be chosen for pathfinding e. g. a safe road should have a low weight, whereas a dangerous place should have a high weight<br />
** room color<br />
** room character e. g. the symbol $ to symbolize a bank or H for a hotel.<br />
<br />
== Advanced Map Features ==<br />
=== Map Labels ===<br />
Maps can be embellised with images and text labels. Map labels can be either used as background (default) or as the top most foreground e. g. for player name location scripts. Labels are defined by position and size according to the map coordinate system and keep their position and size relative to the rest of the map when the map is zoomed or moved.<br />
Contrary to rooms which work on the basis of integer (natural numbers) coordinates, labels are described (with respect to both position & size) by real numbers in order to allow for more advanced placement and label sizes within the map coordinate system. Map labels are stored in form of png images directly in the map file and are thus a direct part of the map. As these images are being scaled to fit the label creation size, the image quality will depend on the initial size of the label (the large the better the quality, but the more memory will be used).<br />
<br />
[[File:MapTextLabelDemo.PNG|250px|frameless|misc label types]]<br />
[[File:MalLabelsScaled.PNG|250px|frameless|zoomed]]<br />
[[File:MapBackgroundImageLabel.PNG|250px|frameless|label as background image]]<br />
<br />
(The desert and dragon images used in this example are licensed under the Creative Commons Attribution 2.0 Generic license and can be found here: http://en.wikipedia.org/wiki/File:Ninedragonwallpic1.jpg and http://en.wikipedia.org/wiki/File:Siwa_sand_dunes2009a.jpg)<br />
<br />
=== Custom Exit Line Definitions ===<br />
The mapper supports user defined visual exit lines on the basis of a sequence of line points in the map coordinate system. Custom lines as well as labels work on real numbers to allow for fine grained placement. User defined lines can be solid, dotted, dashed etc. line types with or without ending arrows. The line color can be freely selected. By default the regular exit color is being used.<br />
<br />
[[File:CustomExitSelection.PNG|500px|frameless|custom exit line demo]]<br />
<br />
The above example shows 3 different types of user defined exit lines, where the orange one on the left has been selected by the user in order to be edited.<br />
<br />
Custom exit lines are purely visual tools and have no effect on the pathfinding, but each custom line must be linked to a valid room exit - either standard or special exit.<br />
<br />
==Visual Map Editor==<br />
Maps can be comfortably edited by using the visual map editor or by scripts. The editor behaves like the usual WYSIWYG editors. Select objects with a left click and then right click to open a context menus and do actions on the selected objects.<br />
===Object selection===<br />
<br />
* left click = select element<br />
* left click + drag = sizing group selection box choosing all rooms in the box on the current z-level<br />
* left click + shift + drag = sizing group selection box choosing all rooms in the box on all z-levels<br />
* left click + alt (or the mapper menu move map buttons) = move map<br />
* left click + control = add a room to current group selection or remove it<br />
<br />
if multiple rooms are being selected a room id selection list box is being shown where you can fine tune the current room selection via the usual ''left click + control'' or ''left click + shift''. The box disappears if the number of rooms in group selection is zero.<br />
<br />
===Moving Objects===<br />
Move selected objects either by right click and select "move" or with following handy short cut:<br />
<br />
* left button down on custom line point + drag = move custom line point<br />
* left button down + drag usually moves the item directly (as a handy shortcut) if only one element has been selected<br />
* '''or''' hold left button down + control + drag if multiple rooms have been selected<br />
<br />
== Mapping Tutorial ==<br />
<br />
<br />
== Notes ==<br />
<references /><br />
<br />
[[Category:Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Category:Mudlet_API&diff=1312Category:Mudlet API2012-02-15T03:39:42Z<p>Rayth: </p>
<hr />
<div>The Mudlet API category contains articles on Mudlet Lua API's.<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=IRE_mapping_script&diff=1310IRE mapping script2012-02-10T23:52:26Z<p>Rayth: Wrong alias. Can't verify what alias/function is used to lock a room.</p>
<hr />
<div>This is the Lua component to make the Mudlet Mapper work for IRE games. You'll need to import the xml below in order for autowalking to work on Achaea, Aetolia, Lusternia, Imperian, or Midkemia Online. See the '''[[IRE_mapping_script#Download|download section]]''' to get started!<br />
<br />
It has many features such as:<br />
* automatic repathing if you get offcourse<br />
* locking of whole areas<br />
* auto-swimming<br />
* mapping<br />
<br />
= Download = <br />
'''[http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/download/head:/mudletmapper.xml-20100916000616-71kbxngi7b3nybta-1/mudlet-mapper.xml latest version]''' (updated very often) - [http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/atom news feed] for updates, or read the changelog [http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/changes/ here].<br />
<br />
If updating and you're on a Mudlet that has the package manager, then just remove the mudlet-mapper package and install the new xml. Otherwise, delete all Mudlet Mapper folders in Mudlet (aliases, triggers, scripts) and import the new xml.<br />
<br />
The mapper script is absolutely free, though if you'll be making adjustments to it, please [http://forums.mudlet.org/viewtopic.php?f=13&t=1696 contribute them back]!<br />
<br />
= Installing =<br />
* make sure you're using a version of Mudlet that has a mapper (either a Map button or a Toolbox -> Show Map option)<br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td>For Mac users this means you must be using at least the download: [http://forums.mudlet.org/viewtopic.php?f=5&t=1874 2.x release]</td><br />
</table><br />
* import this script<br />
* make sure you're connected to 'achaea.com', 'lusternia.com', 'aetolia.com', 'imperian.com' or 'midkemiaonline.com' if you'd like Mudlet to download a map for you<br />
* done!<br />
<br />
= Updating =<br />
To update the '''mapper script''', firstly delete all the Mudlet Mapper trigger, alias and script folders. Then, download the [http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/download/head:/mudletmapper.xml-20100916000616-71kbxngi7b3nybta-1/mudlet-mapper.xml new xml] and import it.<br />
<br />
<br />
----<br />
<br />
To make Mudlet re-download the '''map''', close Mudlet, find the ~/.config/mudlet/profiles/<your profile>/map folder and delete it. ~ is your home folder. Start Mudlet again, click the Map button and it'll download the latest map.<br />
<br />
Note: On Windows its %USERPROFILE%/.config/mudlet/profiles/<your profile>/map<br />
<br />
Mapper changelog is available [http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/changes/ here].<br />
<br />
= Support =<br />
If you wish to leave any feedback on the script, please comment on the [http://forums.mudlet.org/viewtopic.php?f=13&t=1696 Mudlet forums]!<br />
<br />
= Aliases =<br />
== common ==<br />
=== goto ===<br />
: goto <id> - goes to a room of that id<br />
: goto <area> - goes to a specific area<br />
: goto <id> sprint/dash/gallop - goes to a place, sprinting, dashing or galloping whenever possible<br />
: goto <area> # - goes to an area - the number specifies which one exactly if more than one matches<br />
<br />
=== mpp ===<br />
: mpp [on|off] - toggles or sets mapper to be paused<br />
<br />
=== mstop ===<br />
: mstop - stops the mapper completely<br />
<br />
=== rf / room find ===<br />
: rf <name>, room find <name> - searches for a room of a given name<br />
<br />
=== area list ===<br />
: area list - shows the known area list<br />
<br />
=== room list ===<br />
: room list <area> - shows the list of rooms in an area<br />
<br />
=== arealock ===<br />
: arealock, arealock <area> - displays a list of areas you can lock/unlock, can also give it an area name to filter by. If an area is locked the mapper will not attempt to walk through or go through any of the rooms in the area;<br />
<br />
=== rl / room look ===<br />
: ''rl'' or ''room look'' - displays information about the room you're in<br />
: ''rl roomID'' or ''room look roomID'' - displays information on a given room ID (ie, ''rl 34'')<br />
: ''rl room name'' or ''room look room name'' - displays information on a given room, by it's name (ie, ''rl tavern of blah'')<br />
<br />
* Note that this will override the in-game ''rl'' command - but you can use RL to still read the last message.<br />
<br />
=== showpath ===<br />
: ''showpath roomID'' - shows you a path from where you are to another room (by it's ID)<br />
: ''showpath fromID toID'' - shows you a path from a given room to another given to another room<br />
<br />
* Note that this will override the in-game ''rl'' command - but you can use RL to still read the last message.<br />
<br />
== mapping ==<br />
It's best that you always have the latest version of Mudlet 2.0 release candidate installed while mapping (especially not rc4, which was buggy), along with the latest version of this script - because both are still very much in progress and are updated and improved often. Feel free to submit feedback on the mapping script [http://forums.mudlet.org/viewtopic.php?f=13&t=1696 on the forums], or even improve it yourself as all the code is available. General [http://forums.mudlet.org/viewforum.php?f=13 Mudlet Mapper] feedback is welcomed as well.<br />
<br />
=== Some Tips on Mapping ===<br />
<br />
* it's best to map in the 2D mode, because then you can select them en-masse and move them around, as well as doing other things<br />
* when moving around rooms via selection, do not include the room you're currently in, it'll go wild. If this is a problem, then move the current room out to wild coordinates and then move it back<br />
* when the mapper automatically makes a new room it is wise to issue a ''room area <area name>'' command to ensure the room is in the correct area.<br />
* the automatic map view in Mudlet tries to do its best to get the rooms in a sensible order, however the Divine do not always make this easy. Sometimes no matter how much you move the rooms around you simply cannot get the map to look perfect; if this happens:<br />
** you can try to move the rooms around manually (take note of the above tip though)<br />
** if you see yourself in a room but cannot take the apparent exit (e.g. you try to go ''north'' but there is no exit ''north'') you might have two rooms on top of each other; this can be a symptom of this problem<br />
** if you click on a room to walk to that room and you take what seems to be an improbably long path, it is possible some exits are not the direction they appear<br />
** the mapper knows about all the rooms even if Mudlet cannot display them in a way that is easy for us to see, the mapper can still use those rooms to get to or to auto walk through<br />
<br />
'''IMPORTANT:''' ''map save'' is your friend; you don't need to use it after each room you add, but it is suggested you use it after mapping one particular area or a smaller part of a large area; it is better to save more often than have to remap an area because of something totally unexpected.<br />
<br />
Here's a [http://www.youtube.com/watch?v=MgD9Nfz16uQ&hd=1 short mapping video] to get a sense of a possible way to map things.<br />
<br />
==== Mapping new areas ====<br />
The mapper relies on the in-game room IDs for it's own, and so it's best that you keep them in sync when creating new rooms as well - if you're in an unmapped room, 'rl' will tell you the rooms in-game ID. So when starting to map a new room in a new area, it'd best to create the new room with it's in-game ID at 0 0 0 coordinates, create the area, and move the room into the area - ie:<br />
<br />
mc on<br />
<br />
rl<br />
<see the room ID><br />
<br />
rlc v<room id> 0 0 0<br />
<br />
survey<br />
<see area name><br />
<br />
area add <area name><br />
(this will create the area)<br />
<br />
room area <area name><br />
(this will move the room to the new area)<br />
<br />
Proceed to walking about and automapping! Take a look at a small [http://www.youtube.com/watch?v=MgD9Nfz16uQ&hd=1 howto video] to get ideas on solving mapping problems as well that you might run into.<br />
<br />
=== mc - toggle mapping mode ===<br />
Usage: *mc or map create <option>*, where option can be "on" or "off". Turning the mapping mode on enables the mapping aliases, along with several automapping things (that rely on GMCP being enabled):<br />
* room creation - if you enter a room that's not mapped yet, it'll map it<br />
* exit creation - if there is an unmapped exit in the room, the mapper will auto-link it to another room (and create that other room if it doesn't exist yet)<br />
* exit deletion - if the mapper knows about an exit that doesn't really exist, it'll remove it<br />
<br />
=== rlc - create a room ===<br />
Usage: *rlc or room create <option>*, where option will specify the location of the new room. The new room will be auto-linked to the current one, be placed in the same area and take on the same environment type. If the mapper doesn't currently know where you are, you'll have to specify the exact coordinates that you'd like to place the room at (0x,0y,0z is a good place to start at). You can specify the location via several ways:<br />
* relative direction - ie 'rlc n' will create the room north of you, 'rlc se s' will create the room south-east and south of you.<br />
* exact coordinates - ie 'rlc 1 -5 10' will create the room at those exact coordinates. If the mapper doesn't know where you currently are, it'll also assume that you're located in that room now.<br />
* exact coordinates + specific ID - ie 'rlc v34 0 0 0' will create a new room with that exact ID (best to use one from the game, which you can find by doing 'rl') at the center.<br />
* partial coordinates - ie 'rlc 14x 5y' will create the room at 14x and 5y, but the same z-level you're on. You can can include all three of x,y,z coordinates or only one as you wish.<br />
<br />
=== rc - move a room ===<br />
Usage: *rc or room coords [v<id>] <option>*, where option will specify the new location of the room. The room ID is optional, it'll move the current room if you don't provide one. Sample use:<br />
* relative direction - ie 'rc nw' will move the room to be nw of the current location, 'rlc e s' will create the room east and south of the current location, and 'rc v34 w' will move the room ID 34 west<br />
* exact coordinates - ie 'rc 1 -5 10' will move the current room to those exact coordinates. 'rc v12 8 3 -8' will move the room with ID 12 to 8x, 3y and -8z.<br />
* partial coordinates - ie 'rc 14x 5y' will move the room to be at 14x and 5y, but the same z-level you're on. You can can include all three of x,y,z coordinates or only one as you wish<br />
<br />
=== rld - delete a room ===<br />
Usage '''rld or room delete <option>''', where option is the location or ID of the room you'd like to delete. Sample use:<br />
* relative direction - ie 'rld n' will delete the room that's north of you<br />
* exact room ID - ie 'rld 513' will delete the room with ID 513<br />
* current room - ie 'rld' will delete the room you're currently in<br />
<br />
=== rlk - link rooms ===<br />
Usage: *rlk or room link <option>*, where option will specify the room and exit to link with. You can do this in several ways:<br />
* exact room ID and direction - ie 'rlk 351 n' will link the current room to room #351 via a north exit<br />
* relative direction - ie 'rlk n' will link, if there is, a room to the north of this one to the one you're in<br />
<br />
=== urlk - unlink rooms ===<br />
Usage: *urlk or room unlink <direction>*, where direction will specify the direction of the exit to unlink. This function will unlink exits both ways, or one way if there is no incoming exit. Sample use:<br />
* relative direction - ie 'urlk nw' will unlink the exit to the northwest, and from the northwest room to the southeast<br />
<br />
=== spe - link rooms via special commands ===<br />
Usage: '''spe <other room> <command>''' or '''exit special <other room> <command>''', where other room will specify the room to link with, and command the command to us to get to that room. Sample use:<br />
* relative direction - ie 'spe n push rock' will go to the room by doing 'push rock'<br />
* exact room ID - ie 'spe 125 pull lever' will go to room 125 from the current one by pulling a lever<br />
<br />
=== spe clear - unlink all special command links ===<br />
Usage: *spe clear or exit special clear <option>*, where option is the location or the ID of the room you'd like to clear all special exits in. Sample use:<br />
* relative direction - ie 'spe clear n' will delete all special exits in the room that's north of you<br />
* exact room ID - ie 'spe clear 513' will delete all special exits in room with ID 513<br />
* current room - ie 'spe clear' will delete all special exits in the room you're currently in<br />
<br />
=== room area - move room to another area ===<br />
Usage: *room area <different area>* will move the current room to another area you're in. Sample use:<br />
* area name - ie 'room area glomdoring' will move the room you're currently standing in to Glomdoring. You can also specify another room to move with 'room area v# <area>', ie 'room area 1 my new area'<br />
* area id - ie 'room area 44' will move the room to the area ID 44<br />
<br />
=== room label - add a label to a room ===<br />
Usage: *room label <optional another room ID> <optional foreground color> <optional background color> my message*. Examples of using this:<br />
* room label the room I'm in<br />
* room label 342 this is a label in room 342<br />
* room label green this is a green label where I'm at<br />
* room label green black this is a green to black label where I'm at<br />
* room label 34 green black this is a green to black label at room 34<br />
<br />
=== area add - create a new area ===<br />
Usage: *area add <area name>* will create a new area and automatically give it an ID. Sample use:<br />
* area name - ie 'area add Mrr city' will create a new area called such<br />
<br />
=== area rename - rename an area ===<br />
Usage: *area rename <new area name>* will rename the current area you're in to the new name. Sample use:<br />
* area name - ie 'area rename Bobcat place* will call the area you're in like so from now on<br />
<br />
=== area delete - delete an area ===<br />
Usage: *area delete <area name>* will delete the given area. Sample use:<br />
* area name - ie 'area delete Bobcat place* will delete such an area<br />
<br />
=== area labels - view/delete labels in an area ===<br />
Usage: *area labels <area name>* will show the labels in the given area. Click on the small blue minus sign to delete the label.<br />
<br />
=== map save - save the map ===<br />
Usage: *map save <optional name>* will save all of the map. Sample use:<br />
* default map - ie 'map save' will save the map with the default name as the latest one<br />
* map name - ie 'map save map before experiment' will save the map with that name<br />
<br />
=== map load - load the map ===<br />
Usage: *map load <optional name>* will reload the map. Sample use:<br />
* default map - ie 'map load' will load the latest saved map (it may be a named one)<br />
* map name - ie 'map load before experiment' will load the map with that name<br />
<br />
= API =<br />
== functions ==<br />
=== mmp.anytolong ===<br />
;mmp.anytolong(exit)<br />
: converts an exit name to its long version.<br />
<br />
;Parameters:<br />
* ''exit:''<br />
: The exit abbreviation that needs to be converted. This must be a lower case string.<br />
<br />
;Return value:<br />
* ''longExit:''<br />
: The long version of the exit name as a string.<br />
<br />
;Example<br />
<lua><br />
--This would return "north" from the function<br />
mmp.anytolong("n")<br />
--This would return "south" from the function (to be sure that you use the long version)<br />
mmp.anytolong("south")<br />
</lua><br />
=== mmp.anytoshort ===<br />
;mmp.anytoshort(exit)<br />
: converts an exit name to its short version.<br />
<br />
;Parameters:<br />
* ''exit:''<br />
: The exit abbreviation that needs to be converted. This must be a lower case string.<br />
<br />
;Return value:<br />
* ''shortExit:''<br />
: The short version of the exit name as a string.<br />
<br />
;Example<br />
<lua><br />
--This would return "n" from the function<br />
mmp.anytoshort("north")<br />
--This would return "s" from the function (to be sure that you use the long version)<br />
mmp.anytoshort("s")<br />
</lua><br />
=== mmp.deleteArea ===<br />
;mmp.deleteArea(name,exact)<br />
: Deletes an area from the map, if the given name is distinct. If not it shows a clickable list of deletable matches. <br />
<br />
;Parameters:<br />
* ''name:''<br />
: The name of the area that should be deleted. This is a string parameter.<br />
<br />
* ''exact:''<br />
: Boolean value, that describes if the name is the exact (true) or partial (false) name.<br />
<br />
;Raised events<br />
* ''mmp areas changed''<br />
<br />
;Example<br />
<lua><br />
--This would attempt to delete "Hashan" from the map (Achaea)<br />
mmp.deleteArea("Hashan", false)<br />
--[[<br />
Output:<br />
(mapper): Which one of these specifically would you like to delete?<br />
Hashan, the City of (Sewers)<br />
Hashan, the City of (Seneschal Complex)<br />
Hashan, the City of<br />
]]<br />
<br />
--This would delete "Hashan, the City of" from the map (Achaea)<br />
mmp.deleteArea("Hashan, the City of", true) --if you made the second argument false, it'd give the same output as above<br />
</lua><br />
=== mmp.deleteLineP ===<br />
;mmp.deleteLineP()<br />
: Deletes the current line and the following prompt.<br />
<br />
;Example<br />
<lua><br />
--[[<br />
Sample input:<br />
3620h, 3447m, 15755e, 21980w cexb-<br />
Your enhanced senses inform you that Sidai has entered At the southern gates of Hashan nearby.<br />
3620h, 3447m, 15755e, 21980w cexb-<br />
<br />
Trigger:<br />
^Your enhanced senses inform you that (\w+) has entered (.+) nearby\.$<br />
]]<br />
<br />
mmp.deleteLineP()<br />
cecho("WARNING! "..matches[2].."nearby! ("..matches[3]..")")<br />
<br />
--[[<br />
Output:<br />
3620h, 3447m, 15755e, 21980w cexb-<br />
WARNING! Sidai nearby! (At the southern gates of Hashan)<br />
]]<br />
</lua><br />
=== mmp.echo ===<br />
;mmp.echo(what)<br />
: Prints the argument with a prefixed "(mapper): ".<br />
<br />
;Parameters:<br />
* ''what:''<br />
: The message that should be printed.<br />
<br />
;Example<br />
<lua><br />
mmp.echo("We arrived at our destination.")<br />
--[[<br />
Output:<br />
(mapper): We arrived at our destination.<br />
]]<br />
</lua><br />
<br />
=== mmp.echoAreaList ===<br />
;mmp.echoAreaList()<br />
: Prints a list of all known areas. Each name is clickable to display its room list.<br />
<br />
;Example<br />
<lua><br />
mmp.echoAreaList()<br />
--[[<br />
Output of Midkemia-Online:<br />
List of all areas we know of (click to view room list):<br />
2 Caldara<br />
3 Human Introduction<br />
4 Krondor<br />
(...)<br />
100 Fifth Circle of Hell<br />
102 Eagles Reaches<br />
108 Ruins of Veilgarden<br />
]]<br />
</lua><br />
=== mmp.echonums ===<br />
;mmp.echonums(roomname)<br />
: Prints the first three possible room IDs for the given room name. If no room is found, "?" is echoed. A click of the room ID starts the autowalker to there.<br />
<br />
;Parameters:<br />
* ''roomname:''<br />
: Name of the room of which the IDs should be displayed. This must be a lower case string.<br />
<br />
;Example<br />
<lua><br />
mmp.echonums("The Crossroads")<br />
--[[<br />
Output:<br />
4472, 4895, 6162, ...<br />
]]<br />
<br />
mmp.echonums("foobar")<br />
--[[<br />
Output:<br />
?<br />
]]<br />
</lua><br />
<br />
=== mmp.locateAndEcho ===<br />
;mmp.locateAndEcho(roomname, person)<br />
: Prints the first three possible room IDs for the given room name, and the area(s) relevant as well. If no room is found, "?" is echoed. A click of the room ID starts the autowalker to there.<br />
<br />
Fills the mmp.ndb with relevant information as well.<br />
<br />
;Parameters:<br />
* ''roomname:''<br />
: Name of the room of which the IDs should be displayed. This must be a lower case string.<br />
<br />
;Example<br />
<lua><br />
mmp.locateAndEcho("The Crossroads", "Person")<br />
--[[<br />
Output:<br />
(4472)<br />
From your knowledge, that room might be in Shallam, the City of, or Hashan, the City of, or Jaru.<br />
]]<br />
<br />
</lua><br />
<br />
=== mmp.echoRoomList ===<br />
=== mmp.findAreaID ===<br />
=== mmp.getAreaBorders ===<br />
=== mmp.getnums ===<br />
=== mmp.getPath ===<br />
=== mmp.pause ===<br />
=== mmp.ranytolong ===<br />
=== mmp.relativeroom ===<br />
=== mmp.renameArea ===<br />
=== mmp.roomArea ===<br />
=== mmp.roomEcho ===<br />
=== mmp.roomexists ===<br />
=== mmp.roomFind ===<br />
=== mmp.roomLook ===<br />
=== mmp.searchRoom ===<br />
<br />
== mudlet events ==<br />
* mmapper failed path - tried to go from A to B, but failed because there is no known path (or we were walking, got moved offcourse, and can't get to the destination anymore)<br />
* mmapper arrived - arrived at our destination successfully<br />
* mmapper stopped - mapper's stop function was called (this will be raised anytime it was, even if we weren't moving)<br />
* mmapper updated pdb - mmp.pdb table was updated with new data<br />
<br />
= Developers =<br />
Code is hosted on a bzr branch in launchpad.net, [https://code.launchpad.net/~mudlet-makers/mudlet/mapper-lua mapper-lua]. If you'd like to help develop, please feel free to create a branch, add your changes, and then request a merge of your code!<br />
<br />
Credit to: Sidd (for sharing his own mapping aliases that came before any documentation existed), keneanung (contributing to the coding, adding goto <area> and many other things)<br />
<br />
= What else needs to be done =<br />
General things that need work are triggers for where room detection is necessary - player-locating abilities, shrine defilement warnings, mindsense area reports, etc. The general format is that the room ID should be prefixed to the line the room name is given + be made clickable - so the player can click on it and go. An example is provided for the Lusternian scent ability that implements this. Also needs to recognize the need to swim, right now if you don't have waterwalking - it'll loop trying to walk. Another small problem is that if it gets off the path once, it'll keep saying that it ended up off the path, and not realize when it arrived at the location properly (but it does arrive).<br />
<br />
I've also started a bit on a person db - it stores the last known locations of players. This is something that is useful to everybody, so it's best that we don't have to keep reimplementing ourselves but use a common version. This requires more triggers to feed it's hunger for data as well!<br />
<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=IRE_mapping_script&diff=965IRE mapping script2012-01-13T03:08:49Z<p>Rayth: Fixed the Mac note. Please follow that format for all notes. Thank you.</p>
<hr />
<div>This is the Lua component to make the Mudlet Mapper work for IRE games. You'll need to import the xml below in order for autowalking to work on Achaea, Aetolia, Lusternia, Imperian, or Midkemia Online.<br />
<br />
It has many features such as:<br />
* automatic repathing if you get offcourse<br />
* locking of whole areas<br />
* auto-swimming<br />
* mapping<br />
<br />
= Download = <br />
[http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/download/head:/mudletmapper.xml-20100916000616-71kbxngi7b3nybta-1/mudlet-mapper.xml latest version] (updated very often) - [http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/atom news feed] for updates, or read the changelog [http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/changes/ here].<br />
<br />
If updating and you're on a Mudlet that has the package manager, then just remove the mudlet-mapper package and install the new xml. Otherwise, delete all Mudlet Mapper folders in Mudlet (aliases, triggers, scripts) and import the new xml.<br />
<br />
The mapper script is absolutely free, though if you'll be making adjustments to it, please [http://forums.mudlet.org/viewtopic.php?f=13&t=1696 contribute them back]!<br />
<br />
= Installing =<br />
* make sure you're using a version of Mudlet that has a mapper (either a Map button or a Toolbox -> Show Map option)<br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td>For Mac users this means you must be using at least the download: [http://forums.mudlet.org/viewtopic.php?f=5&t=1874 2.x release]</td><br />
</table><br />
* import this script<br />
* make sure you're connected to 'achaea.com', 'lusternia.com', 'aetolia.com', 'imperian.com' or 'midkemiaonline.com' if you'd like Mudlet to download a map for you<br />
* done!<br />
<br />
= Updating =<br />
To update the '''mapper script''', firstly delete all the Mudlet Mapper trigger, alias and script folders. Then, download the [http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/download/head:/mudletmapper.xml-20100916000616-71kbxngi7b3nybta-1/mudlet-mapper.xml new xml] and import it.<br />
<br />
<br />
----<br />
<br />
To make Mudlet re-download the '''map''', close Mudlet, find the ~/.config/mudlet/profiles/<your profile>/map folder and delete it. ~ is your home folder. Start Mudlet again, click the Map button and it'll download the latest map.<br />
<br />
Note: On Windows its %USERPROFILE%/.config/mudlet/profiles/<your profile>/map<br />
<br />
Mapper changelog is available [http://bazaar.launchpad.net/~mudlet-makers/mudlet/mapper-lua/changes/ here].<br />
<br />
= Support =<br />
If you wish to leave any feedback on the script, please comment on the [http://forums.mudlet.org/viewtopic.php?f=13&t=1696 Mudlet forums]!<br />
<br />
= Aliases =<br />
== common ==<br />
=== goto ===<br />
: goto <id> - goes to a room of that id<br />
: goto <area> - goes to a specific area<br />
: goto <id> sprint/dash/gallop - goes to a place, sprinting, dashing or galloping whenever possible<br />
: goto <area> # - goes to an area - the number specifies which one exactly if more than one matches<br />
<br />
=== mpp ===<br />
: mpp [on|off] - toggles or sets mapper to be paused<br />
<br />
=== mstop ===<br />
: mstop - stops the mapper completely<br />
<br />
=== rf / room find ===<br />
: rf <name>, room find <name> - searches for a room of a given name<br />
<br />
=== area list ===<br />
: area list - shows the known area list<br />
<br />
=== room list ===<br />
: room list <area> - shows the list of rooms in an area<br />
<br />
=== arealock ===<br />
: arealock, arealock <area> - displays a list of areas you can lock/unlock, can also give it an area name to filter by<br />
<br />
=== rl / room look ===<br />
: ''rl'' or ''room look'' - displays information about the room you're in<br />
: ''rl roomID'' or ''room look roomID'' - displays information on a given room ID (ie, ''rl 34'')<br />
: ''rl room name'' or ''room look room name'' - displays information on a given room, by it's name (ie, ''rl tavern of blah'')<br />
<br />
* Note that this will override the in-game ''rl'' command - but you can use RL to still read the last message.<br />
<br />
== mapping ==<br />
It's best that you always have the latest version of Mudlet 2.0 release candidate installed while mapping (especially not rc4, which was buggy), along with the latest version of this script - because both are still very much in progress and are updated and improved often. Feel free to submit feedback on the mapping script [http://forums.mudlet.org/viewtopic.php?f=13&t=1696 on the forums], or even improve it yourself as all the code is available. General [http://forums.mudlet.org/viewforum.php?f=13 Mudlet Mapper] feedback is welcomed as well.<br />
<br />
Some tips on mapping:<br />
* it's best to map in the 2D mode, because then you can select them en-masse and move them around, as well as doing other things<br />
* when moving around rooms via selection, do not include the room you're currently in, it'll go wild. If this is a problem, then move the current room out to wild coordinates and then move it back<br />
<br />
Here's a [http://www.youtube.com/watch?v=MgD9Nfz16uQ&hd=1 short mapping video] to get a sense of a possible way to map things.<br />
<br />
==== Mapping new areas ====<br />
The mapper relies on the in-game room IDs for it's own, and so it's best that you keep them in sync when creating new rooms as well - if you're in an unmapped room, 'rl' will tell you the rooms in-game ID. So when starting to map a new room in a new area, it'd best to create the new room with it's in-game ID at 0 0 0 coordinates, create the area, and move the room into the area - ie:<br />
<br />
mc on<br />
<br />
rl<br />
<see the room ID><br />
<br />
rlc v<room id> 0 0 0<br />
<br />
survey<br />
<see area name><br />
<br />
area add <area name><br />
(this will create the area)<br />
<br />
room area <area name><br />
(this will move the room to the new area)<br />
<br />
Proceed to walking about and automapping! Take a look at a small [http://www.youtube.com/watch?v=MgD9Nfz16uQ&hd=1 howto video] to get ideas on solving mapping problems as well that you might run into.<br />
<br />
=== mc - toggle mapping mode ===<br />
Usage: *mc or map create <option>*, where option can be "on" or "off". Turning the mapping mode on enables the mapping aliases, along with several automapping things (that rely on GMCP being enabled):<br />
* room creation - if you enter a room that's not mapped yet, it'll map it<br />
* exit creation - if there is an unmapped exit in the room, the mapper will auto-link it to another room (and create that other room if it doesn't exist yet)<br />
* exit deletion - if the mapper knows about an exit that doesn't really exist, it'll remove it<br />
<br />
=== rlc - create a room ===<br />
Usage: *rlc or room create <option>*, where option will specify the location of the new room. The new room will be auto-linked to the current one, be placed in the same area and take on the same environment type. If the mapper doesn't currently know where you are, you'll have to specify the exact coordinates that you'd like to place the room at (0x,0y,0z is a good place to start at). You can specify the location via several ways:<br />
* relative direction - ie 'rlc n' will create the room north of you, 'rlc se s' will create the room south-east and south of you.<br />
* exact coordinates - ie 'rlc 1 -5 10' will create the room at those exact coordinates. If the mapper doesn't know where you currently are, it'll also assume that you're located in that room now.<br />
* exact coordinates + specific ID - ie 'rlc v34 0 0 0' will create a new room with that exact ID (best to use one from the game, which you can find by doing 'rl') at the center.<br />
* partial coordinates - ie 'rlc 14x 5y' will create the room at 14x and 5y, but the same z-level you're on. You can can include all three of x,y,z coordinates or only one as you wish.<br />
<br />
=== rc - move a room ===<br />
Usage: *rc or room coords [v<id>] <option>*, where option will specify the new location of the room. The room ID is optional, it'll move the current room if you don't provide one. Sample use:<br />
* relative direction - ie 'rc nw' will move the room to be nw of the current location, 'rlc e s' will create the room east and south of the current location, and 'rc v34 w' will move the room ID 34 west<br />
* exact coordinates - ie 'rc 1 -5 10' will move the current room to those exact coordinates. 'rc v12 8 3 -8' will move the room with ID 12 to 8x, 3y and -8z.<br />
* partial coordinates - ie 'rc 14x 5y' will move the room to be at 14x and 5y, but the same z-level you're on. You can can include all three of x,y,z coordinates or only one as you wish<br />
<br />
=== rld - delete a room ===<br />
Usage '''rld or room delete <option>''', where option is the location or ID of the room you'd like to delete. Sample use:<br />
* relative direction - ie 'rld n' will delete the room that's north of you<br />
* exact room ID - ie 'rld 513' will delete the room with ID 513<br />
* current room - ie 'rld' will delete the room you're currently in<br />
<br />
=== rlk - link rooms ===<br />
Usage: *rlk or room link <option>*, where option will specify the room and exit to link with. You can do this in several ways:<br />
* exact room ID and direction - ie 'rlk 351 n' will link the current room to room #351 via a north exit<br />
* relative direction - ie 'rlk n' will link, if there is, a room to the north of this one to the one you're in<br />
<br />
=== urlk - unlink rooms ===<br />
Usage: *urlk or room unlink <direction>*, where direction will specify the direction of the exit to unlink. This function will unlink exits both ways, or one way if there is no incoming exit. Sample use:<br />
* relative direction - ie 'urlk nw' will unlink the exit to the northwest, and from the northwest room to the southeast<br />
<br />
=== spe - link rooms via special commands ===<br />
Usage: '''spe <other room> <command>''' or '''exit special <other room> <command>''', where other room will specify the room to link with, and command the command to us to get to that room. Sample use:<br />
* relative direction - ie 'spe n push rock' will go to the room by doing 'push rock'<br />
* exact room ID - ie 'spe 125 pull lever' will go to room 125 from the current one by pulling a lever<br />
<br />
=== spe clear - unlink all special command links ===<br />
Usage: *spe clear or exit special clear <option>*, where option is the location or the ID of the room you'd like to clear all special exits in. Sample use:<br />
* relative direction - ie 'spe clear n' will delete all special exits in the room that's north of you<br />
* exact room ID - ie 'spe clear 513' will delete all special exits in room with ID 513<br />
* current room - ie 'spe clear' will delete all special exits in the room you're currently in<br />
<br />
=== room area - move room to another area ===<br />
Usage: *room area <different area>* will move the current room to another area you're in. Sample use:<br />
* area name - ie 'room area glomdoring' will move the room you're currently standing in to Glomdoring. You can also specify another room to move with 'room area v# <area>', ie 'room area 1 my new area'<br />
* area id - ie 'room area 44' will move the room to the area ID 44<br />
<br />
=== room label - add a label to a room ===<br />
Usage: *room label <optional another room ID> <optional foreground color> <optional background color> my message*. Examples of using this:<br />
* room label the room I'm in<br />
* room label 342 this is a label in room 342<br />
* room label green this is a green label where I'm at<br />
* room label green black this is a green to black label where I'm at<br />
* room label 34 green black this is a green to black label at room 34<br />
<br />
=== area add - create a new area ===<br />
Usage: *area add <area name>* will create a new area and automatically give it an ID. Sample use:<br />
* area name - ie 'area add Mrr city' will create a new area called such<br />
<br />
=== area rename - rename an area ===<br />
Usage: *area rename <new area name>* will rename the current area you're in to the new name. Sample use:<br />
* area name - ie 'area rename Bobcat place* will call the area you're in like so from now on<br />
<br />
=== area delete - delete an area ===<br />
Usage: *area delete <area name>* will delete the given area. Sample use:<br />
* area name - ie 'area delete Bobcat place* will delete such an area<br />
<br />
=== area labels - view/delete labels in an area ===<br />
Usage: *area labels <area name>* will show the labels in the given area. Click on the small blue minus sign to delete the label.<br />
<br />
=== map save - save the map ===<br />
Usage: *map save <optional name>* will save all of the map. Sample use:<br />
* default map - ie 'map save' will save the map with the default name as the latest one<br />
* map name - ie 'map save map before experiment' will save the map with that name<br />
<br />
=== map load - load the map ===<br />
Usage: *map load <optional name>* will reload the map. Sample use:<br />
* default map - ie 'map load' will load the latest saved map (it may be a named one)<br />
* map name - ie 'map load before experiment' will load the map with that name<br />
<br />
= API =<br />
== functions ==<br />
=== mmp.anytolong ===<br />
;mmp.anytolong(exit)<br />
: converts an exit name to its long version.<br />
<br />
;Parameters:<br />
* ''exit:''<br />
: The exit abbreviation that needs to be converted. This must be a lower case string.<br />
<br />
;Return value:<br />
* ''longExit:''<br />
: The long version of the exit name as a string.<br />
<br />
;Example<br />
<lua><br />
--This would return "north" from the function<br />
mmp.anytolong("n")<br />
--This would return "south" from the function (to be sure that you use the long version)<br />
mmp.anytolong("south")<br />
</lua><br />
=== mmp.anytoshort ===<br />
;mmp.anytoshort(exit)<br />
: converts an exit name to its short version.<br />
<br />
;Parameters:<br />
* ''exit:''<br />
: The exit abbreviation that needs to be converted. This must be a lower case string.<br />
<br />
;Return value:<br />
* ''shortExit:''<br />
: The short version of the exit name as a string.<br />
<br />
;Example<br />
<lua><br />
--This would return "n" from the function<br />
mmp.anytoshort("north")<br />
--This would return "s" from the function (to be sure that you use the long version)<br />
mmp.anytoshort("s")<br />
</lua><br />
=== mmp.deleteArea ===<br />
;mmp.deleteArea(name,exact)<br />
: Deletes an area from the map, if the given name is distinct. If not it shows a clickable list of deletable matches. <br />
<br />
;Parameters:<br />
* ''name:''<br />
: The name of the area that should be deleted. This is a string parameter.<br />
<br />
* ''exact:''<br />
: Boolean value, that describes if the name is the exact (true) or partial (false) name.<br />
<br />
;Raised events<br />
* ''mmp areas changed''<br />
<br />
;Example<br />
<lua><br />
--This would attempt to delete "Hashan" from the map (Achaea)<br />
mmp.deleteArea("Hashan", false)<br />
--[[<br />
Output:<br />
(mapper): Which one of these specifically would you like to delete?<br />
Hashan, the City of (Sewers)<br />
Hashan, the City of (Seneschal Complex)<br />
Hashan, the City of<br />
]]<br />
<br />
--This would delete "Hashan, the City of" from the map (Achaea)<br />
mmp.deleteArea("Hashan, the City of", true) --if you made the second argument false, it'd give the same output as above<br />
</lua><br />
=== mmp.deleteLineP ===<br />
;mmp.deleteLineP()<br />
: Deletes the current line and the following prompt.<br />
<br />
;Example<br />
<lua><br />
--[[<br />
Sample input:<br />
3620h, 3447m, 15755e, 21980w cexb-<br />
Your enhanced senses inform you that Sidai has entered At the southern gates of Hashan nearby.<br />
3620h, 3447m, 15755e, 21980w cexb-<br />
<br />
Trigger:<br />
^Your enhanced senses inform you that (\w+) has entered (.+) nearby\.$<br />
]]<br />
<br />
mmp.deleteLineP()<br />
cecho("WARNING! "..matches[2].."nearby! ("..matches[3]..")")<br />
<br />
--[[<br />
Output:<br />
3620h, 3447m, 15755e, 21980w cexb-<br />
WARNING! Sidai nearby! (At the southern gates of Hashan)<br />
]]<br />
</lua><br />
=== mmp.echo ===<br />
;mmp.echo(what)<br />
: Prints the argument with a prefixed "(mapper): ".<br />
<br />
;Parameters:<br />
* ''what:''<br />
: The message that should be printed.<br />
<br />
;Example<br />
<lua><br />
mmp.echo("We arrived at our destination.")<br />
--[[<br />
Output:<br />
(mapper): We arrived at our destination.<br />
]]<br />
</lua><br />
<br />
=== mmp.echoAreaList ===<br />
;mmp.echoAreaList()<br />
: Prints a list of all known areas. Each name is clickable to display its room list.<br />
<br />
;Example<br />
<lua><br />
mmp.echoAreaList()<br />
--[[<br />
Output of Midkemia-Online:<br />
List of all areas we know of (click to view room list):<br />
2 Caldara<br />
3 Human Introduction<br />
4 Krondor<br />
(...)<br />
100 Fifth Circle of Hell<br />
102 Eagles Reaches<br />
108 Ruins of Veilgarden<br />
]]<br />
</lua><br />
=== mmp.echonums ===<br />
;mmp.echonums(roomname)<br />
: Prints the first three possible room IDs for the given room name. If no room is found, "?" is echoed. A click of the room ID starts the autowalker to there.<br />
<br />
;Parameters:<br />
* ''roomname:''<br />
: Name of the room of which the IDs should be displayed. This must be a lower case string.<br />
<br />
;Example<br />
<lua><br />
mmp.echonums("The Crossroads")<br />
--[[<br />
Output:<br />
4472, 4895, 6162, ...<br />
]]<br />
<br />
mmp.echonums("foobar")<br />
--[[<br />
Output:<br />
?<br />
]]<br />
</lua><br />
<br />
=== mmp.echoRoomList ===<br />
=== mmp.findAreaID ===<br />
=== mmp.getAreaBorders ===<br />
=== mmp.getnums ===<br />
=== mmp.getPath ===<br />
=== mmp.pause ===<br />
=== mmp.ranytolong ===<br />
=== mmp.relativeroom ===<br />
=== mmp.renameArea ===<br />
=== mmp.roomArea ===<br />
=== mmp.roomEcho ===<br />
=== mmp.roomexists ===<br />
=== mmp.roomFind ===<br />
=== mmp.roomLook ===<br />
=== mmp.searchRoom ===<br />
<br />
== mudlet events ==<br />
* mmapper failed path - tried to go from A to B, but failed because there is no known path (or we were walking, got moved offcourse, and can't get to the destination anymore)<br />
* mmapper arrived - arrived at our destination successfully<br />
* mmapper stopped - mapper's stop function was called (this will be raised anytime it was, even if we weren't moving)<br />
* mmapper updated pdb - mmp.pdb table was updated with new data<br />
<br />
= Developers =<br />
Code is hosted on a bzr branch in launchpad.net, [https://code.launchpad.net/~mudlet-makers/mudlet/mapper-lua mapper-lua]. If you'd like to help develop, please feel free to create a branch, add your changes, and then request a merge of your code!<br />
<br />
Credit to: Sidd (for sharing his own mapping aliases that came before any documentation existed), keneanung (contributing to the coding, adding goto <area> and many other things)<br />
<br />
= What else needs to be done =<br />
General things that need work are triggers for where room detection is necessary - player-locating abilities, shrine defilement warnings, mindsense area reports, etc. The general format is that the room ID should be prefixed to the line the room name is given + be made clickable - so the player can click on it and go. An example is provided for the Lusternian scent ability that implements this. Also needs to recognize the need to swim, right now if you don't have waterwalking - it'll loop trying to walk. Another small problem is that if it gets off the path once, it'll keep saying that it ended up off the path, and not realize when it arrived at the location properly (but it does arrive).<br />
<br />
I've also started a bit on a person db - it stores the last known locations of players. This is something that is useful to everybody, so it's best that we don't have to keep reimplementing ourselves but use a common version. This requires more triggers to feed it's hunger for data as well!<br />
<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=833Manual:Migrating2011-09-14T02:48:42Z<p>Rayth: /* Notes to be aware of */</p>
<hr />
<div>=From Nexus=<br />
'''Trigger patterns'''<br />
<br><br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
'''Basic scripting'''<br />
<br><br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
'''Calling functions'''<br />
<table border="1" width="100%"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
'''Setting variables'''<br />
<table border="1" width="100%"><br />
<caption>Setting variables</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<td><br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<br />
'''Wildcards'''<br />
<br><br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<lua><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</lua><br />
</td><br />
<td><br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
</td><br />
<table><br />
<br />
'''#wait'''<br />
<br><br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<br />
'''ifs in Mudlet'''<br />
<br><br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
if <condition> then <text> end<br />
</td><br />
<td><br />
<nowiki>#if <condition> <text></nowiki><br />
<nowiki>#if <condition> { <script> }</nowiki><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
if <condition> then <script> else <script> end<br />
</td><br />
<td><br />
<nowiki>#if <condition> { <script> } else { <script> }</nowiki><br />
<nowiki>#if <condition> { <script> } { <script> }</nowiki><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
if <condition> then <script> elseif <condition> then <script> end<br />
</td><br />
<td><br />
<nowiki>#if <condition> { <script> } elsif <condition> { <script> }</nowiki><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
</td><br />
<td><br />
<nowiki>#if <condition> { <script> } elsif <condition> { <script> } else { <script> }</nowiki><br />
</td><br />
<tr><br />
</table><br />
<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
</lua><br />
</td><br />
<td><br />
<code><br />
<br>// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
<br>// A slight modification of the above that illustrates an 'else' clause.<br />
<br>// The second form shows that the word 'else' is actually optional too.<br />
<br>// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
<br>// Illustration of putting more than one statement in a block (also<br />
<br>// spans lines here). Note the if doesn't end until the last '}' is<br />
<br>// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
<br>// This shows how ifs continue (on 'logical' lines) even though the<br />
<br>// blocks in its constituent clauses may have multiple lines. The<br />
<br>// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
</code><br />
</td><br />
</tr><br />
</table><br />
'''Mudlet equivalents of Nexus functions'''<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><variable name> = "<text value>"</td><br />
<td><nowiki>#set <variable name> <text value></nowiki></td><br />
</tr><br />
<tr><br />
<td><variable name> = <expression></td><br />
<td><nowiki>#set <variable name> = <expression></nowiki></td><br />
</tr><br />
<tr><br />
<td><variable name> = nil</td><br />
<td><nowiki>#unset <variable name></nowiki></td><br />
</tr><br />
<tr><br />
<td><variable> = <variablename> <+ - / *> <number or variable></td><br />
<td><nowiki>#add <variablename> <expression></nowiki></td><br />
</tr><br />
<tr><br />
<td>echo "text\n" or echo("text\n")</td><br />
<td><nowiki>#echo <text></nowiki></td><br />
</tr><br />
<tr><br />
<td>echo "text" or echo("text")</td><br />
<td><nowiki>#echo_ <text></nowiki></td><br />
</tr><br />
<tr><br />
<td>enableAlias("<group name>")/enableTrigger()/enableKey()/enableTimer()</td><br />
<td><nowiki>#groupon <group name></nowiki></td><br />
</tr><br />
<tr><br />
<td>disableAlias("<group name>")disableTrigger()disableKey()disableTimer()</td><br />
<td><nowiki>#groupoff <group name></nowiki></td><br />
</tr><br />
<tr><br />
<td>selectString (line, 1) bg("<color>") resetFormat()</td><br />
<td><nowiki> #highlight <color></nowiki></td><br />
</tr><br />
<tr><br />
<td>deleteLine()</td><br />
<td><nowiki>#gag</nowiki></td><br />
</tr><br />
<tr><br />
<td>openUrl("<url>")</td><br />
<td><nowiki>#openurl <url></nowiki></td><br />
</tr><br />
<tr><br />
<td>send("<stuff>")</td><br />
<td><nowiki>#send <text></nowiki></td><br />
</tr><br />
<tr><br />
<td>sendAll("hi", "hello", "bye")</td><br />
<td><nowiki>#send_ hi #send_ hello #send bye</nowiki></td><br />
</tr><br />
<tr><br />
<td>tempTimer(<time in s>, [[ <nowiki><lua code to do once time is up></nowiki> ]])</td><br />
<td><nowiki>#wait <milliseconds></nowiki></td><br />
</tr><br />
</table><br />
<br />
'''How to call aliases in Mudlet'''<br />
<br><br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<lua><br />
function <name> ()<br />
<stuff it does><br />
end<br />
</lua><br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<lua><br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
</lua><br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<lua><br />
eat_bloodroot()<br />
</lua><br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<lua><br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
</lua><br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<lua><br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
</lua><br />
==Notes to be aware of==<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such as more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
=From MUSHclient=<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
=From CMUD=<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
-- Note: Alias can be an alias, trigger (enableTrigger), timer (enableTimer), key (enableKey), etc. <br />
-- You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
-- Now in cmud if we called this alias from a trigger or another alias,<br />
-- we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
-- Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
-- This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
-- This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
=From zMUD=</div>Raythhttps://wiki.mudlet.org/index.php?title=Misc_Scripts&diff=828Misc Scripts2011-09-11T23:06:33Z<p>Rayth: /* Miscellaneous Scripts */</p>
<hr />
<div>==Example Layout==<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
<br />
=Miscellaneous Scripts=<br />
Small or Large scripts made before the official package system.<br />
----<br />
'''Name:''' Lua from the Command Line<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=100<br><br />
'''Short Description:''' Allows coding small scripts from the command line.<br />
----<br />
'''Name:''' Name Highlighter v3<br><br />
'''Author:'''Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1235<br><br />
'''Short Description:''' Highlight player names according to org affiliation or other chosen criteria.<br />
----<br />
'''Name:''' Lusternia Calendar<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2253<br><br />
'''Short Description:''' Display a small calendar for Lusternia.<br />
----<br />
'''Name:''' Clickable URLs<br><br />
'''Author:''' Yetzederixx<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1818<br><br />
'''Short Description:''' Make on-screen urls clickable, opening the link in your browser.<br />
----<br />
'''Name:''' Tabbed Chat w/ blinking tabs<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1662<br><br />
'''Short Description:''' Capture channel communication to a miniconsole, with the tabs blinking on new text.<br />
----<br />
'''Name:''' Lusternia Fancy GUI<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1180<br><br />
'''Short Description:''' Make Mudlet look similar to Nexus in Lusternia for familiarity's sake.<br />
----<br />
'''Name:''' Achaea Fancy GUI<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=981<br><br />
'''Short Description:''' Make Mudlet look similar to Nexus in Achaea for familiarity's sake.<br />
----<br />
'''Name:''' Achaea, Inventory Organizer <br><br />
'''Author:''' mortagona <br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2286<br><br />
'''Short Description:''' Organize your inventory in Achaea into a clean more easily read format.<br />
----<br />
'''Name:''' Vadi Sipper for Achaea<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=125<br><br />
'''Short Description:''' A basic sipper for Achaea.<br />
----<br />
'''Name:''' Find alias #1<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1233<br><br />
'''Short Description:''' Search through your mudlet window for a specific text.<br />
----<br />
'''Name:''' MAG - Mudlet Aardwolf GUI <br><br />
'''Author:''' lex<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1471<br><br />
'''Short Description:''' GUI made specifically for Aardwolf<br />
----<br />
'''Name:''' Simple Logger<br><br />
'''Author:''' Wyd<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1424<br><br />
'''Short Description:''' Log either specific text or log a section of a mudlet session.<br />
----<br />
'''Name:''' Enemy Script<br><br />
'''Author:''' ThePhoenix<br><br />
'''Link:''' http://dl.dropbox.com/u/22569276/EnemyScript.xml<br><br />
'''Short Description:''' API is included in the script. This is used on Achaea (and possibly other IREs) to enemy groups of people at a time, especially based off a party call of (Party): Leader says, "Enemies: person, person, person."<br />
----<br />
'''Name:''' (Achaea) Gag others breathing<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1520<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' (Achaea) Compress tramples<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1521<br><br />
'''Short Description:''' Compresses full-screen tramples into something more manageable.<br />
----<br />
'''Name:''' Send random commands<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=1234<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' `echo test triggers from input line alias<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=1478<br><br />
'''Short Description:''' This allows for testing triggers from the command line.<br />
----<br />
'''Name:''' Screen shake on critical hits<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1400<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' Find RGB color of MUD text<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1302<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' Get wildcards by color<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1282<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' Repeat Alias<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1275<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' (Achaea) GMCP Inventory Organizer<br><br />
'''Author:'''vRakon<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2431<br><br />
'''Short Description:''' Organizes your inventory using GMCP instead of trigger matching.<br>Concept from Mortagona's Inv Organizer script.<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Mudlet_Packages&diff=823Manual:Mudlet Packages2011-09-10T03:33:51Z<p>Rayth: /* from the MUD */</p>
<hr />
<div>= What is a Mudlet package =<br />
It's a archive file that ends with ''.mpackage'' or ''.zip'' that contains xml files to import along with any resources a package might have (images, sounds and etc). Packages can be installed / uninstalled via a window in Mudlet.<br />
<br />
The system is backwards-compatible and existing ''.xml'' files will also be recognized as packages.<br />
<br />
You'll see packages represented in brown in the script editor everywhere - triggers, aliases, etc. All items of a package have to go into a package folder that they belong in - so the user can know which package do items belong to, and modify the package for their needs (if it didn't have a folder, then you wouldn't be able to 'add' anything to a package).<br />
<br />
Mudlet Packages were introduced to Mudlet in the '''2.0-rc6''' release.<br />
<br />
= How to install a Mudlet package =<br />
== manually ==<br />
Toolbox→Package Manager will open the window where you can 'Install' to install a package.<br />
<br />
(xmls installed via ''Import'' will be converted to packages too, but do not ''Import'' packages.)<br />
<br />
== from the MUD ==<br />
<br />
Packages can also be auto-installed from the MUD server via ATCP - the server should send "Client.GUI\n<url>", ie "Client.GUI\nhttp://blahblahblah.com/SomeGameUI.zip" and Mudlet will offer the user an option of downloading and using it automatically.<br />
<br />
= How to create a Mudlet package =<br />
Create a zip file - the name of the file will be the name of the package - that ends with either ''.mpackage'' (preferred) or ''.zip''. Include all xml's that you'd like to be installed in the top level folder of the package (that is, don't have them within a folder in the archive - just have them be upfront). <br />
<br />
If you'd like to include other folders or files in the package, you can - they will be copied into ''getMudletHomeDir().."/"..packagename'' upon installation, so your scripts can use them - or example, if your package is called "sipper" (thus you have sipper.mpackage as the file) and you have health.png as an image in it, you can place on a label like so:<br />
<br />
<lua><br />
-- you don't have to worry about \ versus / for file paths - use / everywhere, Lua will make it work on Windows fine<br />
<br />
setBackgroundImage("my health", getMudletHomeDir().."/sipper/health.png")<br />
</lua><br />
<br />
== versioning ==<br />
Is not yet available. Will be done soon.<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=User:Rayth&diff=803User:Rayth2011-08-01T21:38:31Z<p>Rayth: </p>
<hr />
<div>=Who is Rayth?=<br />
I've been a mudder for 4-5 years. I started off on [http://www.play.net/gs4/ Gemstone IV], created by [http://www.play.net Simultronics]. After nearly a year of not mudding, I stumbled upon [http://old.lusternia.com/ Lusternia] created by [http://www.ironrealms.com/ Iron Realms Entertainment]. I've since been playing Lusternia for some four years. For half those years I used the Nexus client to get my daily dose of mudding. In 2009, wanting to get into combat, and seeing that Nexus was unable to provide me with the tools to get into combat, I sought out a different mud client. I think I first tried MUSHclient, but just couldn't get into it, then tried cMud or zMud, whichever is free, but couldn't get into it either. So I decided to go back to MUSHclient, since I found it preferable to the other. After a while, my dislike for MUSHclient reached its peak, and I sought out a different client. Finally I found Mudlet and I've yet to look back.<br />
My main mud is Lusternia, though I dabble in Midkemia Online every now and then, and have tried out all the other IRE muds, and a few other non-IRE muds.<br />
<br />
=What is Rayth working on?=<br />
Most of my coding projects aren't really for the public, most are for personal use. One that is semi-public is my Demesne package for Lusternia, It's constantly being re-worked, so unfortunately is not in a state ready for semi-public consumption. A lot of my time is spent working on small personal coding projects, and whenever I'm up to it, wiki editing work. If someone request some coding work/help, if I am able I can try my best to help, and if I need to be found, I'm usually lurking in the #mudlet/#mudlet-help ircs.<br />
<br />
Thanks for reading my ramblings.</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Lua_Functions&diff=733Manual:Lua Functions2011-07-30T23:16:30Z<p>Rayth: /* string.genNocasePattern */</p>
<hr />
<div>== Function Categories ==<br />
'''Standard Functions''': These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
'''UI Functions''': These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation.<br />
<lua><br />
createMiniConsole()<br />
createLabel()<br />
createGauge()<br />
</lua><br />
<br />
'''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.<br />
<br />
'''String Functions'''<br />
<br />
'''Scripting Object Functions'''<br />
<br />
'''Mapper Functions'''<br />
<br />
'''Miscellaneous Functions'''<br />
<br />
== Variables ==<br />
The following variables are provided by Mudlet:<br />
<br><br><br />
;line <br />
:This variable holds the content of the current line that is being processed by the trigger engine. The engine runs all triggers on each line as it arrives from the MUD.<br />
;command <br />
:This variable holds the current user command. This is typically used in alias scripts.<br />
;matches[n]<br />
:This Lua table is being used by Mudlet in the context of triggers that use Perl regular expressions. matches[1] holds the entire match, matches[2] holds the first capture group, matches[n] holds the nth-1 capture group. If the trigger uses the Perl style /g switch to evaluate all possible matches of the given regex within the current line, matches[n+1] will hold the second entire match, matches[n+2] the first capture group of the second match and matches[n+m] the m-th capture group of the second match.<br />
;multimatches[n][m]<br />
:This table is being used by Mudlet in the context of multiline triggers that use Perl regular expression. It holds the table matches[n] as described above for each Perl regular expression based condition of the multiline trigger. multimatches[5][4] may hold the 3rd capture group of the 5th regex in the multiline trigger. This way you can examine and process all relevant data within a single script. Have a look at this example.<br />
= Standard Functions =<br />
: These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
==send==<br />
;send( command, echo the value = true/false )<br />
:This sends "command" directly to the network layer, skipping the alias matching. The optional second argument of type boolean (print) determines if the outgoing command is to be echoed on the screen.<br />
:If you want your command to be checked if it’s an alias, use expandAlias() instead. example:<br />
<lua><br />
send( "Hello Jane" ) --echos the command on the screen<br />
send( "Hello Jane", true ) --echos the command on the screen<br />
send( "Hello Jane", false ) --does not echo the command on the screen<br />
</lua><br />
==echo==<br />
;echo( windowName, text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])<br />
:Echos a piece of text as a clickable link.<br />
:text - text to display in the echo. Same as a normal echo().<br />
:command - lua code to do when the link is clicked.<br />
:hint - text for the tooltip to be displayed when the mouse is over the link.<br />
:boolean - if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.<br />
<br />
= UI Functions =<br />
<br />
<br />
==echo==<br />
;echo( [windowName,] text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name. <br />
: See also: [[Manual:Lua_Functions#paste|paste]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</lua><br />
<br />
==bg==<br />
;bg(colorName)<br />
: Changes the background color of the text. Useful for highlighting text. <br />
: See Also: [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<lua><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
</lua><br />
<br />
==calcFontSize==<br />
;calcFontSize(fontSize)<br />
: Used to calculate the number of pixels wide and high a character would be on a mini console at fontSize.<br />
: Returns two numbers, width/height<br />
: See Also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]]<br />
<br />
;Parameters<br />
* ''fontSize:''<br />
: The font size you are wanting to calculate pixel sizes for. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide <br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</lua><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: Clears the window or miniconsole with the name given as argument.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearUserWindow("Chat")<br />
</lua><br />
<br />
==clearWindow==<br />
;clearWindow(name)<br />
: Clears the window or miniconsole with the name given as argument. <br />
: See also: [[Manual:Lua_Functions#clearUserWindow|clearUserWindow]]<br />
<br />
;Parameters<br />
* name: <br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</lua><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: Creates a named buffer for formatted text, much like a miniconsole, but the buffer cannot be shown on the screen. Intended for temporary use in the formatting of text.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
Examples<br />
<lua><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</lua><br />
<br />
==createConsole==<br />
;createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: Makes a new miniconsole. The background will be black, and the text color white.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide, <br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</lua><br />
<br />
==createGauge==<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, r, g, b)<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, colorName)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge]], [[Manual:Lua_Functions#setGauge|setGauge]], [[Manual:Lua_Functions#setGaugeText|setGaugeText]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</lua><br />
<br />
==createLabel==<br />
;createLabel(name, Xpos, Ypos, width, height, fillBackground)<br />
: Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|setTextFormat]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.<br />
<br />
Examples<br />
<lua><br />
--This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle <br />
--of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent <br />
--and 255 non-transparent) the background text can still be read through. The message box will disappear after 2.3 seconds.<br />
local width, height = getMainWindowSize();<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1);<br />
resizeWindow("messageBox",500,70);<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 );<br />
setBackgroundColor("messageBox", 150,100,100,200);<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]] );<br />
showWindow("messageBox");<br />
tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</lua><br />
<br />
==createMiniConsole==<br />
;createMiniConsole(name, posX, posY, width, height)<br />
: Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc. <br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel]], [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|moveWindow]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent]], [[Manual:Lua_Functions#setBorderTop|setBorderTop]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique, you can not have two or more miniconsoles with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the miniconsole, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the miniconsole, in pixels. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
--This script would create a mini text console called "sys" and write with yellow foreground color and blue background color <br />
--"Hello World".<br />
<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
WindowWidth = 0;<br />
WindowHeight = 0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line<br />
setWindowWrap("sys", 40)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
<br />
echo("sys","Hello world!")<br />
</lua><br />
<br />
==deleteLine==<br />
;deleteLine()<br />
: Deletes the current line under the user cursor. This is a high speed gagging tool and is very good at this task, but is only meant to be use when a line should be omitted entirely in the output. If you echo() to that line it will not be shown, and lines deleted with deleteLine() are simply no longer rendered. For replacing text, replace() is the proper option.<br />
: See Also: [[Manual:Lua_Functions#replace|replace]], [[Manual:Lua_Functions#wrapLine|wrapLine]]<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
</lua><br />
<br />
==deselect==<br />
;deselect(name)<br />
: This is used to clear the current selection (to no longer have anything selected). Should be used after changing the formatting of text, to keep from accidentally changing the text again later with another formatting call.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer/miniConsole to stop having anything selected in. This is an optional argument, if name is not provided the main window will have its selection cleared. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further <br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</lua><br />
<br />
==fg==<br />
; fg(colorName)<br />
: If used on a selection, sets the foreground color to ''colorName'' - otherwise, it will set the color of the next text-inserting calls (''echo(), insertText, echoLink()'', and others)<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Examples<br />
<lua><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
</lua><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels.<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--this will get the size of your main mudlet window and save them <br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</lua><br />
<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.<br />
<br />
;Example<br />
<lua><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</lua><br />
<br />
= Table Functions =<br />
<br />
==table.complement==<br />
; table.complement (set1, set2)<br />
: Returns a table that is the relative complement of the first table with respect to the second table. Returns a complement of key/value pairs.<br />
<br />
; Parameters<br />
* ''table1:''<br />
* ''table2:''<br />
<br />
; Example:<br />
<lua></lua><br />
<br />
==table.concat==<br />
;table.concat(table, delimiter, startingindex, endingindex)<br />
: Joins a table into a string. Each item must be something which can be transformed into a string. <br />
: Returns the joined string.<br />
: See also: [[Manual:Lua_Functions#string.split|string.split]]<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table to concatenate into a string. Passed as a table.<br />
* '''delimiter:'''<br />
: Optional string to use to separate each element in the joined string. Passed as a string.<br />
* '''startingindex:'''<br />
: Optional parameter to specify which index to begin the joining at. Passed as an integer.<br />
* '''endingindex:'''<br />
: Optional parameter to specify the last index to join. Passed as an integer.<br />
<br />
;Examples<br />
<lua><br />
--This shows a basic concat with none of the optional arguments<br />
testTable = {1,2,"hi","blah",}<br />
testString = table.concat(testTable)<br />
--testString would be equal to "12hiblah"<br />
<br />
--This example shows the concat using the optional delimiter<br />
testString = table.concat(testTable, ", ")<br />
--testString would be equal to "1, 2, hi, blah"<br />
<br />
--This example shows the concat using the delimiter and the optional starting index<br />
testString = table.concat(testTable, ", ", 2)<br />
--testString would be equal to "2, hi, blah"<br />
<br />
--And finally, one which uses all of the arguments<br />
testString = table.concat(testTable, ", ", 2, 3)<br />
--testString would be equal to "2, hi"<br />
</lua><br />
<br />
==table.contains==<br />
; table.contains (t, value)<br />
: Determines if a table contains a value as a key or as a value (recursive).<br />
: Returns true or false<br />
<br />
; Parameters<br />
* '''t:''' <br />
: The table in which you are checking for the presence of the value.<br />
* '''value:''' <br />
: The value you are checking for within the table.<br />
<br />
; Example:<br />
<lua>local test_table = { "value1", "value2", "value3", "value4" }<br />
if table.contains(test_table, "value1") then <br />
echo("Got value 1!")<br />
else<br />
echo("Don't have it. Sorry!")<br />
end<br />
</lua><br />
This example would always echo the first one, unless you remove value1 from the table.<br />
<br />
==table.foreachi==<br />
==table.foreach==<br />
==table.getn==<br />
==table.intersection==<br />
==table.insert==<br />
; table.insert(table, [pos,] value)<br />
: Inserts element '''value''' at position '''pos''' in '''table''', shifting up other elements to open space, if necessary. The default '''value''' for '''pos''' is n+1, where n is the length of the table, so that a call table.insert(t,x) inserts x at the end of table t.<br />
: See also: [[Manual:Lua_Functions#table.remove|table.remove]]<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table in which you are inserting the value<br />
* '''pos:'''<br />
: Optional argument, determining where the value will be inserted. <br />
* '''value:'''<br />
: The variable that you are inserting into the table. Can be a regular variable, or even a table or function*. <br />
<table frame="box" width="100%"><br />
<caption>*Note</caption><br />
<tr><br />
<td><br />
Inserting a function into a table is not good coding practice, and will not turn out how you think it would.<br />
</td><br />
</tr><br />
</table><br />
==table.index_of==<br />
==table.is_empty==<br />
; table.is_empty(table)<br />
: Check if a table is devoid of any values.<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table you are checking for values.<br />
==table.load==<br />
; table.load(location, table)<br />
: Load a table from an external file into mudlet.<br />
: See also: [[Manual:Lua_Functions#table.save|table.save]]<br />
<br />
; Parameters:<br />
* '''location:'''<br />
: Where you are loading the table from. Can be anywhere on your computer.<br />
* '''table:'''<br />
: The table that you are loading.<br />
<br />
: Example:<br />
<lua><br />
-- This will load the table mytable from the lua file mytable present in your Mudlet Home Directory.<br />
table.load(getMudletHomeDir().."/mytable.lua", mytable)<br />
-- You can load a table from anywhere on your computer, but it's preferable to have them consolidated somewhere connected to Mudlet.<br />
</lua><br />
==table.maxn==<br />
==table.n_union==<br />
==table.n_complement==<br />
==table.n_intersection==<br />
==table.pickle==<br />
==table.remove==<br />
; table.remove(table, value_position)<br />
: Remove a value from an indexed table, by the values position in the table.<br />
: See also: [[Manual:Lua_Functions#table.insert|table.insert]]<br />
<br />
; Parameters:<br />
* '''table'''<br />
: The indexed table you are removing the value from.<br />
* '''value_position'''<br />
: The indexed number for the value you are removing.<br />
<br />
; Example:<br />
<lua><br />
testTable = { "hi", "bye", "cry", "why" }<br />
table.remove(testTable, 1) -- will remove hi from the table<br />
-- new testTable after the remove<br />
testTable = { "bye", "cry", "why" }<br />
-- original position of hi was 1, after the remove, position 1 has become bye<br />
-- any values under the removed value are moved up, 5 becomes 4, 4 becomes 3, etc<br />
</lua> <br />
<table frame="box" width="100%"><br />
<caption>Note</caption><br />
<tr><br />
<td><br />
To remove a value from a key-value table, it's best to simply change the value to nil.<br />
<lua><br />
testTable = { test = "testing", go = "boom", frown = "glow" }<br />
table.remove(testTable, test) -- this will error<br />
testTable.test = nil -- won't error<br />
testTable["test"] = nil -- won't error<br />
</lua><br />
</td><br />
</tr><br />
</table><br />
==table.save==<br />
; table.save(location, table)<br />
: Save a table into an external file in '''location'''.<br />
: See also: [[Manual:Lua_Functions#table.load|table.load]]<br />
<br />
; Parameters:<br />
* '''location:'''<br />
: Where you want the table file to be saved. Can be anywhere on your computer.<br />
* '''table:'''<br />
: The table that you are saving to the file.<br />
<br />
: Example:<br />
<lua><br />
-- Saves the table mytable to the lua file mytable in your Mudlet Home Directory<br />
table.save(getMudletHomeDir().."/mytable.lua", mytable)<br />
</lua><br />
==table.sort==<br />
==table.size==<br />
; table.size (t)<br />
: Gets the actual size of non-index based tables.<br />
: Returns a number.<br />
<br />
; Parameters<br />
* ''t:'' <br />
: The table you are checking the size of.<br />
<table width="100%" frame="box"><br />
<caption>'''Note:'''</caption><br />
<tr><br />
<td><br />
For index based tables you can get the size with the # operator:<br />
This is the standard Lua way of getting the size of index tables i.e. ipairs() type of tables with numerical indices. <br />
To get the size of tables that use user defined keys instead of automatic indices (pairs() type) you need to use the function table.size() referenced above.<br />
</td><br />
</tr><br />
</table><br />
; Example<br />
<lua><br />
local test_table = { "value1", "value2", "value3", "value4" }<br />
myTableSize = #test_table<br />
-- This would return 4.<br />
local myTable = { 1 = "hello", "key2" = "bye", "key3" = "time to go" }<br />
table.size(myTable)<br />
-- This would return 3.<br />
</lua><br />
==table.setn==<br />
==table.unpickle==<br />
==table.update==<br />
==table.union==<br />
<br />
= String Functions =<br />
==string.byte==<br />
<br />
==string.char==<br />
<br />
==string.cut==<br />
;string.cut(string, maxLen)<br />
: Cuts string to the specified maximum length.<br />
: Returns the modified string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The text you wish to cut. Passed as a string.<br />
* maxLen<br />
: The maximum length you wish the string to be. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--The following call will return 'abc' and store it in myString<br />
mystring = string.cut("abcde", 3)<br />
--You can easily pad string to certain length. Example below will print 'abcde ' e.g. pad/cut string to 10 characters.<br />
local s = "abcde"<br />
s = string.cut(s .. " ", 10) -- append 10 spaces<br />
echo("'" .. s .. "'")<br />
</lua><br />
<br />
==string.dump==<br />
<br />
==string.enclose==<br />
;string.enclose(String)<br />
: Wraps a string with [[ ]]<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String: The string to enclose. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will echo '[[Oh noes!]]' to the main window<br />
echo("'" .. string.enclose("Oh noes!") .. "'")<br />
</lua><br />
<br />
==string.ends==<br />
;string.ends(String, Suffix)<br />
: Test if string is ending with specified suffix.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#string.starts|string.starts]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string.<br />
* ''Suffix:''<br />
: The suffix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will test if the incoming line ends with "in bed" and if not will add it to the end.<br />
if not string.ends(line, "in bed") then<br />
echo("in bed\n")<br />
end<br />
</lua><br />
<br />
==string.find==<br />
<br />
==string.findPattern==<br />
; string.findPattern(text, pattern)<br />
: Return first matching substring or nil.<br />
<br />
; Parameters<br />
: text:<br />
: pattern:<br />
<br />
; Example:<br />
Following example will print: "I did find: Troll" string.<br />
<lua><br />
local match = string.findPattern("Troll is here!", "Troll")<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</lua><br />
This example will find substring regardless of case.<br />
<lua>local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</lua><br />
* Return value:<br />
: nil or first matching substring <br />
See also: [[Manual:Lua_Functions#string.genNocasePattern|string.genNocasePattern()]]<br />
<br />
==string.format==<br />
<br />
==string.genNocasePattern==<br />
; string.genNocasePattern(s)<br />
: Generate case insensitive search pattern from string.<br />
<br />
; Parameters<br />
* s:<br />
<br />
; Example:<br />
: Following example will generate and print "123[aA][bB][cC]" string.<br />
<lua>echo(string.genNocasePattern("123abc"))</lua><br />
* Return value:<br />
: case insensitive pattern string<br />
<br />
==string.gfind==<br />
<br />
==string.gmatch==<br />
<br />
==string.gsub==<br />
<br />
==string.len==<br />
<br />
==string.lower==<br />
<br />
==string.match==<br />
<br />
==string.rep==<br />
<br />
==string.reverse==<br />
<br />
<br />
==string.split==<br />
;string.split(String, delimiter)<br />
;<nowiki>myString:split(delimiter)</nowiki><br />
: Splits a string into a table by the given delimiter. Can be called against a string (or variable holding a string) using the second form above.<br />
: Returns a table containing the split sections of the string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to split. Parameter is not needed if using second form of the syntax above. Passed as a string.<br />
* ''delimiter:''<br />
: The delimiter to use when splitting the string. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
-- This will split the string by ", " delimiter and print the resulting table to the main window.<br />
names = "Alice, Bob, Peter"<br />
name_table = string.split(names, ", ")<br />
display(name_table)<br />
<br />
--The alternate method<br />
names = "Alice, Bob, Peter"<br />
name_table = names:split(", ")<br />
display(name_table)<br />
</lua><br />
<br />
Either method above will print out:<br />
table {<br />
1: 'Alice'<br />
2: 'Bob'<br />
3: 'Peter'<br />
}<br />
<br />
==string.starts==<br />
;string.starts(String, Prefix)<br />
: Test if string is starting with specified prefix.<br />
: Returns true or false<br />
: See also: [[Manual:Lua_Functions#string.ends|string.ends]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string. <br />
* ''Prefix:''<br />
: The prefix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--The following will see if the line begins with "You" and if so will print a statement at the end of the line<br />
if string.starts(line, "You") then<br />
echo("====oh you====\n")<br />
end<br />
</lua><br />
<br />
==string.sub==<br />
<br />
==string.title==<br />
;string.title(String)<br />
;<nowiki>string:title()</nowiki><br />
: Capitalizes the first character in a string.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String<br />
: The string to modify. Not needed if you use the second form of the syntax above.<br />
<br />
;Example<br />
<lua><br />
--Variable testname is now Anna.<br />
testname = string.title("anna")<br />
--Example will set test to "Bob".<br />
test = "bob"<br />
test = test:title()<br />
</lua><br />
<br />
==string.trim==<br />
;string.trim(String)<br />
: Trims String, removing all 'extra' white space at the beginning and end of the text.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to trim. Passed as a string.<br />
<br />
;Example:<br />
<lua><br />
--This will print 'Troll is here!', without the extra spaces.<br />
local str = string.trim(" Troll is here! ")<br />
echo("'" .. str .. "'")<br />
</lua><br />
<br />
==string.upper==<br />
<br />
= Mudlet Object Functions =<br />
==tempTimer==<br />
;tempTimer(time, code to do)<br />
Creates a temporary single shot timer and returns the timer ID for subsequent enableTimer(), disableTimer() and killTimer() calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed. <br />
<br />
;Parameters<br />
* ''time:'' the time in seconds for which to set the timer for<br />
* ''code to do'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
;Note<br />
[[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
==permGroup==<br />
permGroup(name, itemtype)<br />
<br />
Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts.<br />
<br />
<sub>Added to Mudlet in the 2.0 final release.</sub><br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<br />
<lua><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</lua><br />
<br />
<br />
==addAreaName==<br />
areaID = addAreaName(areaName)<br />
<br />
Adds a new area name and returns the new area ID for the new name. If the name already exists, -1 is returned.<br />
: See also: [[Manual:Lua_Functions#deleteArea|deleteArea]]<br />
<br />
<lua><br />
local newID = addAreaName("My house")<br />
<br />
if newID == -1 then echo("That area name is already taken :(\n")<br />
else echo("Created new area with the ID of "..newid..".\n") end<br />
</lua><br />
<br />
==addRoom==<br />
addRoom(roomID)<br />
<br />
Creates a new room with the given ID, returns true if the room was successfully created.<br />
: See also: [[Manual:Lua_Functions#createRoomID|createRoomID]]<br />
<br />
<lua><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</lua><br />
<br />
==addSpecialExit==<br />
addSpecialExit(roomIDFrom, roomIDTo, command)<br />
<br />
Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[Manual:Lua_Functions#clearSpecialExits|clearSpecialExits]]<br />
<br />
<lua><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- mmp.currentroom is your current room ID in this example<br />
addSpecialExit(mmp.currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(mmp.currentroom)<br />
</lua><br />
<br />
==centerview==<br />
centerview (roomID)<br />
<br />
Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
==clearRoomUserData==<br />
clearRoomUserData(roomID)<br />
<br />
Clears all user data from a given room.<br />
: See also: [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]]<br />
<br />
<lua><br />
clearRoomUserData(341)<br />
</lua><br />
<br />
==clearSpecialExits==<br />
clearSpecialExits(roomID) <br />
<br />
Removes all special exits from a room.<br />
: See also: [[Manual:Lua_Functions#addSpecialExit|addSpecialExit]]<br />
<br />
<lua><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will neve fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</lua><br />
<br />
==createMapLabel==<br />
labelID = createMapLabel(areaID, text, posx, posy, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue)<br />
<br />
Creates a visual label on the map for all z-levels at given coordinates, with the given background and foreground colors. It returns a label ID that you can use later for deleting it.<br />
<br />
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 [[Manual:Lua_Functions#getRoomCoordinates|getRoomCoordinates]] will place the label near that room.<br />
: See also: [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]]<br />
<lua><br />
local labelid = createMapLabel( 50, "my map label", 0, 0, 255,0,0,23,0,0)<br />
</lua><br />
<br />
==createMapper==<br />
createMapper(x, y, width, height)<br />
<br />
Creates a miniconsole window for mapper to render in, the with the given dimensions. You can only create one at a time at the moment.<br />
<br />
<lua><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper top-right of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</lua><br />
<br />
==createRoomID==<br />
usableId = createRoomID()<br />
<br />
Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs.<br />
: See also: [[Manual:Lua_Functions#addRoom|addRoom]]<br />
<br />
==deleteArea==<br />
deleteArea(areaID)<br />
<br />
Deletes the given area, permanently. This will also delete all rooms in it!<br />
: See also: [[Manual:Lua_Functions#addAreaName|addAreaName]]<br />
<br />
<lua><br />
deleteArea(23)<br />
</lua><br />
<br />
==deleteMapLabel==<br />
deleteMapLabel(areaID, labelID)<br />
<br />
Deletes a map label from a specfic area.<br />
: See also: [[Manual:Lua_Functions#createMapLabel|createMapLabel]]<br />
<lua><br />
deleteMapLabel(50, 1)<br />
</lua><br />
<br />
==deleteRoom==<br />
deleteRoom(roomID)<br />
<br />
Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
<lua><br />
deleteRoom(335)<br />
</lua><br />
<br />
==getAreaRooms==<br />
getAreaRooms(area id)<br />
<br />
Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
<sub>Note that on Mudlet versions prior to the 2.0 final release, this function would raise an error.</sub><br />
<br />
<lua><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in ipairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</lua><br />
<br />
==getAreaTable==<br />
getAreaTable()<br />
<br />
Returns a key(area name)-value(area id) table with all known areas and their IDs. There is an area with the name of '' and an ID of 0 included in it, you should ignore that.<br />
<br />
<lua><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id")<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</lua><br />
<br />
==getCustomEnvColorTable==<br />
envcolors = getCustomEnvColorTable()<br />
<br />
Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
<br />
<lua><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</lua><br />
<br />
==getMapLabels==<br />
arealabels = getMapLabels(areaID)<br />
<br />
Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]] it.<br />
<br />
<lua><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Svorai's grove'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Svorai's grove'<br />
}<br />
</lua><br />
<br />
==getPath==<br />
getPath(roomID from, roomID to)<br />
<br />
Returns a boolean true/false if a path between two room IDs is possible. If it is, the global `speedWalkPath` table is set to all of the directions that have to be taken to get there, and the global `speedWalkDir` table is set to all of the roomIDs you'll encounter on the way.<br />
<br />
<lua><br />
-- check if we can go to a room - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</lua><br />
<br />
==getRoomArea==<br />
areaID = getRoomArea(roomID)<br />
<br />
Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by getAreaTable() function, or use the getRoomAreaName function.<br />
<br />
<sub>Note that if the room ID does not exist, this function will raise an error</sub><br />
<br />
<lua><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</lua><br />
<br />
==getRoomAreaName==<br />
areaname = getRoomAreaName(areaID)<br />
<br />
Returns the area name for a given area id.<br />
<br />
<lua><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</lua><br />
<br />
==getRoomCoordinates==<br />
x,y,z = getRoomCoordinates(room ID)<br />
<br />
Returns the room coordinates of the given room ID.<br />
<br />
<lua><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</lua><br />
<br />
==getRoomEnv==<br />
envID = getRoomEnv(roomID)<br />
<br />
Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
<lua><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</lua><br />
<br />
== getRoomExits ==<br />
getRoomExits (roomID)<br />
Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid'', ie:<br />
<br />
<lua><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</lua><br />
<br />
==getRoomIDbyHash==<br />
roomID = getRoomIDbyHash(hash)<br />
<br />
Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
<lua><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
_id1 = getRoomIDbyHash( "5dfe55b0c8d769e865fd85ba63127fbc" );<br />
if _id1 == -1 then <br />
_id1 = createRoomID()<br />
setRoomIDbyHash( _id1, "5dfe55b0c8d769e865fd85ba63127fbc" )<br />
addRoom( _id )<br />
setRoomCoordinates( _id1, 0, 0, -1 )<br />
end<br />
</lua><br />
<br />
==getRoomName==<br />
roomName = getRoomName(roomID)<br />
<br />
Returns the room name for a given room id.<br />
<br />
<lua><br />
echo(string.format("The name of the room id #455 is %s.", getRoomname(455))<br />
</lua><br />
<br />
==getRooms==<br />
rooms = getRooms()<br />
<br />
Returns the list of '''all''' rooms in the map in an area in roomid - room name format.<br />
<br />
<lua><br />
-- simple, raw viewer for rooms in an area<br />
display(getRooms())<br />
</lua><br />
<br />
==getRoomsByPosition==<br />
getRoomsByPosition(areaID, x,y,z)<br />
<br />
Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
<lua><br />
-- sample script to determine a room nearby, given a relative direction from the current room<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</lua><br />
<br />
==getRoomUserData==<br />
data = getRoomUserData(roomID, key (as a string))<br />
<br />
Returns the user data stored at a given room with a given key, or "" if none is stored. Use [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]] for setting the user data.<br />
<br />
<lua><br />
display(getRoomUserData(341, "visitcount"))<br />
</lua><br />
<br />
==getRoomWeight==<br />
room weight = getRoomWeight(roomID)<br />
<br />
Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[Manual:Lua_Functions#setRoomWeight|setRoomWeight]]<br />
<br />
<lua><br />
display("Original weight of room 541: "..getRoomWeight(541)<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541)<br />
</lua><br />
<br />
==getSpecialExits==<br />
exits = getSpecialExits(roomID)<br />
<br />
Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
<lua><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</lua><br />
<br />
==getSpecialExitsSwap==<br />
exits = getSpecialExitsSwap(roomID)<br />
<br />
Very similar to [[Manual:Lua_Functions#getSpecialExits|getSpecialExits]], but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
gotoRoom (roomID)<br />
Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(". <br />
<br />
==hasExitLock==<br />
status = hasExitLock(roomID, direction)<br />
<br />
Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''direction'' right now is a number that corresponds to the direction:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples:<br />
<lua><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#lockExit|lockExit]]<br />
<br />
==highlightRoom==<br />
highlightRoom( id, r1,g1,b1,r2,g2,b2, radius, alpha1, alpha2)<br />
<br />
Highlights a room with the given color, which will override it's environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. ''highlightRadius'' is the radius for the highlight circle - if you don't want rooms beside each other to over lap, use ''1'' as the radius. ''alphaColor1'' and ''alphaColor2'' are transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[Manual:Lua_Functions#unHighlightRoom|unHighlightRoom]]<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
-- color some room red to blue<br />
highlightRoom(351, unpack(color_table.red), unpack(color_table.blue), 1, 255, 255)<br />
<br />
-- or use a name from showColors(), gold in this case<br />
highlightRoom(351, unpack(color_table.grey), unpack(color_table.grey), 1, 255, 255)<br />
</lua><br />
<br />
==lockExit==<br />
lockExit(roomID, direction, lock = true/false)<br />
<br />
Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction at the moment is only set as a number, and here's a listing of them:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples<br />
<lua><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#hasExitLock|hasExitLock]]<br />
<br />
==lockRoom==<br />
lockRoom (roomID, lock = true/false)<br />
<br />
Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[Manual:Lua_Functions#roomLocked|roomLocked]]<br />
<br />
<lua><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</lua><br />
<br />
==roomExists==<br />
roomExists(roomID)<br />
<br />
Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
locked = roomLocked(roomID)<br />
<br />
Returns true or false whenever a given room is locked.<br />
: See also: [[Manual:Lua_Functions#lockRoom|lockRoom]]<br />
<br />
<lua><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</lua><br />
<br />
==saveMap==<br />
saveMap(location)<br />
<br />
Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work.<br />
<br />
<lua><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
</lua><br />
<br />
==searchRoom== <br />
searchRoom (room name)<br />
<br />
Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname'', like so:<br />
<br />
<lua><br />
display(searchRoom("master"))<br />
<br />
--[[ would result in:<br />
table {<br />
17463: 'in the branches of the Master Ravenwood'<br />
3652: 'master bedroom'<br />
10361: 'Hall of Cultural Masterpieces'<br />
6324: 'Exhibit of the Techniques of the Master Artisans'<br />
5340: 'office of the Guildmaster'<br />
(...)<br />
2004: 'office of the guildmaster'<br />
14457: 'the Master Gear'<br />
1337: 'before the Master Ravenwood Tree'<br />
}<br />
]]</lua><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
==setAreaName==<br />
setAreaName(areaID, newName)<br />
<br />
Renames an existing area to the new name.<br />
<br />
<lua><br />
setAreaName(2, "My city")<br />
</lua><br />
<br />
==setCustomEnvColor==<br />
setCustomEnvColor(environmentID, r,g,b)<br />
<br />
Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
<br />
<lua><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
setCustomEnvColor(200, unpack(color_table.blue)) -- set the color of environmentID 200 to blue<br />
</lua><br />
<br />
==setExit==<br />
setExit(from roomID, to roomID, direction)<br />
<br />
Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', or a number which represents a direction.<br />
<br />
Returns ''false'' if the exit creation didn't work.<br />
<br />
<lua><br />
-- alias pattern: ^exit (\d+) (\w+)$<br />
<br />
if setExit(mmp.currentroom, tonumber(matches[2]),matches[3]) then<br />
echo("\nExit set to room:"..matches[2]..", Direction:"..string.upper(matches[3]))<br />
centerview(mmp.currentroom)<br />
else<br />
mmp.echo("Failed to set the exit.") end<br />
</lua><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
setExit(from roomID, -1, direction)<br />
<br />
Which will delete an outgoing exit in the specified direction from a room.<br />
<br />
<lua><br />
-- locate the room on the other end, so we can unlink it from there as well if necessary<br />
local otherroom<br />
if getRoomExits(getRoomExits(mmp.currentroom)[dir])[mmp.ranytolong(dir)] then<br />
otherroom = getRoomExits(mmp.currentroom)[dir]<br />
end<br />
<br />
if setExit(mmp.currentroom, -1, dir) then<br />
if otherroom then<br />
if setExit(otherroom, -1, mmp.ranytolong(dir)) then<br />
mmp.echo(string.format("Deleted the %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
else mmp.echo("Couldn't delete the incoming exit.") end<br />
else<br />
mmp.echo(string.format("Deleted the one-way %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
end<br />
else<br />
mmp.echo("Couldn't delete the outgoing exit.")<br />
end<br />
</lua><br />
<br />
You can use these numbers for setting the directions as well:<br />
<lua><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}</lua><br />
<br />
==setGridMode==<br />
setGridMode(area, true/false)<br />
<br />
Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode.<br />
<br />
<lua><br />
setGridMode(55,true) -- set area with ID 55 to be in grid mode<br />
</lua><br />
<br />
==setRoomArea==<br />
setRoomArea(roomID, newAreaID)<br />
<br />
Assigns the given room to a new area. This will have the room be visually moved into the area as well.<br />
<br />
==setRoomChar==<br />
setRoomChar(roomID, character)<br />
<br />
Designed for an area in grid mode, this will set a single character to be on a room. You can use "_" to clear it.<br />
<br />
<lua><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123. "$")<br />
</lua><br />
<br />
==setRoomCoordinates==<br />
setRoomCoordinates(roomID, x, y, z)<br />
<br />
Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
0,0,0 is the center of the map.<br />
<br />
<lua><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
You can make them relative as well:<br />
<br />
<lua><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
==setRoomEnv==<br />
setRoomEnv(roomID, newEnvID)<br />
<br />
Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
<br />
<lua><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</lua><br />
<br />
==setRoomIDbyHash==<br />
setRoomIDbyHash(roomID, hash)<br />
<br />
Sets the hash to be associated with the given roomID. See also [[Manual:Lua_Functions#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
setRoomName(roomID, newName)<br />
<br />
Renames an existing room to a new name.<br />
<br />
<lua><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</lua><br />
<br />
==setRoomUserData==<br />
setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
Returns true if successfully set.<br />
: See also: [[Manual:Lua_Functions#clearRoomUserData|clearRoomUserData]]<br />
<br />
<lua><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</lua><br />
<br />
==setRoomWeight==<br />
setRoomWeight(roomID, weight)<br />
<br />
Sets a weight to the given roomID. By default, all rooms have a weight of 0 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
To completely avoid a room, make use of [[Manual:Lua_Functions#lockRoom|lockRoom()]].<br />
<br />
: See also: [[Manual:Lua_Functions#getRoomWeight|getRoomWeight]]<br />
<br />
<lua><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</lua><br />
<br />
==unHighlightRoom==<br />
unHighlightRoom(roomID)<br />
<br />
Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[Manual:Lua_Functions#highlightRoom|highlightRoom]]<br />
<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
unHighlightRoom(4534)<br />
</lua><br />
<br />
= Miscellaneous Functions =<br />
==expandAlias==<br />
; expandAlias(command,true/false)<br />
<br />
: 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.<br />
<br />
<lua><br />
expandAlias("t rat")<br />
<br />
expandAlias("t rat", false)<br />
</lua><br />
<br />
: 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.<br />
<br />
==spawn==<br />
;t = spawn(read function, process to spawn)<br />
<br />
: 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()''.<br />
<br />
<lua><br />
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function<br />
local f = spawn(display, "ls")<br />
display(f.isRunning())<br />
f.close()<br />
</lua><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Scripting#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Scripting#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
: <sub>Requires Mudlet 2.0+</sub><br />
<br />
;Example<br />
<lua><br />
-- this example will check the Imperian homepage to see how many players are on right now<br />
<br />
-- in an alias, download the Imperian homepage for stats processing<br />
downloadFile(getMudletHomeDir().."/page.html", "http://www.imperian.com/")<br />
<br />
<br />
-- then create a new script with the name of downloaded_file, add the event handler<br />
-- for sysDownloadDone, and use this to parse the webpage and display the amount<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:match("page", 1, true) then return end<br />
<br />
-- parse our ownloaded file for the player count<br />
io.input(filename)<br />
local s = io.read("*all")<br />
local pc = s:match([[<a href='players.php%?search=who'>(%d+)</a>]])<br />
display("Imperian has "..tostring(pc).." players on right now.")<br />
io.open():close()<br />
os.remove(filename)<br />
end<br />
</lua><br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
<br />
: See Also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
<br />
;Example<br />
<lua><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "vision"}]])<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "woodlore", "name": "hide"}]])<br />
</lua><br />
<br />
==sendIrc==<br />
;sendIrc(channel, message)<br />
: Sends a message to an IRC channel or person. You must have the IRC window open, and if speaking to a channel, be joined in that channel. IRC currently only works on the freenode network and password-protected channels aren't supported.<br />
<br />
;Parameters:<br />
* ''channel:''<br />
: The channel to send the message to. Can be #<channelname> to send to a channel, or <person name> to send to a person. Passed as a string.<br />
* ''message:''<br />
: The message to send. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
--This would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
</lua><br />
<br />
==showColors==<br />
;showColors(columns)<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in color_table, in table form. The format is color_table.colorName = {r,g,b}<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#cecho|cecho]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: Number of columns to print the color table in. Passed as an integer number.<br />
<br />
;Example:<br />
<lua><br />
showColors(4)<br />
</lua><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)]]<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Lua_Functions&diff=732Manual:Lua Functions2011-07-30T23:16:06Z<p>Rayth: /* string.genNocasePattern */</p>
<hr />
<div>== Function Categories ==<br />
'''Standard Functions''': These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
'''UI Functions''': These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation.<br />
<lua><br />
createMiniConsole()<br />
createLabel()<br />
createGauge()<br />
</lua><br />
<br />
'''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.<br />
<br />
'''String Functions'''<br />
<br />
'''Scripting Object Functions'''<br />
<br />
'''Mapper Functions'''<br />
<br />
'''Miscellaneous Functions'''<br />
<br />
== Variables ==<br />
The following variables are provided by Mudlet:<br />
<br><br><br />
;line <br />
:This variable holds the content of the current line that is being processed by the trigger engine. The engine runs all triggers on each line as it arrives from the MUD.<br />
;command <br />
:This variable holds the current user command. This is typically used in alias scripts.<br />
;matches[n]<br />
:This Lua table is being used by Mudlet in the context of triggers that use Perl regular expressions. matches[1] holds the entire match, matches[2] holds the first capture group, matches[n] holds the nth-1 capture group. If the trigger uses the Perl style /g switch to evaluate all possible matches of the given regex within the current line, matches[n+1] will hold the second entire match, matches[n+2] the first capture group of the second match and matches[n+m] the m-th capture group of the second match.<br />
;multimatches[n][m]<br />
:This table is being used by Mudlet in the context of multiline triggers that use Perl regular expression. It holds the table matches[n] as described above for each Perl regular expression based condition of the multiline trigger. multimatches[5][4] may hold the 3rd capture group of the 5th regex in the multiline trigger. This way you can examine and process all relevant data within a single script. Have a look at this example.<br />
= Standard Functions =<br />
: These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
==send==<br />
;send( command, echo the value = true/false )<br />
:This sends "command" directly to the network layer, skipping the alias matching. The optional second argument of type boolean (print) determines if the outgoing command is to be echoed on the screen.<br />
:If you want your command to be checked if it’s an alias, use expandAlias() instead. example:<br />
<lua><br />
send( "Hello Jane" ) --echos the command on the screen<br />
send( "Hello Jane", true ) --echos the command on the screen<br />
send( "Hello Jane", false ) --does not echo the command on the screen<br />
</lua><br />
==echo==<br />
;echo( windowName, text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])<br />
:Echos a piece of text as a clickable link.<br />
:text - text to display in the echo. Same as a normal echo().<br />
:command - lua code to do when the link is clicked.<br />
:hint - text for the tooltip to be displayed when the mouse is over the link.<br />
:boolean - if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.<br />
<br />
= UI Functions =<br />
<br />
<br />
==echo==<br />
;echo( [windowName,] text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name. <br />
: See also: [[Manual:Lua_Functions#paste|paste]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</lua><br />
<br />
==bg==<br />
;bg(colorName)<br />
: Changes the background color of the text. Useful for highlighting text. <br />
: See Also: [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<lua><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
</lua><br />
<br />
==calcFontSize==<br />
;calcFontSize(fontSize)<br />
: Used to calculate the number of pixels wide and high a character would be on a mini console at fontSize.<br />
: Returns two numbers, width/height<br />
: See Also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]]<br />
<br />
;Parameters<br />
* ''fontSize:''<br />
: The font size you are wanting to calculate pixel sizes for. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide <br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</lua><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: Clears the window or miniconsole with the name given as argument.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearUserWindow("Chat")<br />
</lua><br />
<br />
==clearWindow==<br />
;clearWindow(name)<br />
: Clears the window or miniconsole with the name given as argument. <br />
: See also: [[Manual:Lua_Functions#clearUserWindow|clearUserWindow]]<br />
<br />
;Parameters<br />
* name: <br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</lua><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: Creates a named buffer for formatted text, much like a miniconsole, but the buffer cannot be shown on the screen. Intended for temporary use in the formatting of text.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
Examples<br />
<lua><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</lua><br />
<br />
==createConsole==<br />
;createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: Makes a new miniconsole. The background will be black, and the text color white.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide, <br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</lua><br />
<br />
==createGauge==<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, r, g, b)<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, colorName)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge]], [[Manual:Lua_Functions#setGauge|setGauge]], [[Manual:Lua_Functions#setGaugeText|setGaugeText]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</lua><br />
<br />
==createLabel==<br />
;createLabel(name, Xpos, Ypos, width, height, fillBackground)<br />
: Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|setTextFormat]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.<br />
<br />
Examples<br />
<lua><br />
--This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle <br />
--of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent <br />
--and 255 non-transparent) the background text can still be read through. The message box will disappear after 2.3 seconds.<br />
local width, height = getMainWindowSize();<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1);<br />
resizeWindow("messageBox",500,70);<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 );<br />
setBackgroundColor("messageBox", 150,100,100,200);<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]] );<br />
showWindow("messageBox");<br />
tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</lua><br />
<br />
==createMiniConsole==<br />
;createMiniConsole(name, posX, posY, width, height)<br />
: Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc. <br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel]], [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|moveWindow]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent]], [[Manual:Lua_Functions#setBorderTop|setBorderTop]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique, you can not have two or more miniconsoles with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the miniconsole, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the miniconsole, in pixels. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
--This script would create a mini text console called "sys" and write with yellow foreground color and blue background color <br />
--"Hello World".<br />
<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
WindowWidth = 0;<br />
WindowHeight = 0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line<br />
setWindowWrap("sys", 40)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
<br />
echo("sys","Hello world!")<br />
</lua><br />
<br />
==deleteLine==<br />
;deleteLine()<br />
: Deletes the current line under the user cursor. This is a high speed gagging tool and is very good at this task, but is only meant to be use when a line should be omitted entirely in the output. If you echo() to that line it will not be shown, and lines deleted with deleteLine() are simply no longer rendered. For replacing text, replace() is the proper option.<br />
: See Also: [[Manual:Lua_Functions#replace|replace]], [[Manual:Lua_Functions#wrapLine|wrapLine]]<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
</lua><br />
<br />
==deselect==<br />
;deselect(name)<br />
: This is used to clear the current selection (to no longer have anything selected). Should be used after changing the formatting of text, to keep from accidentally changing the text again later with another formatting call.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer/miniConsole to stop having anything selected in. This is an optional argument, if name is not provided the main window will have its selection cleared. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further <br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</lua><br />
<br />
==fg==<br />
; fg(colorName)<br />
: If used on a selection, sets the foreground color to ''colorName'' - otherwise, it will set the color of the next text-inserting calls (''echo(), insertText, echoLink()'', and others)<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Examples<br />
<lua><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
</lua><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels.<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--this will get the size of your main mudlet window and save them <br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</lua><br />
<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.<br />
<br />
;Example<br />
<lua><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</lua><br />
<br />
= Table Functions =<br />
<br />
==table.complement==<br />
; table.complement (set1, set2)<br />
: Returns a table that is the relative complement of the first table with respect to the second table. Returns a complement of key/value pairs.<br />
<br />
; Parameters<br />
* ''table1:''<br />
* ''table2:''<br />
<br />
; Example:<br />
<lua></lua><br />
<br />
==table.concat==<br />
;table.concat(table, delimiter, startingindex, endingindex)<br />
: Joins a table into a string. Each item must be something which can be transformed into a string. <br />
: Returns the joined string.<br />
: See also: [[Manual:Lua_Functions#string.split|string.split]]<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table to concatenate into a string. Passed as a table.<br />
* '''delimiter:'''<br />
: Optional string to use to separate each element in the joined string. Passed as a string.<br />
* '''startingindex:'''<br />
: Optional parameter to specify which index to begin the joining at. Passed as an integer.<br />
* '''endingindex:'''<br />
: Optional parameter to specify the last index to join. Passed as an integer.<br />
<br />
;Examples<br />
<lua><br />
--This shows a basic concat with none of the optional arguments<br />
testTable = {1,2,"hi","blah",}<br />
testString = table.concat(testTable)<br />
--testString would be equal to "12hiblah"<br />
<br />
--This example shows the concat using the optional delimiter<br />
testString = table.concat(testTable, ", ")<br />
--testString would be equal to "1, 2, hi, blah"<br />
<br />
--This example shows the concat using the delimiter and the optional starting index<br />
testString = table.concat(testTable, ", ", 2)<br />
--testString would be equal to "2, hi, blah"<br />
<br />
--And finally, one which uses all of the arguments<br />
testString = table.concat(testTable, ", ", 2, 3)<br />
--testString would be equal to "2, hi"<br />
</lua><br />
<br />
==table.contains==<br />
; table.contains (t, value)<br />
: Determines if a table contains a value as a key or as a value (recursive).<br />
: Returns true or false<br />
<br />
; Parameters<br />
* '''t:''' <br />
: The table in which you are checking for the presence of the value.<br />
* '''value:''' <br />
: The value you are checking for within the table.<br />
<br />
; Example:<br />
<lua>local test_table = { "value1", "value2", "value3", "value4" }<br />
if table.contains(test_table, "value1") then <br />
echo("Got value 1!")<br />
else<br />
echo("Don't have it. Sorry!")<br />
end<br />
</lua><br />
This example would always echo the first one, unless you remove value1 from the table.<br />
<br />
==table.foreachi==<br />
==table.foreach==<br />
==table.getn==<br />
==table.intersection==<br />
==table.insert==<br />
; table.insert(table, [pos,] value)<br />
: Inserts element '''value''' at position '''pos''' in '''table''', shifting up other elements to open space, if necessary. The default '''value''' for '''pos''' is n+1, where n is the length of the table, so that a call table.insert(t,x) inserts x at the end of table t.<br />
: See also: [[Manual:Lua_Functions#table.remove|table.remove]]<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table in which you are inserting the value<br />
* '''pos:'''<br />
: Optional argument, determining where the value will be inserted. <br />
* '''value:'''<br />
: The variable that you are inserting into the table. Can be a regular variable, or even a table or function*. <br />
<table frame="box" width="100%"><br />
<caption>*Note</caption><br />
<tr><br />
<td><br />
Inserting a function into a table is not good coding practice, and will not turn out how you think it would.<br />
</td><br />
</tr><br />
</table><br />
==table.index_of==<br />
==table.is_empty==<br />
; table.is_empty(table)<br />
: Check if a table is devoid of any values.<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table you are checking for values.<br />
==table.load==<br />
; table.load(location, table)<br />
: Load a table from an external file into mudlet.<br />
: See also: [[Manual:Lua_Functions#table.save|table.save]]<br />
<br />
; Parameters:<br />
* '''location:'''<br />
: Where you are loading the table from. Can be anywhere on your computer.<br />
* '''table:'''<br />
: The table that you are loading.<br />
<br />
: Example:<br />
<lua><br />
-- This will load the table mytable from the lua file mytable present in your Mudlet Home Directory.<br />
table.load(getMudletHomeDir().."/mytable.lua", mytable)<br />
-- You can load a table from anywhere on your computer, but it's preferable to have them consolidated somewhere connected to Mudlet.<br />
</lua><br />
==table.maxn==<br />
==table.n_union==<br />
==table.n_complement==<br />
==table.n_intersection==<br />
==table.pickle==<br />
==table.remove==<br />
; table.remove(table, value_position)<br />
: Remove a value from an indexed table, by the values position in the table.<br />
: See also: [[Manual:Lua_Functions#table.insert|table.insert]]<br />
<br />
; Parameters:<br />
* '''table'''<br />
: The indexed table you are removing the value from.<br />
* '''value_position'''<br />
: The indexed number for the value you are removing.<br />
<br />
; Example:<br />
<lua><br />
testTable = { "hi", "bye", "cry", "why" }<br />
table.remove(testTable, 1) -- will remove hi from the table<br />
-- new testTable after the remove<br />
testTable = { "bye", "cry", "why" }<br />
-- original position of hi was 1, after the remove, position 1 has become bye<br />
-- any values under the removed value are moved up, 5 becomes 4, 4 becomes 3, etc<br />
</lua> <br />
<table frame="box" width="100%"><br />
<caption>Note</caption><br />
<tr><br />
<td><br />
To remove a value from a key-value table, it's best to simply change the value to nil.<br />
<lua><br />
testTable = { test = "testing", go = "boom", frown = "glow" }<br />
table.remove(testTable, test) -- this will error<br />
testTable.test = nil -- won't error<br />
testTable["test"] = nil -- won't error<br />
</lua><br />
</td><br />
</tr><br />
</table><br />
==table.save==<br />
; table.save(location, table)<br />
: Save a table into an external file in '''location'''.<br />
: See also: [[Manual:Lua_Functions#table.load|table.load]]<br />
<br />
; Parameters:<br />
* '''location:'''<br />
: Where you want the table file to be saved. Can be anywhere on your computer.<br />
* '''table:'''<br />
: The table that you are saving to the file.<br />
<br />
: Example:<br />
<lua><br />
-- Saves the table mytable to the lua file mytable in your Mudlet Home Directory<br />
table.save(getMudletHomeDir().."/mytable.lua", mytable)<br />
</lua><br />
==table.sort==<br />
==table.size==<br />
; table.size (t)<br />
: Gets the actual size of non-index based tables.<br />
: Returns a number.<br />
<br />
; Parameters<br />
* ''t:'' <br />
: The table you are checking the size of.<br />
<table width="100%" frame="box"><br />
<caption>'''Note:'''</caption><br />
<tr><br />
<td><br />
For index based tables you can get the size with the # operator:<br />
This is the standard Lua way of getting the size of index tables i.e. ipairs() type of tables with numerical indices. <br />
To get the size of tables that use user defined keys instead of automatic indices (pairs() type) you need to use the function table.size() referenced above.<br />
</td><br />
</tr><br />
</table><br />
; Example<br />
<lua><br />
local test_table = { "value1", "value2", "value3", "value4" }<br />
myTableSize = #test_table<br />
-- This would return 4.<br />
local myTable = { 1 = "hello", "key2" = "bye", "key3" = "time to go" }<br />
table.size(myTable)<br />
-- This would return 3.<br />
</lua><br />
==table.setn==<br />
==table.unpickle==<br />
==table.update==<br />
==table.union==<br />
<br />
= String Functions =<br />
==string.byte==<br />
<br />
==string.char==<br />
<br />
==string.cut==<br />
;string.cut(string, maxLen)<br />
: Cuts string to the specified maximum length.<br />
: Returns the modified string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The text you wish to cut. Passed as a string.<br />
* maxLen<br />
: The maximum length you wish the string to be. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--The following call will return 'abc' and store it in myString<br />
mystring = string.cut("abcde", 3)<br />
--You can easily pad string to certain length. Example below will print 'abcde ' e.g. pad/cut string to 10 characters.<br />
local s = "abcde"<br />
s = string.cut(s .. " ", 10) -- append 10 spaces<br />
echo("'" .. s .. "'")<br />
</lua><br />
<br />
==string.dump==<br />
<br />
==string.enclose==<br />
;string.enclose(String)<br />
: Wraps a string with [[ ]]<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String: The string to enclose. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will echo '[[Oh noes!]]' to the main window<br />
echo("'" .. string.enclose("Oh noes!") .. "'")<br />
</lua><br />
<br />
==string.ends==<br />
;string.ends(String, Suffix)<br />
: Test if string is ending with specified suffix.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#string.starts|string.starts]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string.<br />
* ''Suffix:''<br />
: The suffix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will test if the incoming line ends with "in bed" and if not will add it to the end.<br />
if not string.ends(line, "in bed") then<br />
echo("in bed\n")<br />
end<br />
</lua><br />
<br />
==string.find==<br />
<br />
==string.findPattern==<br />
; string.findPattern(text, pattern)<br />
: Return first matching substring or nil.<br />
<br />
; Parameters<br />
: text:<br />
: pattern:<br />
<br />
; Example:<br />
Following example will print: "I did find: Troll" string.<br />
<lua><br />
local match = string.findPattern("Troll is here!", "Troll")<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</lua><br />
This example will find substring regardless of case.<br />
<lua>local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</lua><br />
* Return value:<br />
: nil or first matching substring <br />
See also: [[Manual:Lua_Functions#string.genNocasePattern|string.genNocasePattern()]]<br />
<br />
==string.format==<br />
<br />
==string.genNocasePattern==<br />
; string.genNocasePattern(s)<br />
: Generate case insensitive search pattern from string.<br />
<br />
; Parameters<br />
* s:<br />
<br />
; Example:<br />
: Following example will generate and print "123[aA][bB][cC]" string.<br />
<lua>echo(string.genNocasePattern("123abc"))</lua><br />
: Return value:<br />
case insensitive pattern string<br />
<br />
==string.gfind==<br />
<br />
==string.gmatch==<br />
<br />
==string.gsub==<br />
<br />
==string.len==<br />
<br />
==string.lower==<br />
<br />
==string.match==<br />
<br />
==string.rep==<br />
<br />
==string.reverse==<br />
<br />
<br />
==string.split==<br />
;string.split(String, delimiter)<br />
;<nowiki>myString:split(delimiter)</nowiki><br />
: Splits a string into a table by the given delimiter. Can be called against a string (or variable holding a string) using the second form above.<br />
: Returns a table containing the split sections of the string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to split. Parameter is not needed if using second form of the syntax above. Passed as a string.<br />
* ''delimiter:''<br />
: The delimiter to use when splitting the string. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
-- This will split the string by ", " delimiter and print the resulting table to the main window.<br />
names = "Alice, Bob, Peter"<br />
name_table = string.split(names, ", ")<br />
display(name_table)<br />
<br />
--The alternate method<br />
names = "Alice, Bob, Peter"<br />
name_table = names:split(", ")<br />
display(name_table)<br />
</lua><br />
<br />
Either method above will print out:<br />
table {<br />
1: 'Alice'<br />
2: 'Bob'<br />
3: 'Peter'<br />
}<br />
<br />
==string.starts==<br />
;string.starts(String, Prefix)<br />
: Test if string is starting with specified prefix.<br />
: Returns true or false<br />
: See also: [[Manual:Lua_Functions#string.ends|string.ends]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string. <br />
* ''Prefix:''<br />
: The prefix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--The following will see if the line begins with "You" and if so will print a statement at the end of the line<br />
if string.starts(line, "You") then<br />
echo("====oh you====\n")<br />
end<br />
</lua><br />
<br />
==string.sub==<br />
<br />
==string.title==<br />
;string.title(String)<br />
;<nowiki>string:title()</nowiki><br />
: Capitalizes the first character in a string.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String<br />
: The string to modify. Not needed if you use the second form of the syntax above.<br />
<br />
;Example<br />
<lua><br />
--Variable testname is now Anna.<br />
testname = string.title("anna")<br />
--Example will set test to "Bob".<br />
test = "bob"<br />
test = test:title()<br />
</lua><br />
<br />
==string.trim==<br />
;string.trim(String)<br />
: Trims String, removing all 'extra' white space at the beginning and end of the text.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to trim. Passed as a string.<br />
<br />
;Example:<br />
<lua><br />
--This will print 'Troll is here!', without the extra spaces.<br />
local str = string.trim(" Troll is here! ")<br />
echo("'" .. str .. "'")<br />
</lua><br />
<br />
==string.upper==<br />
<br />
= Mudlet Object Functions =<br />
==tempTimer==<br />
;tempTimer(time, code to do)<br />
Creates a temporary single shot timer and returns the timer ID for subsequent enableTimer(), disableTimer() and killTimer() calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed. <br />
<br />
;Parameters<br />
* ''time:'' the time in seconds for which to set the timer for<br />
* ''code to do'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
;Note<br />
[[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
==permGroup==<br />
permGroup(name, itemtype)<br />
<br />
Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts.<br />
<br />
<sub>Added to Mudlet in the 2.0 final release.</sub><br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<br />
<lua><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</lua><br />
<br />
<br />
==addAreaName==<br />
areaID = addAreaName(areaName)<br />
<br />
Adds a new area name and returns the new area ID for the new name. If the name already exists, -1 is returned.<br />
: See also: [[Manual:Lua_Functions#deleteArea|deleteArea]]<br />
<br />
<lua><br />
local newID = addAreaName("My house")<br />
<br />
if newID == -1 then echo("That area name is already taken :(\n")<br />
else echo("Created new area with the ID of "..newid..".\n") end<br />
</lua><br />
<br />
==addRoom==<br />
addRoom(roomID)<br />
<br />
Creates a new room with the given ID, returns true if the room was successfully created.<br />
: See also: [[Manual:Lua_Functions#createRoomID|createRoomID]]<br />
<br />
<lua><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</lua><br />
<br />
==addSpecialExit==<br />
addSpecialExit(roomIDFrom, roomIDTo, command)<br />
<br />
Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[Manual:Lua_Functions#clearSpecialExits|clearSpecialExits]]<br />
<br />
<lua><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- mmp.currentroom is your current room ID in this example<br />
addSpecialExit(mmp.currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(mmp.currentroom)<br />
</lua><br />
<br />
==centerview==<br />
centerview (roomID)<br />
<br />
Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
==clearRoomUserData==<br />
clearRoomUserData(roomID)<br />
<br />
Clears all user data from a given room.<br />
: See also: [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]]<br />
<br />
<lua><br />
clearRoomUserData(341)<br />
</lua><br />
<br />
==clearSpecialExits==<br />
clearSpecialExits(roomID) <br />
<br />
Removes all special exits from a room.<br />
: See also: [[Manual:Lua_Functions#addSpecialExit|addSpecialExit]]<br />
<br />
<lua><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will neve fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</lua><br />
<br />
==createMapLabel==<br />
labelID = createMapLabel(areaID, text, posx, posy, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue)<br />
<br />
Creates a visual label on the map for all z-levels at given coordinates, with the given background and foreground colors. It returns a label ID that you can use later for deleting it.<br />
<br />
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 [[Manual:Lua_Functions#getRoomCoordinates|getRoomCoordinates]] will place the label near that room.<br />
: See also: [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]]<br />
<lua><br />
local labelid = createMapLabel( 50, "my map label", 0, 0, 255,0,0,23,0,0)<br />
</lua><br />
<br />
==createMapper==<br />
createMapper(x, y, width, height)<br />
<br />
Creates a miniconsole window for mapper to render in, the with the given dimensions. You can only create one at a time at the moment.<br />
<br />
<lua><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper top-right of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</lua><br />
<br />
==createRoomID==<br />
usableId = createRoomID()<br />
<br />
Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs.<br />
: See also: [[Manual:Lua_Functions#addRoom|addRoom]]<br />
<br />
==deleteArea==<br />
deleteArea(areaID)<br />
<br />
Deletes the given area, permanently. This will also delete all rooms in it!<br />
: See also: [[Manual:Lua_Functions#addAreaName|addAreaName]]<br />
<br />
<lua><br />
deleteArea(23)<br />
</lua><br />
<br />
==deleteMapLabel==<br />
deleteMapLabel(areaID, labelID)<br />
<br />
Deletes a map label from a specfic area.<br />
: See also: [[Manual:Lua_Functions#createMapLabel|createMapLabel]]<br />
<lua><br />
deleteMapLabel(50, 1)<br />
</lua><br />
<br />
==deleteRoom==<br />
deleteRoom(roomID)<br />
<br />
Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
<lua><br />
deleteRoom(335)<br />
</lua><br />
<br />
==getAreaRooms==<br />
getAreaRooms(area id)<br />
<br />
Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
<sub>Note that on Mudlet versions prior to the 2.0 final release, this function would raise an error.</sub><br />
<br />
<lua><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in ipairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</lua><br />
<br />
==getAreaTable==<br />
getAreaTable()<br />
<br />
Returns a key(area name)-value(area id) table with all known areas and their IDs. There is an area with the name of '' and an ID of 0 included in it, you should ignore that.<br />
<br />
<lua><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id")<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</lua><br />
<br />
==getCustomEnvColorTable==<br />
envcolors = getCustomEnvColorTable()<br />
<br />
Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
<br />
<lua><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</lua><br />
<br />
==getMapLabels==<br />
arealabels = getMapLabels(areaID)<br />
<br />
Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]] it.<br />
<br />
<lua><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Svorai's grove'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Svorai's grove'<br />
}<br />
</lua><br />
<br />
==getPath==<br />
getPath(roomID from, roomID to)<br />
<br />
Returns a boolean true/false if a path between two room IDs is possible. If it is, the global `speedWalkPath` table is set to all of the directions that have to be taken to get there, and the global `speedWalkDir` table is set to all of the roomIDs you'll encounter on the way.<br />
<br />
<lua><br />
-- check if we can go to a room - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</lua><br />
<br />
==getRoomArea==<br />
areaID = getRoomArea(roomID)<br />
<br />
Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by getAreaTable() function, or use the getRoomAreaName function.<br />
<br />
<sub>Note that if the room ID does not exist, this function will raise an error</sub><br />
<br />
<lua><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</lua><br />
<br />
==getRoomAreaName==<br />
areaname = getRoomAreaName(areaID)<br />
<br />
Returns the area name for a given area id.<br />
<br />
<lua><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</lua><br />
<br />
==getRoomCoordinates==<br />
x,y,z = getRoomCoordinates(room ID)<br />
<br />
Returns the room coordinates of the given room ID.<br />
<br />
<lua><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</lua><br />
<br />
==getRoomEnv==<br />
envID = getRoomEnv(roomID)<br />
<br />
Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
<lua><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</lua><br />
<br />
== getRoomExits ==<br />
getRoomExits (roomID)<br />
Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid'', ie:<br />
<br />
<lua><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</lua><br />
<br />
==getRoomIDbyHash==<br />
roomID = getRoomIDbyHash(hash)<br />
<br />
Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
<lua><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
_id1 = getRoomIDbyHash( "5dfe55b0c8d769e865fd85ba63127fbc" );<br />
if _id1 == -1 then <br />
_id1 = createRoomID()<br />
setRoomIDbyHash( _id1, "5dfe55b0c8d769e865fd85ba63127fbc" )<br />
addRoom( _id )<br />
setRoomCoordinates( _id1, 0, 0, -1 )<br />
end<br />
</lua><br />
<br />
==getRoomName==<br />
roomName = getRoomName(roomID)<br />
<br />
Returns the room name for a given room id.<br />
<br />
<lua><br />
echo(string.format("The name of the room id #455 is %s.", getRoomname(455))<br />
</lua><br />
<br />
==getRooms==<br />
rooms = getRooms()<br />
<br />
Returns the list of '''all''' rooms in the map in an area in roomid - room name format.<br />
<br />
<lua><br />
-- simple, raw viewer for rooms in an area<br />
display(getRooms())<br />
</lua><br />
<br />
==getRoomsByPosition==<br />
getRoomsByPosition(areaID, x,y,z)<br />
<br />
Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
<lua><br />
-- sample script to determine a room nearby, given a relative direction from the current room<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</lua><br />
<br />
==getRoomUserData==<br />
data = getRoomUserData(roomID, key (as a string))<br />
<br />
Returns the user data stored at a given room with a given key, or "" if none is stored. Use [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]] for setting the user data.<br />
<br />
<lua><br />
display(getRoomUserData(341, "visitcount"))<br />
</lua><br />
<br />
==getRoomWeight==<br />
room weight = getRoomWeight(roomID)<br />
<br />
Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[Manual:Lua_Functions#setRoomWeight|setRoomWeight]]<br />
<br />
<lua><br />
display("Original weight of room 541: "..getRoomWeight(541)<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541)<br />
</lua><br />
<br />
==getSpecialExits==<br />
exits = getSpecialExits(roomID)<br />
<br />
Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
<lua><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</lua><br />
<br />
==getSpecialExitsSwap==<br />
exits = getSpecialExitsSwap(roomID)<br />
<br />
Very similar to [[Manual:Lua_Functions#getSpecialExits|getSpecialExits]], but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
gotoRoom (roomID)<br />
Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(". <br />
<br />
==hasExitLock==<br />
status = hasExitLock(roomID, direction)<br />
<br />
Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''direction'' right now is a number that corresponds to the direction:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples:<br />
<lua><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#lockExit|lockExit]]<br />
<br />
==highlightRoom==<br />
highlightRoom( id, r1,g1,b1,r2,g2,b2, radius, alpha1, alpha2)<br />
<br />
Highlights a room with the given color, which will override it's environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. ''highlightRadius'' is the radius for the highlight circle - if you don't want rooms beside each other to over lap, use ''1'' as the radius. ''alphaColor1'' and ''alphaColor2'' are transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[Manual:Lua_Functions#unHighlightRoom|unHighlightRoom]]<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
-- color some room red to blue<br />
highlightRoom(351, unpack(color_table.red), unpack(color_table.blue), 1, 255, 255)<br />
<br />
-- or use a name from showColors(), gold in this case<br />
highlightRoom(351, unpack(color_table.grey), unpack(color_table.grey), 1, 255, 255)<br />
</lua><br />
<br />
==lockExit==<br />
lockExit(roomID, direction, lock = true/false)<br />
<br />
Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction at the moment is only set as a number, and here's a listing of them:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples<br />
<lua><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#hasExitLock|hasExitLock]]<br />
<br />
==lockRoom==<br />
lockRoom (roomID, lock = true/false)<br />
<br />
Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[Manual:Lua_Functions#roomLocked|roomLocked]]<br />
<br />
<lua><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</lua><br />
<br />
==roomExists==<br />
roomExists(roomID)<br />
<br />
Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
locked = roomLocked(roomID)<br />
<br />
Returns true or false whenever a given room is locked.<br />
: See also: [[Manual:Lua_Functions#lockRoom|lockRoom]]<br />
<br />
<lua><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</lua><br />
<br />
==saveMap==<br />
saveMap(location)<br />
<br />
Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work.<br />
<br />
<lua><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
</lua><br />
<br />
==searchRoom== <br />
searchRoom (room name)<br />
<br />
Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname'', like so:<br />
<br />
<lua><br />
display(searchRoom("master"))<br />
<br />
--[[ would result in:<br />
table {<br />
17463: 'in the branches of the Master Ravenwood'<br />
3652: 'master bedroom'<br />
10361: 'Hall of Cultural Masterpieces'<br />
6324: 'Exhibit of the Techniques of the Master Artisans'<br />
5340: 'office of the Guildmaster'<br />
(...)<br />
2004: 'office of the guildmaster'<br />
14457: 'the Master Gear'<br />
1337: 'before the Master Ravenwood Tree'<br />
}<br />
]]</lua><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
==setAreaName==<br />
setAreaName(areaID, newName)<br />
<br />
Renames an existing area to the new name.<br />
<br />
<lua><br />
setAreaName(2, "My city")<br />
</lua><br />
<br />
==setCustomEnvColor==<br />
setCustomEnvColor(environmentID, r,g,b)<br />
<br />
Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
<br />
<lua><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
setCustomEnvColor(200, unpack(color_table.blue)) -- set the color of environmentID 200 to blue<br />
</lua><br />
<br />
==setExit==<br />
setExit(from roomID, to roomID, direction)<br />
<br />
Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', or a number which represents a direction.<br />
<br />
Returns ''false'' if the exit creation didn't work.<br />
<br />
<lua><br />
-- alias pattern: ^exit (\d+) (\w+)$<br />
<br />
if setExit(mmp.currentroom, tonumber(matches[2]),matches[3]) then<br />
echo("\nExit set to room:"..matches[2]..", Direction:"..string.upper(matches[3]))<br />
centerview(mmp.currentroom)<br />
else<br />
mmp.echo("Failed to set the exit.") end<br />
</lua><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
setExit(from roomID, -1, direction)<br />
<br />
Which will delete an outgoing exit in the specified direction from a room.<br />
<br />
<lua><br />
-- locate the room on the other end, so we can unlink it from there as well if necessary<br />
local otherroom<br />
if getRoomExits(getRoomExits(mmp.currentroom)[dir])[mmp.ranytolong(dir)] then<br />
otherroom = getRoomExits(mmp.currentroom)[dir]<br />
end<br />
<br />
if setExit(mmp.currentroom, -1, dir) then<br />
if otherroom then<br />
if setExit(otherroom, -1, mmp.ranytolong(dir)) then<br />
mmp.echo(string.format("Deleted the %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
else mmp.echo("Couldn't delete the incoming exit.") end<br />
else<br />
mmp.echo(string.format("Deleted the one-way %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
end<br />
else<br />
mmp.echo("Couldn't delete the outgoing exit.")<br />
end<br />
</lua><br />
<br />
You can use these numbers for setting the directions as well:<br />
<lua><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}</lua><br />
<br />
==setGridMode==<br />
setGridMode(area, true/false)<br />
<br />
Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode.<br />
<br />
<lua><br />
setGridMode(55,true) -- set area with ID 55 to be in grid mode<br />
</lua><br />
<br />
==setRoomArea==<br />
setRoomArea(roomID, newAreaID)<br />
<br />
Assigns the given room to a new area. This will have the room be visually moved into the area as well.<br />
<br />
==setRoomChar==<br />
setRoomChar(roomID, character)<br />
<br />
Designed for an area in grid mode, this will set a single character to be on a room. You can use "_" to clear it.<br />
<br />
<lua><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123. "$")<br />
</lua><br />
<br />
==setRoomCoordinates==<br />
setRoomCoordinates(roomID, x, y, z)<br />
<br />
Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
0,0,0 is the center of the map.<br />
<br />
<lua><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
You can make them relative as well:<br />
<br />
<lua><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
==setRoomEnv==<br />
setRoomEnv(roomID, newEnvID)<br />
<br />
Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
<br />
<lua><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</lua><br />
<br />
==setRoomIDbyHash==<br />
setRoomIDbyHash(roomID, hash)<br />
<br />
Sets the hash to be associated with the given roomID. See also [[Manual:Lua_Functions#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
setRoomName(roomID, newName)<br />
<br />
Renames an existing room to a new name.<br />
<br />
<lua><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</lua><br />
<br />
==setRoomUserData==<br />
setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
Returns true if successfully set.<br />
: See also: [[Manual:Lua_Functions#clearRoomUserData|clearRoomUserData]]<br />
<br />
<lua><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</lua><br />
<br />
==setRoomWeight==<br />
setRoomWeight(roomID, weight)<br />
<br />
Sets a weight to the given roomID. By default, all rooms have a weight of 0 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
To completely avoid a room, make use of [[Manual:Lua_Functions#lockRoom|lockRoom()]].<br />
<br />
: See also: [[Manual:Lua_Functions#getRoomWeight|getRoomWeight]]<br />
<br />
<lua><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</lua><br />
<br />
==unHighlightRoom==<br />
unHighlightRoom(roomID)<br />
<br />
Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[Manual:Lua_Functions#highlightRoom|highlightRoom]]<br />
<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
unHighlightRoom(4534)<br />
</lua><br />
<br />
= Miscellaneous Functions =<br />
==expandAlias==<br />
; expandAlias(command,true/false)<br />
<br />
: 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.<br />
<br />
<lua><br />
expandAlias("t rat")<br />
<br />
expandAlias("t rat", false)<br />
</lua><br />
<br />
: 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.<br />
<br />
==spawn==<br />
;t = spawn(read function, process to spawn)<br />
<br />
: 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()''.<br />
<br />
<lua><br />
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function<br />
local f = spawn(display, "ls")<br />
display(f.isRunning())<br />
f.close()<br />
</lua><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Scripting#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Scripting#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
: <sub>Requires Mudlet 2.0+</sub><br />
<br />
;Example<br />
<lua><br />
-- this example will check the Imperian homepage to see how many players are on right now<br />
<br />
-- in an alias, download the Imperian homepage for stats processing<br />
downloadFile(getMudletHomeDir().."/page.html", "http://www.imperian.com/")<br />
<br />
<br />
-- then create a new script with the name of downloaded_file, add the event handler<br />
-- for sysDownloadDone, and use this to parse the webpage and display the amount<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:match("page", 1, true) then return end<br />
<br />
-- parse our ownloaded file for the player count<br />
io.input(filename)<br />
local s = io.read("*all")<br />
local pc = s:match([[<a href='players.php%?search=who'>(%d+)</a>]])<br />
display("Imperian has "..tostring(pc).." players on right now.")<br />
io.open():close()<br />
os.remove(filename)<br />
end<br />
</lua><br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
<br />
: See Also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
<br />
;Example<br />
<lua><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "vision"}]])<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "woodlore", "name": "hide"}]])<br />
</lua><br />
<br />
==sendIrc==<br />
;sendIrc(channel, message)<br />
: Sends a message to an IRC channel or person. You must have the IRC window open, and if speaking to a channel, be joined in that channel. IRC currently only works on the freenode network and password-protected channels aren't supported.<br />
<br />
;Parameters:<br />
* ''channel:''<br />
: The channel to send the message to. Can be #<channelname> to send to a channel, or <person name> to send to a person. Passed as a string.<br />
* ''message:''<br />
: The message to send. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
--This would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
</lua><br />
<br />
==showColors==<br />
;showColors(columns)<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in color_table, in table form. The format is color_table.colorName = {r,g,b}<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#cecho|cecho]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: Number of columns to print the color table in. Passed as an integer number.<br />
<br />
;Example:<br />
<lua><br />
showColors(4)<br />
</lua><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)]]<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Lua_Functions&diff=731Manual:Lua Functions2011-07-30T23:14:57Z<p>Rayth: /* string.findPattern */</p>
<hr />
<div>== Function Categories ==<br />
'''Standard Functions''': These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
'''UI Functions''': These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation.<br />
<lua><br />
createMiniConsole()<br />
createLabel()<br />
createGauge()<br />
</lua><br />
<br />
'''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.<br />
<br />
'''String Functions'''<br />
<br />
'''Scripting Object Functions'''<br />
<br />
'''Mapper Functions'''<br />
<br />
'''Miscellaneous Functions'''<br />
<br />
== Variables ==<br />
The following variables are provided by Mudlet:<br />
<br><br><br />
;line <br />
:This variable holds the content of the current line that is being processed by the trigger engine. The engine runs all triggers on each line as it arrives from the MUD.<br />
;command <br />
:This variable holds the current user command. This is typically used in alias scripts.<br />
;matches[n]<br />
:This Lua table is being used by Mudlet in the context of triggers that use Perl regular expressions. matches[1] holds the entire match, matches[2] holds the first capture group, matches[n] holds the nth-1 capture group. If the trigger uses the Perl style /g switch to evaluate all possible matches of the given regex within the current line, matches[n+1] will hold the second entire match, matches[n+2] the first capture group of the second match and matches[n+m] the m-th capture group of the second match.<br />
;multimatches[n][m]<br />
:This table is being used by Mudlet in the context of multiline triggers that use Perl regular expression. It holds the table matches[n] as described above for each Perl regular expression based condition of the multiline trigger. multimatches[5][4] may hold the 3rd capture group of the 5th regex in the multiline trigger. This way you can examine and process all relevant data within a single script. Have a look at this example.<br />
= Standard Functions =<br />
: These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
==send==<br />
;send( command, echo the value = true/false )<br />
:This sends "command" directly to the network layer, skipping the alias matching. The optional second argument of type boolean (print) determines if the outgoing command is to be echoed on the screen.<br />
:If you want your command to be checked if it’s an alias, use expandAlias() instead. example:<br />
<lua><br />
send( "Hello Jane" ) --echos the command on the screen<br />
send( "Hello Jane", true ) --echos the command on the screen<br />
send( "Hello Jane", false ) --does not echo the command on the screen<br />
</lua><br />
==echo==<br />
;echo( windowName, text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])<br />
:Echos a piece of text as a clickable link.<br />
:text - text to display in the echo. Same as a normal echo().<br />
:command - lua code to do when the link is clicked.<br />
:hint - text for the tooltip to be displayed when the mouse is over the link.<br />
:boolean - if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.<br />
<br />
= UI Functions =<br />
<br />
<br />
==echo==<br />
;echo( [windowName,] text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name. <br />
: See also: [[Manual:Lua_Functions#paste|paste]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</lua><br />
<br />
==bg==<br />
;bg(colorName)<br />
: Changes the background color of the text. Useful for highlighting text. <br />
: See Also: [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<lua><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
</lua><br />
<br />
==calcFontSize==<br />
;calcFontSize(fontSize)<br />
: Used to calculate the number of pixels wide and high a character would be on a mini console at fontSize.<br />
: Returns two numbers, width/height<br />
: See Also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]]<br />
<br />
;Parameters<br />
* ''fontSize:''<br />
: The font size you are wanting to calculate pixel sizes for. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide <br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</lua><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: Clears the window or miniconsole with the name given as argument.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearUserWindow("Chat")<br />
</lua><br />
<br />
==clearWindow==<br />
;clearWindow(name)<br />
: Clears the window or miniconsole with the name given as argument. <br />
: See also: [[Manual:Lua_Functions#clearUserWindow|clearUserWindow]]<br />
<br />
;Parameters<br />
* name: <br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</lua><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: Creates a named buffer for formatted text, much like a miniconsole, but the buffer cannot be shown on the screen. Intended for temporary use in the formatting of text.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
Examples<br />
<lua><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</lua><br />
<br />
==createConsole==<br />
;createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: Makes a new miniconsole. The background will be black, and the text color white.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide, <br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</lua><br />
<br />
==createGauge==<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, r, g, b)<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, colorName)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge]], [[Manual:Lua_Functions#setGauge|setGauge]], [[Manual:Lua_Functions#setGaugeText|setGaugeText]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</lua><br />
<br />
==createLabel==<br />
;createLabel(name, Xpos, Ypos, width, height, fillBackground)<br />
: Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|setTextFormat]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.<br />
<br />
Examples<br />
<lua><br />
--This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle <br />
--of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent <br />
--and 255 non-transparent) the background text can still be read through. The message box will disappear after 2.3 seconds.<br />
local width, height = getMainWindowSize();<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1);<br />
resizeWindow("messageBox",500,70);<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 );<br />
setBackgroundColor("messageBox", 150,100,100,200);<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]] );<br />
showWindow("messageBox");<br />
tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</lua><br />
<br />
==createMiniConsole==<br />
;createMiniConsole(name, posX, posY, width, height)<br />
: Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc. <br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel]], [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|moveWindow]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent]], [[Manual:Lua_Functions#setBorderTop|setBorderTop]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique, you can not have two or more miniconsoles with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the miniconsole, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the miniconsole, in pixels. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
--This script would create a mini text console called "sys" and write with yellow foreground color and blue background color <br />
--"Hello World".<br />
<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
WindowWidth = 0;<br />
WindowHeight = 0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line<br />
setWindowWrap("sys", 40)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
<br />
echo("sys","Hello world!")<br />
</lua><br />
<br />
==deleteLine==<br />
;deleteLine()<br />
: Deletes the current line under the user cursor. This is a high speed gagging tool and is very good at this task, but is only meant to be use when a line should be omitted entirely in the output. If you echo() to that line it will not be shown, and lines deleted with deleteLine() are simply no longer rendered. For replacing text, replace() is the proper option.<br />
: See Also: [[Manual:Lua_Functions#replace|replace]], [[Manual:Lua_Functions#wrapLine|wrapLine]]<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
</lua><br />
<br />
==deselect==<br />
;deselect(name)<br />
: This is used to clear the current selection (to no longer have anything selected). Should be used after changing the formatting of text, to keep from accidentally changing the text again later with another formatting call.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer/miniConsole to stop having anything selected in. This is an optional argument, if name is not provided the main window will have its selection cleared. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further <br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</lua><br />
<br />
==fg==<br />
; fg(colorName)<br />
: If used on a selection, sets the foreground color to ''colorName'' - otherwise, it will set the color of the next text-inserting calls (''echo(), insertText, echoLink()'', and others)<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Examples<br />
<lua><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
</lua><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels.<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--this will get the size of your main mudlet window and save them <br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</lua><br />
<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.<br />
<br />
;Example<br />
<lua><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</lua><br />
<br />
= Table Functions =<br />
<br />
==table.complement==<br />
; table.complement (set1, set2)<br />
: Returns a table that is the relative complement of the first table with respect to the second table. Returns a complement of key/value pairs.<br />
<br />
; Parameters<br />
* ''table1:''<br />
* ''table2:''<br />
<br />
; Example:<br />
<lua></lua><br />
<br />
==table.concat==<br />
;table.concat(table, delimiter, startingindex, endingindex)<br />
: Joins a table into a string. Each item must be something which can be transformed into a string. <br />
: Returns the joined string.<br />
: See also: [[Manual:Lua_Functions#string.split|string.split]]<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table to concatenate into a string. Passed as a table.<br />
* '''delimiter:'''<br />
: Optional string to use to separate each element in the joined string. Passed as a string.<br />
* '''startingindex:'''<br />
: Optional parameter to specify which index to begin the joining at. Passed as an integer.<br />
* '''endingindex:'''<br />
: Optional parameter to specify the last index to join. Passed as an integer.<br />
<br />
;Examples<br />
<lua><br />
--This shows a basic concat with none of the optional arguments<br />
testTable = {1,2,"hi","blah",}<br />
testString = table.concat(testTable)<br />
--testString would be equal to "12hiblah"<br />
<br />
--This example shows the concat using the optional delimiter<br />
testString = table.concat(testTable, ", ")<br />
--testString would be equal to "1, 2, hi, blah"<br />
<br />
--This example shows the concat using the delimiter and the optional starting index<br />
testString = table.concat(testTable, ", ", 2)<br />
--testString would be equal to "2, hi, blah"<br />
<br />
--And finally, one which uses all of the arguments<br />
testString = table.concat(testTable, ", ", 2, 3)<br />
--testString would be equal to "2, hi"<br />
</lua><br />
<br />
==table.contains==<br />
; table.contains (t, value)<br />
: Determines if a table contains a value as a key or as a value (recursive).<br />
: Returns true or false<br />
<br />
; Parameters<br />
* '''t:''' <br />
: The table in which you are checking for the presence of the value.<br />
* '''value:''' <br />
: The value you are checking for within the table.<br />
<br />
; Example:<br />
<lua>local test_table = { "value1", "value2", "value3", "value4" }<br />
if table.contains(test_table, "value1") then <br />
echo("Got value 1!")<br />
else<br />
echo("Don't have it. Sorry!")<br />
end<br />
</lua><br />
This example would always echo the first one, unless you remove value1 from the table.<br />
<br />
==table.foreachi==<br />
==table.foreach==<br />
==table.getn==<br />
==table.intersection==<br />
==table.insert==<br />
; table.insert(table, [pos,] value)<br />
: Inserts element '''value''' at position '''pos''' in '''table''', shifting up other elements to open space, if necessary. The default '''value''' for '''pos''' is n+1, where n is the length of the table, so that a call table.insert(t,x) inserts x at the end of table t.<br />
: See also: [[Manual:Lua_Functions#table.remove|table.remove]]<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table in which you are inserting the value<br />
* '''pos:'''<br />
: Optional argument, determining where the value will be inserted. <br />
* '''value:'''<br />
: The variable that you are inserting into the table. Can be a regular variable, or even a table or function*. <br />
<table frame="box" width="100%"><br />
<caption>*Note</caption><br />
<tr><br />
<td><br />
Inserting a function into a table is not good coding practice, and will not turn out how you think it would.<br />
</td><br />
</tr><br />
</table><br />
==table.index_of==<br />
==table.is_empty==<br />
; table.is_empty(table)<br />
: Check if a table is devoid of any values.<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table you are checking for values.<br />
==table.load==<br />
; table.load(location, table)<br />
: Load a table from an external file into mudlet.<br />
: See also: [[Manual:Lua_Functions#table.save|table.save]]<br />
<br />
; Parameters:<br />
* '''location:'''<br />
: Where you are loading the table from. Can be anywhere on your computer.<br />
* '''table:'''<br />
: The table that you are loading.<br />
<br />
: Example:<br />
<lua><br />
-- This will load the table mytable from the lua file mytable present in your Mudlet Home Directory.<br />
table.load(getMudletHomeDir().."/mytable.lua", mytable)<br />
-- You can load a table from anywhere on your computer, but it's preferable to have them consolidated somewhere connected to Mudlet.<br />
</lua><br />
==table.maxn==<br />
==table.n_union==<br />
==table.n_complement==<br />
==table.n_intersection==<br />
==table.pickle==<br />
==table.remove==<br />
; table.remove(table, value_position)<br />
: Remove a value from an indexed table, by the values position in the table.<br />
: See also: [[Manual:Lua_Functions#table.insert|table.insert]]<br />
<br />
; Parameters:<br />
* '''table'''<br />
: The indexed table you are removing the value from.<br />
* '''value_position'''<br />
: The indexed number for the value you are removing.<br />
<br />
; Example:<br />
<lua><br />
testTable = { "hi", "bye", "cry", "why" }<br />
table.remove(testTable, 1) -- will remove hi from the table<br />
-- new testTable after the remove<br />
testTable = { "bye", "cry", "why" }<br />
-- original position of hi was 1, after the remove, position 1 has become bye<br />
-- any values under the removed value are moved up, 5 becomes 4, 4 becomes 3, etc<br />
</lua> <br />
<table frame="box" width="100%"><br />
<caption>Note</caption><br />
<tr><br />
<td><br />
To remove a value from a key-value table, it's best to simply change the value to nil.<br />
<lua><br />
testTable = { test = "testing", go = "boom", frown = "glow" }<br />
table.remove(testTable, test) -- this will error<br />
testTable.test = nil -- won't error<br />
testTable["test"] = nil -- won't error<br />
</lua><br />
</td><br />
</tr><br />
</table><br />
==table.save==<br />
; table.save(location, table)<br />
: Save a table into an external file in '''location'''.<br />
: See also: [[Manual:Lua_Functions#table.load|table.load]]<br />
<br />
; Parameters:<br />
* '''location:'''<br />
: Where you want the table file to be saved. Can be anywhere on your computer.<br />
* '''table:'''<br />
: The table that you are saving to the file.<br />
<br />
: Example:<br />
<lua><br />
-- Saves the table mytable to the lua file mytable in your Mudlet Home Directory<br />
table.save(getMudletHomeDir().."/mytable.lua", mytable)<br />
</lua><br />
==table.sort==<br />
==table.size==<br />
; table.size (t)<br />
: Gets the actual size of non-index based tables.<br />
: Returns a number.<br />
<br />
; Parameters<br />
* ''t:'' <br />
: The table you are checking the size of.<br />
<table width="100%" frame="box"><br />
<caption>'''Note:'''</caption><br />
<tr><br />
<td><br />
For index based tables you can get the size with the # operator:<br />
This is the standard Lua way of getting the size of index tables i.e. ipairs() type of tables with numerical indices. <br />
To get the size of tables that use user defined keys instead of automatic indices (pairs() type) you need to use the function table.size() referenced above.<br />
</td><br />
</tr><br />
</table><br />
; Example<br />
<lua><br />
local test_table = { "value1", "value2", "value3", "value4" }<br />
myTableSize = #test_table<br />
-- This would return 4.<br />
local myTable = { 1 = "hello", "key2" = "bye", "key3" = "time to go" }<br />
table.size(myTable)<br />
-- This would return 3.<br />
</lua><br />
==table.setn==<br />
==table.unpickle==<br />
==table.update==<br />
==table.union==<br />
<br />
= String Functions =<br />
==string.byte==<br />
<br />
==string.char==<br />
<br />
==string.cut==<br />
;string.cut(string, maxLen)<br />
: Cuts string to the specified maximum length.<br />
: Returns the modified string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The text you wish to cut. Passed as a string.<br />
* maxLen<br />
: The maximum length you wish the string to be. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--The following call will return 'abc' and store it in myString<br />
mystring = string.cut("abcde", 3)<br />
--You can easily pad string to certain length. Example below will print 'abcde ' e.g. pad/cut string to 10 characters.<br />
local s = "abcde"<br />
s = string.cut(s .. " ", 10) -- append 10 spaces<br />
echo("'" .. s .. "'")<br />
</lua><br />
<br />
==string.dump==<br />
<br />
==string.enclose==<br />
;string.enclose(String)<br />
: Wraps a string with [[ ]]<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String: The string to enclose. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will echo '[[Oh noes!]]' to the main window<br />
echo("'" .. string.enclose("Oh noes!") .. "'")<br />
</lua><br />
<br />
==string.ends==<br />
;string.ends(String, Suffix)<br />
: Test if string is ending with specified suffix.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#string.starts|string.starts]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string.<br />
* ''Suffix:''<br />
: The suffix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will test if the incoming line ends with "in bed" and if not will add it to the end.<br />
if not string.ends(line, "in bed") then<br />
echo("in bed\n")<br />
end<br />
</lua><br />
<br />
==string.find==<br />
<br />
==string.findPattern==<br />
; string.findPattern(text, pattern)<br />
: Return first matching substring or nil.<br />
<br />
; Parameters<br />
: text:<br />
: pattern:<br />
<br />
; Example:<br />
Following example will print: "I did find: Troll" string.<br />
<lua><br />
local match = string.findPattern("Troll is here!", "Troll")<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</lua><br />
This example will find substring regardless of case.<br />
<lua>local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</lua><br />
* Return value:<br />
: nil or first matching substring <br />
See also: [[Manual:Lua_Functions#string.genNocasePattern|string.genNocasePattern()]]<br />
<br />
==string.format==<br />
<br />
==string.genNocasePattern==<br />
string.genNocasePattern(s)<br />
<br />
Generate case insensitive search pattern from string.<br />
<br />
Parameters<br />
s:<br />
<br />
Usage:<br />
Following example will generate and print "123[aA][bB][cC]" string.<br />
echo(string.genNocasePattern("123abc"))<br />
<br />
Return value:<br />
case insensitive pattern string <br />
==string.gfind==<br />
<br />
==string.gmatch==<br />
<br />
==string.gsub==<br />
<br />
==string.len==<br />
<br />
==string.lower==<br />
<br />
==string.match==<br />
<br />
==string.rep==<br />
<br />
==string.reverse==<br />
<br />
<br />
==string.split==<br />
;string.split(String, delimiter)<br />
;<nowiki>myString:split(delimiter)</nowiki><br />
: Splits a string into a table by the given delimiter. Can be called against a string (or variable holding a string) using the second form above.<br />
: Returns a table containing the split sections of the string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to split. Parameter is not needed if using second form of the syntax above. Passed as a string.<br />
* ''delimiter:''<br />
: The delimiter to use when splitting the string. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
-- This will split the string by ", " delimiter and print the resulting table to the main window.<br />
names = "Alice, Bob, Peter"<br />
name_table = string.split(names, ", ")<br />
display(name_table)<br />
<br />
--The alternate method<br />
names = "Alice, Bob, Peter"<br />
name_table = names:split(", ")<br />
display(name_table)<br />
</lua><br />
<br />
Either method above will print out:<br />
table {<br />
1: 'Alice'<br />
2: 'Bob'<br />
3: 'Peter'<br />
}<br />
<br />
==string.starts==<br />
;string.starts(String, Prefix)<br />
: Test if string is starting with specified prefix.<br />
: Returns true or false<br />
: See also: [[Manual:Lua_Functions#string.ends|string.ends]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string. <br />
* ''Prefix:''<br />
: The prefix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--The following will see if the line begins with "You" and if so will print a statement at the end of the line<br />
if string.starts(line, "You") then<br />
echo("====oh you====\n")<br />
end<br />
</lua><br />
<br />
==string.sub==<br />
<br />
==string.title==<br />
;string.title(String)<br />
;<nowiki>string:title()</nowiki><br />
: Capitalizes the first character in a string.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String<br />
: The string to modify. Not needed if you use the second form of the syntax above.<br />
<br />
;Example<br />
<lua><br />
--Variable testname is now Anna.<br />
testname = string.title("anna")<br />
--Example will set test to "Bob".<br />
test = "bob"<br />
test = test:title()<br />
</lua><br />
<br />
==string.trim==<br />
;string.trim(String)<br />
: Trims String, removing all 'extra' white space at the beginning and end of the text.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to trim. Passed as a string.<br />
<br />
;Example:<br />
<lua><br />
--This will print 'Troll is here!', without the extra spaces.<br />
local str = string.trim(" Troll is here! ")<br />
echo("'" .. str .. "'")<br />
</lua><br />
<br />
==string.upper==<br />
<br />
= Mudlet Object Functions =<br />
==tempTimer==<br />
;tempTimer(time, code to do)<br />
Creates a temporary single shot timer and returns the timer ID for subsequent enableTimer(), disableTimer() and killTimer() calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed. <br />
<br />
;Parameters<br />
* ''time:'' the time in seconds for which to set the timer for<br />
* ''code to do'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
;Note<br />
[[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
==permGroup==<br />
permGroup(name, itemtype)<br />
<br />
Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts.<br />
<br />
<sub>Added to Mudlet in the 2.0 final release.</sub><br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<br />
<lua><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</lua><br />
<br />
<br />
==addAreaName==<br />
areaID = addAreaName(areaName)<br />
<br />
Adds a new area name and returns the new area ID for the new name. If the name already exists, -1 is returned.<br />
: See also: [[Manual:Lua_Functions#deleteArea|deleteArea]]<br />
<br />
<lua><br />
local newID = addAreaName("My house")<br />
<br />
if newID == -1 then echo("That area name is already taken :(\n")<br />
else echo("Created new area with the ID of "..newid..".\n") end<br />
</lua><br />
<br />
==addRoom==<br />
addRoom(roomID)<br />
<br />
Creates a new room with the given ID, returns true if the room was successfully created.<br />
: See also: [[Manual:Lua_Functions#createRoomID|createRoomID]]<br />
<br />
<lua><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</lua><br />
<br />
==addSpecialExit==<br />
addSpecialExit(roomIDFrom, roomIDTo, command)<br />
<br />
Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[Manual:Lua_Functions#clearSpecialExits|clearSpecialExits]]<br />
<br />
<lua><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- mmp.currentroom is your current room ID in this example<br />
addSpecialExit(mmp.currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(mmp.currentroom)<br />
</lua><br />
<br />
==centerview==<br />
centerview (roomID)<br />
<br />
Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
==clearRoomUserData==<br />
clearRoomUserData(roomID)<br />
<br />
Clears all user data from a given room.<br />
: See also: [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]]<br />
<br />
<lua><br />
clearRoomUserData(341)<br />
</lua><br />
<br />
==clearSpecialExits==<br />
clearSpecialExits(roomID) <br />
<br />
Removes all special exits from a room.<br />
: See also: [[Manual:Lua_Functions#addSpecialExit|addSpecialExit]]<br />
<br />
<lua><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will neve fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</lua><br />
<br />
==createMapLabel==<br />
labelID = createMapLabel(areaID, text, posx, posy, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue)<br />
<br />
Creates a visual label on the map for all z-levels at given coordinates, with the given background and foreground colors. It returns a label ID that you can use later for deleting it.<br />
<br />
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 [[Manual:Lua_Functions#getRoomCoordinates|getRoomCoordinates]] will place the label near that room.<br />
: See also: [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]]<br />
<lua><br />
local labelid = createMapLabel( 50, "my map label", 0, 0, 255,0,0,23,0,0)<br />
</lua><br />
<br />
==createMapper==<br />
createMapper(x, y, width, height)<br />
<br />
Creates a miniconsole window for mapper to render in, the with the given dimensions. You can only create one at a time at the moment.<br />
<br />
<lua><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper top-right of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</lua><br />
<br />
==createRoomID==<br />
usableId = createRoomID()<br />
<br />
Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs.<br />
: See also: [[Manual:Lua_Functions#addRoom|addRoom]]<br />
<br />
==deleteArea==<br />
deleteArea(areaID)<br />
<br />
Deletes the given area, permanently. This will also delete all rooms in it!<br />
: See also: [[Manual:Lua_Functions#addAreaName|addAreaName]]<br />
<br />
<lua><br />
deleteArea(23)<br />
</lua><br />
<br />
==deleteMapLabel==<br />
deleteMapLabel(areaID, labelID)<br />
<br />
Deletes a map label from a specfic area.<br />
: See also: [[Manual:Lua_Functions#createMapLabel|createMapLabel]]<br />
<lua><br />
deleteMapLabel(50, 1)<br />
</lua><br />
<br />
==deleteRoom==<br />
deleteRoom(roomID)<br />
<br />
Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
<lua><br />
deleteRoom(335)<br />
</lua><br />
<br />
==getAreaRooms==<br />
getAreaRooms(area id)<br />
<br />
Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
<sub>Note that on Mudlet versions prior to the 2.0 final release, this function would raise an error.</sub><br />
<br />
<lua><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in ipairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</lua><br />
<br />
==getAreaTable==<br />
getAreaTable()<br />
<br />
Returns a key(area name)-value(area id) table with all known areas and their IDs. There is an area with the name of '' and an ID of 0 included in it, you should ignore that.<br />
<br />
<lua><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id")<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</lua><br />
<br />
==getCustomEnvColorTable==<br />
envcolors = getCustomEnvColorTable()<br />
<br />
Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
<br />
<lua><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</lua><br />
<br />
==getMapLabels==<br />
arealabels = getMapLabels(areaID)<br />
<br />
Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]] it.<br />
<br />
<lua><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Svorai's grove'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Svorai's grove'<br />
}<br />
</lua><br />
<br />
==getPath==<br />
getPath(roomID from, roomID to)<br />
<br />
Returns a boolean true/false if a path between two room IDs is possible. If it is, the global `speedWalkPath` table is set to all of the directions that have to be taken to get there, and the global `speedWalkDir` table is set to all of the roomIDs you'll encounter on the way.<br />
<br />
<lua><br />
-- check if we can go to a room - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</lua><br />
<br />
==getRoomArea==<br />
areaID = getRoomArea(roomID)<br />
<br />
Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by getAreaTable() function, or use the getRoomAreaName function.<br />
<br />
<sub>Note that if the room ID does not exist, this function will raise an error</sub><br />
<br />
<lua><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</lua><br />
<br />
==getRoomAreaName==<br />
areaname = getRoomAreaName(areaID)<br />
<br />
Returns the area name for a given area id.<br />
<br />
<lua><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</lua><br />
<br />
==getRoomCoordinates==<br />
x,y,z = getRoomCoordinates(room ID)<br />
<br />
Returns the room coordinates of the given room ID.<br />
<br />
<lua><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</lua><br />
<br />
==getRoomEnv==<br />
envID = getRoomEnv(roomID)<br />
<br />
Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
<lua><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</lua><br />
<br />
== getRoomExits ==<br />
getRoomExits (roomID)<br />
Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid'', ie:<br />
<br />
<lua><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</lua><br />
<br />
==getRoomIDbyHash==<br />
roomID = getRoomIDbyHash(hash)<br />
<br />
Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
<lua><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
_id1 = getRoomIDbyHash( "5dfe55b0c8d769e865fd85ba63127fbc" );<br />
if _id1 == -1 then <br />
_id1 = createRoomID()<br />
setRoomIDbyHash( _id1, "5dfe55b0c8d769e865fd85ba63127fbc" )<br />
addRoom( _id )<br />
setRoomCoordinates( _id1, 0, 0, -1 )<br />
end<br />
</lua><br />
<br />
==getRoomName==<br />
roomName = getRoomName(roomID)<br />
<br />
Returns the room name for a given room id.<br />
<br />
<lua><br />
echo(string.format("The name of the room id #455 is %s.", getRoomname(455))<br />
</lua><br />
<br />
==getRooms==<br />
rooms = getRooms()<br />
<br />
Returns the list of '''all''' rooms in the map in an area in roomid - room name format.<br />
<br />
<lua><br />
-- simple, raw viewer for rooms in an area<br />
display(getRooms())<br />
</lua><br />
<br />
==getRoomsByPosition==<br />
getRoomsByPosition(areaID, x,y,z)<br />
<br />
Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
<lua><br />
-- sample script to determine a room nearby, given a relative direction from the current room<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</lua><br />
<br />
==getRoomUserData==<br />
data = getRoomUserData(roomID, key (as a string))<br />
<br />
Returns the user data stored at a given room with a given key, or "" if none is stored. Use [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]] for setting the user data.<br />
<br />
<lua><br />
display(getRoomUserData(341, "visitcount"))<br />
</lua><br />
<br />
==getRoomWeight==<br />
room weight = getRoomWeight(roomID)<br />
<br />
Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[Manual:Lua_Functions#setRoomWeight|setRoomWeight]]<br />
<br />
<lua><br />
display("Original weight of room 541: "..getRoomWeight(541)<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541)<br />
</lua><br />
<br />
==getSpecialExits==<br />
exits = getSpecialExits(roomID)<br />
<br />
Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
<lua><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</lua><br />
<br />
==getSpecialExitsSwap==<br />
exits = getSpecialExitsSwap(roomID)<br />
<br />
Very similar to [[Manual:Lua_Functions#getSpecialExits|getSpecialExits]], but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
gotoRoom (roomID)<br />
Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(". <br />
<br />
==hasExitLock==<br />
status = hasExitLock(roomID, direction)<br />
<br />
Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''direction'' right now is a number that corresponds to the direction:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples:<br />
<lua><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#lockExit|lockExit]]<br />
<br />
==highlightRoom==<br />
highlightRoom( id, r1,g1,b1,r2,g2,b2, radius, alpha1, alpha2)<br />
<br />
Highlights a room with the given color, which will override it's environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. ''highlightRadius'' is the radius for the highlight circle - if you don't want rooms beside each other to over lap, use ''1'' as the radius. ''alphaColor1'' and ''alphaColor2'' are transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[Manual:Lua_Functions#unHighlightRoom|unHighlightRoom]]<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
-- color some room red to blue<br />
highlightRoom(351, unpack(color_table.red), unpack(color_table.blue), 1, 255, 255)<br />
<br />
-- or use a name from showColors(), gold in this case<br />
highlightRoom(351, unpack(color_table.grey), unpack(color_table.grey), 1, 255, 255)<br />
</lua><br />
<br />
==lockExit==<br />
lockExit(roomID, direction, lock = true/false)<br />
<br />
Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction at the moment is only set as a number, and here's a listing of them:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples<br />
<lua><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#hasExitLock|hasExitLock]]<br />
<br />
==lockRoom==<br />
lockRoom (roomID, lock = true/false)<br />
<br />
Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[Manual:Lua_Functions#roomLocked|roomLocked]]<br />
<br />
<lua><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</lua><br />
<br />
==roomExists==<br />
roomExists(roomID)<br />
<br />
Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
locked = roomLocked(roomID)<br />
<br />
Returns true or false whenever a given room is locked.<br />
: See also: [[Manual:Lua_Functions#lockRoom|lockRoom]]<br />
<br />
<lua><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</lua><br />
<br />
==saveMap==<br />
saveMap(location)<br />
<br />
Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work.<br />
<br />
<lua><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
</lua><br />
<br />
==searchRoom== <br />
searchRoom (room name)<br />
<br />
Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname'', like so:<br />
<br />
<lua><br />
display(searchRoom("master"))<br />
<br />
--[[ would result in:<br />
table {<br />
17463: 'in the branches of the Master Ravenwood'<br />
3652: 'master bedroom'<br />
10361: 'Hall of Cultural Masterpieces'<br />
6324: 'Exhibit of the Techniques of the Master Artisans'<br />
5340: 'office of the Guildmaster'<br />
(...)<br />
2004: 'office of the guildmaster'<br />
14457: 'the Master Gear'<br />
1337: 'before the Master Ravenwood Tree'<br />
}<br />
]]</lua><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
==setAreaName==<br />
setAreaName(areaID, newName)<br />
<br />
Renames an existing area to the new name.<br />
<br />
<lua><br />
setAreaName(2, "My city")<br />
</lua><br />
<br />
==setCustomEnvColor==<br />
setCustomEnvColor(environmentID, r,g,b)<br />
<br />
Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
<br />
<lua><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
setCustomEnvColor(200, unpack(color_table.blue)) -- set the color of environmentID 200 to blue<br />
</lua><br />
<br />
==setExit==<br />
setExit(from roomID, to roomID, direction)<br />
<br />
Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', or a number which represents a direction.<br />
<br />
Returns ''false'' if the exit creation didn't work.<br />
<br />
<lua><br />
-- alias pattern: ^exit (\d+) (\w+)$<br />
<br />
if setExit(mmp.currentroom, tonumber(matches[2]),matches[3]) then<br />
echo("\nExit set to room:"..matches[2]..", Direction:"..string.upper(matches[3]))<br />
centerview(mmp.currentroom)<br />
else<br />
mmp.echo("Failed to set the exit.") end<br />
</lua><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
setExit(from roomID, -1, direction)<br />
<br />
Which will delete an outgoing exit in the specified direction from a room.<br />
<br />
<lua><br />
-- locate the room on the other end, so we can unlink it from there as well if necessary<br />
local otherroom<br />
if getRoomExits(getRoomExits(mmp.currentroom)[dir])[mmp.ranytolong(dir)] then<br />
otherroom = getRoomExits(mmp.currentroom)[dir]<br />
end<br />
<br />
if setExit(mmp.currentroom, -1, dir) then<br />
if otherroom then<br />
if setExit(otherroom, -1, mmp.ranytolong(dir)) then<br />
mmp.echo(string.format("Deleted the %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
else mmp.echo("Couldn't delete the incoming exit.") end<br />
else<br />
mmp.echo(string.format("Deleted the one-way %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
end<br />
else<br />
mmp.echo("Couldn't delete the outgoing exit.")<br />
end<br />
</lua><br />
<br />
You can use these numbers for setting the directions as well:<br />
<lua><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}</lua><br />
<br />
==setGridMode==<br />
setGridMode(area, true/false)<br />
<br />
Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode.<br />
<br />
<lua><br />
setGridMode(55,true) -- set area with ID 55 to be in grid mode<br />
</lua><br />
<br />
==setRoomArea==<br />
setRoomArea(roomID, newAreaID)<br />
<br />
Assigns the given room to a new area. This will have the room be visually moved into the area as well.<br />
<br />
==setRoomChar==<br />
setRoomChar(roomID, character)<br />
<br />
Designed for an area in grid mode, this will set a single character to be on a room. You can use "_" to clear it.<br />
<br />
<lua><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123. "$")<br />
</lua><br />
<br />
==setRoomCoordinates==<br />
setRoomCoordinates(roomID, x, y, z)<br />
<br />
Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
0,0,0 is the center of the map.<br />
<br />
<lua><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
You can make them relative as well:<br />
<br />
<lua><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
==setRoomEnv==<br />
setRoomEnv(roomID, newEnvID)<br />
<br />
Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
<br />
<lua><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</lua><br />
<br />
==setRoomIDbyHash==<br />
setRoomIDbyHash(roomID, hash)<br />
<br />
Sets the hash to be associated with the given roomID. See also [[Manual:Lua_Functions#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
setRoomName(roomID, newName)<br />
<br />
Renames an existing room to a new name.<br />
<br />
<lua><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</lua><br />
<br />
==setRoomUserData==<br />
setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
Returns true if successfully set.<br />
: See also: [[Manual:Lua_Functions#clearRoomUserData|clearRoomUserData]]<br />
<br />
<lua><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</lua><br />
<br />
==setRoomWeight==<br />
setRoomWeight(roomID, weight)<br />
<br />
Sets a weight to the given roomID. By default, all rooms have a weight of 0 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
To completely avoid a room, make use of [[Manual:Lua_Functions#lockRoom|lockRoom()]].<br />
<br />
: See also: [[Manual:Lua_Functions#getRoomWeight|getRoomWeight]]<br />
<br />
<lua><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</lua><br />
<br />
==unHighlightRoom==<br />
unHighlightRoom(roomID)<br />
<br />
Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[Manual:Lua_Functions#highlightRoom|highlightRoom]]<br />
<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
unHighlightRoom(4534)<br />
</lua><br />
<br />
= Miscellaneous Functions =<br />
==expandAlias==<br />
; expandAlias(command,true/false)<br />
<br />
: 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.<br />
<br />
<lua><br />
expandAlias("t rat")<br />
<br />
expandAlias("t rat", false)<br />
</lua><br />
<br />
: 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.<br />
<br />
==spawn==<br />
;t = spawn(read function, process to spawn)<br />
<br />
: 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()''.<br />
<br />
<lua><br />
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function<br />
local f = spawn(display, "ls")<br />
display(f.isRunning())<br />
f.close()<br />
</lua><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Scripting#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Scripting#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
: <sub>Requires Mudlet 2.0+</sub><br />
<br />
;Example<br />
<lua><br />
-- this example will check the Imperian homepage to see how many players are on right now<br />
<br />
-- in an alias, download the Imperian homepage for stats processing<br />
downloadFile(getMudletHomeDir().."/page.html", "http://www.imperian.com/")<br />
<br />
<br />
-- then create a new script with the name of downloaded_file, add the event handler<br />
-- for sysDownloadDone, and use this to parse the webpage and display the amount<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:match("page", 1, true) then return end<br />
<br />
-- parse our ownloaded file for the player count<br />
io.input(filename)<br />
local s = io.read("*all")<br />
local pc = s:match([[<a href='players.php%?search=who'>(%d+)</a>]])<br />
display("Imperian has "..tostring(pc).." players on right now.")<br />
io.open():close()<br />
os.remove(filename)<br />
end<br />
</lua><br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
<br />
: See Also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
<br />
;Example<br />
<lua><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "vision"}]])<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "woodlore", "name": "hide"}]])<br />
</lua><br />
<br />
==sendIrc==<br />
;sendIrc(channel, message)<br />
: Sends a message to an IRC channel or person. You must have the IRC window open, and if speaking to a channel, be joined in that channel. IRC currently only works on the freenode network and password-protected channels aren't supported.<br />
<br />
;Parameters:<br />
* ''channel:''<br />
: The channel to send the message to. Can be #<channelname> to send to a channel, or <person name> to send to a person. Passed as a string.<br />
* ''message:''<br />
: The message to send. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
--This would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
</lua><br />
<br />
==showColors==<br />
;showColors(columns)<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in color_table, in table form. The format is color_table.colorName = {r,g,b}<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#cecho|cecho]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: Number of columns to print the color table in. Passed as an integer number.<br />
<br />
;Example:<br />
<lua><br />
showColors(4)<br />
</lua><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)]]<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Lua_Functions&diff=730Manual:Lua Functions2011-07-30T23:08:35Z<p>Rayth: /* Table Functions */</p>
<hr />
<div>== Function Categories ==<br />
'''Standard Functions''': These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
'''UI Functions''': These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation.<br />
<lua><br />
createMiniConsole()<br />
createLabel()<br />
createGauge()<br />
</lua><br />
<br />
'''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.<br />
<br />
'''String Functions'''<br />
<br />
'''Scripting Object Functions'''<br />
<br />
'''Mapper Functions'''<br />
<br />
'''Miscellaneous Functions'''<br />
<br />
== Variables ==<br />
The following variables are provided by Mudlet:<br />
<br><br><br />
;line <br />
:This variable holds the content of the current line that is being processed by the trigger engine. The engine runs all triggers on each line as it arrives from the MUD.<br />
;command <br />
:This variable holds the current user command. This is typically used in alias scripts.<br />
;matches[n]<br />
:This Lua table is being used by Mudlet in the context of triggers that use Perl regular expressions. matches[1] holds the entire match, matches[2] holds the first capture group, matches[n] holds the nth-1 capture group. If the trigger uses the Perl style /g switch to evaluate all possible matches of the given regex within the current line, matches[n+1] will hold the second entire match, matches[n+2] the first capture group of the second match and matches[n+m] the m-th capture group of the second match.<br />
;multimatches[n][m]<br />
:This table is being used by Mudlet in the context of multiline triggers that use Perl regular expression. It holds the table matches[n] as described above for each Perl regular expression based condition of the multiline trigger. multimatches[5][4] may hold the 3rd capture group of the 5th regex in the multiline trigger. This way you can examine and process all relevant data within a single script. Have a look at this example.<br />
= Standard Functions =<br />
: These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
==send==<br />
;send( command, echo the value = true/false )<br />
:This sends "command" directly to the network layer, skipping the alias matching. The optional second argument of type boolean (print) determines if the outgoing command is to be echoed on the screen.<br />
:If you want your command to be checked if it’s an alias, use expandAlias() instead. example:<br />
<lua><br />
send( "Hello Jane" ) --echos the command on the screen<br />
send( "Hello Jane", true ) --echos the command on the screen<br />
send( "Hello Jane", false ) --does not echo the command on the screen<br />
</lua><br />
==echo==<br />
;echo( windowName, text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])<br />
:Echos a piece of text as a clickable link.<br />
:text - text to display in the echo. Same as a normal echo().<br />
:command - lua code to do when the link is clicked.<br />
:hint - text for the tooltip to be displayed when the mouse is over the link.<br />
:boolean - if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.<br />
<br />
= UI Functions =<br />
<br />
<br />
==echo==<br />
;echo( [windowName,] text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name. <br />
: See also: [[Manual:Lua_Functions#paste|paste]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</lua><br />
<br />
==bg==<br />
;bg(colorName)<br />
: Changes the background color of the text. Useful for highlighting text. <br />
: See Also: [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<lua><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
</lua><br />
<br />
==calcFontSize==<br />
;calcFontSize(fontSize)<br />
: Used to calculate the number of pixels wide and high a character would be on a mini console at fontSize.<br />
: Returns two numbers, width/height<br />
: See Also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]]<br />
<br />
;Parameters<br />
* ''fontSize:''<br />
: The font size you are wanting to calculate pixel sizes for. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide <br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</lua><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: Clears the window or miniconsole with the name given as argument.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearUserWindow("Chat")<br />
</lua><br />
<br />
==clearWindow==<br />
;clearWindow(name)<br />
: Clears the window or miniconsole with the name given as argument. <br />
: See also: [[Manual:Lua_Functions#clearUserWindow|clearUserWindow]]<br />
<br />
;Parameters<br />
* name: <br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</lua><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: Creates a named buffer for formatted text, much like a miniconsole, but the buffer cannot be shown on the screen. Intended for temporary use in the formatting of text.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
Examples<br />
<lua><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</lua><br />
<br />
==createConsole==<br />
;createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: Makes a new miniconsole. The background will be black, and the text color white.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide, <br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</lua><br />
<br />
==createGauge==<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, r, g, b)<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, colorName)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge]], [[Manual:Lua_Functions#setGauge|setGauge]], [[Manual:Lua_Functions#setGaugeText|setGaugeText]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</lua><br />
<br />
==createLabel==<br />
;createLabel(name, Xpos, Ypos, width, height, fillBackground)<br />
: Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|setTextFormat]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.<br />
<br />
Examples<br />
<lua><br />
--This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle <br />
--of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent <br />
--and 255 non-transparent) the background text can still be read through. The message box will disappear after 2.3 seconds.<br />
local width, height = getMainWindowSize();<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1);<br />
resizeWindow("messageBox",500,70);<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 );<br />
setBackgroundColor("messageBox", 150,100,100,200);<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]] );<br />
showWindow("messageBox");<br />
tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</lua><br />
<br />
==createMiniConsole==<br />
;createMiniConsole(name, posX, posY, width, height)<br />
: Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc. <br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel]], [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|moveWindow]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent]], [[Manual:Lua_Functions#setBorderTop|setBorderTop]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique, you can not have two or more miniconsoles with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the miniconsole, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the miniconsole, in pixels. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
--This script would create a mini text console called "sys" and write with yellow foreground color and blue background color <br />
--"Hello World".<br />
<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
WindowWidth = 0;<br />
WindowHeight = 0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line<br />
setWindowWrap("sys", 40)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
<br />
echo("sys","Hello world!")<br />
</lua><br />
<br />
==deleteLine==<br />
;deleteLine()<br />
: Deletes the current line under the user cursor. This is a high speed gagging tool and is very good at this task, but is only meant to be use when a line should be omitted entirely in the output. If you echo() to that line it will not be shown, and lines deleted with deleteLine() are simply no longer rendered. For replacing text, replace() is the proper option.<br />
: See Also: [[Manual:Lua_Functions#replace|replace]], [[Manual:Lua_Functions#wrapLine|wrapLine]]<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
</lua><br />
<br />
==deselect==<br />
;deselect(name)<br />
: This is used to clear the current selection (to no longer have anything selected). Should be used after changing the formatting of text, to keep from accidentally changing the text again later with another formatting call.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer/miniConsole to stop having anything selected in. This is an optional argument, if name is not provided the main window will have its selection cleared. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further <br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</lua><br />
<br />
==fg==<br />
; fg(colorName)<br />
: If used on a selection, sets the foreground color to ''colorName'' - otherwise, it will set the color of the next text-inserting calls (''echo(), insertText, echoLink()'', and others)<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Examples<br />
<lua><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
</lua><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels.<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--this will get the size of your main mudlet window and save them <br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</lua><br />
<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.<br />
<br />
;Example<br />
<lua><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</lua><br />
<br />
= Table Functions =<br />
<br />
==table.complement==<br />
; table.complement (set1, set2)<br />
: Returns a table that is the relative complement of the first table with respect to the second table. Returns a complement of key/value pairs.<br />
<br />
; Parameters<br />
* ''table1:''<br />
* ''table2:''<br />
<br />
; Example:<br />
<lua></lua><br />
<br />
==table.concat==<br />
;table.concat(table, delimiter, startingindex, endingindex)<br />
: Joins a table into a string. Each item must be something which can be transformed into a string. <br />
: Returns the joined string.<br />
: See also: [[Manual:Lua_Functions#string.split|string.split]]<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table to concatenate into a string. Passed as a table.<br />
* '''delimiter:'''<br />
: Optional string to use to separate each element in the joined string. Passed as a string.<br />
* '''startingindex:'''<br />
: Optional parameter to specify which index to begin the joining at. Passed as an integer.<br />
* '''endingindex:'''<br />
: Optional parameter to specify the last index to join. Passed as an integer.<br />
<br />
;Examples<br />
<lua><br />
--This shows a basic concat with none of the optional arguments<br />
testTable = {1,2,"hi","blah",}<br />
testString = table.concat(testTable)<br />
--testString would be equal to "12hiblah"<br />
<br />
--This example shows the concat using the optional delimiter<br />
testString = table.concat(testTable, ", ")<br />
--testString would be equal to "1, 2, hi, blah"<br />
<br />
--This example shows the concat using the delimiter and the optional starting index<br />
testString = table.concat(testTable, ", ", 2)<br />
--testString would be equal to "2, hi, blah"<br />
<br />
--And finally, one which uses all of the arguments<br />
testString = table.concat(testTable, ", ", 2, 3)<br />
--testString would be equal to "2, hi"<br />
</lua><br />
<br />
==table.contains==<br />
; table.contains (t, value)<br />
: Determines if a table contains a value as a key or as a value (recursive).<br />
: Returns true or false<br />
<br />
; Parameters<br />
* '''t:''' <br />
: The table in which you are checking for the presence of the value.<br />
* '''value:''' <br />
: The value you are checking for within the table.<br />
<br />
; Example:<br />
<lua>local test_table = { "value1", "value2", "value3", "value4" }<br />
if table.contains(test_table, "value1") then <br />
echo("Got value 1!")<br />
else<br />
echo("Don't have it. Sorry!")<br />
end<br />
</lua><br />
This example would always echo the first one, unless you remove value1 from the table.<br />
<br />
==table.foreachi==<br />
==table.foreach==<br />
==table.getn==<br />
==table.intersection==<br />
==table.insert==<br />
; table.insert(table, [pos,] value)<br />
: Inserts element '''value''' at position '''pos''' in '''table''', shifting up other elements to open space, if necessary. The default '''value''' for '''pos''' is n+1, where n is the length of the table, so that a call table.insert(t,x) inserts x at the end of table t.<br />
: See also: [[Manual:Lua_Functions#table.remove|table.remove]]<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table in which you are inserting the value<br />
* '''pos:'''<br />
: Optional argument, determining where the value will be inserted. <br />
* '''value:'''<br />
: The variable that you are inserting into the table. Can be a regular variable, or even a table or function*. <br />
<table frame="box" width="100%"><br />
<caption>*Note</caption><br />
<tr><br />
<td><br />
Inserting a function into a table is not good coding practice, and will not turn out how you think it would.<br />
</td><br />
</tr><br />
</table><br />
==table.index_of==<br />
==table.is_empty==<br />
; table.is_empty(table)<br />
: Check if a table is devoid of any values.<br />
<br />
; Parameters<br />
* '''table:'''<br />
: The table you are checking for values.<br />
==table.load==<br />
; table.load(location, table)<br />
: Load a table from an external file into mudlet.<br />
: See also: [[Manual:Lua_Functions#table.save|table.save]]<br />
<br />
; Parameters:<br />
* '''location:'''<br />
: Where you are loading the table from. Can be anywhere on your computer.<br />
* '''table:'''<br />
: The table that you are loading.<br />
<br />
: Example:<br />
<lua><br />
-- This will load the table mytable from the lua file mytable present in your Mudlet Home Directory.<br />
table.load(getMudletHomeDir().."/mytable.lua", mytable)<br />
-- You can load a table from anywhere on your computer, but it's preferable to have them consolidated somewhere connected to Mudlet.<br />
</lua><br />
==table.maxn==<br />
==table.n_union==<br />
==table.n_complement==<br />
==table.n_intersection==<br />
==table.pickle==<br />
==table.remove==<br />
; table.remove(table, value_position)<br />
: Remove a value from an indexed table, by the values position in the table.<br />
: See also: [[Manual:Lua_Functions#table.insert|table.insert]]<br />
<br />
; Parameters:<br />
* '''table'''<br />
: The indexed table you are removing the value from.<br />
* '''value_position'''<br />
: The indexed number for the value you are removing.<br />
<br />
; Example:<br />
<lua><br />
testTable = { "hi", "bye", "cry", "why" }<br />
table.remove(testTable, 1) -- will remove hi from the table<br />
-- new testTable after the remove<br />
testTable = { "bye", "cry", "why" }<br />
-- original position of hi was 1, after the remove, position 1 has become bye<br />
-- any values under the removed value are moved up, 5 becomes 4, 4 becomes 3, etc<br />
</lua> <br />
<table frame="box" width="100%"><br />
<caption>Note</caption><br />
<tr><br />
<td><br />
To remove a value from a key-value table, it's best to simply change the value to nil.<br />
<lua><br />
testTable = { test = "testing", go = "boom", frown = "glow" }<br />
table.remove(testTable, test) -- this will error<br />
testTable.test = nil -- won't error<br />
testTable["test"] = nil -- won't error<br />
</lua><br />
</td><br />
</tr><br />
</table><br />
==table.save==<br />
; table.save(location, table)<br />
: Save a table into an external file in '''location'''.<br />
: See also: [[Manual:Lua_Functions#table.load|table.load]]<br />
<br />
; Parameters:<br />
* '''location:'''<br />
: Where you want the table file to be saved. Can be anywhere on your computer.<br />
* '''table:'''<br />
: The table that you are saving to the file.<br />
<br />
: Example:<br />
<lua><br />
-- Saves the table mytable to the lua file mytable in your Mudlet Home Directory<br />
table.save(getMudletHomeDir().."/mytable.lua", mytable)<br />
</lua><br />
==table.sort==<br />
==table.size==<br />
; table.size (t)<br />
: Gets the actual size of non-index based tables.<br />
: Returns a number.<br />
<br />
; Parameters<br />
* ''t:'' <br />
: The table you are checking the size of.<br />
<table width="100%" frame="box"><br />
<caption>'''Note:'''</caption><br />
<tr><br />
<td><br />
For index based tables you can get the size with the # operator:<br />
This is the standard Lua way of getting the size of index tables i.e. ipairs() type of tables with numerical indices. <br />
To get the size of tables that use user defined keys instead of automatic indices (pairs() type) you need to use the function table.size() referenced above.<br />
</td><br />
</tr><br />
</table><br />
; Example<br />
<lua><br />
local test_table = { "value1", "value2", "value3", "value4" }<br />
myTableSize = #test_table<br />
-- This would return 4.<br />
local myTable = { 1 = "hello", "key2" = "bye", "key3" = "time to go" }<br />
table.size(myTable)<br />
-- This would return 3.<br />
</lua><br />
==table.setn==<br />
==table.unpickle==<br />
==table.update==<br />
==table.union==<br />
<br />
= String Functions =<br />
==string.byte==<br />
<br />
==string.char==<br />
<br />
==string.cut==<br />
;string.cut(string, maxLen)<br />
: Cuts string to the specified maximum length.<br />
: Returns the modified string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The text you wish to cut. Passed as a string.<br />
* maxLen<br />
: The maximum length you wish the string to be. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--The following call will return 'abc' and store it in myString<br />
mystring = string.cut("abcde", 3)<br />
--You can easily pad string to certain length. Example below will print 'abcde ' e.g. pad/cut string to 10 characters.<br />
local s = "abcde"<br />
s = string.cut(s .. " ", 10) -- append 10 spaces<br />
echo("'" .. s .. "'")<br />
</lua><br />
<br />
==string.dump==<br />
<br />
==string.enclose==<br />
;string.enclose(String)<br />
: Wraps a string with [[ ]]<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String: The string to enclose. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will echo '[[Oh noes!]]' to the main window<br />
echo("'" .. string.enclose("Oh noes!") .. "'")<br />
</lua><br />
<br />
==string.ends==<br />
;string.ends(String, Suffix)<br />
: Test if string is ending with specified suffix.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#string.starts|string.starts]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string.<br />
* ''Suffix:''<br />
: The suffix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will test if the incoming line ends with "in bed" and if not will add it to the end.<br />
if not string.ends(line, "in bed") then<br />
echo("in bed\n")<br />
end<br />
</lua><br />
<br />
==string.find==<br />
<br />
==string.findPattern==<br />
string.findPattern(text, pattern)<br />
Return first matching substring or nil.<br />
<br />
Parameters<br />
text:<br />
pattern:<br />
<br />
Usage:<br />
Following example will print: "I did find: Troll" string.<br />
<lua><br />
local match = string.findPattern("Troll is here!", "Troll")<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</lua><br />
This example will find substring regardless of case.<br />
local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
<br />
Return value:<br />
nil or first matching substring <br />
<br />
See also:<br />
[[Manual:Lua_Functions#string.genNocasePattern|string.genNocasePattern()]]<br />
<br />
==string.format==<br />
<br />
==string.genNocasePattern==<br />
string.genNocasePattern(s)<br />
<br />
Generate case insensitive search pattern from string.<br />
<br />
Parameters<br />
s:<br />
<br />
Usage:<br />
Following example will generate and print "123[aA][bB][cC]" string.<br />
echo(string.genNocasePattern("123abc"))<br />
<br />
Return value:<br />
case insensitive pattern string <br />
==string.gfind==<br />
<br />
==string.gmatch==<br />
<br />
==string.gsub==<br />
<br />
==string.len==<br />
<br />
==string.lower==<br />
<br />
==string.match==<br />
<br />
==string.rep==<br />
<br />
==string.reverse==<br />
<br />
<br />
==string.split==<br />
;string.split(String, delimiter)<br />
;<nowiki>myString:split(delimiter)</nowiki><br />
: Splits a string into a table by the given delimiter. Can be called against a string (or variable holding a string) using the second form above.<br />
: Returns a table containing the split sections of the string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to split. Parameter is not needed if using second form of the syntax above. Passed as a string.<br />
* ''delimiter:''<br />
: The delimiter to use when splitting the string. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
-- This will split the string by ", " delimiter and print the resulting table to the main window.<br />
names = "Alice, Bob, Peter"<br />
name_table = string.split(names, ", ")<br />
display(name_table)<br />
<br />
--The alternate method<br />
names = "Alice, Bob, Peter"<br />
name_table = names:split(", ")<br />
display(name_table)<br />
</lua><br />
<br />
Either method above will print out:<br />
table {<br />
1: 'Alice'<br />
2: 'Bob'<br />
3: 'Peter'<br />
}<br />
<br />
==string.starts==<br />
;string.starts(String, Prefix)<br />
: Test if string is starting with specified prefix.<br />
: Returns true or false<br />
: See also: [[Manual:Lua_Functions#string.ends|string.ends]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string. <br />
* ''Prefix:''<br />
: The prefix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--The following will see if the line begins with "You" and if so will print a statement at the end of the line<br />
if string.starts(line, "You") then<br />
echo("====oh you====\n")<br />
end<br />
</lua><br />
<br />
==string.sub==<br />
<br />
==string.title==<br />
;string.title(String)<br />
;<nowiki>string:title()</nowiki><br />
: Capitalizes the first character in a string.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String<br />
: The string to modify. Not needed if you use the second form of the syntax above.<br />
<br />
;Example<br />
<lua><br />
--Variable testname is now Anna.<br />
testname = string.title("anna")<br />
--Example will set test to "Bob".<br />
test = "bob"<br />
test = test:title()<br />
</lua><br />
<br />
==string.trim==<br />
;string.trim(String)<br />
: Trims String, removing all 'extra' white space at the beginning and end of the text.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to trim. Passed as a string.<br />
<br />
;Example:<br />
<lua><br />
--This will print 'Troll is here!', without the extra spaces.<br />
local str = string.trim(" Troll is here! ")<br />
echo("'" .. str .. "'")<br />
</lua><br />
<br />
==string.upper==<br />
<br />
= Mudlet Object Functions =<br />
==tempTimer==<br />
;tempTimer(time, code to do)<br />
Creates a temporary single shot timer and returns the timer ID for subsequent enableTimer(), disableTimer() and killTimer() calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed. <br />
<br />
;Parameters<br />
* ''time:'' the time in seconds for which to set the timer for<br />
* ''code to do'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
;Note<br />
[[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
==permGroup==<br />
permGroup(name, itemtype)<br />
<br />
Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts.<br />
<br />
<sub>Added to Mudlet in the 2.0 final release.</sub><br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<br />
<lua><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</lua><br />
<br />
<br />
==addAreaName==<br />
areaID = addAreaName(areaName)<br />
<br />
Adds a new area name and returns the new area ID for the new name. If the name already exists, -1 is returned.<br />
: See also: [[Manual:Lua_Functions#deleteArea|deleteArea]]<br />
<br />
<lua><br />
local newID = addAreaName("My house")<br />
<br />
if newID == -1 then echo("That area name is already taken :(\n")<br />
else echo("Created new area with the ID of "..newid..".\n") end<br />
</lua><br />
<br />
==addRoom==<br />
addRoom(roomID)<br />
<br />
Creates a new room with the given ID, returns true if the room was successfully created.<br />
: See also: [[Manual:Lua_Functions#createRoomID|createRoomID]]<br />
<br />
<lua><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</lua><br />
<br />
==addSpecialExit==<br />
addSpecialExit(roomIDFrom, roomIDTo, command)<br />
<br />
Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[Manual:Lua_Functions#clearSpecialExits|clearSpecialExits]]<br />
<br />
<lua><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- mmp.currentroom is your current room ID in this example<br />
addSpecialExit(mmp.currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(mmp.currentroom)<br />
</lua><br />
<br />
==centerview==<br />
centerview (roomID)<br />
<br />
Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
==clearRoomUserData==<br />
clearRoomUserData(roomID)<br />
<br />
Clears all user data from a given room.<br />
: See also: [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]]<br />
<br />
<lua><br />
clearRoomUserData(341)<br />
</lua><br />
<br />
==clearSpecialExits==<br />
clearSpecialExits(roomID) <br />
<br />
Removes all special exits from a room.<br />
: See also: [[Manual:Lua_Functions#addSpecialExit|addSpecialExit]]<br />
<br />
<lua><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will neve fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</lua><br />
<br />
==createMapLabel==<br />
labelID = createMapLabel(areaID, text, posx, posy, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue)<br />
<br />
Creates a visual label on the map for all z-levels at given coordinates, with the given background and foreground colors. It returns a label ID that you can use later for deleting it.<br />
<br />
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 [[Manual:Lua_Functions#getRoomCoordinates|getRoomCoordinates]] will place the label near that room.<br />
: See also: [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]]<br />
<lua><br />
local labelid = createMapLabel( 50, "my map label", 0, 0, 255,0,0,23,0,0)<br />
</lua><br />
<br />
==createMapper==<br />
createMapper(x, y, width, height)<br />
<br />
Creates a miniconsole window for mapper to render in, the with the given dimensions. You can only create one at a time at the moment.<br />
<br />
<lua><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper top-right of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</lua><br />
<br />
==createRoomID==<br />
usableId = createRoomID()<br />
<br />
Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs.<br />
: See also: [[Manual:Lua_Functions#addRoom|addRoom]]<br />
<br />
==deleteArea==<br />
deleteArea(areaID)<br />
<br />
Deletes the given area, permanently. This will also delete all rooms in it!<br />
: See also: [[Manual:Lua_Functions#addAreaName|addAreaName]]<br />
<br />
<lua><br />
deleteArea(23)<br />
</lua><br />
<br />
==deleteMapLabel==<br />
deleteMapLabel(areaID, labelID)<br />
<br />
Deletes a map label from a specfic area.<br />
: See also: [[Manual:Lua_Functions#createMapLabel|createMapLabel]]<br />
<lua><br />
deleteMapLabel(50, 1)<br />
</lua><br />
<br />
==deleteRoom==<br />
deleteRoom(roomID)<br />
<br />
Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
<lua><br />
deleteRoom(335)<br />
</lua><br />
<br />
==getAreaRooms==<br />
getAreaRooms(area id)<br />
<br />
Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
<sub>Note that on Mudlet versions prior to the 2.0 final release, this function would raise an error.</sub><br />
<br />
<lua><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in ipairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</lua><br />
<br />
==getAreaTable==<br />
getAreaTable()<br />
<br />
Returns a key(area name)-value(area id) table with all known areas and their IDs. There is an area with the name of '' and an ID of 0 included in it, you should ignore that.<br />
<br />
<lua><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id")<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</lua><br />
<br />
==getCustomEnvColorTable==<br />
envcolors = getCustomEnvColorTable()<br />
<br />
Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
<br />
<lua><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</lua><br />
<br />
==getMapLabels==<br />
arealabels = getMapLabels(areaID)<br />
<br />
Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]] it.<br />
<br />
<lua><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Svorai's grove'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Svorai's grove'<br />
}<br />
</lua><br />
<br />
==getPath==<br />
getPath(roomID from, roomID to)<br />
<br />
Returns a boolean true/false if a path between two room IDs is possible. If it is, the global `speedWalkPath` table is set to all of the directions that have to be taken to get there, and the global `speedWalkDir` table is set to all of the roomIDs you'll encounter on the way.<br />
<br />
<lua><br />
-- check if we can go to a room - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</lua><br />
<br />
==getRoomArea==<br />
areaID = getRoomArea(roomID)<br />
<br />
Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by getAreaTable() function, or use the getRoomAreaName function.<br />
<br />
<sub>Note that if the room ID does not exist, this function will raise an error</sub><br />
<br />
<lua><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</lua><br />
<br />
==getRoomAreaName==<br />
areaname = getRoomAreaName(areaID)<br />
<br />
Returns the area name for a given area id.<br />
<br />
<lua><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</lua><br />
<br />
==getRoomCoordinates==<br />
x,y,z = getRoomCoordinates(room ID)<br />
<br />
Returns the room coordinates of the given room ID.<br />
<br />
<lua><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</lua><br />
<br />
==getRoomEnv==<br />
envID = getRoomEnv(roomID)<br />
<br />
Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
<lua><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</lua><br />
<br />
== getRoomExits ==<br />
getRoomExits (roomID)<br />
Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid'', ie:<br />
<br />
<lua><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</lua><br />
<br />
==getRoomIDbyHash==<br />
roomID = getRoomIDbyHash(hash)<br />
<br />
Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
<lua><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
_id1 = getRoomIDbyHash( "5dfe55b0c8d769e865fd85ba63127fbc" );<br />
if _id1 == -1 then <br />
_id1 = createRoomID()<br />
setRoomIDbyHash( _id1, "5dfe55b0c8d769e865fd85ba63127fbc" )<br />
addRoom( _id )<br />
setRoomCoordinates( _id1, 0, 0, -1 )<br />
end<br />
</lua><br />
<br />
==getRoomName==<br />
roomName = getRoomName(roomID)<br />
<br />
Returns the room name for a given room id.<br />
<br />
<lua><br />
echo(string.format("The name of the room id #455 is %s.", getRoomname(455))<br />
</lua><br />
<br />
==getRooms==<br />
rooms = getRooms()<br />
<br />
Returns the list of '''all''' rooms in the map in an area in roomid - room name format.<br />
<br />
<lua><br />
-- simple, raw viewer for rooms in an area<br />
display(getRooms())<br />
</lua><br />
<br />
==getRoomsByPosition==<br />
getRoomsByPosition(areaID, x,y,z)<br />
<br />
Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
<lua><br />
-- sample script to determine a room nearby, given a relative direction from the current room<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</lua><br />
<br />
==getRoomUserData==<br />
data = getRoomUserData(roomID, key (as a string))<br />
<br />
Returns the user data stored at a given room with a given key, or "" if none is stored. Use [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]] for setting the user data.<br />
<br />
<lua><br />
display(getRoomUserData(341, "visitcount"))<br />
</lua><br />
<br />
==getRoomWeight==<br />
room weight = getRoomWeight(roomID)<br />
<br />
Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[Manual:Lua_Functions#setRoomWeight|setRoomWeight]]<br />
<br />
<lua><br />
display("Original weight of room 541: "..getRoomWeight(541)<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541)<br />
</lua><br />
<br />
==getSpecialExits==<br />
exits = getSpecialExits(roomID)<br />
<br />
Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
<lua><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</lua><br />
<br />
==getSpecialExitsSwap==<br />
exits = getSpecialExitsSwap(roomID)<br />
<br />
Very similar to [[Manual:Lua_Functions#getSpecialExits|getSpecialExits]], but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
gotoRoom (roomID)<br />
Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(". <br />
<br />
==hasExitLock==<br />
status = hasExitLock(roomID, direction)<br />
<br />
Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''direction'' right now is a number that corresponds to the direction:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples:<br />
<lua><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#lockExit|lockExit]]<br />
<br />
==highlightRoom==<br />
highlightRoom( id, r1,g1,b1,r2,g2,b2, radius, alpha1, alpha2)<br />
<br />
Highlights a room with the given color, which will override it's environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. ''highlightRadius'' is the radius for the highlight circle - if you don't want rooms beside each other to over lap, use ''1'' as the radius. ''alphaColor1'' and ''alphaColor2'' are transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[Manual:Lua_Functions#unHighlightRoom|unHighlightRoom]]<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
-- color some room red to blue<br />
highlightRoom(351, unpack(color_table.red), unpack(color_table.blue), 1, 255, 255)<br />
<br />
-- or use a name from showColors(), gold in this case<br />
highlightRoom(351, unpack(color_table.grey), unpack(color_table.grey), 1, 255, 255)<br />
</lua><br />
<br />
==lockExit==<br />
lockExit(roomID, direction, lock = true/false)<br />
<br />
Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction at the moment is only set as a number, and here's a listing of them:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples<br />
<lua><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#hasExitLock|hasExitLock]]<br />
<br />
==lockRoom==<br />
lockRoom (roomID, lock = true/false)<br />
<br />
Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[Manual:Lua_Functions#roomLocked|roomLocked]]<br />
<br />
<lua><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</lua><br />
<br />
==roomExists==<br />
roomExists(roomID)<br />
<br />
Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
locked = roomLocked(roomID)<br />
<br />
Returns true or false whenever a given room is locked.<br />
: See also: [[Manual:Lua_Functions#lockRoom|lockRoom]]<br />
<br />
<lua><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</lua><br />
<br />
==saveMap==<br />
saveMap(location)<br />
<br />
Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work.<br />
<br />
<lua><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
</lua><br />
<br />
==searchRoom== <br />
searchRoom (room name)<br />
<br />
Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname'', like so:<br />
<br />
<lua><br />
display(searchRoom("master"))<br />
<br />
--[[ would result in:<br />
table {<br />
17463: 'in the branches of the Master Ravenwood'<br />
3652: 'master bedroom'<br />
10361: 'Hall of Cultural Masterpieces'<br />
6324: 'Exhibit of the Techniques of the Master Artisans'<br />
5340: 'office of the Guildmaster'<br />
(...)<br />
2004: 'office of the guildmaster'<br />
14457: 'the Master Gear'<br />
1337: 'before the Master Ravenwood Tree'<br />
}<br />
]]</lua><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
==setAreaName==<br />
setAreaName(areaID, newName)<br />
<br />
Renames an existing area to the new name.<br />
<br />
<lua><br />
setAreaName(2, "My city")<br />
</lua><br />
<br />
==setCustomEnvColor==<br />
setCustomEnvColor(environmentID, r,g,b)<br />
<br />
Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
<br />
<lua><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
setCustomEnvColor(200, unpack(color_table.blue)) -- set the color of environmentID 200 to blue<br />
</lua><br />
<br />
==setExit==<br />
setExit(from roomID, to roomID, direction)<br />
<br />
Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', or a number which represents a direction.<br />
<br />
Returns ''false'' if the exit creation didn't work.<br />
<br />
<lua><br />
-- alias pattern: ^exit (\d+) (\w+)$<br />
<br />
if setExit(mmp.currentroom, tonumber(matches[2]),matches[3]) then<br />
echo("\nExit set to room:"..matches[2]..", Direction:"..string.upper(matches[3]))<br />
centerview(mmp.currentroom)<br />
else<br />
mmp.echo("Failed to set the exit.") end<br />
</lua><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
setExit(from roomID, -1, direction)<br />
<br />
Which will delete an outgoing exit in the specified direction from a room.<br />
<br />
<lua><br />
-- locate the room on the other end, so we can unlink it from there as well if necessary<br />
local otherroom<br />
if getRoomExits(getRoomExits(mmp.currentroom)[dir])[mmp.ranytolong(dir)] then<br />
otherroom = getRoomExits(mmp.currentroom)[dir]<br />
end<br />
<br />
if setExit(mmp.currentroom, -1, dir) then<br />
if otherroom then<br />
if setExit(otherroom, -1, mmp.ranytolong(dir)) then<br />
mmp.echo(string.format("Deleted the %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
else mmp.echo("Couldn't delete the incoming exit.") end<br />
else<br />
mmp.echo(string.format("Deleted the one-way %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
end<br />
else<br />
mmp.echo("Couldn't delete the outgoing exit.")<br />
end<br />
</lua><br />
<br />
You can use these numbers for setting the directions as well:<br />
<lua><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}</lua><br />
<br />
==setGridMode==<br />
setGridMode(area, true/false)<br />
<br />
Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode.<br />
<br />
<lua><br />
setGridMode(55,true) -- set area with ID 55 to be in grid mode<br />
</lua><br />
<br />
==setRoomArea==<br />
setRoomArea(roomID, newAreaID)<br />
<br />
Assigns the given room to a new area. This will have the room be visually moved into the area as well.<br />
<br />
==setRoomChar==<br />
setRoomChar(roomID, character)<br />
<br />
Designed for an area in grid mode, this will set a single character to be on a room. You can use "_" to clear it.<br />
<br />
<lua><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123. "$")<br />
</lua><br />
<br />
==setRoomCoordinates==<br />
setRoomCoordinates(roomID, x, y, z)<br />
<br />
Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
0,0,0 is the center of the map.<br />
<br />
<lua><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
You can make them relative as well:<br />
<br />
<lua><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
==setRoomEnv==<br />
setRoomEnv(roomID, newEnvID)<br />
<br />
Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
<br />
<lua><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</lua><br />
<br />
==setRoomIDbyHash==<br />
setRoomIDbyHash(roomID, hash)<br />
<br />
Sets the hash to be associated with the given roomID. See also [[Manual:Lua_Functions#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
setRoomName(roomID, newName)<br />
<br />
Renames an existing room to a new name.<br />
<br />
<lua><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</lua><br />
<br />
==setRoomUserData==<br />
setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
Returns true if successfully set.<br />
: See also: [[Manual:Lua_Functions#clearRoomUserData|clearRoomUserData]]<br />
<br />
<lua><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</lua><br />
<br />
==setRoomWeight==<br />
setRoomWeight(roomID, weight)<br />
<br />
Sets a weight to the given roomID. By default, all rooms have a weight of 0 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
To completely avoid a room, make use of [[Manual:Lua_Functions#lockRoom|lockRoom()]].<br />
<br />
: See also: [[Manual:Lua_Functions#getRoomWeight|getRoomWeight]]<br />
<br />
<lua><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</lua><br />
<br />
==unHighlightRoom==<br />
unHighlightRoom(roomID)<br />
<br />
Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[Manual:Lua_Functions#highlightRoom|highlightRoom]]<br />
<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
unHighlightRoom(4534)<br />
</lua><br />
<br />
= Miscellaneous Functions =<br />
==expandAlias==<br />
; expandAlias(command,true/false)<br />
<br />
: 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.<br />
<br />
<lua><br />
expandAlias("t rat")<br />
<br />
expandAlias("t rat", false)<br />
</lua><br />
<br />
: 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.<br />
<br />
==spawn==<br />
;t = spawn(read function, process to spawn)<br />
<br />
: 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()''.<br />
<br />
<lua><br />
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function<br />
local f = spawn(display, "ls")<br />
display(f.isRunning())<br />
f.close()<br />
</lua><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Scripting#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Scripting#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
: <sub>Requires Mudlet 2.0+</sub><br />
<br />
;Example<br />
<lua><br />
-- this example will check the Imperian homepage to see how many players are on right now<br />
<br />
-- in an alias, download the Imperian homepage for stats processing<br />
downloadFile(getMudletHomeDir().."/page.html", "http://www.imperian.com/")<br />
<br />
<br />
-- then create a new script with the name of downloaded_file, add the event handler<br />
-- for sysDownloadDone, and use this to parse the webpage and display the amount<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:match("page", 1, true) then return end<br />
<br />
-- parse our ownloaded file for the player count<br />
io.input(filename)<br />
local s = io.read("*all")<br />
local pc = s:match([[<a href='players.php%?search=who'>(%d+)</a>]])<br />
display("Imperian has "..tostring(pc).." players on right now.")<br />
io.open():close()<br />
os.remove(filename)<br />
end<br />
</lua><br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
<br />
: See Also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
<br />
;Example<br />
<lua><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "vision"}]])<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "woodlore", "name": "hide"}]])<br />
</lua><br />
<br />
==sendIrc==<br />
;sendIrc(channel, message)<br />
: Sends a message to an IRC channel or person. You must have the IRC window open, and if speaking to a channel, be joined in that channel. IRC currently only works on the freenode network and password-protected channels aren't supported.<br />
<br />
;Parameters:<br />
* ''channel:''<br />
: The channel to send the message to. Can be #<channelname> to send to a channel, or <person name> to send to a person. Passed as a string.<br />
* ''message:''<br />
: The message to send. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
--This would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
</lua><br />
<br />
==showColors==<br />
;showColors(columns)<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in color_table, in table form. The format is color_table.colorName = {r,g,b}<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#cecho|cecho]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: Number of columns to print the color table in. Passed as an integer number.<br />
<br />
;Example:<br />
<lua><br />
showColors(4)<br />
</lua><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)]]<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Lua_Functions&diff=729Manual:Lua Functions2011-07-30T22:05:12Z<p>Rayth: /* table.insert */</p>
<hr />
<div>== Function Categories ==<br />
'''Standard Functions''': These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
'''UI Functions''': These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation.<br />
<lua><br />
createMiniConsole()<br />
createLabel()<br />
createGauge()<br />
</lua><br />
<br />
'''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.<br />
<br />
'''String Functions'''<br />
<br />
'''Scripting Object Functions'''<br />
<br />
'''Mapper Functions'''<br />
<br />
'''Miscellaneous Functions'''<br />
<br />
== Variables ==<br />
The following variables are provided by Mudlet:<br />
<br><br><br />
;line <br />
:This variable holds the content of the current line that is being processed by the trigger engine. The engine runs all triggers on each line as it arrives from the MUD.<br />
;command <br />
:This variable holds the current user command. This is typically used in alias scripts.<br />
;matches[n]<br />
:This Lua table is being used by Mudlet in the context of triggers that use Perl regular expressions. matches[1] holds the entire match, matches[2] holds the first capture group, matches[n] holds the nth-1 capture group. If the trigger uses the Perl style /g switch to evaluate all possible matches of the given regex within the current line, matches[n+1] will hold the second entire match, matches[n+2] the first capture group of the second match and matches[n+m] the m-th capture group of the second match.<br />
;multimatches[n][m]<br />
:This table is being used by Mudlet in the context of multiline triggers that use Perl regular expression. It holds the table matches[n] as described above for each Perl regular expression based condition of the multiline trigger. multimatches[5][4] may hold the 3rd capture group of the 5th regex in the multiline trigger. This way you can examine and process all relevant data within a single script. Have a look at this example.<br />
= Standard Functions =<br />
: These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
==send==<br />
;send( command, echo the value = true/false )<br />
:This sends "command" directly to the network layer, skipping the alias matching. The optional second argument of type boolean (print) determines if the outgoing command is to be echoed on the screen.<br />
:If you want your command to be checked if it’s an alias, use expandAlias() instead. example:<br />
<lua><br />
send( "Hello Jane" ) --echos the command on the screen<br />
send( "Hello Jane", true ) --echos the command on the screen<br />
send( "Hello Jane", false ) --does not echo the command on the screen<br />
</lua><br />
==echo==<br />
;echo( windowName, text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])<br />
:Echos a piece of text as a clickable link.<br />
:text - text to display in the echo. Same as a normal echo().<br />
:command - lua code to do when the link is clicked.<br />
:hint - text for the tooltip to be displayed when the mouse is over the link.<br />
:boolean - if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.<br />
<br />
= UI Functions =<br />
<br />
<br />
==echo==<br />
;echo( [windowName,] text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name. <br />
: See also: [[Manual:Lua_Functions#paste|paste]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</lua><br />
<br />
==bg==<br />
;bg(colorName)<br />
: Changes the background color of the text. Useful for highlighting text. <br />
: See Also: [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<lua><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
</lua><br />
<br />
==calcFontSize==<br />
;calcFontSize(fontSize)<br />
: Used to calculate the number of pixels wide and high a character would be on a mini console at fontSize.<br />
: Returns two numbers, width/height<br />
: See Also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]]<br />
<br />
;Parameters<br />
* ''fontSize:''<br />
: The font size you are wanting to calculate pixel sizes for. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide <br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</lua><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: Clears the window or miniconsole with the name given as argument.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearUserWindow("Chat")<br />
</lua><br />
<br />
==clearWindow==<br />
;clearWindow(name)<br />
: Clears the window or miniconsole with the name given as argument. <br />
: See also: [[Manual:Lua_Functions#clearUserWindow|clearUserWindow]]<br />
<br />
;Parameters<br />
* name: <br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</lua><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: Creates a named buffer for formatted text, much like a miniconsole, but the buffer cannot be shown on the screen. Intended for temporary use in the formatting of text.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
Examples<br />
<lua><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</lua><br />
<br />
==createConsole==<br />
;createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: Makes a new miniconsole. The background will be black, and the text color white.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide, <br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</lua><br />
<br />
==createGauge==<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, r, g, b)<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, colorName)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge]], [[Manual:Lua_Functions#setGauge|setGauge]], [[Manual:Lua_Functions#setGaugeText|setGaugeText]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</lua><br />
<br />
==createLabel==<br />
;createLabel(name, Xpos, Ypos, width, height, fillBackground)<br />
: Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|setTextFormat]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.<br />
<br />
Examples<br />
<lua><br />
--This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle <br />
--of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent <br />
--and 255 non-transparent) the background text can still be read through. The message box will disappear after 2.3 seconds.<br />
local width, height = getMainWindowSize();<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1);<br />
resizeWindow("messageBox",500,70);<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 );<br />
setBackgroundColor("messageBox", 150,100,100,200);<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]] );<br />
showWindow("messageBox");<br />
tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</lua><br />
<br />
==createMiniConsole==<br />
;createMiniConsole(name, posX, posY, width, height)<br />
: Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc. <br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel]], [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|moveWindow]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent]], [[Manual:Lua_Functions#setBorderTop|setBorderTop]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique, you can not have two or more miniconsoles with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the miniconsole, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the miniconsole, in pixels. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
--This script would create a mini text console called "sys" and write with yellow foreground color and blue background color <br />
--"Hello World".<br />
<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
WindowWidth = 0;<br />
WindowHeight = 0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line<br />
setWindowWrap("sys", 40)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
<br />
echo("sys","Hello world!")<br />
</lua><br />
<br />
==deleteLine==<br />
;deleteLine()<br />
: Deletes the current line under the user cursor. This is a high speed gagging tool and is very good at this task, but is only meant to be use when a line should be omitted entirely in the output. If you echo() to that line it will not be shown, and lines deleted with deleteLine() are simply no longer rendered. For replacing text, replace() is the proper option.<br />
: See Also: [[Manual:Lua_Functions#replace|replace]], [[Manual:Lua_Functions#wrapLine|wrapLine]]<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
</lua><br />
<br />
==deselect==<br />
;deselect(name)<br />
: This is used to clear the current selection (to no longer have anything selected). Should be used after changing the formatting of text, to keep from accidentally changing the text again later with another formatting call.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer/miniConsole to stop having anything selected in. This is an optional argument, if name is not provided the main window will have its selection cleared. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further <br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</lua><br />
<br />
==fg==<br />
; fg(colorName)<br />
: If used on a selection, sets the foreground color to ''colorName'' - otherwise, it will set the color of the next text-inserting calls (''echo(), insertText, echoLink()'', and others)<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Examples<br />
<lua><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
</lua><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels.<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--this will get the size of your main mudlet window and save them <br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</lua><br />
<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.<br />
<br />
;Example<br />
<lua><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</lua><br />
<br />
= Table Functions =<br />
<br />
==table.complement==<br />
; table.complement (set1, set2)<br />
: Returns a table that is the relative complement of the first table with respect to the second table. Returns a complement of key/value pairs.<br />
<br />
; Parameters<br />
* ''table1:''<br />
* ''table2:''<br />
<br />
; Example:<br />
<lua></lua><br />
<br />
==table.concat==<br />
;table.concat(table, delimiter, startingindex, endingindex)<br />
: Joins a table into a string. Each item must be something which can be transformed into a string. <br />
: Returns the joined string.<br />
: See also: [[Manual:Lua_Functions#string.split|string.split]]<br />
<br />
;Parameters<br />
* table:<br />
: The table to concatenate into a string. Passed as a table.<br />
* delimiter:<br />
: Optional string to use to separate each element in the joined string. Passed as a string.<br />
* startingindex:<br />
: Optional parameter to specify which index to begin the joining at. Passed as an integer.<br />
* endingindex:<br />
: Optional parameter to specify the last index to join. Passed as an integer.<br />
<br />
;Examples<br />
<lua><br />
--This shows a basic concat with none of the optional arguments<br />
testTable = {1,2,"hi","blah",}<br />
testString = table.concat(testTable)<br />
--testString would be equal to "12hiblah"<br />
<br />
--This example shows the concat using the optional delimiter<br />
testString = table.concat(testTable, ", ")<br />
--testString would be equal to "1, 2, hi, blah"<br />
<br />
--This example shows the concat using the delimiter and the optional starting index<br />
testString = table.concat(testTable, ", ", 2)<br />
--testString would be equal to "2, hi, blah"<br />
<br />
--And finally, one which uses all of the arguments<br />
testString = table.concat(testTable, ", ", 2, 3)<br />
--testString would be equal to "2, hi"<br />
</lua><br />
<br />
==table.contains==<br />
; table.contains (t, value)<br />
: Determines if a table contains a value as a key or as a value (recursive).<br />
: Returns true or false<br />
<br />
; Parameters<br />
* ''t:'' <br />
: The table in which you are checking for the presence of the value.<br />
* ''value:'' <br />
: The value you are checking for within the table.<br />
<br />
; Example:<br />
<lua>local test_table = { "value1", "value2", "value3", "value4" }<br />
if table.contains(test_table, "value1") then <br />
echo("Got value 1!")<br />
else<br />
echo("Don't have it. Sorry!")<br />
end<br />
</lua><br />
This example would always echo the first one, unless you remove value1 from the table.<br />
<br />
==table.foreachi==<br />
==table.foreach==<br />
==table.getn==<br />
==table.intersection==<br />
==table.insert==<br />
'''table.insert'''(table, [pos,] value)<br />
<br />
Inserts element value at position pos in table, shifting up other elements to open space, if necessary. The default value for pos is n+1, where n is the length of the table, so that a call table.insert(t,x) inserts x at the end of table t.<br />
<br />
==table.index_of==<br />
==table.is_empty==<br />
==table.load==<br />
==table.maxn==<br />
==table.n_union==<br />
==table.n_complement==<br />
==table.n_intersection==<br />
==table.pickle==<br />
==table.remove==<br />
==table.save==<br />
==table.sort==<br />
==table.size==<br />
; table.size (t)<br />
: Gets the actual size of non-index based tables.<br />
: Returns a number.<br />
<br />
; Parameters<br />
* ''t:'' The table you are checking the size of.<br />
<table width="100%" frame="box"><br />
<caption>'''Note:'''</caption><br />
<tr><br />
<td><br />
For index based tables you can get the size with the # operator:<br />
This is the standard Lua way of getting the size of index tables i.e. ipairs() type of tables with numerical indices. <br />
To get the size of tables that use user defined keys instead of automatic indices (pairs() type) you need to use the function table.size() referenced above.<br />
</td><br />
</tr><br />
</table><br />
; Example<br />
<lua><br />
local test_table = { "value1", "value2", "value3", "value4" }<br />
myTableSize = #test_table<br />
-- This would return 4.<br />
local myTable = { 1 = "hello", "key2" = "bye", "key3" = "time to go" }<br />
table.size(myTable)<br />
-- This would return 3.<br />
</lua><br />
<br />
==table.setn==<br />
==table.unpickle==<br />
==table.update==<br />
==table.union==<br />
<br />
= String Functions =<br />
==string.byte==<br />
<br />
==string.char==<br />
<br />
==string.cut==<br />
;string.cut(string, maxLen)<br />
: Cuts string to the specified maximum length.<br />
: Returns the modified string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The text you wish to cut. Passed as a string.<br />
* maxLen<br />
: The maximum length you wish the string to be. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--The following call will return 'abc' and store it in myString<br />
mystring = string.cut("abcde", 3)<br />
--You can easily pad string to certain length. Example below will print 'abcde ' e.g. pad/cut string to 10 characters.<br />
local s = "abcde"<br />
s = string.cut(s .. " ", 10) -- append 10 spaces<br />
echo("'" .. s .. "'")<br />
</lua><br />
<br />
==string.dump==<br />
<br />
==string.enclose==<br />
;string.enclose(String)<br />
: Wraps a string with [[ ]]<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String: The string to enclose. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will echo '[[Oh noes!]]' to the main window<br />
echo("'" .. string.enclose("Oh noes!") .. "'")<br />
</lua><br />
<br />
==string.ends==<br />
;string.ends(String, Suffix)<br />
: Test if string is ending with specified suffix.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#string.starts|string.starts]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string.<br />
* ''Suffix:''<br />
: The suffix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will test if the incoming line ends with "in bed" and if not will add it to the end.<br />
if not string.ends(line, "in bed") then<br />
echo("in bed\n")<br />
end<br />
</lua><br />
<br />
==string.find==<br />
<br />
==string.findPattern==<br />
string.findPattern(text, pattern)<br />
Return first matching substring or nil.<br />
<br />
Parameters<br />
text:<br />
pattern:<br />
<br />
Usage:<br />
Following example will print: "I did find: Troll" string.<br />
<lua><br />
local match = string.findPattern("Troll is here!", "Troll")<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</lua><br />
This example will find substring regardless of case.<br />
local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
<br />
Return value:<br />
nil or first matching substring <br />
<br />
See also:<br />
[[Manual:Lua_Functions#string.genNocasePattern|string.genNocasePattern()]]<br />
<br />
==string.format==<br />
<br />
==string.genNocasePattern==<br />
string.genNocasePattern(s)<br />
<br />
Generate case insensitive search pattern from string.<br />
<br />
Parameters<br />
s:<br />
<br />
Usage:<br />
Following example will generate and print "123[aA][bB][cC]" string.<br />
echo(string.genNocasePattern("123abc"))<br />
<br />
Return value:<br />
case insensitive pattern string <br />
==string.gfind==<br />
<br />
==string.gmatch==<br />
<br />
==string.gsub==<br />
<br />
==string.len==<br />
<br />
==string.lower==<br />
<br />
==string.match==<br />
<br />
==string.rep==<br />
<br />
==string.reverse==<br />
<br />
<br />
==string.split==<br />
;string.split(String, delimiter)<br />
;<nowiki>myString:split(delimiter)</nowiki><br />
: Splits a string into a table by the given delimiter. Can be called against a string (or variable holding a string) using the second form above.<br />
: Returns a table containing the split sections of the string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to split. Parameter is not needed if using second form of the syntax above. Passed as a string.<br />
* ''delimiter:''<br />
: The delimiter to use when splitting the string. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
-- This will split the string by ", " delimiter and print the resulting table to the main window.<br />
names = "Alice, Bob, Peter"<br />
name_table = string.split(names, ", ")<br />
display(name_table)<br />
<br />
--The alternate method<br />
names = "Alice, Bob, Peter"<br />
name_table = names:split(", ")<br />
display(name_table)<br />
</lua><br />
<br />
Either method above will print out:<br />
table {<br />
1: 'Alice'<br />
2: 'Bob'<br />
3: 'Peter'<br />
}<br />
<br />
==string.starts==<br />
;string.starts(String, Prefix)<br />
: Test if string is starting with specified prefix.<br />
: Returns true or false<br />
: See also: [[Manual:Lua_Functions#string.ends|string.ends]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string. <br />
* ''Prefix:''<br />
: The prefix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--The following will see if the line begins with "You" and if so will print a statement at the end of the line<br />
if string.starts(line, "You") then<br />
echo("====oh you====\n")<br />
end<br />
</lua><br />
<br />
==string.sub==<br />
<br />
==string.title==<br />
;string.title(String)<br />
;<nowiki>string:title()</nowiki><br />
: Capitalizes the first character in a string.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String<br />
: The string to modify. Not needed if you use the second form of the syntax above.<br />
<br />
;Example<br />
<lua><br />
--Variable testname is now Anna.<br />
testname = string.title("anna")<br />
--Example will set test to "Bob".<br />
test = "bob"<br />
test = test:title()<br />
</lua><br />
<br />
==string.trim==<br />
;string.trim(String)<br />
: Trims String, removing all 'extra' white space at the beginning and end of the text.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to trim. Passed as a string.<br />
<br />
;Example:<br />
<lua><br />
--This will print 'Troll is here!', without the extra spaces.<br />
local str = string.trim(" Troll is here! ")<br />
echo("'" .. str .. "'")<br />
</lua><br />
<br />
==string.upper==<br />
<br />
= Mudlet Object Functions =<br />
==tempTimer==<br />
;tempTimer(time, code to do)<br />
Creates a temporary single shot timer and returns the timer ID for subsequent enableTimer(), disableTimer() and killTimer() calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed. <br />
<br />
;Parameters<br />
* ''time:'' the time in seconds for which to set the timer for<br />
* ''code to do'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
;Note<br />
[[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
==permGroup==<br />
permGroup(name, itemtype)<br />
<br />
Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts.<br />
<br />
<sub>Added to Mudlet in the 2.0 final release.</sub><br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<br />
<lua><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</lua><br />
<br />
<br />
==addAreaName==<br />
areaID = addAreaName(areaName)<br />
<br />
Adds a new area name and returns the new area ID for the new name. If the name already exists, -1 is returned.<br />
: See also: [[Manual:Lua_Functions#deleteArea|deleteArea]]<br />
<br />
<lua><br />
local newID = addAreaName("My house")<br />
<br />
if newID == -1 then echo("That area name is already taken :(\n")<br />
else echo("Created new area with the ID of "..newid..".\n") end<br />
</lua><br />
<br />
==addRoom==<br />
addRoom(roomID)<br />
<br />
Creates a new room with the given ID, returns true if the room was successfully created.<br />
: See also: [[Manual:Lua_Functions#createRoomID|createRoomID]]<br />
<br />
<lua><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</lua><br />
<br />
==addSpecialExit==<br />
addSpecialExit(roomIDFrom, roomIDTo, command)<br />
<br />
Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[Manual:Lua_Functions#clearSpecialExits|clearSpecialExits]]<br />
<br />
<lua><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- mmp.currentroom is your current room ID in this example<br />
addSpecialExit(mmp.currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(mmp.currentroom)<br />
</lua><br />
<br />
==centerview==<br />
centerview (roomID)<br />
<br />
Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
==clearRoomUserData==<br />
clearRoomUserData(roomID)<br />
<br />
Clears all user data from a given room.<br />
: See also: [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]]<br />
<br />
<lua><br />
clearRoomUserData(341)<br />
</lua><br />
<br />
==clearSpecialExits==<br />
clearSpecialExits(roomID) <br />
<br />
Removes all special exits from a room.<br />
: See also: [[Manual:Lua_Functions#addSpecialExit|addSpecialExit]]<br />
<br />
<lua><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will neve fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</lua><br />
<br />
==createMapLabel==<br />
labelID = createMapLabel(areaID, text, posx, posy, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue)<br />
<br />
Creates a visual label on the map for all z-levels at given coordinates, with the given background and foreground colors. It returns a label ID that you can use later for deleting it.<br />
<br />
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 [[Manual:Lua_Functions#getRoomCoordinates|getRoomCoordinates]] will place the label near that room.<br />
: See also: [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]]<br />
<lua><br />
local labelid = createMapLabel( 50, "my map label", 0, 0, 255,0,0,23,0,0)<br />
</lua><br />
<br />
==createMapper==<br />
createMapper(x, y, width, height)<br />
<br />
Creates a miniconsole window for mapper to render in, the with the given dimensions. You can only create one at a time at the moment.<br />
<br />
<lua><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper top-right of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</lua><br />
<br />
==createRoomID==<br />
usableId = createRoomID()<br />
<br />
Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs.<br />
: See also: [[Manual:Lua_Functions#addRoom|addRoom]]<br />
<br />
==deleteArea==<br />
deleteArea(areaID)<br />
<br />
Deletes the given area, permanently. This will also delete all rooms in it!<br />
: See also: [[Manual:Lua_Functions#addAreaName|addAreaName]]<br />
<br />
<lua><br />
deleteArea(23)<br />
</lua><br />
<br />
==deleteMapLabel==<br />
deleteMapLabel(areaID, labelID)<br />
<br />
Deletes a map label from a specfic area.<br />
: See also: [[Manual:Lua_Functions#createMapLabel|createMapLabel]]<br />
<lua><br />
deleteMapLabel(50, 1)<br />
</lua><br />
<br />
==deleteRoom==<br />
deleteRoom(roomID)<br />
<br />
Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
<lua><br />
deleteRoom(335)<br />
</lua><br />
<br />
==getAreaRooms==<br />
getAreaRooms(area id)<br />
<br />
Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
<sub>Note that on Mudlet versions prior to the 2.0 final release, this function would raise an error.</sub><br />
<br />
<lua><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in ipairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</lua><br />
<br />
==getAreaTable==<br />
getAreaTable()<br />
<br />
Returns a key(area name)-value(area id) table with all known areas and their IDs. There is an area with the name of '' and an ID of 0 included in it, you should ignore that.<br />
<br />
<lua><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id")<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</lua><br />
<br />
==getCustomEnvColorTable==<br />
envcolors = getCustomEnvColorTable()<br />
<br />
Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
<br />
<lua><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</lua><br />
<br />
==getMapLabels==<br />
arealabels = getMapLabels(areaID)<br />
<br />
Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]] it.<br />
<br />
<lua><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Svorai's grove'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Svorai's grove'<br />
}<br />
</lua><br />
<br />
==getPath==<br />
getPath(roomID from, roomID to)<br />
<br />
Returns a boolean true/false if a path between two room IDs is possible. If it is, the global `speedWalkPath` table is set to all of the directions that have to be taken to get there, and the global `speedWalkDir` table is set to all of the roomIDs you'll encounter on the way.<br />
<br />
<lua><br />
-- check if we can go to a room - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</lua><br />
<br />
==getRoomArea==<br />
areaID = getRoomArea(roomID)<br />
<br />
Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by getAreaTable() function, or use the getRoomAreaName function.<br />
<br />
<sub>Note that if the room ID does not exist, this function will raise an error</sub><br />
<br />
<lua><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</lua><br />
<br />
==getRoomAreaName==<br />
areaname = getRoomAreaName(areaID)<br />
<br />
Returns the area name for a given area id.<br />
<br />
<lua><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</lua><br />
<br />
==getRoomCoordinates==<br />
x,y,z = getRoomCoordinates(room ID)<br />
<br />
Returns the room coordinates of the given room ID.<br />
<br />
<lua><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</lua><br />
<br />
==getRoomEnv==<br />
envID = getRoomEnv(roomID)<br />
<br />
Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
<lua><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</lua><br />
<br />
== getRoomExits ==<br />
getRoomExits (roomID)<br />
Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid'', ie:<br />
<br />
<lua><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</lua><br />
<br />
==getRoomIDbyHash==<br />
roomID = getRoomIDbyHash(hash)<br />
<br />
Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
<lua><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
_id1 = getRoomIDbyHash( "5dfe55b0c8d769e865fd85ba63127fbc" );<br />
if _id1 == -1 then <br />
_id1 = createRoomID()<br />
setRoomIDbyHash( _id1, "5dfe55b0c8d769e865fd85ba63127fbc" )<br />
addRoom( _id )<br />
setRoomCoordinates( _id1, 0, 0, -1 )<br />
end<br />
</lua><br />
<br />
==getRoomName==<br />
roomName = getRoomName(roomID)<br />
<br />
Returns the room name for a given room id.<br />
<br />
<lua><br />
echo(string.format("The name of the room id #455 is %s.", getRoomname(455))<br />
</lua><br />
<br />
==getRooms==<br />
rooms = getRooms()<br />
<br />
Returns the list of '''all''' rooms in the map in an area in roomid - room name format.<br />
<br />
<lua><br />
-- simple, raw viewer for rooms in an area<br />
display(getRooms())<br />
</lua><br />
<br />
==getRoomsByPosition==<br />
getRoomsByPosition(areaID, x,y,z)<br />
<br />
Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
<lua><br />
-- sample script to determine a room nearby, given a relative direction from the current room<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</lua><br />
<br />
==getRoomUserData==<br />
data = getRoomUserData(roomID, key (as a string))<br />
<br />
Returns the user data stored at a given room with a given key, or "" if none is stored. Use [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]] for setting the user data.<br />
<br />
<lua><br />
display(getRoomUserData(341, "visitcount"))<br />
</lua><br />
<br />
==getRoomWeight==<br />
room weight = getRoomWeight(roomID)<br />
<br />
Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[Manual:Lua_Functions#setRoomWeight|setRoomWeight]]<br />
<br />
<lua><br />
display("Original weight of room 541: "..getRoomWeight(541)<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541)<br />
</lua><br />
<br />
==getSpecialExits==<br />
exits = getSpecialExits(roomID)<br />
<br />
Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
<lua><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</lua><br />
<br />
==getSpecialExitsSwap==<br />
exits = getSpecialExitsSwap(roomID)<br />
<br />
Very similar to [[Manual:Lua_Functions#getSpecialExits|getSpecialExits]], but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
gotoRoom (roomID)<br />
Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(". <br />
<br />
==hasExitLock==<br />
status = hasExitLock(roomID, direction)<br />
<br />
Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''direction'' right now is a number that corresponds to the direction:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples:<br />
<lua><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#lockExit|lockExit]]<br />
<br />
==highlightRoom==<br />
highlightRoom( id, r1,g1,b1,r2,g2,b2, radius, alpha1, alpha2)<br />
<br />
Highlights a room with the given color, which will override it's environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. ''highlightRadius'' is the radius for the highlight circle - if you don't want rooms beside each other to over lap, use ''1'' as the radius. ''alphaColor1'' and ''alphaColor2'' are transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[Manual:Lua_Functions#unHighlightRoom|unHighlightRoom]]<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
-- color some room red to blue<br />
highlightRoom(351, unpack(color_table.red), unpack(color_table.blue), 1, 255, 255)<br />
<br />
-- or use a name from showColors(), gold in this case<br />
highlightRoom(351, unpack(color_table.grey), unpack(color_table.grey), 1, 255, 255)<br />
</lua><br />
<br />
==lockExit==<br />
lockExit(roomID, direction, lock = true/false)<br />
<br />
Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction at the moment is only set as a number, and here's a listing of them:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples<br />
<lua><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#hasExitLock|hasExitLock]]<br />
<br />
==lockRoom==<br />
lockRoom (roomID, lock = true/false)<br />
<br />
Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[Manual:Lua_Functions#roomLocked|roomLocked]]<br />
<br />
<lua><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</lua><br />
<br />
==roomExists==<br />
roomExists(roomID)<br />
<br />
Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
locked = roomLocked(roomID)<br />
<br />
Returns true or false whenever a given room is locked.<br />
: See also: [[Manual:Lua_Functions#lockRoom|lockRoom]]<br />
<br />
<lua><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</lua><br />
<br />
==saveMap==<br />
saveMap(location)<br />
<br />
Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work.<br />
<br />
<lua><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
</lua><br />
<br />
==searchRoom== <br />
searchRoom (room name)<br />
<br />
Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname'', like so:<br />
<br />
<lua><br />
display(searchRoom("master"))<br />
<br />
--[[ would result in:<br />
table {<br />
17463: 'in the branches of the Master Ravenwood'<br />
3652: 'master bedroom'<br />
10361: 'Hall of Cultural Masterpieces'<br />
6324: 'Exhibit of the Techniques of the Master Artisans'<br />
5340: 'office of the Guildmaster'<br />
(...)<br />
2004: 'office of the guildmaster'<br />
14457: 'the Master Gear'<br />
1337: 'before the Master Ravenwood Tree'<br />
}<br />
]]</lua><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
==setAreaName==<br />
setAreaName(areaID, newName)<br />
<br />
Renames an existing area to the new name.<br />
<br />
<lua><br />
setAreaName(2, "My city")<br />
</lua><br />
<br />
==setCustomEnvColor==<br />
setCustomEnvColor(environmentID, r,g,b)<br />
<br />
Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
<br />
<lua><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
setCustomEnvColor(200, unpack(color_table.blue)) -- set the color of environmentID 200 to blue<br />
</lua><br />
<br />
==setExit==<br />
setExit(from roomID, to roomID, direction)<br />
<br />
Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', or a number which represents a direction.<br />
<br />
Returns ''false'' if the exit creation didn't work.<br />
<br />
<lua><br />
-- alias pattern: ^exit (\d+) (\w+)$<br />
<br />
if setExit(mmp.currentroom, tonumber(matches[2]),matches[3]) then<br />
echo("\nExit set to room:"..matches[2]..", Direction:"..string.upper(matches[3]))<br />
centerview(mmp.currentroom)<br />
else<br />
mmp.echo("Failed to set the exit.") end<br />
</lua><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
setExit(from roomID, -1, direction)<br />
<br />
Which will delete an outgoing exit in the specified direction from a room.<br />
<br />
<lua><br />
-- locate the room on the other end, so we can unlink it from there as well if necessary<br />
local otherroom<br />
if getRoomExits(getRoomExits(mmp.currentroom)[dir])[mmp.ranytolong(dir)] then<br />
otherroom = getRoomExits(mmp.currentroom)[dir]<br />
end<br />
<br />
if setExit(mmp.currentroom, -1, dir) then<br />
if otherroom then<br />
if setExit(otherroom, -1, mmp.ranytolong(dir)) then<br />
mmp.echo(string.format("Deleted the %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
else mmp.echo("Couldn't delete the incoming exit.") end<br />
else<br />
mmp.echo(string.format("Deleted the one-way %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
end<br />
else<br />
mmp.echo("Couldn't delete the outgoing exit.")<br />
end<br />
</lua><br />
<br />
You can use these numbers for setting the directions as well:<br />
<lua><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}</lua><br />
<br />
==setGridMode==<br />
setGridMode(area, true/false)<br />
<br />
Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode.<br />
<br />
<lua><br />
setGridMode(55,true) -- set area with ID 55 to be in grid mode<br />
</lua><br />
<br />
==setRoomArea==<br />
setRoomArea(roomID, newAreaID)<br />
<br />
Assigns the given room to a new area. This will have the room be visually moved into the area as well.<br />
<br />
==setRoomChar==<br />
setRoomChar(roomID, character)<br />
<br />
Designed for an area in grid mode, this will set a single character to be on a room. You can use "_" to clear it.<br />
<br />
<lua><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123. "$")<br />
</lua><br />
<br />
==setRoomCoordinates==<br />
setRoomCoordinates(roomID, x, y, z)<br />
<br />
Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
0,0,0 is the center of the map.<br />
<br />
<lua><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
You can make them relative as well:<br />
<br />
<lua><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
==setRoomEnv==<br />
setRoomEnv(roomID, newEnvID)<br />
<br />
Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
<br />
<lua><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</lua><br />
<br />
==setRoomIDbyHash==<br />
setRoomIDbyHash(roomID, hash)<br />
<br />
Sets the hash to be associated with the given roomID. See also [[Manual:Lua_Functions#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
setRoomName(roomID, newName)<br />
<br />
Renames an existing room to a new name.<br />
<br />
<lua><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</lua><br />
<br />
==setRoomUserData==<br />
setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
Returns true if successfully set.<br />
: See also: [[Manual:Lua_Functions#clearRoomUserData|clearRoomUserData]]<br />
<br />
<lua><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</lua><br />
<br />
==setRoomWeight==<br />
setRoomWeight(roomID, weight)<br />
<br />
Sets a weight to the given roomID. By default, all rooms have a weight of 0 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
To completely avoid a room, make use of [[Manual:Lua_Functions#lockRoom|lockRoom()]].<br />
<br />
: See also: [[Manual:Lua_Functions#getRoomWeight|getRoomWeight]]<br />
<br />
<lua><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</lua><br />
<br />
==unHighlightRoom==<br />
unHighlightRoom(roomID)<br />
<br />
Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[Manual:Lua_Functions#highlightRoom|highlightRoom]]<br />
<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
unHighlightRoom(4534)<br />
</lua><br />
<br />
= Miscellaneous Functions =<br />
==expandAlias==<br />
; expandAlias(command,true/false)<br />
<br />
: 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.<br />
<br />
<lua><br />
expandAlias("t rat")<br />
<br />
expandAlias("t rat", false)<br />
</lua><br />
<br />
: 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.<br />
<br />
==spawn==<br />
;t = spawn(read function, process to spawn)<br />
<br />
: 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()''.<br />
<br />
<lua><br />
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function<br />
local f = spawn(display, "ls")<br />
display(f.isRunning())<br />
f.close()<br />
</lua><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Scripting#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Scripting#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
: <sub>Requires Mudlet 2.0+</sub><br />
<br />
;Example<br />
<lua><br />
-- this example will check the Imperian homepage to see how many players are on right now<br />
<br />
-- in an alias, download the Imperian homepage for stats processing<br />
downloadFile(getMudletHomeDir().."/page.html", "http://www.imperian.com/")<br />
<br />
<br />
-- then create a new script with the name of downloaded_file, add the event handler<br />
-- for sysDownloadDone, and use this to parse the webpage and display the amount<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:match("page", 1, true) then return end<br />
<br />
-- parse our ownloaded file for the player count<br />
io.input(filename)<br />
local s = io.read("*all")<br />
local pc = s:match([[<a href='players.php%?search=who'>(%d+)</a>]])<br />
display("Imperian has "..tostring(pc).." players on right now.")<br />
io.open():close()<br />
os.remove(filename)<br />
end<br />
</lua><br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
<br />
: See Also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
<br />
;Example<br />
<lua><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "vision"}]])<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "woodlore", "name": "hide"}]])<br />
</lua><br />
<br />
==sendIrc==<br />
;sendIrc(channel, message)<br />
: Sends a message to an IRC channel or person. You must have the IRC window open, and if speaking to a channel, be joined in that channel. IRC currently only works on the freenode network and password-protected channels aren't supported.<br />
<br />
;Parameters:<br />
* ''channel:''<br />
: The channel to send the message to. Can be #<channelname> to send to a channel, or <person name> to send to a person. Passed as a string.<br />
* ''message:''<br />
: The message to send. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
--This would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
</lua><br />
<br />
==showColors==<br />
;showColors(columns)<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in color_table, in table form. The format is color_table.colorName = {r,g,b}<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#cecho|cecho]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: Number of columns to print the color table in. Passed as an integer number.<br />
<br />
;Example:<br />
<lua><br />
showColors(4)<br />
</lua><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)]]<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=DynDesc&diff=722DynDesc2011-07-29T04:44:59Z<p>Rayth: </p>
<hr />
<div>==Package Info==<br />
<br />
By: [[User:Saraphae|Saraphae]] and [[User:Phoenix|ThePhoenix]]<br />
<br />
For(MUD): [http://www.achaea.com Achaea]<br />
<br />
Size: N/A<br />
<br />
Download: N/A<br />
<br />
Version: 3.X.X<br />
<br />
Contents: N/A<br />
<br />
Summary: DynDesc is an in-development description script with various features and utilities, aptly named the Dynamic Descriptor. As of right now it's in the late stages of development, preparing for release to the general public. You may have even seen some of the Alpha testers using it around Sapience! More to come shortly...</div>Raythhttps://wiki.mudlet.org/index.php?title=Misc_Scripts&diff=662Misc Scripts2011-07-27T22:08:54Z<p>Rayth: </p>
<hr />
<div>==Example Layout==<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
<br />
=Miscellaneous Scripts=<br />
Small or Large scripts made before the official package system.<br />
----<br />
'''Name:''' Lua from the Command Line<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=100<br><br />
'''Short Description:''' Allows coding small scripts from the command line.<br />
----<br />
'''Name:''' Name Highlighter v3<br><br />
'''Author:'''Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1235<br><br />
'''Short Description:''' Highlight player names according to org affiliation or other chosen criteria.<br />
----<br />
'''Name:''' Lusternia Calendar<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2253<br><br />
'''Short Description:''' Display a small calendar for Lusternia.<br />
----<br />
'''Name:''' Clickable URLs<br><br />
'''Author:''' Yetzederixx<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1818<br><br />
'''Short Description:''' Make on-screen urls clickable, opening the link in your browser.<br />
----<br />
'''Name:''' Tabbed Chat w/ blinking tabs<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1662<br><br />
'''Short Description:''' Capture channel communication to a miniconsole, with the tabs blinking on new text.<br />
----<br />
'''Name:''' Lusternia Fancy GUI<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1180<br><br />
'''Short Description:''' Make Mudlet look similar to Nexus in Lusternia for familiarity's sake.<br />
----<br />
'''Name:''' Achaea Fancy GUI<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=981<br><br />
'''Short Description:''' Make Mudlet look similar to Nexus in Achaea for familiarity's sake.<br />
----<br />
'''Name:''' Achaea, Inventory Organizer <br><br />
'''Author:''' mortagona <br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2286<br><br />
'''Short Description:''' Organize your inventory in Achaea into a clean more easily read format.<br />
----<br />
'''Name:''' Vadi Sipper for Achaea<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=125<br><br />
'''Short Description:''' A basic sipper for Achaea.<br />
----<br />
'''Name:''' Find alias #1<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1233<br><br />
'''Short Description:''' Search through your mudlet window for a specific text.<br />
----<br />
'''Name:''' MAG - Mudlet Aardwolf GUI <br><br />
'''Author:''' lex<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1471<br><br />
'''Short Description:''' GUI made specifically for Aardwolf<br />
----<br />
'''Name:''' Simple Logger<br><br />
'''Author:''' Wyd<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1424<br><br />
'''Short Description:''' Log either specific text or log a section of a mudlet session.<br />
----<br />
'''Name:''' Enemy Script<br><br />
'''Author:''' ThePhoenix<br><br />
'''Link:''' http://dl.dropbox.com/u/22569276/EnemyScript.xml<br><br />
'''Short Description:''' API is included in the script. This is used on Achaea (and possibly other IREs) to enemy groups of people at a time, especially based off a party call of (Party): Leader says, "Enemies: person, person, person."<br />
----<br />
'''Name:''' (Achaea) Gag others breathing<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1520<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' (Achaea) Compress tramples<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1521<br><br />
'''Short Description:''' Compresses full-screen tramples into something more manageable.<br />
----<br />
'''Name:''' Send random commands<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=1234<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' `echo test triggers from input line alias<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=1478<br><br />
'''Short Description:''' This allows for testing triggers from the command line.<br />
----<br />
'''Name:''' Screen shake on critical hits<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1400<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' Find RGB color of MUD text<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1302<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' Get wildcards by color<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1282<br><br />
'''Short Description:'''<br />
----<br />
'''Name:''' Repeat Alias<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1275<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Category:Mudlet_Package_Listing&diff=654Category:Mudlet Package Listing2011-07-27T21:40:59Z<p>Rayth: /* Achaea */</p>
<hr />
<div>=Mudlet Packages=<br />
==Current MUDs with listed packages==<br />
* Achaea<br />
* Aetolia<br />
* God Wars II<br />
* Imperian<br />
* Lusternia<br />
* Midkemia Online<br />
<br />
=Package listing by MUD=<br />
==Achaea==<br />
# [[RiftTracker|Rift Tracker]]<br />
# [[Enemy_Highlighter|Enemy Highlighter]]<br />
# [[ShardCounter| Shard Counter]]<br />
# [[Sacrificer| Sacrificer]]<br />
<br />
==Aetolia==<br />
==God Wars II==<br />
==Imperian==<br />
==Lusternia==<br />
==Midkemia Online==<br />
==Non-specific packages==<br />
# [[IRE mapping script|IRE Mapping Script]]<br />
# [[Misc Scripts]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Enemy_Highlighter&diff=614Enemy Highlighter2011-07-27T01:42:59Z<p>Rayth: </p>
<hr />
<div>==Package Info==<br />
By: [[User:Phoenix| ThePhoenix]]<br />
<br />
For(MUD): [http://www.achaea.com Achaea]<br />
<br />
Size: 4kb<br />
<br />
Website: http://dl.dropbox.com/u/22569276/EnemyHighlighter.zip<br />
<br />
Version: 1.3<br />
<br />
Contents: EnemyHighlighter.xml<br />
<br />
Summary/Description: This system has one alias, which will allow you to colour the enemies for any Achaean organisation. Simply use 'enhi <enemy checking command>' to check them. For example, to highlight the enemies of your city, you would do 'enhi city enemies'. <br />
<br />
The code is fully commented, allowing you to easily make enemies for different orgs show up different colours. Pretty much the only place you'd need to edit in the code would be between lines 5 and 9 in EnemyList trigger, adding orgs or changing the default easily, based on the templates.<br />
<br />
Related Packages: None.<br />
<br />
Other Packages made by this Package Author:<br />
* [[RiftTracker| Rift Tracker 2.1]]<br />
<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Category:Mudlet_Package_Listing&diff=602Category:Mudlet Package Listing2011-07-26T06:59:28Z<p>Rayth: </p>
<hr />
<div>=Mudlet Packages=<br />
==Current MUDs with listed packages==<br />
* Achaea<br />
* Aetolia<br />
* God Wars II<br />
* Imperian<br />
* Lusternia<br />
* Midkemia Online<br />
<br />
=Package listing by MUD=<br />
==Achaea==<br />
# [[RiftTracker|Rift Tracker]]<br />
<br />
==Aetolia==<br />
==God Wars II==<br />
==Imperian==<br />
==Lusternia==<br />
==Midkemia Online==<br />
==Non-specific packages==<br />
# [[IRE mapping script|IRE Mapping Script]]<br />
# [[Misc Scripts]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Category:Mudlet_Package_Listing&diff=601Category:Mudlet Package Listing2011-07-26T06:57:47Z<p>Rayth: /* Achaea */</p>
<hr />
<div>=Mudlet Packages=<br />
==Current MUDs with listed packages==<br />
* Achaea<br />
* Aetolia<br />
* God Wars II<br />
* Imperian<br />
* Lusternia<br />
* Midkemia Online<br />
<br />
=Package listing by MUD=<br />
==Achaea==<br />
# Rift Tracker<br />
<br />
==Aetolia==<br />
==God Wars II==<br />
==Imperian==<br />
==Lusternia==<br />
==Midkemia Online==<br />
==Non-specific packages==<br />
# [[IRE mapping script|IRE Mapping Script]]<br />
# [[Misc Scripts]]</div>Raythhttps://wiki.mudlet.org/index.php?title=RiftTracker&diff=599RiftTracker2011-07-26T06:56:39Z<p>Rayth: </p>
<hr />
<div>==Package Info==<br />
By: The Phoenix<br />
<br />
For(MUD): [http://www.achaea.com Achaea]<br />
<br />
Size: 8kb<br />
<br />
Website: http://dl.dropbox.com/u/22569276/PhoenixRiftScript.zip<br />
<br />
Version: 2.1<br />
<br />
Contents: Script.xml, Triggers.xml, Aliases.xml <br />
<br />
Summary/Description: The rift is sorted by type, and within each type it is sorted alphabetically. Any one group of items is ignorable on 'ir'. You can use 'ir group' to see a specific group, whether or not it is disabled. Currently, anything below 750 will be coloured red, though this will be changeable in future versions by group. Within the system, the 'ir help' alias will give you more information on the aliases to use. There is no API for this system.<br />
<br />
[[File:RiftTracker.png]]<br />
<br />
Related Packages: Currently none, though addons are being made for it.<br />
<br />
Other Packages made by this Package Author:<br />
<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Lua_Functions&diff=569Manual:Lua Functions2011-07-22T16:08:50Z<p>Rayth: /* table.size */</p>
<hr />
<div>== Function Categories ==<br />
'''Standard Functions''': These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
'''UI Functions''': These functions are used to construct custom user GUIs. They deal mainly with miniconsole/label/gauge creation and manipulation.<br />
<lua><br />
createMiniConsole()<br />
createLabel()<br />
createGauge()<br />
</lua><br />
<br />
'''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.<br />
<br />
'''String Functions'''<br />
<br />
'''Scripting Object Functions'''<br />
<br />
'''Mapper Functions'''<br />
<br />
'''Miscellaneous Functions'''<br />
<br />
== Variables ==<br />
The following variables are provided by Mudlet:<br />
<br><br><br />
;line <br />
:This variable holds the content of the current line that is being processed by the trigger engine. The engine runs all triggers on each line as it arrives from the MUD.<br />
;command <br />
:This variable holds the current user command. This is typically used in alias scripts.<br />
;matches[n]<br />
:This Lua table is being used by Mudlet in the context of triggers that use Perl regular expressions. matches[1] holds the entire match, matches[2] holds the first capture group, matches[n] holds the nth-1 capture group. If the trigger uses the Perl style /g switch to evaluate all possible matches of the given regex within the current line, matches[n+1] will hold the second entire match, matches[n+2] the first capture group of the second match and matches[n+m] the m-th capture group of the second match.<br />
;multimatches[n][m]<br />
:This table is being used by Mudlet in the context of multiline triggers that use Perl regular expression. It holds the table matches[n] as described above for each Perl regular expression based condition of the multiline trigger. multimatches[5][4] may hold the 3rd capture group of the 5th regex in the multiline trigger. This way you can examine and process all relevant data within a single script. Have a look at this example.<br />
= Standard Functions =<br />
: These functions are generic functions used in normal scripting. These deal with mainly everyday things, like sending stuff and echoing to the screen.<br />
<br />
==send==<br />
;send( command, echo the value = true/false )<br />
:This sends "command" directly to the network layer, skipping the alias matching. The optional second argument of type boolean (print) determines if the outgoing command is to be echoed on the screen.<br />
:If you want your command to be checked if it’s an alias, use expandAlias() instead. example:<br />
<lua><br />
send( "Hello Jane" ) --echos the command on the screen<br />
send( "Hello Jane", true ) --echos the command on the screen<br />
send( "Hello Jane", false ) --does not echo the command on the screen<br />
</lua><br />
==echo==<br />
;echo( windowName, text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==echoLink==<br />
;echoLink([windowName], text, command, hint, [bool use_current_format or defaultLinkFormat])<br />
:Echos a piece of text as a clickable link.<br />
:text - text to display in the echo. Same as a normal echo().<br />
:command - lua code to do when the link is clicked.<br />
:hint - text for the tooltip to be displayed when the mouse is over the link.<br />
:boolean - if true, then the link will use the current selection style (colors, underline, etc). If missing or false, it will use the default link style - blue on black underlined text.<br />
<br />
= UI Functions =<br />
<br />
<br />
==echo==<br />
;echo( [windowName,] text )<br />
:This function appends text at the end of the current line. The current cursor position is ignored. Use moveCursor() and insertText() if you want to print at a different cursor position.<br />
:If the first argument is omitted the main console is used, otherwise the mini console windowName. === Example 1:<br />
<lua><br />
echo( "Hello world\n" ) -- writes "Hello world" to the main screen.<br />
echo( "info", "Hello this is the info window" ) -- writes text to the mini console named "info" if such a window exists<br />
</lua><br />
==appendBuffer==<br />
;appendBuffer(name)<br />
: Pastes the previously copied rich text (including text formats like color etc.) into user window name. <br />
: See also: [[Manual:Lua_Functions#paste|paste]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to paste into. Passed as a string.<br />
<br />
;Examples<br />
<lua><br />
--selects and copies an entire line to user window named "Chat"<br />
selectCurrentLine()<br />
copy()<br />
appendBuffer("Chat")<br />
</lua><br />
<br />
==bg==<br />
;bg(colorName)<br />
: Changes the background color of the text. Useful for highlighting text. <br />
: See Also: [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the background to. [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Example<br />
<lua><br />
--This would change the background color of the text on the current line to magenta<br />
selectCurrentLine()<br />
bg("magenta")<br />
</lua><br />
<br />
==calcFontSize==<br />
;calcFontSize(fontSize)<br />
: Used to calculate the number of pixels wide and high a character would be on a mini console at fontSize.<br />
: Returns two numbers, width/height<br />
: See Also: [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]]<br />
<br />
;Parameters<br />
* ''fontSize:''<br />
: The font size you are wanting to calculate pixel sizes for. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--this snippet will calculate how wide and tall a miniconsole designed to hold 4 lines of text 20 characters wide <br />
--would need to be at 9 point font, and then changes miniconsole Chat to be that size<br />
local width,height = calcFontSize(9)<br />
width = width * 20<br />
height = height * 4<br />
resizeWindow("Chat", width, height)<br />
</lua><br />
<br />
==clearUserWindow==<br />
;clearUserWindow(name)<br />
: Clears the window or miniconsole with the name given as argument.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearUserWindow("Chat")<br />
</lua><br />
<br />
==clearWindow==<br />
;clearWindow(name)<br />
: Clears the window or miniconsole with the name given as argument. <br />
: See also: [[Manual:Lua_Functions#clearUserWindow|clearUserWindow]]<br />
<br />
;Parameters<br />
* name: <br />
: The name of the user window to clear. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
--This would clear a label, user window, or miniconsole with the name "Chat"<br />
clearWindow("Chat")<br />
</lua><br />
<br />
==createBuffer==<br />
;createBuffer(name)<br />
: Creates a named buffer for formatted text, much like a miniconsole, but the buffer cannot be shown on the screen. Intended for temporary use in the formatting of text.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer to create.<br />
<br />
Examples<br />
<lua><br />
--This creates a named buffer called "scratchpad"<br />
createBuffer("scratchpad")<br />
</lua><br />
<br />
==createConsole==<br />
;createConsole(consoleName, fontSize, charsPerLine, numberOfLines, Xpos, Ypos)<br />
: Makes a new miniconsole. The background will be black, and the text color white.<br />
<br />
;Parameters<br />
* ''consoleName:''<br />
: The name of your new miniconsole. Passed as a string.<br />
* ''fontSize:''<br />
: The font size to use for the miniconsole. Passed as an integer number.<br />
* ''charsPerLine:''<br />
: How many characters wide to make the miniconsole. Passed as an integer number.<br />
* ''numberOfLines:''<br />
: How many lines high to make the miniconsole. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
-- this will create a console with the name of "myConsoleWindow", font size 8, 80 characters wide, <br />
-- 20 lines high, at coordinates 300x,400y<br />
createConsole("myConsoleWindow", 8, 80, 20, 200, 400)<br />
</lua><br />
<br />
==createGauge==<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, r, g, b)<br />
;createGauge(name, width, Xpos, Ypos, gaugeText, colorName)<br />
: Creates a gauge that you can use to express completion with. For example, you can use this as your healthbar or xpbar.<br />
: See also: [[Manual:Lua_Functions#moveGauge|moveGauge]], [[Manual:Lua_Functions#setGauge|setGauge]], [[Manual:Lua_Functions#setGaugeText|setGaugeText]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the gauge. Must be unique, you can not have two or more gauges with the same name. Passed as a string.<br />
* ''width:''<br />
: The width of the gauge, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the gauge, in pixels. Passed as an integer number.<br />
* ''Xpos:''<br />
: X position of gauge. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of gauge. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''gaugeText:''<br />
: Text to display on the gauge. Passed as a string, unless you do not wish to have any text, in which case you pass nil<br />
* ''r:''<br />
: The red component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''g:''<br />
: The green component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''b:''<br />
: The blue component of the gauge color. Passed as an integer number from 0 to 255<br />
* ''colorName:''<br />
: the name of color for the gauge. Passed as a string.<br />
<br />
Examples<br />
<lua><br />
-- This would make a gauge at that's 300px width, 20px in height, located at Xpos and Ypos and is green.<br />
-- The second example is using the same names you'd use for something like [[fg]]() or [[bg]]().<br />
createGauge("healthBar", 300, 20, 30, 300, nil, 0, 255, 0)<br />
createGauge("healthBar", 300, 20, 30, 300, nil, "green")<br />
<br />
<br />
-- If you wish to have some text on your label, you'll change the nil part and make it look like this:<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", 0, 255, 0)<br />
-- or<br />
createGauge("healthBar", 300, 20, 30, 300, "Now with some text", "green")<br />
</lua><br />
<br />
==createLabel==<br />
;createLabel(name, Xpos, Ypos, width, height, fillBackground)<br />
: Creates a highly manipulable overlay which can take some css and html code for text formatting. Labels are clickable, and as such can be used as a sort of button. Labels are meant for small variable or prompt displays, messages, images, and the like. You should not use them for larger text displays or things which will be updated rapidly and in high volume, as they are much slower than miniconsoles.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setLabelClickCallback|setLabelClickCallback]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|setTextFormat]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#setBackgroundColor|setBackgroundColor]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the label. Must be unique, you can not have two or more labels with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the label. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the label. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the label, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the label, in pixels. Passed as an integer number.<br />
* ''fillBackground:''<br />
: Whether or not to display the background. Passed as either 1 or 0. 1 will display the background color, 0 will not.<br />
<br />
Examples<br />
<lua><br />
--This example creates a transparent overlay message box to show a big warning message "You are under attack!" in the middle <br />
--of the screen. Because the background color has a transparency level of 150 (0-255, with 0 being completely transparent <br />
--and 255 non-transparent) the background text can still be read through. The message box will disappear after 2.3 seconds.<br />
local width, height = getMainWindowSize();<br />
createLabel("messageBox",(width/2)-300,(height/2)-100,250,150,1);<br />
resizeWindow("messageBox",500,70);<br />
moveWindow("messageBox", (width/2)-300,(height/2)-100 );<br />
setBackgroundColor("messageBox", 150,100,100,200);<br />
echo("messageBox", [[<p style="font-size:35px"><b><center><font color="red">You are under attack!</font></center></b></p>]] );<br />
showWindow("messageBox");<br />
tempTimer(2.3, [[hideWindow("messageBox")]] ) -- close the warning message box after 2.3 seconds<br />
</lua><br />
<br />
==createMiniConsole==<br />
;createMiniConsole(name, posX, posY, width, height)<br />
: Opens a miniconsole window inside the main window of Mudlet. This is the ideal fast colored text display for everything that requires a bit more text, such as status screens, chat windows, etc. <br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#createLabel|createLabel]], [[Manual:Lua_Functions#hideWindow|hideWindow]], [[Manual:Lua_Functions#showWindow|showWindow]], [[Manual:Lua_Functions#resizeWindow|resizeWindow]], [[Manual:Lua_Functions#setTextFormat|setTextFormat]], [[Manual:Lua_Functions#moveWindow|moveWindow]], [[Manual:Lua_Functions#setMiniConsoleFontSize|setMiniConsoleFontSize]], [[Manual:Lua_Functions#handleWindowResizeEvent|handleWindowResizeEvent]], [[Manual:Lua_Functions#setBorderTop|setBorderTop]], [[Manual:Lua_Functions#setWindowWrap|setWindowWrap]], [[Manual:Lua_Functions#getMainWindowSize|getMainWindowSize]], [[Manual:Lua_Functions#calcFontSize|calcFontSize]]<br />
<br />
;Parameters<br />
<br />
* ''name:''<br />
: The name of the miniconsole. Must be unique, you can not have two or more miniconsoles with the same name. Passed as a string.<br />
* ''Xpos:''<br />
: X position of the miniconsole. Measured in pixels, with 0 being the very left. Passed as an integer number.<br />
* ''Ypos:''<br />
: Y position of the miniconsole. Measured in pixels, with 0 being the very top. Passed as an integer number.<br />
* ''width:''<br />
: The width of the miniconsole, in pixels. Passed as an integer number.<br />
* ''height:''<br />
: The height of the miniconsole, in pixels. Passed as an integer number.<br />
<br />
Examples<br />
<lua><br />
--This script would create a mini text console called "sys" and write with yellow foreground color and blue background color <br />
--"Hello World".<br />
<br />
<br />
-- set up the small system message window in the top right corner<br />
-- determine the size of your screen<br />
WindowWidth = 0;<br />
WindowHeight = 0;<br />
WindowWidth, WindowHeight = getMainWindowSize();<br />
<br />
createMiniConsole("sys",WindowWidth-650,0,650,300)<br />
setBackgroundColor("sys",85,55,0,255)<br />
setMiniConsoleFontSize("sys", 8)<br />
-- wrap lines in window "sys" at 40 characters per line<br />
setWindowWrap("sys", 40)<br />
-- set default font colors and font style for window "sys"<br />
setTextFormat("sys",0,35,255,50,50,50,0,0,0)<br />
<br />
echo("sys","Hello world!")<br />
</lua><br />
<br />
==deleteLine==<br />
;deleteLine()<br />
: Deletes the current line under the user cursor. This is a high speed gagging tool and is very good at this task, but is only meant to be use when a line should be omitted entirely in the output. If you echo() to that line it will not be shown, and lines deleted with deleteLine() are simply no longer rendered. For replacing text, replace() is the proper option.<br />
: See Also: [[Manual:Lua_Functions#replace|replace]], [[Manual:Lua_Functions#wrapLine|wrapLine]]<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--This example creates a temporary line trigger to test if the next line is a prompt, and if so gags it entirely.<br />
--This can be useful for keeping a pile of prompts from forming if you're gagging chat channels in the main window<br />
--Note: isPrompt() only works on servers which send a GA signal with their prompt.<br />
tempLineTrigger(1, 1, [[if isPrompt() then deleteLine() end]])<br />
</lua><br />
<br />
==deselect==<br />
;deselect(name)<br />
: This is used to clear the current selection (to no longer have anything selected). Should be used after changing the formatting of text, to keep from accidentally changing the text again later with another formatting call.<br />
<br />
;Parameters<br />
* ''name:''<br />
: The name of the buffer/miniConsole to stop having anything selected in. This is an optional argument, if name is not provided the main window will have its selection cleared. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will change the background on an entire line in the main window to red, and then properly clear the selection to keep further <br />
--changes from effecting this line as well.<br />
selectCurrentLine()<br />
bg("red")<br />
deselect()<br />
</lua><br />
<br />
==fg==<br />
; fg(colorName)<br />
: If used on a selection, sets the foreground color to ''colorName'' - otherwise, it will set the color of the next text-inserting calls (''echo(), insertText, echoLink()'', and others)<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#setBgColor|setBgColor]]<br />
<br />
;Parameters<br />
* ''colorName:''<br />
: The name of the color to set the foreground to - list of possible names: [[File:ShowColors.png|50px|frameless|Color Table]]<br />
<br />
;Examples<br />
<lua><br />
--This would change the color of the text on the current line to green<br />
selectCurrentLine()<br />
fg("green")<br />
resetFormat()<br />
<br />
--This will echo red, green, blue in their respective colors<br />
fg("red")<br />
echo("red ")<br />
fg("green")<br />
echo("green ")<br />
fg("blue")<br />
echo("blue ")<br />
resetFormat()<br />
</lua><br />
<br />
==getMainWindowSize==<br />
;getMainWindowSize()<br />
: Returns two numbers, the width and height in pixels.<br />
<br />
;No Parameters<br />
<br />
;Example<br />
<lua><br />
--this will get the size of your main mudlet window and save them <br />
--into the variables mainHeight and mainWidth<br />
mainWidth, mainHeight = getMainWindowSize()<br />
</lua><br />
<br />
<br />
==resetFormat==<br />
;resetFormat()<br />
: Resets the colour/bold/italics formatting. Always use this function when done adjusting formatting, so make sure what you've set doesn't 'bleed' onto other triggers/aliases.<br />
<br />
;Example<br />
<lua><br />
-- select and set the 'Tommy' to red in the line<br />
if selectString("Tommy", 1) ~= -1 then fg("red") end<br />
<br />
-- now reset the formatting, so our echo isn't red<br />
resetFormat()<br />
echo(" Hi Tommy!")<br />
<br />
-- another example: just highlighting some words<br />
for _, word in ipairs{"he", "she", "her", "their"} do<br />
if selectString(word, 1) ~= -1 then<br />
bg("blue")<br />
end<br />
end<br />
resetFormat()<br />
</lua><br />
<br />
= Table Functions =<br />
<br />
==table.complement==<br />
; table.complement (set1, set2)<br />
: Returns a table that is the relative complement of the first table with respect to the second table. Returns a complement of key/value pairs.<br />
<br />
; Parameters<br />
* ''table1:''<br />
* ''table2:''<br />
<br />
; Example:<br />
<lua></lua><br />
<br />
==table.concat==<br />
;table.concat(table, delimiter, startingindex, endingindex)<br />
: Joins a table into a string. Each item must be something which can be transformed into a string. <br />
: Returns the joined string.<br />
: See also: [[Manual:Lua_Functions#string.split|string.split]]<br />
<br />
;Parameters<br />
* table:<br />
: The table to concatenate into a string. Passed as a table.<br />
* delimiter:<br />
: Optional string to use to separate each element in the joined string. Passed as a string.<br />
* startingindex:<br />
: Optional parameter to specify which index to begin the joining at. Passed as an integer.<br />
* endingindex:<br />
: Optional parameter to specify the last index to join. Passed as an integer.<br />
<br />
;Examples<br />
<lua><br />
--This shows a basic concat with none of the optional arguments<br />
testTable = {1,2,"hi","blah",}<br />
testString = table.concat(testTable)<br />
--testString would be equal to "12hiblah"<br />
<br />
--This example shows the concat using the optional delimiter<br />
testString = table.concat(testTable, ", ")<br />
--testString would be equal to "1, 2, hi, blah"<br />
<br />
--This example shows the concat using the delimiter and the optional starting index<br />
testString = table.concat(testTable, ", ", 2)<br />
--testString would be equal to "2, hi, blah"<br />
<br />
--And finally, one which uses all of the arguments<br />
testString = table.concat(testTable, ", ", 2, 3)<br />
--testString would be equal to "2, hi"<br />
</lua><br />
<br />
==table.contains==<br />
; table.contains (t, value)<br />
: Determines if a table contains a value as a key or as a value (recursive).<br />
: Returns true or false<br />
<br />
; Parameters<br />
* ''t:'' <br />
: The table in which you are checking for the presence of the value.<br />
* ''value:'' <br />
: The value you are checking for within the table.<br />
<br />
; Example:<br />
<lua>local test_table = { "value1", "value2", "value3", "value4" }<br />
if table.contains(test_table, "value1") then <br />
echo("Got value 1!")<br />
else<br />
echo("Don't have it. Sorry!")<br />
end<br />
</lua><br />
This example would always echo the first one, unless you remove value1 from the table.<br />
<br />
==table.foreachi==<br />
==table.foreach==<br />
==table.getn==<br />
==table.intersection==<br />
==table.insert==<br />
==table.index_of==<br />
==table.is_empty==<br />
==table.load==<br />
==table.maxn==<br />
==table.n_union==<br />
==table.n_complement==<br />
==table.n_intersection==<br />
==table.pickle==<br />
==table.remove==<br />
==table.save==<br />
==table.sort==<br />
==table.size==<br />
; table.size (t)<br />
: Gets the actual size of non-index based tables.<br />
: Returns a number.<br />
<br />
; Parameters<br />
* ''t:'' The table you are checking the size of.<br />
<table width="100%" frame="box"><br />
<caption>'''Note:'''</caption><br />
<tr><br />
<td><br />
For index based tables you can get the size with the # operator:<br />
This is the standard Lua way of getting the size of index tables i.e. ipairs() type of tables with numerical indices. <br />
To get the size of tables that use user defined keys instead of automatic indices (pairs() type) you need to use the function table.size() referenced above.<br />
</td><br />
</tr><br />
</table><br />
; Example<br />
<lua><br />
local test_table = { "value1", "value2", "value3", "value4" }<br />
myTableSize = #test_table<br />
-- This would return 4.<br />
local myTable = { 1 = "hello", "key2" = "bye", "key3" = "time to go" }<br />
table.size(myTable)<br />
-- This would return 3.<br />
</lua><br />
<br />
==table.setn==<br />
==table.unpickle==<br />
==table.update==<br />
==table.union==<br />
<br />
= String Functions =<br />
==string.byte==<br />
<br />
==string.char==<br />
<br />
==string.cut==<br />
;string.cut(string, maxLen)<br />
: Cuts string to the specified maximum length.<br />
: Returns the modified string.<br />
<br />
;Parameters:<br />
* ''string:''<br />
: The text you wish to cut. Passed as a string.<br />
* maxLen<br />
: The maximum length you wish the string to be. Passed as an integer number.<br />
<br />
;Example<br />
<lua><br />
--The following call will return 'abc' and store it in myString<br />
mystring = string.cut("abcde", 3)<br />
--You can easily pad string to certain length. Example below will print 'abcde ' e.g. pad/cut string to 10 characters.<br />
local s = "abcde"<br />
s = string.cut(s .. " ", 10) -- append 10 spaces<br />
echo("'" .. s .. "'")<br />
</lua><br />
<br />
==string.dump==<br />
<br />
==string.enclose==<br />
;string.enclose(String)<br />
: Wraps a string with [[ ]]<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String: The string to enclose. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will echo '[[Oh noes!]]' to the main window<br />
echo("'" .. string.enclose("Oh noes!") .. "'")<br />
</lua><br />
<br />
==string.ends==<br />
;string.ends(String, Suffix)<br />
: Test if string is ending with specified suffix.<br />
: Returns true or false.<br />
: See also: [[Manual:Lua_Functions#string.starts|string.starts]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string.<br />
* ''Suffix:''<br />
: The suffix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This will test if the incoming line ends with "in bed" and if not will add it to the end.<br />
if not string.ends(line, "in bed") then<br />
echo("in bed\n")<br />
end<br />
</lua><br />
<br />
==string.find==<br />
<br />
==string.findPattern==<br />
string.findPattern(text, pattern)<br />
Return first matching substring or nil.<br />
<br />
Parameters<br />
text:<br />
pattern:<br />
<br />
Usage:<br />
Following example will print: "I did find: Troll" string.<br />
<lua><br />
local match = string.findPattern("Troll is here!", "Troll")<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
</lua><br />
This example will find substring regardless of case.<br />
local match = string.findPattern("Troll is here!", string.genNocasePattern("troll"))<br />
if match then<br />
echo("I did find: " .. match)<br />
end<br />
<br />
Return value:<br />
nil or first matching substring <br />
<br />
See also:<br />
[[Manual:Lua_Functions#string.genNocasePattern|string.genNocasePattern()]]<br />
<br />
==string.format==<br />
<br />
==string.genNocasePattern==<br />
string.genNocasePattern(s)<br />
<br />
Generate case insensitive search pattern from string.<br />
<br />
Parameters<br />
s:<br />
<br />
Usage:<br />
Following example will generate and print "123[aA][bB][cC]" string.<br />
echo(string.genNocasePattern("123abc"))<br />
<br />
Return value:<br />
case insensitive pattern string <br />
==string.gfind==<br />
<br />
==string.gmatch==<br />
<br />
==string.gsub==<br />
<br />
==string.len==<br />
<br />
==string.lower==<br />
<br />
==string.match==<br />
<br />
==string.rep==<br />
<br />
==string.reverse==<br />
<br />
<br />
==string.split==<br />
;string.split(String, delimiter)<br />
;<nowiki>myString:split(delimiter)</nowiki><br />
: Splits a string into a table by the given delimiter. Can be called against a string (or variable holding a string) using the second form above.<br />
: Returns a table containing the split sections of the string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to split. Parameter is not needed if using second form of the syntax above. Passed as a string.<br />
* ''delimiter:''<br />
: The delimiter to use when splitting the string. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
-- This will split the string by ", " delimiter and print the resulting table to the main window.<br />
names = "Alice, Bob, Peter"<br />
name_table = string.split(names, ", ")<br />
display(name_table)<br />
<br />
--The alternate method<br />
names = "Alice, Bob, Peter"<br />
name_table = names:split(", ")<br />
display(name_table)<br />
</lua><br />
<br />
Either method above will print out:<br />
table {<br />
1: 'Alice'<br />
2: 'Bob'<br />
3: 'Peter'<br />
}<br />
<br />
==string.starts==<br />
;string.starts(String, Prefix)<br />
: Test if string is starting with specified prefix.<br />
: Returns true or false<br />
: See also: [[Manual:Lua_Functions#string.ends|string.ends]]<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to test. Passed as a string. <br />
* ''Prefix:''<br />
: The prefix to test for. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--The following will see if the line begins with "You" and if so will print a statement at the end of the line<br />
if string.starts(line, "You") then<br />
echo("====oh you====\n")<br />
end<br />
</lua><br />
<br />
==string.sub==<br />
<br />
==string.title==<br />
;string.title(String)<br />
;<nowiki>string:title()</nowiki><br />
: Capitalizes the first character in a string.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* String<br />
: The string to modify. Not needed if you use the second form of the syntax above.<br />
<br />
;Example<br />
<lua><br />
--Variable testname is now Anna.<br />
testname = string.title("anna")<br />
--Example will set test to "Bob".<br />
test = "bob"<br />
test = test:title()<br />
</lua><br />
<br />
==string.trim==<br />
;string.trim(String)<br />
: Trims String, removing all 'extra' white space at the beginning and end of the text.<br />
: Returns the altered string.<br />
<br />
;Parameters:<br />
* ''String:''<br />
: The string to trim. Passed as a string.<br />
<br />
;Example:<br />
<lua><br />
--This will print 'Troll is here!', without the extra spaces.<br />
local str = string.trim(" Troll is here! ")<br />
echo("'" .. str .. "'")<br />
</lua><br />
<br />
==string.upper==<br />
<br />
= Mudlet Object Functions =<br />
==tempTimer==<br />
;tempTimer(time, code to do)<br />
Creates a temporary single shot timer and returns the timer ID for subsequent enableTimer(), disableTimer() and killTimer() calls. You can use 2.3 seconds or 0.45 etc. After it has fired, the timer will be deactivated and killed. <br />
<br />
;Parameters<br />
* ''time:'' the time in seconds for which to set the timer for<br />
* ''code to do'': the code to do when the timer is up - wrap it in [[ ]], or provide a Lua function<br />
<br />
;Examples<br />
<lua><br />
-- wait half a second and then run the command<br />
tempTimer( 0.5, [[send("kill monster")]] )<br />
<br />
-- or an another example - two ways to 'embed' variable in a code for later:<br />
local name = matches[2]<br />
tempTimer(2, [[send("hello, ]]..name..[[ !")]])<br />
-- or:<br />
tempTimer(2, function()<br />
send("hello, "..name)<br />
end)<br />
</lua><br />
<br />
;Note<br />
[[ ]] can be used to quote strings in Lua. The difference to the usual `" " quote syntax is that `[[ ]] also accepts the character ". Consequently, you don’t have to escape the " character in the above script. The other advantage is that it can be used as a multiline quote, so your script can span several lines.<br />
Also note that the Lua code that you provide as an argument is compiled from a string value when the timer fires. This means that if you want to pass any parameters by value e.g. you want to make a function call that uses the value of your variable myGold as a parameter you have to do things like this:<br />
<br />
<lua><br />
tempTimer( 3.8, [[echo("at the time of the tempTimer call I had ]] .. myGold .. [[ gold.")]] )<br />
tempTimer also accepts functions (and thus closures) - which can be an easier way to embed variables and make the code for timers look less messy:<br />
<br />
local variable = matches[2]<br />
tempTimer(3, function () send("hello, " .. variable) end)<br />
</lua><br />
<br />
==permGroup==<br />
permGroup(name, itemtype)<br />
<br />
Creates a new group of a given type at the root level (not nested in any other groups). This group will persist through Mudlet restarts.<br />
<br />
<sub>Added to Mudlet in the 2.0 final release.</sub><br />
<br />
<lua><br />
--create a new trigger group<br />
permGroup("Combat triggers", "trigger")<br />
<br />
--create a new alias group only if one doesn't exist already<br />
if exists("Defensive aliases", "alias") == 0 then<br />
permGroup("Defensive aliases", "alias")<br />
end<br />
</lua><br />
<br />
= Mapper Functions =<br />
These are functions that are to be used with the Mudlet Mapper. The mapper is designed to be MUD-generic - it only provides the display and pathway calculations, to be used in Lua scripts that are tailored to the MUD you're playing. For a collection of pre-made scripts and general mapper talk, visit the [http://forums.mudlet.org/viewforum.php?f=13 mapper section] of the forums.<br />
<br />
To register a script as a mapping one with Mudlet (so Mudlet knows the profile has one and won't bother the user when they open the map), please do this in your script:<br />
<br />
<lua><br />
mudlet = mudlet or {}; mudlet.mapper_script = true<br />
</lua><br />
<br />
<br />
==addAreaName==<br />
areaID = addAreaName(areaName)<br />
<br />
Adds a new area name and returns the new area ID for the new name. If the name already exists, -1 is returned.<br />
: See also: [[Manual:Lua_Functions#deleteArea|deleteArea]]<br />
<br />
<lua><br />
local newID = addAreaName("My house")<br />
<br />
if newID == -1 then echo("That area name is already taken :(\n")<br />
else echo("Created new area with the ID of "..newid..".\n") end<br />
</lua><br />
<br />
==addRoom==<br />
addRoom(roomID)<br />
<br />
Creates a new room with the given ID, returns true if the room was successfully created.<br />
: See also: [[Manual:Lua_Functions#createRoomID|createRoomID]]<br />
<br />
<lua><br />
local newroomid = createRoomID()<br />
addRoom(newroomid)<br />
</lua><br />
<br />
==addSpecialExit==<br />
addSpecialExit(roomIDFrom, roomIDTo, command)<br />
<br />
Creates a one-way from one room to another, that will use the given command for going through them.<br />
: See also: [[Manual:Lua_Functions#clearSpecialExits|clearSpecialExits]]<br />
<br />
<lua><br />
-- sample alias pattern: ^spe (\d+) (.*?)$<br />
-- mmp.currentroom is your current room ID in this example<br />
addSpecialExit(mmp.currentroom,tonumber(matches[2]), matches[3])<br />
echo("\n SPECIAL EXIT ADDED TO ROOMID:"..matches[2]..", Command:"..matches[3])<br />
centerview(mmp.currentroom)<br />
</lua><br />
<br />
==centerview==<br />
centerview (roomID)<br />
<br />
Centers the map view onto the given room ID. The map must be open to see this take effect. This function can also be used to see the map of an area if you know the number of a room there and the area and room are mapped.<br />
<br />
==clearRoomUserData==<br />
clearRoomUserData(roomID)<br />
<br />
Clears all user data from a given room.<br />
: See also: [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]]<br />
<br />
<lua><br />
clearRoomUserData(341)<br />
</lua><br />
<br />
==clearSpecialExits==<br />
clearSpecialExits(roomID) <br />
<br />
Removes all special exits from a room.<br />
: See also: [[Manual:Lua_Functions#addSpecialExit|addSpecialExit]]<br />
<br />
<lua><br />
clearSpecialExits(1337)<br />
<br />
if #getSpecialExits(1337) == 0 then -- clearSpecialExits will neve fail on a valid room ID, this is an example<br />
echo("All special exits successfully cleared from 1337.\n")<br />
end<br />
</lua><br />
<br />
==createMapLabel==<br />
labelID = createMapLabel(areaID, text, posx, posy, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue)<br />
<br />
Creates a visual label on the map for all z-levels at given coordinates, with the given background and foreground colors. It returns a label ID that you can use later for deleting it.<br />
<br />
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 [[Manual:Lua_Functions#getRoomCoordinates|getRoomCoordinates]] will place the label near that room.<br />
: See also: [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]]<br />
<lua><br />
local labelid = createMapLabel( 50, "my map label", 0, 0, 255,0,0,23,0,0)<br />
</lua><br />
<br />
==createMapper==<br />
createMapper(x, y, width, height)<br />
<br />
Creates a miniconsole window for mapper to render in, the with the given dimensions. You can only create one at a time at the moment.<br />
<br />
<lua><br />
createMapper(0,0,300,300) -- creates a 300x300 mapper top-right of Mudlet<br />
setBorderLeft(305) -- adds a border so text doesn't underlap the mapper display<br />
</lua><br />
<br />
==createRoomID==<br />
usableId = createRoomID()<br />
<br />
Returns the lowest possible room ID you can use for creating a new room. If there are gaps in room IDs your map uses it, this function will go through the gaps first before creating higher IDs.<br />
: See also: [[Manual:Lua_Functions#addRoom|addRoom]]<br />
<br />
==deleteArea==<br />
deleteArea(areaID)<br />
<br />
Deletes the given area, permanently. This will also delete all rooms in it!<br />
: See also: [[Manual:Lua_Functions#addAreaName|addAreaName]]<br />
<br />
<lua><br />
deleteArea(23)<br />
</lua><br />
<br />
==deleteMapLabel==<br />
deleteMapLabel(areaID, labelID)<br />
<br />
Deletes a map label from a specfic area.<br />
: See also: [[Manual:Lua_Functions#createMapLabel|createMapLabel]]<br />
<lua><br />
deleteMapLabel(50, 1)<br />
</lua><br />
<br />
==deleteRoom==<br />
deleteRoom(roomID)<br />
<br />
Deletes an individual room, and unlinks all exits leading to and from it.<br />
<br />
<lua><br />
deleteRoom(335)<br />
</lua><br />
<br />
==getAreaRooms==<br />
getAreaRooms(area id)<br />
<br />
Returns an indexed table with all rooms IDs for a given area ID (room IDs are values), or ''nil'' if no such area exists. <br />
<br />
<sub>Note that on Mudlet versions prior to the 2.0 final release, this function would raise an error.</sub><br />
<br />
<lua><br />
-- using the sample findAreaID() function defined in the getAreaTable() example, <br />
-- we'll define a function that echo's us a nice list of all rooms in an area with their ID<br />
function echoRoomList(areaname)<br />
local id, msg = findAreaID(areaname)<br />
if id then<br />
local roomlist, endresult = getAreaRooms(id), {}<br />
<br />
-- obtain a room list for each of the room IDs we got<br />
for _, id in ipairs(roomlist) do<br />
endresult[id] = getRoomName(id)<br />
end<br />
<br />
-- now display something half-decent looking<br />
cecho(string.format(<br />
"List of all rooms in %s (%d):\n", msg, table.size(endresult)))<br />
<br />
for roomid, roomname in pairs(endresult) do<br />
cecho(string.format(<br />
"%6s: %s\n", roomid, roomname))<br />
end<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
end<br />
</lua><br />
<br />
==getAreaTable==<br />
getAreaTable()<br />
<br />
Returns a key(area name)-value(area id) table with all known areas and their IDs. There is an area with the name of '' and an ID of 0 included in it, you should ignore that.<br />
<br />
<lua><br />
-- example function that returns the area ID for a given area<br />
<br />
function findAreaID(areaname)<br />
local list = getAreaTable()<br />
<br />
-- iterate over the list of areas, matching them with substring match. <br />
-- if we get match a single area, then return it's ID, otherwise return<br />
-- 'false' and a message that there are than one are matches<br />
local returnid, fullareaname<br />
for area, id in pairs(list) do<br />
if area:find(areaname, 1, true) then<br />
if returnid then return false, "more than one area matches" end<br />
returnid = id; fullareaname = area<br />
end<br />
end<br />
<br />
return returnid, fullareaname<br />
end<br />
<br />
-- sample use:<br />
local id, msg = findAreaID("blahblah")<br />
if id then<br />
echo("Found a matching ID: " .. id")<br />
elseif not id and msg then<br />
echo("ID not found; " .. msg)<br />
else<br />
echo("No areas matched the query.")<br />
end<br />
</lua><br />
<br />
==getCustomEnvColorTable==<br />
envcolors = getCustomEnvColorTable()<br />
<br />
Returns a table with customized environments, where the key is the environment ID and the value is a indexed table of rgb values.<br />
<br />
<lua><br />
{<br />
envid1 = {r,g,b},<br />
envid2 = {r,g,b}<br />
}<br />
</lua><br />
<br />
==getMapLabels==<br />
arealabels = getMapLabels(areaID)<br />
<br />
Returns an indexed table (that starts indexing from 0) of all of the labels in the area, plus their label text. You can use the label id to [[Manual:Lua_Functions#deleteMapLabel|deleteMapLabel]] it.<br />
<br />
<lua><br />
display(getMapLabels(43))<br />
table {<br />
0: ''<br />
1: 'Svorai's grove'<br />
}<br />
<br />
deleteMapLabel(43, 0)<br />
display(getMapLabels(43))<br />
table {<br />
1: 'Svorai's grove'<br />
}<br />
</lua><br />
<br />
==getPath==<br />
getPath(roomID from, roomID to)<br />
<br />
Returns a boolean true/false if a path between two room IDs is possible. If it is, the global `speedWalkPath` table is set to all of the directions that have to be taken to get there, and the global `speedWalkDir` table is set to all of the roomIDs you'll encounter on the way.<br />
<br />
<lua><br />
-- check if we can go to a room - if yes, go to it<br />
if getPath(34,155) then<br />
gotoRoom(155)<br />
else<br />
echo("\nCan't go there!")<br />
end<br />
</lua><br />
<br />
==getRoomArea==<br />
areaID = getRoomArea(roomID)<br />
<br />
Returns the area ID of a given room ID. To get the area name, you can check the area ID against the data given by getAreaTable() function, or use the getRoomAreaName function.<br />
<br />
<sub>Note that if the room ID does not exist, this function will raise an error</sub><br />
<br />
<lua><br />
display("Area ID of room #100 is: "..getRoomArea(100))<br />
<br />
display("Area name for room #100 is: "..getRoomAreaName(getRoomArea(100)))<br />
</lua><br />
<br />
==getRoomAreaName==<br />
areaname = getRoomAreaName(areaID)<br />
<br />
Returns the area name for a given area id.<br />
<br />
<lua><br />
echo(string.format("room id #455 is in %s.", getRoomAreaName(getRoomArea(455))))<br />
</lua><br />
<br />
==getRoomCoordinates==<br />
x,y,z = getRoomCoordinates(room ID)<br />
<br />
Returns the room coordinates of the given room ID.<br />
<br />
<lua><br />
local x,y,z = getRoomCoordinates(roomID)<br />
echo("Room Coordinates for "..roomID..":")<br />
echo("\n X:"..x)<br />
echo("\n Y:"..y)<br />
echo("\n Z:"..z)<br />
</lua><br />
<br />
==getRoomEnv==<br />
envID = getRoomEnv(roomID)<br />
<br />
Returns the environment ID of a room. The mapper does not store environment names, so you'd need to keep track of which ID is what name yourself.<br />
<br />
<lua><br />
funtion checkID(id)<br />
echo(strinf.format("The env ID of room #%d is %d.\n", id, getRoomEnv(id)))<br />
end<br />
</lua><br />
<br />
== getRoomExits ==<br />
getRoomExits (roomID)<br />
Returns the currently known non-special exits for a room in an key-index form: ''exit = exitroomid'', ie:<br />
<br />
<lua><br />
table {<br />
'northwest': 80<br />
'east': 78<br />
}<br />
</lua><br />
<br />
==getRoomIDbyHash==<br />
roomID = getRoomIDbyHash(hash)<br />
<br />
Returns a room ID that is associated with a given hash in the mapper. This is primarily for MUDs that make use of hashes instead of room IDs (like [http://avalon.mud.de/index.php?enter=1 Avalon.de] MUD). ''-1'' is returned if no room ID matches the hash.<br />
<br />
<lua><br />
-- example taken from http://forums.mudlet.org/viewtopic.php?f=13&t=2177<br />
_id1 = getRoomIDbyHash( "5dfe55b0c8d769e865fd85ba63127fbc" );<br />
if _id1 == -1 then <br />
_id1 = createRoomID()<br />
setRoomIDbyHash( _id1, "5dfe55b0c8d769e865fd85ba63127fbc" )<br />
addRoom( _id )<br />
setRoomCoordinates( _id1, 0, 0, -1 )<br />
end<br />
</lua><br />
<br />
==getRoomName==<br />
roomName = getRoomName(roomID)<br />
<br />
Returns the room name for a given room id.<br />
<br />
<lua><br />
echo(string.format("The name of the room id #455 is %s.", getRoomname(455))<br />
</lua><br />
<br />
==getRooms==<br />
rooms = getRooms()<br />
<br />
Returns the list of '''all''' rooms in the map in an area in roomid - room name format.<br />
<br />
<lua><br />
-- simple, raw viewer for rooms in an area<br />
display(getRooms())<br />
</lua><br />
<br />
==getRoomsByPosition==<br />
getRoomsByPosition(areaID, x,y,z)<br />
<br />
Returns an indexed table of all rooms at the given coordinates in the given area, or an empty one if there are none. This function can be useful for checking if a room exists at certain coordinates, or whenever you have rooms overlapping.<br />
<br />
<lua><br />
-- sample script to determine a room nearby, given a relative direction from the current room<br />
local otherroom<br />
if matches[2] == "" then<br />
local w = matches[3]<br />
local ox, oy, oz, x,y,z = getRoomCoordinates(mmp.currentroom)<br />
local has = table.contains<br />
if has({"west", "left", "w", "l"}, w) then<br />
x = (x or ox) - 1; y = (y or oy); z = (z or oz)<br />
elseif has({"east", "right", "e", "r"}, w) then<br />
x = (x or ox) + 1; y = (y or oy); z = (z or oz)<br />
elseif has({"north", "top", "n", "t"}, w) then<br />
x = (x or ox); y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"south", "bottom", "s", "b"}, w) then<br />
x = (x or ox); y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"northwest", "topleft", "nw", "tl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"northeast", "topright", "ne", "tr"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) + 1; z = (z or oz)<br />
elseif has({"southeast", "bottomright", "se", "br"}, w) then<br />
x = (x or ox) + 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"southwest", "bottomleft", "sw", "bl"}, w) then<br />
x = (x or ox) - 1; y = (y or oy) - 1; z = (z or oz)<br />
elseif has({"up", "u"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) + 1<br />
elseif has({"down", "d"}, w) then<br />
x = (x or ox); y = (y or oy); z = (z or oz) - 1<br />
end<br />
<br />
local carea = getRoomArea(mmp.currentroom)<br />
if not carea then mmp.echo("Don't know what area are we in.") return end<br />
<br />
otherroom = select(2, next(getRoomsByPosition(carea,x,y,z)))<br />
<br />
if not otherroom then<br />
mmp.echo("There isn't a room to the "..w.." that I see - try with an exact room id.") return<br />
else<br />
mmp.echo("The room "..w.." of us has an ID of "..otherroom)<br />
end<br />
</lua><br />
<br />
==getRoomUserData==<br />
data = getRoomUserData(roomID, key (as a string))<br />
<br />
Returns the user data stored at a given room with a given key, or "" if none is stored. Use [[Manual:Lua_Functions#setRoomUserData|setRoomUserData]] for setting the user data.<br />
<br />
<lua><br />
display(getRoomUserData(341, "visitcount"))<br />
</lua><br />
<br />
==getRoomWeight==<br />
room weight = getRoomWeight(roomID)<br />
<br />
Returns the weight of a room. By default, all new rooms have a weight of 1.<br />
: See also: [[Manual:Lua_Functions#setRoomWeight|setRoomWeight]]<br />
<br />
<lua><br />
display("Original weight of room 541: "..getRoomWeight(541)<br />
setRoomWeight(541, 3)<br />
display("New weight of room 541: "..getRoomWeight(541)<br />
</lua><br />
<br />
==getSpecialExits==<br />
exits = getSpecialExits(roomID)<br />
<br />
Returns a roomid - command table of all special exits in the room. If there are no special exits in the room, the table returned will be empty.<br />
<br />
<lua><br />
getSpecialExits(1337)<br />
<br />
-- results in:<br />
--[[<br />
table {<br />
12106: 'faiglom nexus'<br />
}<br />
]]<br />
</lua><br />
<br />
==getSpecialExitsSwap==<br />
exits = getSpecialExitsSwap(roomID)<br />
<br />
Very similar to [[Manual:Lua_Functions#getSpecialExits|getSpecialExits]], but returns the rooms in the command - roomid style.<br />
<br />
==gotoRoom==<br />
gotoRoom (roomID)<br />
Speedwalks you to the given room from your current room if it is able and knows the way. You must turn the map on for this to work, else it will return "(mapper): Don't know how to get there from here :(". <br />
<br />
==hasExitLock==<br />
status = hasExitLock(roomID, direction)<br />
<br />
Returns ''true'' or ''false'' depending on whenever a given exit leading out from a room is locked. ''direction'' right now is a number that corresponds to the direction:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples:<br />
<lua><br />
-- check if the east exit of room 1201 is locked<br />
display(hasExitLock(1201, 4))<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#lockExit|lockExit]]<br />
<br />
==highlightRoom==<br />
highlightRoom( id, r1,g1,b1,r2,g2,b2, radius, alpha1, alpha2)<br />
<br />
Highlights a room with the given color, which will override it's environment color. If you use two different colors, then there'll be a shading from the center going outwards that changes into the other color. ''highlightRadius'' is the radius for the highlight circle - if you don't want rooms beside each other to over lap, use ''1'' as the radius. ''alphaColor1'' and ''alphaColor2'' are transparency values from 0 (completely transparent) to 255 (not transparent at all).<br />
<br />
: See also: [[Manual:Lua_Functions#unHighlightRoom|unHighlightRoom]]<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
-- color some room red to blue<br />
highlightRoom(351, unpack(color_table.red), unpack(color_table.blue), 1, 255, 255)<br />
<br />
-- or use a name from showColors(), gold in this case<br />
highlightRoom(351, unpack(color_table.grey), unpack(color_table.grey), 1, 255, 255)<br />
</lua><br />
<br />
==lockExit==<br />
lockExit(roomID, direction, lock = true/false)<br />
<br />
Locks a given exit from a room (which means that unless all exits in the incoming room are locked, it'll still be accessible). Direction at the moment is only set as a number, and here's a listing of them:<br />
<br />
<code><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}<br />
</code><br />
<br />
; Examples<br />
<lua><br />
-- lock the east exit of room 1201 so we never path through it<br />
lockExit(1201, 4, true)<br />
</lua><br />
<br />
: See also: [[Manual:Lua_Functions#hasExitLock|hasExitLock]]<br />
<br />
==lockRoom==<br />
lockRoom (roomID, lock = true/false)<br />
<br />
Locks a given room id from future speed walks (thus the mapper will never path through that room).<br />
: See also: [[Manual:Lua_Functions#roomLocked|roomLocked]]<br />
<br />
<lua><br />
lockRoom(1, true) -- locks a room if from being walked through when speedwalking.<br />
lockRoom(1, false) -- unlocks the room, adding it back to possible rooms that can be walked through.<br />
</lua><br />
<br />
==roomExists==<br />
roomExists(roomID)<br />
<br />
Returns a boolean true/false depending if the room with that ID exists (is created) or not.<br />
<br />
==roomLocked==<br />
locked = roomLocked(roomID)<br />
<br />
Returns true or false whenever a given room is locked.<br />
: See also: [[Manual:Lua_Functions#lockRoom|lockRoom]]<br />
<br />
<lua><br />
echo(string.format("Is room #4545 locked? %s.", roomLocked(4545) and "Yep" or "Nope"))<br />
</lua><br />
<br />
==saveMap==<br />
saveMap(location)<br />
<br />
Saves the map to a given location, and returns true on success. The location folder needs to be already created for save to work.<br />
<br />
<lua><br />
local savedok = saveMap(getMudletHomeDir().."/my fancy map.dat")<br />
if not savedok then<br />
echo("Couldn't save :(\n")<br />
else<br />
echo("Saved fine!\n")<br />
end<br />
</lua><br />
<br />
==searchRoom== <br />
searchRoom (room name)<br />
<br />
Searches for rooms that match (by case-insensitive, substring match) the given room name. It returns a key-value table in form of ''roomid = roomname'', like so:<br />
<br />
<lua><br />
display(searchRoom("master"))<br />
<br />
--[[ would result in:<br />
table {<br />
17463: 'in the branches of the Master Ravenwood'<br />
3652: 'master bedroom'<br />
10361: 'Hall of Cultural Masterpieces'<br />
6324: 'Exhibit of the Techniques of the Master Artisans'<br />
5340: 'office of the Guildmaster'<br />
(...)<br />
2004: 'office of the guildmaster'<br />
14457: 'the Master Gear'<br />
1337: 'before the Master Ravenwood Tree'<br />
}<br />
]]</lua><br />
<br />
If no rooms are found, then an empty table is returned.<br />
<br />
==setAreaName==<br />
setAreaName(areaID, newName)<br />
<br />
Renames an existing area to the new name.<br />
<br />
<lua><br />
setAreaName(2, "My city")<br />
</lua><br />
<br />
==setCustomEnvColor==<br />
setCustomEnvColor(environmentID, r,g,b)<br />
<br />
Creates, or overrides an already created custom color definition for a given environment ID. Note that this will not work on the default environment colors - those are adjustable by the user in the preferences. You can however create your own environment and use a custom color definition for it.<br />
<br />
<lua><br />
setRoomEnv(571, 200) -- change the room's environment ID to something arbitrary, like 200<br />
setCustomEnvColor(200, unpack(color_table.blue)) -- set the color of environmentID 200 to blue<br />
</lua><br />
<br />
==setExit==<br />
setExit(from roomID, to roomID, direction)<br />
<br />
Creates a one-way exit from one room to another using a standard direction - which can be either one of ''n, ne, nw, e, w, s, se, sw, u, d, in, out'', or a number which represents a direction.<br />
<br />
Returns ''false'' if the exit creation didn't work.<br />
<br />
<lua><br />
-- alias pattern: ^exit (\d+) (\w+)$<br />
<br />
if setExit(mmp.currentroom, tonumber(matches[2]),matches[3]) then<br />
echo("\nExit set to room:"..matches[2]..", Direction:"..string.upper(matches[3]))<br />
centerview(mmp.currentroom)<br />
else<br />
mmp.echo("Failed to set the exit.") end<br />
</lua><br />
<br />
This function can also delete exits from a room if you use it like so:<br />
setExit(from roomID, -1, direction)<br />
<br />
Which will delete an outgoing exit in the specified direction from a room.<br />
<br />
<lua><br />
-- locate the room on the other end, so we can unlink it from there as well if necessary<br />
local otherroom<br />
if getRoomExits(getRoomExits(mmp.currentroom)[dir])[mmp.ranytolong(dir)] then<br />
otherroom = getRoomExits(mmp.currentroom)[dir]<br />
end<br />
<br />
if setExit(mmp.currentroom, -1, dir) then<br />
if otherroom then<br />
if setExit(otherroom, -1, mmp.ranytolong(dir)) then<br />
mmp.echo(string.format("Deleted the %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
else mmp.echo("Couldn't delete the incoming exit.") end<br />
else<br />
mmp.echo(string.format("Deleted the one-way %s exit from %s (%d).",<br />
dir, getRoomName(mmp.currentroom), mmp.currentroom))<br />
end<br />
else<br />
mmp.echo("Couldn't delete the outgoing exit.")<br />
end<br />
</lua><br />
<br />
You can use these numbers for setting the directions as well:<br />
<lua><br />
exitmap = {<br />
n = 1,<br />
north = 1,<br />
ne = 2,<br />
northeast = 2,<br />
nw = 3,<br />
northwest = 3,<br />
e = 4,<br />
east = 4,<br />
w = 5,<br />
west = 5,<br />
s = 6,<br />
south = 6,<br />
se = 7,<br />
southeast = 7,<br />
sw = 8,<br />
southwest = 8,<br />
u = 9,<br />
up = 9,<br />
d = 10,<br />
down = 10,<br />
["in"] = 11,<br />
out = 12<br />
}</lua><br />
<br />
==setGridMode==<br />
setGridMode(area, true/false)<br />
<br />
Enables grid/wilderness view mode for an area - this will cause the rooms to lose their visible exit connections, like you'd see on compressed ASCII maps, both in 2D and 3D view mode.<br />
<br />
<lua><br />
setGridMode(55,true) -- set area with ID 55 to be in grid mode<br />
</lua><br />
<br />
==setRoomArea==<br />
setRoomArea(roomID, newAreaID)<br />
<br />
Assigns the given room to a new area. This will have the room be visually moved into the area as well.<br />
<br />
==setRoomChar==<br />
setRoomChar(roomID, character)<br />
<br />
Designed for an area in grid mode, this will set a single character to be on a room. You can use "_" to clear it.<br />
<br />
<lua><br />
setRoomChar(431, "#")<br />
<br />
setRoomChar(123. "$")<br />
</lua><br />
<br />
==setRoomCoordinates==<br />
setRoomCoordinates(roomID, x, y, z)<br />
<br />
Sets the given room ID to be at the following coordinates visually on the map, where ''z'' is the up/down level. <br />
<br />
0,0,0 is the center of the map.<br />
<br />
<lua><br />
-- alias pattern: ^set rc (-?\d+) (-?\d+) (-?\d+)$<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
You can make them relative as well:<br />
<br />
<lua><br />
-- alias pattern: ^src (\w+)$<br />
<br />
local x,y,z = getRoomCoordinates(previousRoomID)<br />
local dir = matches[2]<br />
<br />
if dir == "n" then<br />
y = y+1<br />
elseif dir == "ne" then<br />
y = y+1<br />
x = x+1<br />
elseif dir == "e" then<br />
x = x+1<br />
elseif dir == "se" then<br />
y = y-1<br />
x = x+1<br />
elseif dir == "s" then<br />
y = y-1<br />
elseif dir == "sw" then<br />
y = y-1<br />
x = x-1<br />
elseif dir == "w" then<br />
x = x-1<br />
elseif dir == "nw" then<br />
y = y+1<br />
x = x-1<br />
elseif dir == "u" or dir == "up" then<br />
z = z+1<br />
elseif dir == "down" then<br />
z = z-1<br />
end<br />
setRoomCoordinates(roomID,x,y,z)<br />
centerview(roomID)<br />
</lua><br />
<br />
==setRoomEnv==<br />
setRoomEnv(roomID, newEnvID)<br />
<br />
Sets the given room to a new environment ID. You don't have to use any functions to create it - can just set it right away.<br />
<br />
<lua><br />
setRoomEnv(551, 34) -- set room with the ID of 551 to the environment ID 34<br />
</lua><br />
<br />
==setRoomIDbyHash==<br />
setRoomIDbyHash(roomID, hash)<br />
<br />
Sets the hash to be associated with the given roomID. See also [[Manual:Lua_Functions#getRoomIDbyHash|getRoomIDbyHash()]].<br />
<br />
==setRoomName==<br />
setRoomName(roomID, newName)<br />
<br />
Renames an existing room to a new name.<br />
<br />
<lua><br />
setRoomName(534, "That evil room I shouldn't visit again.")<br />
lockRoom(534, true) -- and lock it just to be safe<br />
</lua><br />
<br />
==setRoomUserData==<br />
setRoomUserData(roomID, key (as a string), value (as a string))<br />
<br />
Stores information about a room under a given key. Similar to Lua's key-value tables, except only strings may be used here. One advantage of using userdata is that it's stored within the map file itself - so sharing the map with someone else will pass on the user data. You can have as many keys as you'd like. <br />
<br />
Returns true if successfully set.<br />
: See also: [[Manual:Lua_Functions#clearRoomUserData|clearRoomUserData]]<br />
<br />
<lua><br />
-- can use it to store room descriptions...<br />
setRoomUserData(341, "description", "This is a plain-looking room.")<br />
<br />
-- or whenever it's outdoors or not...<br />
setRoomUserData(341, "ourdoors", "true")<br />
<br />
-- how how many times we visited that room<br />
local visited = getRoomUserData(341, "visitcount")<br />
visited = (tonumber(visited) or 0) + 1<br />
setRoomUserData(341, "visitcount", tostring(visited))<br />
<br />
-- can even store tables in it, using the built-in yajl.to_string function<br />
setRoomUserData(341, "some table", yajl.to_string({name = "bub", age = 23}))<br />
display("The denizens name is: "..yajl.to_value(getRoomUserData(341, "some table")).name)<br />
</lua><br />
<br />
==setRoomWeight==<br />
setRoomWeight(roomID, weight)<br />
<br />
Sets a weight to the given roomID. By default, all rooms have a weight of 0 - the higher the weight is, the more likely the room is to be avoided for pathfinding. For example, if travelling across water rooms takes more time than land ones - then you'd want to assign a weight to all water rooms, so they'd be avoided if there are possible land pathways.<br />
<br />
To completely avoid a room, make use of [[Manual:Lua_Functions#lockRoom|lockRoom()]].<br />
<br />
: See also: [[Manual:Lua_Functions#getRoomWeight|getRoomWeight]]<br />
<br />
<lua><br />
setRoomWeight(1532, 3) -- avoid using this room if possible, but don't completely ignore it<br />
</lua><br />
<br />
==unHighlightRoom==<br />
unHighlightRoom(roomID)<br />
<br />
Unhighlights a room if it was previously highlighted and restores the rooms original environment color.<br />
: See also: [[Manual:Lua_Functions#highlightRoom|highlightRoom]]<br />
<br />
<sub>Available since Mudlet 2.0 final release</sub><br />
<br />
<lua><br />
unHighlightRoom(4534)<br />
</lua><br />
<br />
= Miscellaneous Functions =<br />
==expandAlias==<br />
; expandAlias(command,true/false)<br />
<br />
: 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.<br />
<br />
<lua><br />
expandAlias("t rat")<br />
<br />
expandAlias("t rat", false)<br />
</lua><br />
<br />
: 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.<br />
<br />
==spawn==<br />
;t = spawn(read function, process to spawn)<br />
<br />
: 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()''.<br />
<br />
<lua><br />
-- simple example on a program that quits right away, but prints whatever it gets using the 'display' function<br />
local f = spawn(display, "ls")<br />
display(f.isRunning())<br />
f.close()<br />
</lua><br />
<br />
==downloadFile==<br />
;downloadFile(saveto, url)<br />
<br />
: Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the [[Manual:Scripting#sysDownloadDone|sysDownloadDone]] event is raised (with the saveto location as the argument), or when a download fails, the [[Manual:Scripting#sysDownloadError|sysDownloadError]] event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.<br />
<br />
: <sub>Requires Mudlet 2.0+</sub><br />
<br />
;Example<br />
<lua><br />
-- this example will check the Imperian homepage to see how many players are on right now<br />
<br />
-- in an alias, download the Imperian homepage for stats processing<br />
downloadFile(getMudletHomeDir().."/page.html", "http://www.imperian.com/")<br />
<br />
<br />
-- then create a new script with the name of downloaded_file, add the event handler<br />
-- for sysDownloadDone, and use this to parse the webpage and display the amount<br />
function downloaded_file(_, filename)<br />
-- is the file that downloaded ours?<br />
if not filename:match("page", 1, true) then return end<br />
<br />
-- parse our ownloaded file for the player count<br />
io.input(filename)<br />
local s = io.read("*all")<br />
local pc = s:match([[<a href='players.php%?search=who'>(%d+)</a>]])<br />
display("Imperian has "..tostring(pc).." players on right now.")<br />
io.open():close()<br />
os.remove(filename)<br />
end<br />
</lua><br />
<br />
==sendGMCP==<br />
;sendGMCP(command)<br />
: Sends a GMCP message to the server. The [http://www.ironrealms.com/gmcp-doc IRE document on GMCP] has information about what can be sent, and what tables it will use, etcetera.<br />
<br />
: See Also: [[Manual:Scripting#GMCP|GMCP Scripting]]<br />
<br />
<br />
;Example<br />
<lua><br />
--This would send "Core.KeepAlive" to the server, which resets the timeout<br />
sendGMCP("Core.KeepAlive")<br />
<br />
--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.<br />
sendGMCP("Char.Skills.Get {}")<br />
<br />
--This would send a request for the server to send a list of the skills in the <br />
--vision group to the gmcp.Char.Skills.List table.<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "vision"}]])<br />
<br />
--And finally, this would send a request for the server to send the info for <br />
--hide in the woodlore group to the gmcp.Char.Skills.Info table<br />
<br />
sendGMCP([[Char.Skills.Get { "group": "woodlore", "name": "hide"}]])<br />
</lua><br />
<br />
==sendIrc==<br />
;sendIrc(channel, message)<br />
: Sends a message to an IRC channel or person. You must have the IRC window open, and if speaking to a channel, be joined in that channel. IRC currently only works on the freenode network and password-protected channels aren't supported.<br />
<br />
;Parameters:<br />
* ''channel:''<br />
: The channel to send the message to. Can be #<channelname> to send to a channel, or <person name> to send to a person. Passed as a string.<br />
* ''message:''<br />
: The message to send. Passed as a string.<br />
<br />
;Example<br />
<lua><br />
--This would send "hello from Mudlet!" to the channel #mudlet on freenode.net<br />
sendIrc("#mudlet", "hello from Mudlet!")<br />
--This would send "identify password" in a private message to Nickserv on freenode.net<br />
sendIrc("Nickserv", "identify password")<br />
</lua><br />
<br />
==showColors==<br />
;showColors(columns)<br />
: shows the named colors currently available in Mudlet's color table. These colors are stored in color_table, in table form. The format is color_table.colorName = {r,g,b}<br />
: See Also: [[Manual:Lua_Functions#bg|bg]], [[Manual:Lua_Functions#fg|fg]], [[Manual:Lua_Functions#cecho|cecho]]<br />
<br />
;Parameters<br />
* ''columns:''<br />
: Number of columns to print the color table in. Passed as an integer number.<br />
<br />
;Example:<br />
<lua><br />
showColors(4)<br />
</lua><br />
The output for this is:<br />
<br />
[[File:ShowColors.png|showColors(4)]]<br />
<br />
[[Category:Mudlet Manual]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Misc_Scripts&diff=526Misc Scripts2011-07-09T23:01:25Z<p>Rayth: /* Miscellaneous Scripts */</p>
<hr />
<div>==Example Layout==<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
<br />
=Miscellaneous Scripts=<br />
Small or Large scripts made before the official package system.<br />
----<br />
'''Name:''' Lua from the Command Line<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=100<br><br />
'''Short Description:''' Allows coding small scripts from the command line.<br />
----<br />
'''Name:''' Name Highlighter v3<br><br />
'''Author:'''Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1235<br><br />
'''Short Description:''' Highlight player names according to org affiliation or other chosen criteria.<br />
----<br />
'''Name:''' Lusternia Calendar<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2253<br><br />
'''Short Description:''' Display a small calendar for Lusternia.<br />
----<br />
<br />
'''Name:''' Clickable URLs<br><br />
'''Author:''' Yetzederixx<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1818<br><br />
'''Short Description:''' Make on-screen urls clickable, opening the link in your browser.<br />
----<br />
'''Name:''' Tabbed Chat w/ blinking tabs<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1662<br><br />
'''Short Description:''' Capture channel communication to a miniconsole, with the tabs blinking on new text.<br />
----<br />
'''Name:''' Lusternia Fancy GUI<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1180<br><br />
'''Short Description:''' Make Mudlet look similar to Nexus in Lusternia for familiarity's sake.<br />
----<br />
'''Name:''' Achaea Fancy GUI<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=981<br><br />
'''Short Description:''' Make Mudlet look similar to Nexus in Achaea for familiarity's sake.<br />
----<br />
'''Name:''' Achaea, Inventory Organizer <br><br />
'''Author:''' mortagona <br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2286<br><br />
'''Short Description:''' Organize your inventory in Achaea into a clean more easily read format.<br />
----<br />
'''Name:''' Vadi Sipper for Achaea<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=125<br><br />
'''Short Description:''' A basic sipper for Achaea.<br />
----<br />
'''Name:''' Find alias #1<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1233<br><br />
'''Short Description:''' Search through your mudlet window for a specific text.<br />
----<br />
'''Name:''' MAG - Mudlet Aardwolf GUI <br><br />
'''Author:''' lex<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1471<br><br />
'''Short Description:''' GUI made specifically for Aardwolf<br />
----<br />
'''Name:''' Simple Logger<br><br />
'''Author:''' Wyd<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1424<br><br />
'''Short Description:''' Log either specific text or log a section of a mudlet session.<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Misc_Scripts&diff=525Misc Scripts2011-07-09T23:00:55Z<p>Rayth: /* Miscellaneous Scripts */</p>
<hr />
<div>==Example Layout==<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
<br />
=Miscellaneous Scripts=<br />
Small or Large scripts made before the official package system.<br />
----<br />
'''Name:''' Lua from the Command Line<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=100<br><br />
'''Short Description:''' Allows coding small scripts from the command line.<br />
----<br />
'''Name:''' Name Highlighter v3<br><br />
'''Author:'''Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1235<br><br />
'''Short Description:''' Highlight player names according to org affiliation or other chosen criteria.<br />
----<br />
'''Name:''' Lusternia Calendar<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2253<br><br />
'''Short Description:''' Display a small calendar for Lusternia.<br />
----<br />
<br />
'''Name:''' Clickable URLs<br><br />
'''Author:''' Yetzederixx<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1818<br><br />
'''Short Description:''' Make on-screen urls clickable, opening the link in your browser.<br />
----<br />
'''Name:''' Tabbed Chat w/ blinking tabs<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1662<br><br />
'''Short Description:''' Capture channel communication to a miniconsole, with the tabs blinking on new text.<br />
----<br />
'''Name:''' Lusternia Fancy GUI<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1180<br><br />
'''Short Description:''' Make Mudlet look similar to Nexus in Lusternia for familiarity's sake.<br />
----<br />
'''Name:''' Achaea Fancy GUI<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=981<br><br />
'''Short Description:''' Make Mudlet look similar to Nexus in Achaea for familiarity's sake.<br />
----<br />
'''Name:''' Achaea, Inventory Organizer <br><br />
'''Author:''' mortagona <br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2286<br><br />
'''Short Description:''' Organize your inventory in Achaea into a clean more easily read format.<br />
----<br />
'''Name:''' Vadi Sipper for Achaea<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=125<br><br />
'''Short Description:''' A basic sipper for Achaea.<br />
----<br />
'''Name:''' Find alias #1<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1233<br><br />
'''Short Description:''' Search through your mudlet window for a specific text.<br />
----<br />
'''Name:''' MAG - Mudlet Aardwolf GUI <br><br />
'''Author:''' lex<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1471<br><br />
'''Short Description:''' GUI made specifically for Aardwolf<br />
----<br />
'''Name:''' Simple Logger<br><br />
'''Author:''' Wyde<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1424<br><br />
'''Short Description:''' Log either specific text or log a section of a mudlet session.<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Misc_Scripts&diff=524Misc Scripts2011-07-09T21:26:13Z<p>Rayth: /* Miscellaneous Scripts */</p>
<hr />
<div>==Example Layout==<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
<br />
=Miscellaneous Scripts=<br />
Small or Large scripts made before the official package system.<br />
----<br />
'''Name:''' Lua from the Command Line<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=100<br><br />
'''Short Description:''' Allows coding small scripts from the command line.<br />
----<br />
'''Name:''' Name Highlighter v3<br><br />
'''Author:'''Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1235<br><br />
'''Short Description:''' Highlight player names according to org affiliation or other chosen criteria.<br />
----<br />
'''Name:''' Lusternia Calendar<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2253<br><br />
'''Short Description:''' Display a small calendar for Lusternia.<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Misc_Scripts&diff=523Misc Scripts2011-07-09T21:24:25Z<p>Rayth: </p>
<hr />
<div>==Example Layout==<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
<br />
=Miscellaneous Scripts=<br />
Small or Large scripts made before the official package system.<br />
----<br />
'''Name:''' Lua from the Command Line<br><br />
'''Author:''' Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=8&t=100<br><br />
'''Short Description:''' Allows coding small scripts from the command line.<br />
----<br />
'''Name:''' Name Highlighter v3<br><br />
'''Author:'''Vadi<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=1235<br><br />
'''Short Description:''' Highlight player names according to org affiliation or other chosen criteria.<br />
----<br />
'''Name:''' Lusternia Calendar<br><br />
'''Author:''' Demonnic<br><br />
'''Link:''' http://forums.mudlet.org/viewtopic.php?f=6&t=2253<br><br />
'''Short Description: Display a small calendar for Lusternia.'''<br />
----<br />
'''Name:'''<br><br />
'''Author:'''<br><br />
'''Link:'''<br><br />
'''Short Description:'''<br />
[[Category:Mudlet Package Listing]]</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=517Manual:Migrating2011-07-07T20:46:04Z<p>Rayth: /* From Nexus */</p>
<hr />
<div>=From Nexus=<br />
'''Trigger patterns'''<br />
<br><br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
'''Basic scripting'''<br />
<br><br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
'''Calling functions'''<br />
<table border="1" width="100%"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
'''Setting variables'''<br />
<table border="1" width="100%"><br />
<caption>Setting variables</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<td><br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<br />
'''Wildcards'''<br />
<br><br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<lua><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</lua><br />
</td><br />
<td><br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
</td><br />
<table><br />
<br />
'''#wait'''<br />
<br><br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<br />
'''ifs in Mudlet'''<br />
<br><br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
if <condition> then <text> end<br />
</td><br />
<td><br />
<p>#if <condition> <text></p><br />
<p>#if <condition> { <script> }</p><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
if <condition> then <script> else <script> end<br />
</td><br />
<td><br />
<p>#if <condition> { <script> } else { <script> }</p><br />
<p>#if <condition> { <script> } { <script> }</p><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
if <condition> then <script> elseif <condition> then <script> end<br />
</td><br />
<td><br />
<p>#if <condition> { <script> } elsif <condition> { <script> }</p><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
</td><br />
<td><br />
<p>#if <condition> { <script> } elsif <condition> { <script> } else { <script> }</p><br />
</td><br />
<tr><br />
</table><br />
<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
</lua><br />
</td><br />
<td><br />
<code><br />
<br>// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
<br>// A slight modification of the above that illustrates an 'else' clause.<br />
<br>// The second form shows that the word 'else' is actually optional too.<br />
<br>// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
<br>// Illustration of putting more than one statement in a block (also<br />
<br>// spans lines here). Note the if doesn't end until the last '}' is<br />
<br>// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
<br>// This shows how ifs continue (on 'logical' lines) even though the<br />
<br>// blocks in its constituent clauses may have multiple lines. The<br />
<br>// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
</code><br />
</td><br />
</tr><br />
</table><br />
'''Mudlet equivalents of Nexus functions'''<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><variable name> = "<text value>"</td><br />
<td><p>#set <variable name> <text value></p></td><br />
</tr><br />
<tr><br />
<td><variable name> = <expression></td><br />
<td><p>#set <variable name> = <expression></p></td><br />
</tr><br />
<tr><br />
<td><variable name> = nil</td><br />
<td><p>#unset <variable name></p></td><br />
</tr><br />
<tr><br />
<td><variable> = <variablename> <+ - / *> <number or variable></td><br />
<td><p>#add <variablename> <expression></p></td><br />
</tr><br />
<tr><br />
<td>echo "text\n" or echo("text\n")</td><br />
<td><p>#echo <text></p></td><br />
</tr><br />
<tr><br />
<td>echo "text" or echo("text")</td><br />
<td><p>#echo_ <text></p></td><br />
</tr><br />
<tr><br />
<td>enableAlias("<group name>")/enableTrigger()/enableKey()/enableTimer()</td><br />
<td><p>#groupon <group name></p></td><br />
</tr><br />
<tr><br />
<td>disableAlias("<group name>")disableTrigger()disableKey()disableTimer()</td><br />
<td><p>#groupoff <group name></p></td><br />
</tr><br />
<tr><br />
<td>selectString (line, 1) bg("<color>") resetFormat()</td><br />
<td><p> #highlight <color></p></td><br />
</tr><br />
<tr><br />
<td>deleteLine()</td><br />
<td><p>#gag</p></td><br />
</tr><br />
<tr><br />
<td>openUrl("<url>")</td><br />
<td><p>#openurl <url></p></td><br />
</tr><br />
<tr><br />
<td>send("<stuff>")</td><br />
<td><p>#send <text></p></td><br />
</tr><br />
<tr><br />
<td>sendAll("hi", "hello", "bye")</td><br />
<td><p>#send_ hi #send_ hello #send bye</p></td><br />
</tr><br />
<tr><br />
<td>tempTimer(<time in s>, [[ <nowiki><lua code to do once time is up></nowiki> ]])</td><br />
<td><p>#wait <milliseconds></p></td><br />
</tr><br />
</table><br />
<br />
'''How to call aliases in Mudlet'''<br />
<br><br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<lua><br />
function <name> ()<br />
<stuff it does><br />
end<br />
</lua><br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<lua><br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
</lua><br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<lua><br />
eat_bloodroot()<br />
</lua><br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<lua><br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
</lua><br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<lua><br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
</lua><br />
==Notes to be aware of==<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
=From MUSHclient=<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
=From CMUD=<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
=From zMUD=</div>Raythhttps://wiki.mudlet.org/index.php?title=User:Rayth&diff=516User:Rayth2011-07-07T20:42:32Z<p>Rayth: </p>
<hr />
<div><table><br />
<th></th><br />
<th>Test1</th><br />
<th>Test2</th><br />
<tr><br />
<td><br />
Test1<br />
</td><br />
</tr><br />
</table><br />
<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><variable name> = "<text value>"</td><br />
<td><p>#set <variable name> <text value></p></td><br />
</tr><br />
<tr><br />
<td><variable name> = <expression></td><br />
<td><p>#set <variable name> = <expression></p></td><br />
</tr><br />
<tr><br />
<td><variable name> = nil</td><br />
<td><p>#unset <variable name></p></td><br />
</tr><br />
<tr><br />
<td><variable> = <variablename> <+ - / *> <number or variable></td><br />
<td><p>#add <variablename> <expression></p></td><br />
</tr><br />
<tr><br />
<td>echo "text\n" or echo("text\n")</td><br />
<td><p>#echo <text></p></td><br />
</tr><br />
<tr><br />
<td>echo "text" or echo("text")</td><br />
<td><p>#echo_ <text></p></td><br />
</tr><br />
<tr><br />
<td>enableAlias("<group name>")/enableTrigger()/enableKey()/enableTimer()</td><br />
<td><p>#groupon <group name></p></td><br />
</tr><br />
<tr><br />
<td>disableAlias("<group name>")disableTrigger()disableKey()disableTimer()</td><br />
<td><p>#groupoff <group name></p></td><br />
</tr><br />
<tr><br />
<td>selectString (line, 1) bg("<color>") resetFormat()</td><br />
<td><p> #highlight <color></p></td><br />
</tr><br />
<tr><br />
<td>deleteLine()</td><br />
<td><p>#gag</p></td><br />
</tr><br />
<tr><br />
<td>openUrl("<url>")</td><br />
<td><p>#openurl <url></p></td><br />
</tr><br />
<tr><br />
<td>send("<stuff>")</td><br />
<td><p>#send <text></p></td><br />
</tr><br />
<tr><br />
<td>sendAll("hi", "hello", "bye")</td><br />
<td><p>#send_ hi #send_ hello #send bye</p></td><br />
</tr><br />
<tr><br />
<td>tempTimer(<time in s>, [[ <nowiki><lua code to do once time is up></nowiki> ]])</td><br />
<td><p>#wait <milliseconds></p></td><br />
</tr><br />
</table></div>Raythhttps://wiki.mudlet.org/index.php?title=User:Rayth&diff=515User:Rayth2011-07-07T19:01:03Z<p>Rayth: Created page with "<table> <th></th> <th>Test1</th> <th>Test2</th> <tr> <td> Test1 </td> </tr> </table> <table> <th></th> <th>Mudlet</th> <th>Nexus</th> <tr> <td> Variables * Setting * Clearing ..."</p>
<hr />
<div><table><br />
<th></th><br />
<th>Test1</th><br />
<th>Test2</th><br />
<tr><br />
<td><br />
Test1<br />
</td><br />
</tr><br />
</table><br />
<br />
<table><br />
<th></th><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
Variables<br />
* Setting<br />
* Clearing<br />
* Math<br />
</td><br />
<td><br />
* <variable name> = "<text value>"<br />
* <variable name> = <expression><br />
* <variable name> = nil<br />
* <variable> = <variablename> <+ - / *> <number or variable><br />
</td><br />
<td><br />
* #set <variable name> <text value><br />
* #set <variable name> = <expression> <br />
* #unset <variable name> <br />
* #add <variablename> <expression><br />
</tr><br />
<tr><br />
<td><br />
Echo<br />
</td><br />
<td><br />
echo "text\n" or echo("text\n")<br />
<br><br />
echo "text" or echo("text")<br />
</td><br />
<td><br />
/#echo <text><br />
<br><br />
#echo_ <text><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
Enabling Groups/Aliases/Triggers/Keybindings/Timers<br />
</td><br />
<td><br />
enableAlias("<group name>")<br />
<br>enableTrigger()<br />
<br>enableKey()<br />
<br>enableTimer()<br />
</td><br />
<td><br />
#groupon <group name> <br />
</td><br />
</tr><br />
<tr><br />
<td><br />
Disabling Groups/Aliases/Triggers/Keybindings/Timers<br />
</td><br />
<td><br />
disableAlias("<group name>")<br />
<br>disableTrigger()<br />
<br>disableKey()<br />
<br>disableTimer()<br />
</td><br />
<td><br />
!#groupoff <group name><br />
</td><br />
</table></div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=514Manual:Migrating2011-07-07T16:50:37Z<p>Rayth: /* From Nexus */</p>
<hr />
<div>=From Nexus=<br />
'''Trigger patterns'''<br />
<br><br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
'''Basic scripting'''<br />
<br><br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
'''Calling functions'''<br />
<table border="1" width="100%"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
'''Setting variables'''<br />
<table border="1" width="100%"><br />
<caption>Setting variables</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<td><br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<br />
'''Wildcards'''<br />
<br><br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<lua><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</lua><br />
</td><br />
<td><br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
</td><br />
<table><br />
<br />
'''#wait'''<br />
<br><br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<br />
'''ifs in Mudlet'''<br />
<br><br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
if <condition> then <text> end<br />
</td><br />
<td><br />
#if <condition> <text><br />
#if <condition> { <script> }<br />
</td><br />
</tr><br />
<tr><br />
<td><br />
if <condition> then <script> else <script> end<br />
</td><br />
<td><br />
#if <condition> { <script> } else { <script> }<br />
#if <condition> { <script> } { <script> }<br />
</td><br />
</tr><br />
<tr><br />
<td><br />
if <condition> then <script> elseif <condition> then <script> end<br />
</td><br />
<td><br />
#if <condition> { <script> } elsif <condition> { <script> }<br />
</td><br />
</tr><br />
<tr><br />
<td><br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
</td><br />
<td><br />
#if <condition> { <script> } elsif <condition> { <script> } else { <script> }<br />
</td><br />
<tr><br />
</table><br />
<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
</lua><br />
</td><br />
<td><br />
<code><br />
<br>// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
<br>// A slight modification of the above that illustrates an 'else' clause.<br />
<br>// The second form shows that the word 'else' is actually optional too.<br />
<br>// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
<br>// Illustration of putting more than one statement in a block (also<br />
<br>// spans lines here). Note the if doesn't end until the last '}' is<br />
<br>// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
<br>// This shows how ifs continue (on 'logical' lines) even though the<br />
<br>// blocks in its constituent clauses may have multiple lines. The<br />
<br>// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
</code><br />
</td><br />
</tr><br />
</table><br />
'''Mudlet equivalents of Nexus functions'''<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
Mudlet Nexus<br />
<br />
*Math with Variables<br />
** <variable> = <variablename> <+ - / *> <number or variable> <br />
** #add <variablename> <expression><br />
<br />
*Echo<br />
** echo "text\n" or echo("text\n") <br />
** #echo <text><br />
** echo "text" or echo("text") <br />
** #echo_ <text><br />
<br />
*Enable Group/Alias/Trigger/Keybinding/Timer<br />
** enableAlias("<group name>"), enableTrigger(), enableKey() or enableTimer() <br />
** #groupon <group name><br />
<br />
*Disable Group/Alias/Trigger/Keybinding/Timer<br />
** disableAlias("<group name>"), disableTrigger(), disableKey() or disableTimer() <br />
** #groupoff <group name><br />
<br />
*Highlight<br />
** selectString (line, 1) bg("<color>") resetFormat() <br />
** #highlight <color><br />
<br />
*Gag<br />
** deleteLine() <br />
** #gag<br />
<br />
*Open Url/Links<br />
** openUrl("<url>")* <br />
** #openurl <url><br />
<br />
*Send text to Mud<br />
** send("<stuff>") <br />
** #send <text><br />
<br />
*Send Multiple text to Mud at once<br />
** sendAll("hi", "hello", "bye") <br />
** #send_ hi #send_ hello #send bye<br />
<br />
*Variable Setting<br />
** <variable name> = "<text value>" <br />
** #set <variable name> <text value><br />
** <variable name> = <expression> <br />
** #set <variable name> = <expression><br />
<br />
*Clear Variables<br />
** <variable name> = nil <br />
** #unset <variable name><br />
<br />
*Wait/Timers<br />
** <lua>tempTimer(<time in s>, [[ <lua code to do once time is up> ]])</lua><br />
** #wait <milliseconds><br />
<br />
'''How to call aliases in Mudlet'''<br />
<br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<br />
function <name> ()<br />
<stuff it does><br />
end<br />
<br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
<br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<br />
eat_bloodroot()<br />
<br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
<br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
<br />
==Notes to be aware of==<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
=From MUSHclient=<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
=From CMUD=<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
=From zMUD=</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=513Manual:Migrating2011-07-07T16:20:42Z<p>Rayth: </p>
<hr />
<div>=From Nexus=<br />
'''Trigger patterns'''<br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
'''Basic scripting'''<br />
<br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
'''Calling functions'''<br />
<table border="1" width="100%"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
'''Setting variables'''<br />
<table border="1" width="100%"><br />
<caption>Setting variables</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<td><br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<br />
'''Wildcards'''<br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<lua><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</lua><br />
</td><br />
<td><br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
</td><br />
<table><br />
<br />
'''#wait in Mudlet'''<br />
<br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<br />
Nexus script:<br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
<br />
'''ifs in Mudlet'''<br />
<br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
Mudlet Nexus<br />
<br />
if <condition> then <text> end<br />
<br />
<br />
#if <condition> <text><br />
<br />
#if <condition> { <script> }<br />
<br />
if <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } else { <script> }<br />
<br />
#if <condition> { <script> } { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> } else { <script> }<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
Mudlet Nexus<br />
<br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
<br />
<br />
<br />
// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
// A slight modification of the above that illustrates an 'else' clause.<br />
// The second form shows that the word 'else' is actually optional too.<br />
// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
// Illustration of putting more than one statement in a block (also<br />
// spans lines here). Note the if doesn't end until the last '}' is<br />
// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
// This shows how ifs continue (on 'logical' lines) even though the<br />
// blocks in its constituent clauses may have multiple lines. The<br />
// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
<br />
'''Mudlet equivalents of Nexus functions'''<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
Mudlet Nexus<br />
<br />
*Math with Variables<br />
** <variable> = <variablename> <+ - / *> <number or variable> <br />
** #add <variablename> <expression><br />
<br />
*Echo<br />
** echo "text\n" or echo("text\n") <br />
** #echo <text><br />
** echo "text" or echo("text") <br />
** #echo_ <text><br />
<br />
*Enable Group/Alias/Trigger/Keybinding/Timer<br />
** enableAlias("<group name>"), enableTrigger(), enableKey() or enableTimer() <br />
** #groupon <group name><br />
<br />
*Disable Group/Alias/Trigger/Keybinding/Timer<br />
** disableAlias("<group name>"), disableTrigger(), disableKey() or disableTimer() <br />
** #groupoff <group name><br />
<br />
*Highlight<br />
** selectString (line, 1) bg("<color>") resetFormat() <br />
** #highlight <color><br />
<br />
*Gag<br />
** deleteLine() <br />
** #gag<br />
<br />
*Open Url/Links<br />
** openUrl("<url>")* <br />
** #openurl <url><br />
<br />
*Send text to Mud<br />
** send("<stuff>") <br />
** #send <text><br />
<br />
*Send Multiple text to Mud at once<br />
** sendAll("hi", "hello", "bye") <br />
** #send_ hi #send_ hello #send bye<br />
<br />
*Variable Setting<br />
** <variable name> = "<text value>" <br />
** #set <variable name> <text value><br />
** <variable name> = <expression> <br />
** #set <variable name> = <expression><br />
<br />
*Clear Variables<br />
** <variable name> = nil <br />
** #unset <variable name><br />
<br />
*Wait/Timers<br />
** <lua>tempTimer(<time in s>, [[ <lua code to do once time is up> ]])</lua><br />
** #wait <milliseconds><br />
<br />
'''How to call aliases in Mudlet'''<br />
<br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<br />
function <name> ()<br />
<stuff it does><br />
end<br />
<br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
<br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<br />
eat_bloodroot()<br />
<br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
<br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
<br />
==Notes to be aware of==<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
=From MUSHclient=<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
=From CMUD=<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
=From zMUD=</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=512Manual:Migrating2011-07-07T02:00:33Z<p>Rayth: /* From Nexus */</p>
<hr />
<div>=Migrating to Mudlet=<br />
<br />
==From Nexus==<br />
'''Trigger patterns'''<br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
'''Basic scripting'''<br />
<br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
'''Calling functions'''<br />
<table border="1" width="100%"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
'''Setting variables'''<br />
<table border="1" width="100%"><br />
<caption>Setting variables</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<td><br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<br />
'''Wildcards'''<br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
<table border="1" width="100%"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<lua><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</lua><br />
</td><br />
<td><br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<table frame="box"><br />
<caption>'''Note:'''</caption><br />
<td><br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
</td><br />
<table><br />
<br />
'''#wait in Mudlet'''<br />
<br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<br />
Nexus script:<br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
<br />
'''ifs in Mudlet'''<br />
<br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
Mudlet Nexus<br />
<br />
if <condition> then <text> end<br />
<br />
<br />
#if <condition> <text><br />
<br />
#if <condition> { <script> }<br />
<br />
if <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } else { <script> }<br />
<br />
#if <condition> { <script> } { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> } else { <script> }<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
Mudlet Nexus<br />
<br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
<br />
<br />
<br />
// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
// A slight modification of the above that illustrates an 'else' clause.<br />
// The second form shows that the word 'else' is actually optional too.<br />
// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
// Illustration of putting more than one statement in a block (also<br />
// spans lines here). Note the if doesn't end until the last '}' is<br />
// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
// This shows how ifs continue (on 'logical' lines) even though the<br />
// blocks in its constituent clauses may have multiple lines. The<br />
// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
<br />
'''Mudlet equivalents of Nexus functions'''<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
Mudlet Nexus<br />
<br />
*Math with Variables<br />
** <variable> = <variablename> <+ - / *> <number or variable> <br />
** #add <variablename> <expression><br />
<br />
*Echo<br />
** echo "text\n" or echo("text\n") <br />
** #echo <text><br />
** echo "text" or echo("text") <br />
** #echo_ <text><br />
<br />
*Enable Group/Alias/Trigger/Keybinding/Timer<br />
** enableAlias("<group name>"), enableTrigger(), enableKey() or enableTimer() <br />
** #groupon <group name><br />
<br />
*Disable Group/Alias/Trigger/Keybinding/Timer<br />
** disableAlias("<group name>"), disableTrigger(), disableKey() or disableTimer() <br />
** #groupoff <group name><br />
<br />
*Highlight<br />
** selectString (line, 1) bg("<color>") resetFormat() <br />
** #highlight <color><br />
<br />
*Gag<br />
** deleteLine() <br />
** #gag<br />
<br />
*Open Url/Links<br />
** openUrl("<url>")* <br />
** #openurl <url><br />
<br />
*Send text to Mud<br />
** send("<stuff>") <br />
** #send <text><br />
<br />
*Send Multiple text to Mud at once<br />
** sendAll("hi", "hello", "bye") <br />
** #send_ hi #send_ hello #send bye<br />
<br />
*Variable Setting<br />
** <variable name> = "<text value>" <br />
** #set <variable name> <text value><br />
** <variable name> = <expression> <br />
** #set <variable name> = <expression><br />
<br />
*Clear Variables<br />
** <variable name> = nil <br />
** #unset <variable name><br />
<br />
*Wait/Timers<br />
** <lua>tempTimer(<time in s>, [[ <lua code to do once time is up> ]])</lua><br />
** #wait <milliseconds><br />
<br />
'''How to call aliases in Mudlet'''<br />
<br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<br />
function <name> ()<br />
<stuff it does><br />
end<br />
<br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
<br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<br />
eat_bloodroot()<br />
<br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
<br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
<br />
==Notes to be aware of==<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
==From MUSHclient==<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
==From CMUD==<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
==From zMUD==</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=511Manual:Migrating2011-07-07T01:08:20Z<p>Rayth: /* =Notes to be aware of */</p>
<hr />
<div>=Migrating to Mudlet=<br />
<br />
==From Nexus==<br />
'''Trigger patterns'''<br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
<table border="1"><br />
<caption>'''Note:'''</caption><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
'''Basic scripting'''<br />
<br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
'''Calling functions'''<br />
<table border="1"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<table border="1"><br />
<caption>'''Note:'''</caption><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
'''Setting variables'''<br />
<table border="1"><br />
<caption>Setting variables</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<td><br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<br />
'''Wildcards'''<br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
<table border="1"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<lua><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</lua><br />
</td><br />
<td><br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<table border="1"><br />
<caption>'''Note:'''</caption><br />
<td><br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
</td><br />
<table><br />
<br />
'''#wait in Mudlet'''<br />
<br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<br />
Nexus script:<br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
<br />
'''ifs in Mudlet'''<br />
<br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
Mudlet Nexus<br />
<br />
if <condition> then <text> end<br />
<br />
<br />
#if <condition> <text><br />
<br />
#if <condition> { <script> }<br />
<br />
if <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } else { <script> }<br />
<br />
#if <condition> { <script> } { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> } else { <script> }<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
Mudlet Nexus<br />
<br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
<br />
<br />
<br />
// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
// A slight modification of the above that illustrates an 'else' clause.<br />
// The second form shows that the word 'else' is actually optional too.<br />
// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
// Illustration of putting more than one statement in a block (also<br />
// spans lines here). Note the if doesn't end until the last '}' is<br />
// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
// This shows how ifs continue (on 'logical' lines) even though the<br />
// blocks in its constituent clauses may have multiple lines. The<br />
// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
<br />
'''Mudlet equivalents of Nexus functions'''<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
Mudlet Nexus<br />
<br />
*Math with Variables<br />
** <variable> = <variablename> <+ - / *> <number or variable> <br />
** #add <variablename> <expression><br />
<br />
*Echo<br />
** echo "text\n" or echo("text\n") <br />
** #echo <text><br />
** echo "text" or echo("text") <br />
** #echo_ <text><br />
<br />
*Enable Group/Alias/Trigger/Keybinding/Timer<br />
** enableAlias("<group name>"), enableTrigger(), enableKey() or enableTimer() <br />
** #groupon <group name><br />
<br />
*Disable Group/Alias/Trigger/Keybinding/Timer<br />
** disableAlias("<group name>"), disableTrigger(), disableKey() or disableTimer() <br />
** #groupoff <group name><br />
<br />
*Highlight<br />
** selectString (line, 1) bg("<color>") resetFormat() <br />
** #highlight <color><br />
<br />
*Gag<br />
** deleteLine() <br />
** #gag<br />
<br />
*Open Url/Links<br />
** openUrl("<url>")* <br />
** #openurl <url><br />
<br />
*Send text to Mud<br />
** send("<stuff>") <br />
** #send <text><br />
<br />
*Send Multiple text to Mud at once<br />
** sendAll("hi", "hello", "bye") <br />
** #send_ hi #send_ hello #send bye<br />
<br />
*Variable Setting<br />
** <variable name> = "<text value>" <br />
** #set <variable name> <text value><br />
** <variable name> = <expression> <br />
** #set <variable name> = <expression><br />
<br />
*Clear Variables<br />
** <variable name> = nil <br />
** #unset <variable name><br />
<br />
*Wait/Timers<br />
** <lua>tempTimer(<time in s>, [[ <lua code to do once time is up> ]])</lua><br />
** #wait <milliseconds><br />
<br />
'''How to call aliases in Mudlet'''<br />
<br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<br />
function <name> ()<br />
<stuff it does><br />
end<br />
<br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
<br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<br />
eat_bloodroot()<br />
<br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
<br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
<br />
==Notes to be aware of==<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
==From MUSHclient==<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
==From CMUD==<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
==From zMUD==</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=510Manual:Migrating2011-07-07T01:07:56Z<p>Rayth: /* From Nexus */</p>
<hr />
<div>=Migrating to Mudlet=<br />
<br />
==From Nexus==<br />
'''Trigger patterns'''<br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
<table border="1"><br />
<caption>'''Note:'''</caption><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
'''Basic scripting'''<br />
<br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
'''Calling functions'''<br />
<table border="1"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
<table border="1"><br />
<caption>'''Note:'''</caption><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
'''Setting variables'''<br />
<table border="1"><br />
<caption>Setting variables</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<td><br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<br />
'''Wildcards'''<br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
<table border="1"><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
</td><br />
</tr><br />
<tr><br />
<td><br />
<lua><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</lua><br />
</td><br />
<td><br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
</td><br />
</tr><br />
<table><br />
<table border="1"><br />
<caption>'''Note:'''</caption><br />
<td><br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
</td><br />
<table><br />
<br />
'''#wait in Mudlet'''<br />
<br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<br />
Nexus script:<br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
<br />
'''ifs in Mudlet'''<br />
<br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
Mudlet Nexus<br />
<br />
if <condition> then <text> end<br />
<br />
<br />
#if <condition> <text><br />
<br />
#if <condition> { <script> }<br />
<br />
if <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } else { <script> }<br />
<br />
#if <condition> { <script> } { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> } else { <script> }<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
Mudlet Nexus<br />
<br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
<br />
<br />
<br />
// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
// A slight modification of the above that illustrates an 'else' clause.<br />
// The second form shows that the word 'else' is actually optional too.<br />
// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
// Illustration of putting more than one statement in a block (also<br />
// spans lines here). Note the if doesn't end until the last '}' is<br />
// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
// This shows how ifs continue (on 'logical' lines) even though the<br />
// blocks in its constituent clauses may have multiple lines. The<br />
// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
<br />
'''Mudlet equivalents of Nexus functions'''<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
Mudlet Nexus<br />
<br />
*Math with Variables<br />
** <variable> = <variablename> <+ - / *> <number or variable> <br />
** #add <variablename> <expression><br />
<br />
*Echo<br />
** echo "text\n" or echo("text\n") <br />
** #echo <text><br />
** echo "text" or echo("text") <br />
** #echo_ <text><br />
<br />
*Enable Group/Alias/Trigger/Keybinding/Timer<br />
** enableAlias("<group name>"), enableTrigger(), enableKey() or enableTimer() <br />
** #groupon <group name><br />
<br />
*Disable Group/Alias/Trigger/Keybinding/Timer<br />
** disableAlias("<group name>"), disableTrigger(), disableKey() or disableTimer() <br />
** #groupoff <group name><br />
<br />
*Highlight<br />
** selectString (line, 1) bg("<color>") resetFormat() <br />
** #highlight <color><br />
<br />
*Gag<br />
** deleteLine() <br />
** #gag<br />
<br />
*Open Url/Links<br />
** openUrl("<url>")* <br />
** #openurl <url><br />
<br />
*Send text to Mud<br />
** send("<stuff>") <br />
** #send <text><br />
<br />
*Send Multiple text to Mud at once<br />
** sendAll("hi", "hello", "bye") <br />
** #send_ hi #send_ hello #send bye<br />
<br />
*Variable Setting<br />
** <variable name> = "<text value>" <br />
** #set <variable name> <text value><br />
** <variable name> = <expression> <br />
** #set <variable name> = <expression><br />
<br />
*Clear Variables<br />
** <variable name> = nil <br />
** #unset <variable name><br />
<br />
*Wait/Timers<br />
** <lua>tempTimer(<time in s>, [[ <lua code to do once time is up> ]])</lua><br />
** #wait <milliseconds><br />
<br />
'''How to call aliases in Mudlet'''<br />
<br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<br />
function <name> ()<br />
<stuff it does><br />
end<br />
<br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
<br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<br />
eat_bloodroot()<br />
<br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
<br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
<br />
===Notes to be aware of==<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
==From MUSHclient==<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
==From CMUD==<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
==From zMUD==</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=509Manual:Migrating2011-07-06T21:11:01Z<p>Rayth: </p>
<hr />
<div>=Migrating to Mudlet=<br />
<br />
==From Nexus==<br />
===Trigger patterns===<br />
<br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
'''Note:'''<br />
<table border="1"><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
===Basic scripting===<br />
<br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
====Calling functions====<br />
<table border="1"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
'''Note:'''<br />
<table border="1"><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
====Setting variables====<br />
<br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
<br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<br />
====Wildcards====<br />
<br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
Nexus:<br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
<br />
Another example would be the targetting alias:<br />
<br />
Nexus:<br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
<br />
Mudlet:<br />
<code><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</code><br />
<br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
<br />
====#wait in Mudlet====<br />
<br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<br />
Nexus script:<br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
<br />
====ifs in Mudlet====<br />
<br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
Mudlet Nexus<br />
<br />
if <condition> then <text> end<br />
<br />
<br />
#if <condition> <text><br />
<br />
#if <condition> { <script> }<br />
<br />
if <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } else { <script> }<br />
<br />
#if <condition> { <script> } { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> } else { <script> }<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
Mudlet Nexus<br />
<br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
<br />
<br />
<br />
// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
// A slight modification of the above that illustrates an 'else' clause.<br />
// The second form shows that the word 'else' is actually optional too.<br />
// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
// Illustration of putting more than one statement in a block (also<br />
// spans lines here). Note the if doesn't end until the last '}' is<br />
// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
// This shows how ifs continue (on 'logical' lines) even though the<br />
// blocks in its constituent clauses may have multiple lines. The<br />
// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
<br />
====Mudlet equivalents of Nexus functions====<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
Mudlet Nexus<br />
<br />
*Math with Variables<br />
** <variable> = <variablename> <+ - / *> <number or variable> <br />
** #add <variablename> <expression><br />
<br />
*Echo<br />
** echo "text\n" or echo("text\n") <br />
** #echo <text><br />
** echo "text" or echo("text") <br />
** #echo_ <text><br />
<br />
*Enable Group/Alias/Trigger/Keybinding/Timer<br />
** enableAlias("<group name>"), enableTrigger(), enableKey() or enableTimer() <br />
** #groupon <group name><br />
<br />
*Disable Group/Alias/Trigger/Keybinding/Timer<br />
** disableAlias("<group name>"), disableTrigger(), disableKey() or disableTimer() <br />
** #groupoff <group name><br />
<br />
*Highlight<br />
** selectString (line, 1) bg("<color>") resetFormat() <br />
** #highlight <color><br />
<br />
*Gag<br />
** deleteLine() <br />
** #gag<br />
<br />
*Open Url/Links<br />
** openUrl("<url>")* <br />
** #openurl <url><br />
<br />
*Send text to Mud<br />
** send("<stuff>") <br />
** #send <text><br />
<br />
*Send Multiple text to Mud at once<br />
** sendAll("hi", "hello", "bye") <br />
** #send_ hi #send_ hello #send bye<br />
<br />
*Variable Setting<br />
** <variable name> = "<text value>" <br />
** #set <variable name> <text value><br />
** <variable name> = <expression> <br />
** #set <variable name> = <expression><br />
<br />
*Clear Variables<br />
** <variable name> = nil <br />
** #unset <variable name><br />
<br />
*Wait/Timers<br />
** <lua>tempTimer(<time in s>, [[ <lua code to do once time is up> ]])</lua><br />
** #wait <milliseconds><br />
<br />
====How to call aliases in Mudlet====<br />
<br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<br />
function <name> ()<br />
<stuff it does><br />
end<br />
<br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
<br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<br />
eat_bloodroot()<br />
<br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
<br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
<br />
===Notes to be aware of===<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
==From MUSHclient==<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
==From CMUD==<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
==From zMUD==</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=508Manual:Migrating2011-07-06T21:10:24Z<p>Rayth: </p>
<hr />
<div>=Migrating to Mudlet=<br />
<br />
==From Nexus==<br />
===Trigger patterns===<br />
<br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
'''Note:'''<br />
<table border="1"><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
===Basic scripting===<br />
<br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
====Calling functions====<br />
<table border="1"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
'''Note:'''<br />
<table border="1"><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
===Setting variables===<br />
<br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
<br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<br />
====Wildcards====<br />
<br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
Nexus:<br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
<br />
Another example would be the targetting alias:<br />
<br />
Nexus:<br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
<br />
Mudlet:<br />
<code><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</code><br />
<br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
<br />
====#wait in Mudlet====<br />
<br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<br />
Nexus script:<br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
<br />
====ifs in Mudlet====<br />
<br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
Mudlet Nexus<br />
<br />
if <condition> then <text> end<br />
<br />
<br />
#if <condition> <text><br />
<br />
#if <condition> { <script> }<br />
<br />
if <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } else { <script> }<br />
<br />
#if <condition> { <script> } { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> } else { <script> }<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
Mudlet Nexus<br />
<br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
<br />
<br />
<br />
// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
// A slight modification of the above that illustrates an 'else' clause.<br />
// The second form shows that the word 'else' is actually optional too.<br />
// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
// Illustration of putting more than one statement in a block (also<br />
// spans lines here). Note the if doesn't end until the last '}' is<br />
// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
// This shows how ifs continue (on 'logical' lines) even though the<br />
// blocks in its constituent clauses may have multiple lines. The<br />
// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
<br />
====Mudlet equivalents of Nexus functions====<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
Mudlet Nexus<br />
<br />
*Math with Variables<br />
** <variable> = <variablename> <+ - / *> <number or variable> <br />
** #add <variablename> <expression><br />
<br />
*Echo<br />
** echo "text\n" or echo("text\n") <br />
** #echo <text><br />
** echo "text" or echo("text") <br />
** #echo_ <text><br />
<br />
*Enable Group/Alias/Trigger/Keybinding/Timer<br />
** enableAlias("<group name>"), enableTrigger(), enableKey() or enableTimer() <br />
** #groupon <group name><br />
<br />
*Disable Group/Alias/Trigger/Keybinding/Timer<br />
** disableAlias("<group name>"), disableTrigger(), disableKey() or disableTimer() <br />
** #groupoff <group name><br />
<br />
*Highlight<br />
** selectString (line, 1) bg("<color>") resetFormat() <br />
** #highlight <color><br />
<br />
*Gag<br />
** deleteLine() <br />
** #gag<br />
<br />
*Open Url/Links<br />
** openUrl("<url>")* <br />
** #openurl <url><br />
<br />
*Send text to Mud<br />
** send("<stuff>") <br />
** #send <text><br />
<br />
*Send Multiple text to Mud at once<br />
** sendAll("hi", "hello", "bye") <br />
** #send_ hi #send_ hello #send bye<br />
<br />
*Variable Setting<br />
** <variable name> = "<text value>" <br />
** #set <variable name> <text value><br />
** <variable name> = <expression> <br />
** #set <variable name> = <expression><br />
<br />
*Clear Variables<br />
** <variable name> = nil <br />
** #unset <variable name><br />
<br />
*Wait/Timers<br />
** <lua>tempTimer(<time in s>, [[ <lua code to do once time is up> ]])</lua><br />
** #wait <milliseconds><br />
<br />
====How to call aliases in Mudlet====<br />
<br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<br />
function <name> ()<br />
<stuff it does><br />
end<br />
<br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
<br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<br />
eat_bloodroot()<br />
<br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
<br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
<br />
===Notes to be aware of===<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
==From MUSHclient==<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
==From CMUD==<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
==From zMUD==</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=507Manual:Migrating2011-07-06T21:08:11Z<p>Rayth: /* Setting variables */</p>
<hr />
<div>=Migrating to Mudlet=<br />
<br />
==From Nexus==<br />
===Trigger patterns===<br />
<br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
'''Note:'''<br />
<table border="1"><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
===Basic scripting===<br />
<br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
====Calling functions====<br />
<table border="1"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
'''Note:'''<br />
<table border="1"><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
===Setting variables===<br />
<br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
<br />
====Setting variables in Mudlet====<br />
<br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<br />
====Wildcards====<br />
<br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
Nexus:<br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
<br />
Another example would be the targetting alias:<br />
<br />
Nexus:<br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
<br />
Mudlet:<br />
<code><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</code><br />
<br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
<br />
====#wait in Mudlet====<br />
<br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<br />
Nexus script:<br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
<br />
====ifs in Mudlet====<br />
<br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
Mudlet Nexus<br />
<br />
if <condition> then <text> end<br />
<br />
<br />
#if <condition> <text><br />
<br />
#if <condition> { <script> }<br />
<br />
if <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } else { <script> }<br />
<br />
#if <condition> { <script> } { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> } else { <script> }<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
Mudlet Nexus<br />
<br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
<br />
<br />
<br />
// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
// A slight modification of the above that illustrates an 'else' clause.<br />
// The second form shows that the word 'else' is actually optional too.<br />
// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
// Illustration of putting more than one statement in a block (also<br />
// spans lines here). Note the if doesn't end until the last '}' is<br />
// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
// This shows how ifs continue (on 'logical' lines) even though the<br />
// blocks in its constituent clauses may have multiple lines. The<br />
// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
<br />
====Mudlet equivalents of Nexus functions====<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
Mudlet Nexus<br />
<br />
*Math with Variables<br />
** <variable> = <variablename> <+ - / *> <number or variable> <br />
** #add <variablename> <expression><br />
<br />
*Echo<br />
** echo "text\n" or echo("text\n") <br />
** #echo <text><br />
** echo "text" or echo("text") <br />
** #echo_ <text><br />
<br />
*Enable Group/Alias/Trigger/Keybinding/Timer<br />
** enableAlias("<group name>"), enableTrigger(), enableKey() or enableTimer() <br />
** #groupon <group name><br />
<br />
*Disable Group/Alias/Trigger/Keybinding/Timer<br />
** disableAlias("<group name>"), disableTrigger(), disableKey() or disableTimer() <br />
** #groupoff <group name><br />
<br />
*Highlight<br />
** selectString (line, 1) bg("<color>") resetFormat() <br />
** #highlight <color><br />
<br />
*Gag<br />
** deleteLine() <br />
** #gag<br />
<br />
*Open Url/Links<br />
** openUrl("<url>")* <br />
** #openurl <url><br />
<br />
*Send text to Mud<br />
** send("<stuff>") <br />
** #send <text><br />
<br />
*Send Multiple text to Mud at once<br />
** sendAll("hi", "hello", "bye") <br />
** #send_ hi #send_ hello #send bye<br />
<br />
*Variable Setting<br />
** <variable name> = "<text value>" <br />
** #set <variable name> <text value><br />
** <variable name> = <expression> <br />
** #set <variable name> = <expression><br />
<br />
*Clear Variables<br />
** <variable name> = nil <br />
** #unset <variable name><br />
<br />
*Wait/Timers<br />
** <lua>tempTimer(<time in s>, [[ <lua code to do once time is up> ]])</lua><br />
** #wait <milliseconds><br />
<br />
====How to call aliases in Mudlet====<br />
<br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<br />
function <name> ()<br />
<stuff it does><br />
end<br />
<br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
<br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<br />
eat_bloodroot()<br />
<br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
<br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
<br />
===Notes to be aware of===<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
==From MUSHclient==<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
==From CMUD==<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
==From zMUD==</div>Raythhttps://wiki.mudlet.org/index.php?title=Manual:Migrating&diff=506Manual:Migrating2011-07-06T19:51:54Z<p>Rayth: /* Basic scripting */</p>
<hr />
<div>=Migrating to Mudlet=<br />
<br />
==From Nexus==<br />
===Trigger patterns===<br />
<br />
Lets start with triggers. For translating Nexus patterns into Mudlet, use the following table below. Make sure to set the pattern type in Mudlet to be perl regex, because the default substring works differently.<br />
<table border="1"><br />
<th>Mudlet</th><br />
<th>Nexus</th> <br />
<th>What it does</th> <br />
<tr><br />
<td>(\w+)</td><br />
<td>{w}</td><br />
<td>Match one or more non-whitespace characters (a 'word')</td><br />
</tr><br />
<tr><br />
<td>(\d+)</td><br />
<td>{d}</td><br />
<td>Match one or more numeric digits (a number)</td><br />
</tr><br />
<tr><br />
<td>([abc])</td><br />
<td>{[abc]}</td><br />
<td>Match one or more of either 'a', 'b' or 'c'. (a character class)</td><br />
</tr><br />
<tr><br />
<td>([^abc])</td><br />
<td>{[^abc]}</td><br />
<td>Match one or more of anything EXCEPT 'a', 'b', or 'c'</td><br />
</tr><br />
<tr><br />
<td>(.*)</td><br />
<td>{*}</td><br />
<td>Match zero or more characters (anything)</td><br />
</tr><br />
<tr><br />
<td>^</td><br />
<td>{<} </td><br />
<td>Match the beginning of a line (not the actual newline character)</td><br />
</tr><br />
<tr><br />
<td>$</td><br />
<td>{>}</td><br />
<td>Match the end of a line (not the actual newline character)</td><br />
</table> <br />
'''Note:'''<br />
<table border="1"><br />
<td>If you just have a pattern with a {<} and {>} and nothing else, copy the pattern over without the {<}{>} and select the exact match pattern type. For example {<}You sit down.{>} in Nexus would become '''You sit down.''' in Mudlet with the pattern type of exact match. This is easier to read and matches way faster!</td><br />
</table><br />
<br />
===Basic scripting===<br />
<br />
The Nexus way of doing a function is like this: #function stuff it does. In Mudlet, it’s function(stuff it does). Note that if you’d like to give text to a function, you put it inside double or single quotes.<br />
<br />
====Calling functions====<br />
<table border="1"><br />
<caption>Calling functions</caption><br />
<th>Mudlet</th><br />
<th>Nexus</th><br />
<tr><br />
<td><br />
<lua><br />
send("hi")<br />
echo("Hello to me!")<br />
</lua><br />
</td><br />
<td><br />
<code><br />
#send hi<br />
#echo Hello to me!<br />
</code><br />
</td><br />
</tr><br />
</table><br />
'''Note:'''<br />
<table border="1"><br />
<td><br />
If you’d like to use a variable inside text, you’d put it outside the quotes and glue it together with two dots.<br />
</td><br />
</table><br />
<br />
====Setting variables====<br />
<br />
<code><br />
#set number 1234<br />
#echo My number is: $number<br />
#echo the $number is in the middle of my text<br />
</code><br />
<br />
====Setting variables in Mudlet====<br />
<br />
<lua><br />
number = 1234<br />
echo("My number is: " .. number.. "\n")<br />
echo("the " .. number .. " is in the middle of my text\n")<br />
echo(string.format("And here's another - %s - way to format things\n", number))<br />
</lua><br />
<br />
====Wildcards====<br />
<br />
To use the wildcard variable in Nexus, you’d use $1 for the first match, $2 for the second and so on. In Mudlet, the matches[] table contains the matches - and it starts placing the matches from 2. So the Nexus $1 would be matches[2], $2 would be matches[3].<br />
<br />
Nexus:<br />
<code><br />
{w} kicks you.<br />
#set badguy $1<br />
#echo $badguy kicked me!<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
(\w+) kicks you\.<br />
badguy = matches[2]<br />
echo(badguy .. " kicked me!")<br />
</lua><br />
<br />
Another example would be the targetting alias:<br />
<br />
Nexus:<br />
<code><br />
alias name: t<br />
alias script: #set target $1<br />
</code><br />
<br />
Mudlet:<br />
<code><br />
alias pattern: ^t (.*)$<br />
alias script: target = matches[2]<br />
</code><br />
<br />
The reason the first match goes into matches[2] and not matches[1] is because matches[1] contains the part of the line that matched your trigger / alias.<br />
<br />
====#wait in Mudlet====<br />
<br />
In Nexus, a #wait will freeze the script while it’s executing - such that commands after it are delayed. In Mudlet, we use tempTimer which that works a bit differently - it doesn’t freeze the script, but instead makes it so commands a tempTimer is asked to do will get done in the future.<br />
<br />
So the difference is that a tempTimer doesn’t freeze the commands following it at all, everything gets done at once as usual. Just things a tempTimer was asked to do get done in the future.<br />
<br />
Nexus script:<br />
<code><br />
#send hello<br />
#wait 1000<br />
#send hi<br />
#wait 500<br />
#send bye<br />
</code><br />
<br />
Mudlet:<br />
<lua><br />
send("hello")<br />
tempTimer(1, [[send("hi")]])<br />
tempTimer(1.5, [[send("bye")]])<br />
</lua><br />
<br />
====ifs in Mudlet====<br />
<br />
Next are the #if statements. Here’s a table comparing the syntaxes of Nexus and Mudlet:<br />
Mudlet Nexus<br />
<br />
if <condition> then <text> end<br />
<br />
<br />
#if <condition> <text><br />
<br />
#if <condition> { <script> }<br />
<br />
if <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } else { <script> }<br />
<br />
#if <condition> { <script> } { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> }<br />
<br />
if <condition> then <script> elseif <condition> then <script> else <script> end<br />
<br />
<br />
#if <condition> { <script> } elsif <condition> { <script> } else { <script> }<br />
<br />
Here is the sample side-by-side comparison of how you’d use it:<br />
Mudlet Nexus<br />
<br />
-- If foo is true, echo that fact.<br />
if foo then echo ("Foo is true!") end -- If foo is true, echo that fact.<br />
<br />
-- A slight modification of the above that illustrates an 'else' clause.<br />
-- Note that the 'then' is always necessary to avoid confusion.<br />
if foo then echo ("Foo is true!") else echo ("Foo is false!") end<br />
<br />
-- Illustration of putting more than one statement in a block (also<br />
-- spans lines here). Note the if doesn't end until the last 'end' is<br />
-- encountered.<br />
-- We also add a \n at the end of multiple echos so each one is on it's own line.<br />
if foo then<br />
echo ("Foo is true!\n")<br />
echo ("Isn't it grand?\n")<br />
echo ("These commands are all on separate lines too!\n")<br />
end<br />
<br />
-- This shows how ifs continue (on 'logical' lines) even though the<br />
-- blocks in its constituent clauses may have multiple lines. The<br />
-- following lines are all _one_ single if statement.<br />
if foo > 50 then<br />
echo ("Foo is big!\nYes it is.")<br />
elseif foo > 10 then<br />
echo ("Foo is pretty big...\n")<br />
echo ("I've seen bigger.")<br />
else<br />
echo ("Foo is actually kind of small.")<br />
end<br />
<br />
-- Ifs can be nested too.<br />
if foo then<br />
if bar then<br />
echo ("Both foo and bar are true.")<br />
else<br />
echo ("Foo's true, but bar isn't.")<br />
end<br />
end<br />
<br />
<br />
<br />
// If $foo is true, echo that fact.<br />
#if $foo #echo Foo is true! // If $foo is true, echo that fact.<br />
<br />
// A slight modification of the above that illustrates an 'else' clause.<br />
// The second form shows that the word 'else' is actually optional too.<br />
// (The two lines are functionally the same.)<br />
#if $foo { #echo Foo is true! } else { #echo Foo is false! }<br />
#if $foo { #echo Foo is true! } { #echo Foo is false! }<br />
<br />
// Illustration of putting more than one statement in a block (also<br />
// spans lines here). Note the if doesn't end until the last '}' is<br />
// encountered.<br />
#if $foo {<br />
#echo Foo is true!<br />
#echo Isn't it grand?<br />
#echo These commands are all on separate lines too!<br />
}<br />
<br />
// This shows how ifs continue (on 'logical' lines) even though the<br />
// blocks in its constituent clauses may have multiple lines. The<br />
// following lines are all _one_ single if statement.<br />
#if $foo > 50 {<br />
#echo Foo is big!<br />
#echo Yes it is.<br />
} elsif $foo > 10 {<br />
#echo Foo is pretty big...<br />
#echo I've seen bigger.<br />
} else {<br />
#echo Foo is actually kind of small.<br />
}<br />
<br />
// Ifs can be nested too.<br />
#if $foo {<br />
#if $bar {<br />
#echo Both foo and bar are true.<br />
} else {<br />
#echo Foo's true, but bar isn't.<br />
}<br />
}<br />
<br />
====Mudlet equivalents of Nexus functions====<br />
<br />
Now that we got the ifs covered, lets go over the Mudlet equivalents of other Nexus functions. Note that this is a direct Nexus→Mudlet comparison; certain functions in Mudlet have much more capability.<br />
Mudlet Nexus<br />
<br />
*Math with Variables<br />
** <variable> = <variablename> <+ - / *> <number or variable> <br />
** #add <variablename> <expression><br />
<br />
*Echo<br />
** echo "text\n" or echo("text\n") <br />
** #echo <text><br />
** echo "text" or echo("text") <br />
** #echo_ <text><br />
<br />
*Enable Group/Alias/Trigger/Keybinding/Timer<br />
** enableAlias("<group name>"), enableTrigger(), enableKey() or enableTimer() <br />
** #groupon <group name><br />
<br />
*Disable Group/Alias/Trigger/Keybinding/Timer<br />
** disableAlias("<group name>"), disableTrigger(), disableKey() or disableTimer() <br />
** #groupoff <group name><br />
<br />
*Highlight<br />
** selectString (line, 1) bg("<color>") resetFormat() <br />
** #highlight <color><br />
<br />
*Gag<br />
** deleteLine() <br />
** #gag<br />
<br />
*Open Url/Links<br />
** openUrl("<url>")* <br />
** #openurl <url><br />
<br />
*Send text to Mud<br />
** send("<stuff>") <br />
** #send <text><br />
<br />
*Send Multiple text to Mud at once<br />
** sendAll("hi", "hello", "bye") <br />
** #send_ hi #send_ hello #send bye<br />
<br />
*Variable Setting<br />
** <variable name> = "<text value>" <br />
** #set <variable name> <text value><br />
** <variable name> = <expression> <br />
** #set <variable name> = <expression><br />
<br />
*Clear Variables<br />
** <variable name> = nil <br />
** #unset <variable name><br />
<br />
*Wait/Timers<br />
** <lua>tempTimer(<time in s>, [[ <lua code to do once time is up> ]])</lua><br />
** #wait <milliseconds><br />
<br />
====How to call aliases in Mudlet====<br />
<br />
The typical workflow in Nexus is that you’d define the aliases for yourself to use, and also use aliases for system-related things (things like checking if you’d need to eat a herb, etc).<br />
<br />
While the first use is good, the second isn’t - because the user can also run this alias at an inopportune time, because if you want to call an alias it has to match all alises again, and so on.<br />
<br />
Now, while in Mudlet you can call another alias with the expandAlias() function, this is strongly discouraged. What you do instead if create a function (for example, send() and echo() are functions) that you can then call from your alias or trigger. This has many advantages - it’s faster, you can easily give your function values, and your function can return you values, too.<br />
<br />
To make a function, you go to the Scripts section, create a new script, and write in your function:<br />
<br />
function <name> ()<br />
<stuff it does><br />
end<br />
<br />
For example, if we want to make a function that does two things for us at once, we’d do this:<br />
<br />
function eat_bloodroot()<br />
send ("outr bloodroot")<br />
send ("eat bloodroot")<br />
end<br />
<br />
Then just do this in our alias or trigger to outr and eat bloodroot:<br />
<br />
eat_bloodroot()<br />
<br />
As mentioned, you can also give things to functions - in this case lets expand the function to eat any herb for us we tell it:<br />
<br />
function eat (what)<br />
send ("outr " .. what)<br />
send ("eat " .. what)<br />
end<br />
[...]<br />
eat ("bloodroot")<br />
eat ("kelp")<br />
eat ("ginseng")<br />
<br />
Lastly, functions can also give you data back. One useful example for this is to break down tasks into functions, which will help your code readability:<br />
<br />
function can_i_stand()<br />
if not paralyzed and not prone and not stunned then<br />
return true<br />
else<br />
return false<br />
end<br />
[...]<br />
if can_i_stand() and have_balance and have_equilibrium then<br />
send ("stand")<br />
end<br />
<br />
===Notes to be aware of===<br />
<br />
To finish off, a couple of points that should be remembered:<br />
* Mudlet does profile snapshots (nexus archives) automatically - to load a different one, select it from the list when connecting<br />
* Mudlet can import and export xml<br />
* Mudlet and Nexus xml formats aren’t compatible<br />
* Mudlet can do nexus graphics, here is a package for - [[http://forums.mudlet.org/viewtopic.php?f=6&t=981 Achaea]], [[http://forums.lusternia.com/lofiversion/index.php/t18507.html Lusternia]]<br />
* Mudlet has a ton more features such are more speed, less bugs, copy from the normal window, replay logging, color html logging, more powerful scripting, and the list goes on.<br />
<br />
==From MUSHclient==<br />
<br />
#Mudlet doesn't use %#'s - uses matches[] instead. "%1" or %1 would be matches[2], "%2" or %2 would be matches[3] and so on<br />
#No variables in trigger patterns - but you can check against your variables in scripts, or lua function pattern types<br />
<br />
==From CMUD==<br />
Changing over to Mudlet requires learning some simple syntax changes and some general concept changes:<br />
<br />
'''In a mudlet trigger for example:'''<br />
Name is just the name you want to use to label the trigger. It doesn't effect the actual firing of the trigger. The trigger fires based on the "pattern" and you can have multiple patterns for a single piece of code. You can also have a multi-line trigger, where the entire trigger must see all the patterns to fire.<br />
'''Example #1 - Using a variable and a temp trigger'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
#IF (@autogold) {<br />
#temp {You have recovered balance on all limbs.} <br />
{get shard}<br />
} <br />
</lua><br />
<br />
'''Mudlet Example:'''<br />
<lua><br />
Pattern: <br />
^A (.*) shard appears and clatters to the ground\.$<br />
<br />
Code:<br />
if autogold then<br />
shardtrigger = tempTrigger("You have recovered balance on all limbs.)", [[send("get shard") killTrigger(shardtrigger)]])<br />
end<br />
</lua><br />
<br />
'''Example #2 - Doing Math:'''<br />
'''Cmud:'''<br />
<lua><br />
Pattern:<br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
#ADD goldcounter %1<br />
</lua><br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^You put (\d+) gold sovereigns in (.*)\.$<br />
<br />
Code:<br />
goldcounter = goldcounter + tonumber(matches[2])<br />
</lua><br />
<br />
'''Example #3 - Replacing Text'''<br />
'''Cmud'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
#sub {%ansi(yellow,cyan,bold)(*X*)%ansi(white) RAZED %ansi(red)%1's %ansi(white)Shield %ansi(yellow,cyan,bold)(*X*)}<br />
</lua><br />
'''Mudlet'''<br />
<lua><br />
Pattern:<br />
^You raze (\w+) magical shield with (.*)\.$<br />
<br />
Code:<br />
deleteLine()<br />
cecho("<yellow:cyan>You RAZED " .. matches[2] .. " shield")<br />
</lua><br />
<br />
'''Example #4 - Enable/Disable Classes'''<br />
<br />
'''Cmud:'''<br />
<lua><br />
#T+ ClassFolderName<br />
</lua><br />
<br />
'''Mudlet:''' <br />
<lua><br />
enableAlias("ClassFolderName")<br />
<br />
Note: Alias can be an alias, trigger, time, key, etc. <br />
You can disable entire classes or just single triggers.<br />
</lua><br />
<br />
'''Example 5 - Multi-action Commands<br />
Let's say we create an alias called silly<br />
<br />
Cmud:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
look;ct Hello City;pt Hello Party;laugh<br />
<br />
Now in cmud if we called this alias from a trigger or another alias,<br />
we would just call sillyAction<br />
<br />
</lua><br />
'''<br />
Mudlet:'''<br />
<lua><br />
Pattern: <br />
sillyAction<br />
<br />
Code:<br />
sendAll("look","ct Hello City","pt Hello Party", "laugh") <br />
</lua><br />
<br />
Now, in mudlet, if we want to call on that alias, we need to tell mudlet that we want to execute the alias sillyAction rather than sending "sillyAction" directly to the mud. To do that we would do:<br />
<br />
<lua><br />
expandAlias("sillyAction")<br />
</lua><br />
<br />
'''Example 6 - Using if statements with and, or and nil.'''<br />
<br />
'''Cmud Code:'''<br />
<lua><br />
#IF (@myclass="knight" & !(@pets))<br />
{<br />
say cool<br />
}<br />
</lua><br />
'''<br />
Mudlet Code:'''<br />
<lua><br />
if myclass == "knight" and not pets then<br />
send("say cool")<br />
end<br />
</lua><br />
<br />
'''Example 7 - Hitting your target OR your first argument.'''<br />
This is for when you want to either hit the person you have targeted, or the name you type. <br />
<br />
For example, to kick Das you'd type:<br />
kk Das<br />
<br />
Or if Das is your target, just typing kk<br />
<br />
'''Cmud:'''<br />
<lua><br />
Pattern: ^kk ?(\w+)?$<br />
#VAR target Das<br />
if (@target) {<br />
kick @target<br />
}<br />
if (%1) {<br />
kick %1<br />
}<br />
</lua><br />
<br />
'''Mudlet:'''<br />
<lua><br />
Pattern: <br />
^kk ?(\w+)?$<br />
<br />
Code:<br />
target = "Das"<br />
send("kick "..(matches[2] or target))<br />
</lua><br />
'''<br />
Example #7 - Two Pattern Examples'''<br />
<lua>^rz(?:(.*)|)$ <br />
This would let you do rzDas to raze Das for example.<br />
</lua><br />
Versus:<br />
<lua><br />
^rz ?(\w+)?$ <br />
This would require you to do rz Das with a space between rz and Das.<br />
</lua><br />
<br />
==From zMUD==</div>Rayth