
- #MUDLET STRING FUNCTIONS HOW TO#
- #MUDLET STRING FUNCTIONS INSTALL#
- #MUDLET STRING FUNCTIONS FULL#
- #MUDLET STRING FUNCTIONS CODE#
#MUDLET STRING FUNCTIONS CODE#
Now when a code comes across your screen saying that "A cat enters the room." you will instantaneously pet the cute little thing! Now, just as aliases are case sensitive Triggers are as well. and set the command to be executed as - send("pet cat"). Triggers are lines of code that you tell the system "if this comes across the screen then execute the command listed below." One can enter into a trigger line - A cat enters the room.

The easiest explanation of a trigger in the Mudlet environment is a giant "if/then" statement. The periods before and after the quotations are needed to indicate that the word before, in between of, or after them is a variable and it needs to put it's value there. When using a variable in a Lua script if it's not in a command that is to be sent it can be left alone for further evaluation, like - if target = "Vaxarn" then send("attack ".target). Values can be set to variables by either using aliases or triggers. Basically until you hit the enter key, you're going to set the variable's value to whatever you have just put as the input. So if i entered "z rock" into the input line it would get the value as "rock". var = matches - This would set the variable "var" to the captured value. Not this is useless unless you assign a specified variable to it.įor the regex line listed above the captured line can be set to a variable by using the "matches" function. This captures anything and everything after "z" until i hit the enter key. The Perl Regex line that i use is ^z (\w+)$. One that i use often is my targeting script. Most of the time we tell what value to set to what variable. If you're working on coding Mudlet itself, use this function to tell where the actual definition of a function is.Variables are items that have values associated with them. You can also use it to get more information on the Alias# / Trigger# objects you see in the error console: Lua brings a helpful debug.getinfo(function) function, which gets you some information about where a function comes from: whenever it's your own, or one defined by Mudlet (in C++ or Lua). Newer ones that do support them are completely fine, however!Ĭoroutines have many uses: finite state machines, running intensive tasks (yielding every once in a while so Mudlet isn't frozen), and so on. Older Mudlets that don't support coroutines might crash, which sucks. Note that if you'll be using coroutines as part of a package you'll give to others, remember about the if mudlet.supportscoroutines then return end bit.
#MUDLET STRING FUNCTIONS INSTALL#
You can also install the demo as a package - paste this into Mudlet: You'll see that the send()'s are being sent one at a time, instead of all at once as they would have been without the yields. create a coroutine that'll be running our ritual function - or re-use the one we're already using if there is one ritualcoroutine = ritualcoroutine or coroutine.create ( ritual ) - run the coroutine until a coroutine.yield() and see - if there's any more code to run local moretocome = coroutine.resume ( ritualcoroutine ) - if there's no more code to run - remove the coroutine, - so next time you call the alias - a new one gets made if not moretocome then ritualcoroutine = nil end This is stored in multimatches as the value of key=1 in the sub-table matches which, in turn, is the value of key=1 of the table multimatches.
#MUDLET STRING FUNCTIONS FULL#
The first trigger condition (=regex 1) got as the first full match "You have not completed any quests". You can now see what the table multimatches contains in this case. The function showMultimatches() prints out the content of the table multimatches. The table multimatches contains : - regex 1 captured : ( multimatches ) key = 1 value = You have not completed any quests key = 2 value = not key = 3 value = completed key = 4 value = any key = 5 value = quests regex 2 captured : ( multimatches ) key = 1 value = You are refreshed, hungry, very young and brave key = 2 value = refreshed key = 3 value = young key = 4 value = and key = 5 value = brave.

You are refreshed, hungry, very young and brave.

You have an almost non-existent ability for avoiding hits. The command "score" generates the following output on batMUD: In the case of a multiline trigger with these 2 Perl regex as conditions: The following example can be tested on the game : multimatches stores its matches by lines, inside each line are the relevant matches to it.

Multimatches is the complement of matches when matching multi-line triggers.
#MUDLET STRING FUNCTIONS HOW TO#
Nick Gammon has also written a nice overview on how to deal with Lua tables. A good overview of tables is available on Lua's wiki in the TablesTutorial.
