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
➜ Matching Vague Triggers
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Lessthanluminous
(9 posts) Bio
|
Date
| Sun 14 Mar 2010 07:19 AM (UTC) |
Message
| I want to change my 'tummy' variable whenever I eat something with the word 'steak' in it. However, I am fairly useless when it comes to this sort of thing, this being the most complicated trigger/anything I have (and I spent about a week searching forums trying to get this), so I can't figure out how to get a match whenever 'steak' appears, so I ended up having to do this and just create a separate part for each food.
<triggers>
<trigger
enabled="y"
expand_variables="y"
group="Kitchen"
keep_evaluating="y"
match="^You eat a (.*?)\\.$"
name="fridge"
regexp="y"
send_to="12"
sequence="95"
variable="onbalance"
>
<send>if "%1" == "burnt steak" then
SetVariable ("tummy", "steak")
elseif "%1" == "steak soup" then
SetVariable ("tummy", "steak")
elseif "%1" == "rare steak" then
SetVariable ("tummy", "steak")
end</send>
</trigger>
</triggers>
If there is a way (preferably one that at least looks a little similar) to match steak anywhere in the (.*?) (or however it needs to be changed), that would be a huge help. Also, I also want to be able to set it up to send set 'tummy' to 'chicken' if something with that word appears (in the same . (I'm not too concerned about chicken steaks). Once I see how to do this, I expect this trigger to get a little long so if it can be done without being ridiculously long, that would be even greater.
Question round two: is there a way I could send 'eat @tummy' to a variable, regardless of the result, in this same trigger without adding it to every possibility? I currently have the sequence at 95 just because I need another trigger to do that, and they don't like having the same sequence.
Question round three: while I want the 'eat @tummy' to be sent to the variable 'onbalance' in the trigger, I have no idea why it is said there. I only noticed it because I copied it, and if I change the 'send to script' to 'send to variable' the variable field is blank. (I guess this is unimportant, but I am a little curious)
Any help is appreciated! (And feel free to tidy up anything!) | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 14 Mar 2010 09:07 PM (UTC) |
Message
| Well the simple thing is to search for steak, eg.
if string.match ("%1", "steak") then
SetVariable ("tummy", "steak")
end -- if
A more general solution (taking into account chickens) is to break the line into words and check against a table, eg.
foods = {
steak = true,
chicken = true,
fish = true,
}
for w in string.gmatch ("%1", "%%a+") do
if foods [w] then
SetVariable ("tummy", w)
break
end -- if
end -- for
I doubled the second % because that is part of the string.gmatch.
This will match on any of the words in the table (steak, chicken, fish) and set the variable "tummy" to whichever it finds first. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Lessthanluminous
(9 posts) Bio
|
Date
| Reply #2 on Sun 14 Mar 2010 11:05 PM (UTC) |
Message
| Thanks! Not only does it work, it looks like a good place for me to start understanding/working on tables a little bit! | Top |
|
Posted by
| Lessthanluminous
(9 posts) Bio
|
Date
| Reply #3 on Thu 25 Mar 2010 04:39 PM (UTC) |
Message
| Wee! Follow up time!
I did a little extrapolation from what was given above (which worked great!) and got this:
<triggers>
<trigger
enabled="y"
expand_variables="y"
keep_evaluating="y"
match="^Humming softly\, (\w+) begins to spin pizza dough in (?:his|her) hands\.$"
name="Pizza"
regexp="y"
send_to="12"
sequence="100"
>
<send>Chef = {
@enemy = true,
@target = true,
Domino = true,
John = true,
CeeCee = true,
}
for w in string.gmatch ("%1", "%%a+") do
if cook [w] then
Send("throw sauce %1")
break
end
end</send>
</trigger>
</triggers>
Which works fine if it is CeeCee, John, or Domino (not sure if the variables work properly, but they haven't been an issue so far), but if anyone else does it I get:
Compile error
World: Midkemia
Immediate execution
[string "Trigger: Cripple"]:3: unexpected symbol near '=' | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #4 on Thu 25 Mar 2010 07:41 PM (UTC) |
Message
|
Lessthanluminous said:
name="Pizza"
...
[string "Trigger: Cripple"]:3: unexpected symbol near '='
That is the Pizza trigger, not the Cripple trigger. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Lessthanluminous
(9 posts) Bio
|
Date
| Reply #5 on Fri 26 Mar 2010 01:56 AM (UTC) |
Message
| Ah, I suppose that is a problem, though the only difference between them (and about 12 other triggers that have the same problem) is what they are supposed to trigger on. The send field only differs in the names. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #6 on Fri 26 Mar 2010 03:42 AM (UTC) |
Message
| Line 3 is:
So what is the variable "target" set to at this point? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Lessthanluminous
(9 posts) Bio
|
Date
| Reply #7 on Sat 27 Mar 2010 02:13 AM (UTC) |
Message
| Well, it was actually blank. That one is used so much that it changes a lot, but that gets in the way so I have it cleared after it is used. Removing it fixed the problem, but I am curious why it affected the trigger in the way it did. | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #8 on Sat 27 Mar 2010 03:21 AM (UTC) |
Message
|
Lessthanluminous said:
Well, it was actually blank. That one is used so much that it changes a lot, but that gets in the way so I have it cleared after it is used. Removing it fixed the problem, but I am curious why it affected the trigger in the way it did.
Because when it's blank, MUSHclient interprets this:
as this:
which is incorrect, because there's no name to assign the true value to. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | 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.
19,805 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top