Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Trigger match on a variable list
Trigger match on a variable list
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Chaosmstr
(21 posts) Bio
|
Date
| Sat 18 Jul 2015 05:36 AM (UTC) |
Message
| Gah! I've been reading for hours and I can't find this.
It seems like a such a simple thing! I've taken other examples found in the forum and tried to get them to work in mine, and I'm just not getting it.
I get output like this on the game.
The corpse of a stray dog contains:
(Artifact magic) a studded leather cap
(Artifact magic) a pair of studded leather gloves
<733hp(733) 522ma(522) 565mv(29223) s: stn 140003gp >
I trigger on (Artifact magic)* and want to compare the words in %1 to the variable Items.
If it finds a match, do something like "get %1"
<variables>
<variable name="items">ring|amulet|cap|bracelet|shirt|robe|sleeves|harness|gloves|bracers|armlets</variable>
</variables>
<triggers>
<trigger
enabled="y"
expand_variables="y"
group="random"
match="^(Artifact magic)*"
name="get_artifact"
regexp="y"
send_to="12"
sequence="100"
>
<send>if "%1"=="@!items") then
print("get %1)
end</send>
</trigger>
</triggers>
| Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 19 Jul 2015 01:02 AM (UTC) |
Message
| Try:
<triggers>
<trigger
enabled="y"
expand_variables="y"
group="random"
match="(Artifact magic) *"
name="get_artifact"
send_to="12"
sequence="100"
>
<send>
for word in string.gmatch (GetVariable ("items"), "%%a+") do
if string.match ("%1", word) then
print ("get %1")
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 string.gmatch breaks up the variable into words. Then we try to match that word on wildcard 1 in the response.
Note I turned off regular expressions, otherwise you would have to "escape" the brackets. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Chaosmstr
(21 posts) Bio
|
Date
| Reply #2 on Sun 19 Jul 2015 04:25 PM (UTC) Amended on Sun 19 Jul 2015 04:31 PM (UTC) by Chaosmstr
|
Message
| Almost!!
the output of your script gives:
get a studded leather cap
I'm trying for just:
get cap
I couldn't get it to just work with the word though.
I've modified the code a little, but it's... one behind.
It seems the "SetVariable" is a little slow.
The corpse of a stray dog contains:
(Artifact magic) a studded leather cap
get
(Artifact magic) a pair of studded leather gloves
get cap
<variables>
<variable name="items">ring|amulet|cap|bracelet|shirt|robe|sleeves|harness|gloves|bracers|armlets</variable>
</variables>
<triggers>
<trigger
expand_variables="y"
group="random"
match="(Artifact magic) *"
name="get_artifact"
send_to="12"
sequence="100"
variable="word"
>
<send>
for word in string.gmatch (GetVariable ("items"), "%%a+") do
if string.match ("%1", word) then
SetVariable ("word", word)
print ("get @word")
end -- if
end -- for
</send>
</trigger>
</triggers>
| Top |
|
Posted by
| Nick Gammon
Australia (23,140 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sun 19 Jul 2015 08:27 PM (UTC) |
Message
| The SetVariable does not take effect on @variables inside a script (the replacement has already been done).
All you need is:
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,063 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top