Mush Triggers

by Unknown

Back to Mechanic's Corner.

Unknown2010-06-07 17:39:10
QUOTE (Faymar Mes'ard @ Jun 7 2010, 09:40 AM) <{POST_SNAPBACK}>
Here, from the module that deals with my offense:
CODE
AcceleratorTo ("F4", "offense:exec ('attack', 'man_bashbrains')", 12)

I used apostrophe instead of quotation marks because that would end the string started by the quotation marks. When I press F4 mush calls the function offense:exec ("attack", "man_bashbrains").
I typically use quotation marks for all my strings, and apostrophe for when I write a string inside another string.
Hope this helps.

You can try this in the Immediate Window (CTRL+I) and see what error it raises:
CODE
AcceleratorTo ("CTRL+T", "Note ('it works')", 12) --that will work
AcceleratorTo ("CTRL+T", "Note ("it doesnt work")", 12) --that won't work, because it will end the string inside paranthesis, and mush will expect to close the paranthesis



So use single parenthesis whenever I'm doing an execution of an action within the string? Or a string inside a string?
Siam2010-06-07 18:08:22
A trigger I have doesn't work unless I use the target's full name.

Here's the trigger:

@target's mana stands at */*.

Basically, I want it to fire even if I target Sia instead of using Siam.
Unknown2010-06-07 18:19:02
Use regex, like so:

CODE
^@target*'s mana stands at (\\d+)/(\\d+)\\.$
Siam2010-06-07 18:49:47
QUOTE (Zarquan @ Jun 8 2010, 02:19 AM) <{POST_SNAPBACK}>
Use regex, like so:

CODE
^@target*'s mana stands at (\\d+)/(\\d+)\\.$


Life saver.
Felicia2010-06-07 20:19:18
QUOTE (TheSponge @ Jun 7 2010, 01:39 PM) <{POST_SNAPBACK}>
So use single parenthesis whenever I'm doing an execution of an action within the string? Or a string inside a string?


I suggest reading this Lua tutorial page.

Basically, you can define strings using double quotes, apostrophes, double brackets, or special double brackets:

CODE
"stuff"   'stuff'   ]   =], etc.


There are multiple types so that you can actually use " and ' (and even double brackets, should you need to) normally, to print them for example, without having Lua treat them as part of the code -- or yes, so that you can nest strings properly. Here's what the strings in Faymar's examples would look like broken into chunks per double quotations:


CODE
"CTRL+T"     "Note ('it works')"  -- right

"CTRL+T"     "Note ("                   ")"  -- wrong



You have to use multiple different types of string-nesting symbols in cases like these, so that Lua knows what nests into what and how.