How do I specify a variable?

Post Reply
melk
Posts: 7
Joined: Mon Jun 14, 2010 8:53 pm

How do I specify a variable?

Post by melk »

All I want to do is be able to set a variable in the example:

*playername* says 'iceshield'

so I can then have my mage triggered to cast iceshield on *playername*

I for the life of me can not figure this very simple thing out :( Thanks

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: How do I specify a variable?

Post by Jules »

This sort of thing is pretty easy. I'm guessing your example is a trigger, so I would make a new trigger to look like:
(\w+) says\: "Iceshield."
From there, you make a variable from the regex wildcard by doing:
Code: [show] | [select all] lua
local person = matches[2]
(Notice that I used local. If you're only going to be using a variable in one place for one script, it's generally better to use a local variable, and not clog up the global variable namespace. From there, you'd just send the command:
Code: [show] | [select all] lua
send("cast iceshield on "..person)
Even though it's kind of a cluster, I'd really read through the Mudlet manual and absorb as much as you can. Afterwards, read through a Lua tutorial or something to learn the ins-and-outs of Lua. You'll be very thankful when you're done!

melk
Posts: 7
Joined: Mon Jun 14, 2010 8:53 pm

Re: How do I specify a variable?

Post by melk »

Thanks...

Obviously I am not a scripter ;) I've tried following along in the manual but I'm just even more confused.

I really like Mudlet (especially because it is basically the only real option for mudding on older non-Intel macs/osx) but I just don't understand why it seems to take so much to do so little.

I can appreciate that Mudlet is "better" because it is more efficient and elegant etc etc from a coding point of view. But as someone who doesn't know how to code and just wants something that works easily, I'm quite frustrated by the above example, which in zmud/cmud I would just specify as:

(%1) says 'iceshield'
cast iceshield (%1)

So simple that even I can understand it! :)

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: How do I specify a variable?

Post by Jules »

It's just by the way Lua works and is designed. All wildcards are found using the Perl RegExp engine, with which there's a ton of documentation about. It's a bit more robust than Zugg's implimentation of wildcards, in that it can handle more things, faster. When you learn the secrets of discerning RegExp, you just have to remember that all of those are stored in the matches[] table within Mudlet, and you just pull the captured strings from there.

It just takes practice. Lua might not be as easy to learn at first, compared to ZScript, but it's much more complete and better all around. Just keep at it!

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: How do I specify a variable?

Post by Yetzederixx »

FYI you don't need to use the local variable here unless you need to manipulate it for some reason:
Code: [show] | [select all] lua
send("c iceshield " .. matches[2])
Reading the Mudlet manual will help don't get me wrong, but learning about Lua is going to be necessary also:
Programming in Lua
Lua 5.1 Reference Manual
RegEx Tester they have a nice reference card and a near complete reference for wild card matching

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: How do I specify a variable?

Post by Yetzederixx »

Another regex site: www.regular-expressions.info/

Post Reply