Putting wildcards into triggers

Posted by porridge cat on Sun 18 Mar 2007 05:20 AM — 11 posts, 36,582 views.

#0
i wanna set a trigger like:


[2014mv] 1943/2827hp(68%) 2637/2637mn(100%) <51379g>


but the numbers are variables

how do i change this sentence into regular expressions?


my script is:

if %2 < 400 then
ColourNote("white","red","Warning! health is low")
end

Amended on Sun 18 Mar 2007 05:36 AM by Nick Gammon
USA #1
\[\d+mv\] (\d+)\/\d+hp\(\d+\%\) \d+\/\d+mn\(\d+\%\) \<\d+g\>
http://www.gammon.com.au/mushclient/funwithtriggers.htm for how regex works. I think the bit above should work. I can never remember if % matches something funny or not, so I always escape it with a \ to be safe.
Amended on Sun 18 Mar 2007 05:40 AM by Shaun Biggs
Australia Forum Administrator #2
I've taken the liberty of renaming your forum name from "Mushclient" to "Mushclient user". I think the name Mushclient is a bit misleading as it implies you are affiliated with the developers.

Just put an asterisk whereever a variable occurs, in other words instead of:

[2014mv] 1943/2827hp(68%) 2637/2637mn(100%) <51379g>

use:

[*mv] */*hp(*%) */*mn(*%) <*g>
USA #3
My solution uses the regular expressions, and will match health on %1.

Nick's doesn't use regular expressions, works just as well, and will match health on %2.
#4
success! but this trigger is a "prompt"

when i saw the prompt appeared but nothing happened until the next other sentence shown up

i wanna this trigger reacting immediately when i see it, how did you do that?


Australia Forum Administrator #5
This must have been discussed a hundred times on this forum. Search for "trigger prompt" or something like that, and read the various posts.

There are a number of solutions, depending on your circumstances.
#6
I had checked the option 'convert IAC EOR to newline' on.

However, it didn't yet resolve my problem.

I also read other articles regarding my question, but it looks like some hard.

May I get an instruction step by step?


Australia Forum Administrator #7
The short answer is that MUSHclient evaluates triggers when a newline is received. "Prompt" lines do not end with a newline, and thus do not make the trigger fire, until the next line is received.

There are various workarounds, one is discussed in this thread:

http://www.gammon.com.au/forum/bbshowpost.php?id=7430

That attempts to detect a prompt, and adds a newline to it, and then the triggers will fire. You will need to amend the plugin to match your prompt line.
#8
The prompt messages disappeared occasionally so I give it up after all...

But now, I have another new question!

for example:

AddAlias("fff", "fff", [[DeleteTrigger("i_am_not_one")]], 1+12, "")

I want an alias not sent to world but sent to script

However, the argument 12 doesn't work.

USA #9
Well, the 1+12 currently means that the alias is enabled, omitted from output, and it keeps evaluating. This is a pretty standard way of flagging multiple settings at once instead of having a ton of booleans to pass into a function, but everything is in a power of two so that the sum of any combination of flags is unique. 1+12 is really 1+4+8 when broken down into powers of two. From the AddTrigger page:
Quote:
The trigger flags are built into the "trigger_flag" table, as follows:
Enabled = 1
OmitFromLog = 2
OmitFromOutput = 4
KeepEvaluating = 8
IgnoreCase = 16
RegularExpression = 32
ExpandVariables = 512
Replace = 1024
Temporary = 16384
LowercaseWildcard = 2048


Here's what I would recommend, since I can't find out how to do this in one line:
AddAlias("fff", "fff", [[DeleteTrigger("i_am_not_one")]], 1+12, "")
SetAliasOption ("fff", "send-to", 12)
Amended on Fri 23 Mar 2007 02:34 PM by Shaun Biggs
Australia Forum Administrator #10
Another approach these days is to use ImportXML - this lets you create anything like a trigger, alias, timer etc. by using the XML-style code that is exactly how they are saved to the world file, or copied to the clipboard when you copy them.

http://www.gammon.com.au/scripts/doc.php?function=ImportXML

Also see this post:

http://www.gammon.com.au/forum/bbshowpost.php?id=7123

This describes an easy way to create aliases etc. using Lua tables (see LuaAddAlias in that post).