Adding wildcards together

Posted by Brothfeder on Sun 26 Jul 2015 11:22 AM — 8 posts, 28,481 views.

#0
I'm trying to create a trigger that will SAY the solution to simple word problems.


The MUD says:
If 2 foxes got together with 74 foxes and 46 came later, how many foxes?

You say: 122

How might I approach this? As the title suggests I've been trying to use wildcards.
Amended on Sun 26 Jul 2015 11:24 AM by Brothfeder
Australia Forum Administrator #1
Take a stab at it and post your attempt.

I suggest you would use a small script, and add them together. Make sure you do tonumber () on them so you add the numbers together, not add two strings.
#2
If you insist, Nick! I found a section on math in your FAQ, so this is basically a script you wrote. I haven't had a chance to test this yet...



<triggers>
  <trigger
   enabled="y"
   match="If * cows jumped into Runaway River and * drowned, how many cows would be left?"
   send_to="12"
   sequence="100"
  >
  <send>
x = tonumber (GetVariable ("x")) or 0

x = %1-%2  <---It could be %1*%2, or %1/%2, whatever you      need.

SetVariable ("x", x)

say ", </send>
  </trigger>
</triggers>


You had PRINT () where I simply have 'say ",', I assume that since I'm under <send> it will 'send' a say to the mud, but I don't know if it works that way. I supose I could have a second trigger that is enabled by this one. That will then SEND (say "variable") to the world.

Also, I'm guessing send_to="12" is like checking 'send to script' in Mush.

Appreciate your video/guide on scripting in Mushclient, and FAQ. Very helpful stuff. Any other LUA for the ignorant resources anyone is aware of?
Amended on Mon 27 Jul 2015 07:44 PM by Nick Gammon
Australia Forum Administrator #3
It's a bit simpler than that. Assuming the question always has numbers in it, then this will do:


<triggers>
  <trigger
   enabled="y"
   match="If * cows jumped into Runaway River and * drowned, how many cows would be left?"
   send_to="12"
   sequence="100"
  >
  <send>

Send ("say " .. (%1 - %2))

</send>
  </trigger>
</triggers>



Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
Amended on Mon 27 Jul 2015 09:54 PM by Nick Gammon
#4
I keep getting a compile error.

[string "Trigger: "]:1: unexpected symbol near '<'

I've created the trigger in MUSH, hit send to script, and put

<send>

Send (%1 - %2)

</send>

in the Send box.

Either way, even if it worked, It wouldn't say the answer, right? Wouldn't I have to create a variable so I could then

<send>
say @varname
</send>
Australia Forum Administrator #5
I left off my boilerplate:

Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


Quote:

Either way, even if it worked, It wouldn't say the answer, right? Wouldn't I have to create a variable so I could then ...


No, and that wouldn't work anyway. @Variables are converted at the start of the script, not during it.

What I had works.
Australia Forum Administrator #6
Just put:


  Send ("say " .. (%1 - %2))


in the Send box.
Amended on Mon 27 Jul 2015 09:54 PM by Nick Gammon
#7
Ah okay, that works perfectly. Thanks for your patience and GENEROUS assistance. Seriously.