![]() ![]() When a trigger fires Mudlet calls this invisible function name to run the script e.g. ![]() trigger-scripts etc., secretly define a function name for the script and thus the script is not free code, but function code. On saving the script the script gets compiled and the free code is run instantly. code outside of a function definition - code that is not enclosed by function xyz() …. Script-scripts can contain an unlimited amount of function definitions and also free code i. This is the major difference between trigger-scripts, alias-scripts etc. Whenever you edit this script, it will be recompiled and the code will be run as it is not part of a function definition. Add following code to initialize your new variable myKills to a number and set its value to 0: If you are using an older version of Mudlet or a profile that doesn’t have this script item, simply click on the "Add" icon and make your own script. To do this click on the "Scripts" icon and select the standard script "My Global Variable Definitions". The best place to initialize variables is in script script outside of a function definition as this code is executed when the session is loaded or if you compile the script again after you have edited it. The trigger script expects myKills to be a number so you have to initialze the variable myKills to 0 before running the script for the first time. this one on numbers and this one on strings or this one on Lua tables For an in-depth coverage of variables in Lua take a look at a Lua tutorial e. There is another form of variables in Lua called tables which can be used for lists, arrays or dictionaries. target_health cecho ( msg ) end - this function does the same thing, but uses f function displayTarget () local msg = f " \n Target: " cecho ( msg ) end to glue strings together for display function displayTarget () local msg = " \n Target: ". this function uses the concatenation operator. For the following, we assume the following variables exist: - target which holds the target's name - target_health_color which is a cecho color determined elsewhere - target_health which is the actual health the target has. This variable is going to hold the number of kills we’ve made so far. For the kill counter we declare a variable and call it myKills. Each time you have made a new kill, the trigger matches on the kill message and runs a little script that increases the amount of kills by one each time the trigger fires - in other words, each time you kill a monster and the kill message is sent from the MUD. To give you an example: Let’s make a little trigger that counts how many monsters you have killed. Note Everything shares the same variables
0 Comments
Leave a Reply. |