Mudlet Variables

Ok so I've been playing on mudlet for about a month now, and I still only have very rudimentary knowledge of how to code. I don't think I'm a complete git when it comes to this sort of thing because I've taught myself how to code for other things however even after reading through the mudlet manual I still am pretty lost on a few points. 

My main issue is, you guessed it, variables. I've learned so far that you can use \w+ to capture a single word and use it as a variable with matches[2] (thy does it start at 2 and not 1?) but I still haven't figured out how to capture a string of letters/numbers or multiple words. Is there a a helpfile somewhere that explains specifically the capturing and usage of variables? When do I need to use .. before matches to (expand I think) the variable, and what does that even mean?

I've done my best not to pester people in and out of game because in game it's often difficult to discuss ooc things, often simply because there are more pressing matters like hunting or defending etc. and I read just about every post in the forums pertaining to coding issues and try to understand the problems people are posting and the answers others are giving. What I really wish I had was a few simple examples and a list of the syntax for capturing different sorts of variables/strings.

I tried to make a simple set of triggers to announce mindnet stuff and I just couldn't get it to work, and although I can make an attack alias like "send("kill " .. target)" I coudln't figure out how to make alias' for my strikes which have the target variable in the middle of the equation.

Any help in or out of game would be greatly appreciated and would go a long way in helping me enjoy the coding aspect of playing the game rather than feel like im fighting with syntax instead of orcs.


  • edited June 2014
    Hey, I'll answer some thing here, but FYI, there is a Mudlet clan in game, and the people there are great. Also, my Eleusian (Dalemi) is always open for questioning, if you want to ask.

    As for the coding questions, many can be answered by look at this page. But, I'll answer the few you had here too!

    The matches variable array actually starts with 1, but matches[1] is the entire line that was triggered on. Each subsequent matches is from the specific substring matches in the trigger.

    \w is actually a regular expression that matches any alphanumeric character, and the + means to match one or more of these. There are a lot of regular expressions, and they can be pretty confusing until you get used to them. I like to use this cheat sheet. Also, you can use this site to test your trigger lines. Put the trigger in the top box, and the line you're trying to match in the bottom. If it works, the strings matched will be highlighted. I use it all the time for the more complicated triggers.

    The .. symbol is Lua's concatenation symbol. It means to take two strings and make them into one string. So 
    x = "abc" .. "xyz" 
    will result in x being equal to "abcxyz". You use the symbol to insert matches variables in, because they're strings.

    In order to put a variable like this in the middle of a string, you need to do this:

    send("strike " .. target .. " hamstring")

    This creates the string "strike Carmain hamstring", given target being set to "Carmain". If you want to have a variable for the strike, you can do this:

    send("strike " .. target .. " " .. strikeType)

    So again, find someone in the Mudlet clan (ask in the Sylvan combat clan for an invite) and feel free to ask questions. And if you need help, I'm always willing in game.

  • Another thing to keep in mind is that even though there are plenty of Mudlet-specific API things, the scripting language itself is Lua, and there are doubtlessly plenty of Lua tutorials out there that don't involve Mudlet but might be good once you start coding more complex things (like if/else statements, loops, and naturally tables - probably the most complex thing the language has, which isn't so bad given it's really just a dynamically typed map).
Sign In or Register to comment.