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"
Australia Forum Administrator
#1
#2
Australia Forum Administrator
#3
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>
Try:
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.
<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.
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 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>
The SetVariable does not take effect on @variables inside a script (the replacement has already been done).
All you need is:
All you need is:
print ("get " .. word)