Posted by
| Nick Gammon
Australia (22,928 posts) bio
Forum Administrator |
Message
| I changed your trigger slightly because you had what seemed like a stray quote at the end, and you were sending to "Execute" however with nothing in the Send box.
<triggers>
<trigger
enabled="y"
group="tablegroup"
match="^This is wildcard (.*?) and this is another wildcard (.*?)$"
regexp="y"
script="learn_table"
sequence="100"
>
</trigger>
</triggers>
And the code in the script file would be:
t = {
"Small wildcard",
"Bigger wildcard",
"Biggest wildcard",
}
function learn_table (name, line, wildcards, styles)
local foo = wildcards [2]
for k, v in ipairs (t) do
if v == foo then
Execute ("gt I'm sending this message because I found " .. foo)
end -- if
end -- for
end -- learn_table
Alternatively you can do the whole thing inside the trigger without a script file, in which case you omit the script name "learn_table" from the trigger:
<triggers>
<trigger
enabled="y"
group="tablegroup"
match="^This is wildcard (.*?) and this is another wildcard (.*?)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>
t = {
"Small wildcard",
"Bigger wildcard",
"Biggest wildcard",
}
local foo = "%2"
for k, v in ipairs (t) do
if v == foo then
Execute ("gt I'm sending this message because I found " .. foo)
end -- if
end -- for
</send>
</trigger>
</triggers>
 |
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
The code is slightly inefficient because it involves a linear scan of the table, a better way would be to use a keyed table, and then just do a lookup, eg.
<triggers>
<trigger
enabled="y"
group="tablegroup"
match="^This is wildcard (.*?) and this is another wildcard (.*?)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>
t = {
["Small wildcard"] = true,
["Bigger wildcard"] = true,
["Biggest wildcard"] = true,
}
if t [ "%2" ] then
Execute ("gt I'm sending this message because I found %2" )
end -- if
</send>
</trigger>
</triggers>
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|