Matching Vague Triggers

Posted by Lessthanluminous on Sun 14 Mar 2010 07:19 AM — 9 posts, 26,909 views.

#0
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!)
Australia Forum Administrator #1
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.
#2
Thanks! Not only does it work, it looks like a good place for me to start understanding/working on tables a little bit!
#3
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 '='
Australia Forum Administrator #4
Lessthanluminous said:


name="Pizza"
...

[string "Trigger: Cripple"]:3: unexpected symbol near '='


That is the Pizza trigger, not the Cripple trigger.
#5
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.
Australia Forum Administrator #6
Line 3 is:


@target = true,


So what is the variable "target" set to at this point?
#7
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.
USA #8
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:

@target = true,


as this:

 = true,


which is incorrect, because there's no name to assign the true value to.