Aliases
One of the easiest functions in Mudlets scripting environment are what are called aliases. Aliases are strings of information that, when run successfully, call a specific code. In Mudlet all aliases are compiled in Perl Regex format. Such an example would be ^test$. Where "^" means the beginning of the string and "$" indicates the last character in the alias. if you typed in "test " (note the space at the end) and the Perl Regex line is set for ^test$, it would not call the script function that's associated with it due to the extra space at the end. However, had you set the Perl Regex line to ^test $ then of course the line would then call the function listed.
Now, most of the time the "$" character indicates the space at which the space is sent, usually used by hitting the "Enter" key. Not always is this the case however, some aliases can be compiled in such a way as to set variables in the system as well.
Now, most of the time the "$" character indicates the space at which the space is sent, usually used by hitting the "Enter" key. Not always is this the case however, some aliases can be compiled in such a way as to set variables in the system as well.
Variables
Variables are items that have values associated with them. Most of the time we tell what value to set to what variable. One that i use often is my targeting script. The Perl Regex line that i use is ^z (\w+)$. This captures anything and everything after "z" until i hit the enter key. Not this is useless unless you assign a specified variable to it.
For the regex line listed above the captured line can be set to a variable by using the "matches[2]" function. Simply compiled as
-- var = matches[2] -- This would set the variable "var" to the captured value. So if i entered "z rock" into the input line it would get the value as "rock". Same as if i did "z a frog on the moon". 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. Values can be set to variables by either using aliases or triggers.
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). 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.
For the regex line listed above the captured line can be set to a variable by using the "matches[2]" function. Simply compiled as
-- var = matches[2] -- This would set the variable "var" to the captured value. So if i entered "z rock" into the input line it would get the value as "rock". Same as if i did "z a frog on the moon". 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. Values can be set to variables by either using aliases or triggers.
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). 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.
Triggers
The easiest explanation of a trigger in the Mudlet environment is a giant "if/then" statement. 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. -- and set the command to be executed as -- send("pet cat"). 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. Triggers lines can be set to an Exact Match, beginning of line substring, a substring, or a perl regex code. Setting triggers as a perl regex code is the simplest and most effective way of creating and adjusting variables. Just as when the Alias mentioned above captures everything between the "z" character and the pressing the enter key, triggers can be set to capturing specific lines as well. Here's an example of a successfull variable set from a trigger.
--^(.*) arrives from the ether\.$ --
target = matches[2]
-sendAll("dash n" , "await "..target)-
Now, it's noted that all of the command lines to be executed below the triggers are all scripted in Lua, so some functions may be a little confusing at first, but eventually you'll get the hang of it. Above you'll see that the capture [the (.*)] is going to grab anything and everything before the word "arrives" if the rest of the trigger line is indeed called. Ie, if you get -- Vaxarn arrives from the ether -- it will execute the code successfully. This code then sends two commands; one to dash to the north and the other to await whatever was captured. In this instance it would execute the code "await Vaxarn." Now take note, that if you saw -- Vaxarn arrives from the ether and dies.-- nothing would happen. The "\" at the end of the regex code indicates that the character between it and the "$" symbol is the last character in the string. Making it that much more sensitive.
--^(.*) arrives from the ether\.$ --
target = matches[2]
-sendAll("dash n" , "await "..target)-
Now, it's noted that all of the command lines to be executed below the triggers are all scripted in Lua, so some functions may be a little confusing at first, but eventually you'll get the hang of it. Above you'll see that the capture [the (.*)] is going to grab anything and everything before the word "arrives" if the rest of the trigger line is indeed called. Ie, if you get -- Vaxarn arrives from the ether -- it will execute the code successfully. This code then sends two commands; one to dash to the north and the other to await whatever was captured. In this instance it would execute the code "await Vaxarn." Now take note, that if you saw -- Vaxarn arrives from the ether and dies.-- nothing would happen. The "\" at the end of the regex code indicates that the character between it and the "$" symbol is the last character in the string. Making it that much more sensitive.