Catching varibles within a trigger

Posted by Stowslee on Tue 27 Oct 2009 02:23 AM — 4 posts, 23,648 views.

#0
I am having an issue catching this trigger and saving its values to a set of variables. I just switched to MUSH from ZMud and have no idea how to get started, hoping working with this trigger in particular will give me insight to some of the coding.

H:105% [4552/4309] M:102% [2388/2325] B:100% [26300/26300] Exp:36% [] [eb]H:105% [4552/4309] M:102% [2388/2325] B:100% [26300/26300] Exp:36% [] [eb]

It comes up as the prompt (not sure if that matters)

Thanks in advance for any assistance you can provide.
#1
MUSHclient saves variables on the world file. This is handy as they are available from all other triggers, aliases and timers once you select Expand Variable when you make the trigger, alias or timer.
This trigger matches "Health: 50\100" 100 is the total health and 50 the current health. It then puts the second wildcard (total health) into the Variable "total_health". "Send To:" is set to "Send To Variable"
<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="health: *\*"
   send_to="9"
   sequence="100"
   variable="total_health"
  >
  <send>%2</send>
  </trigger>
</triggers>

This alias uses the Variable set by the above trigger.
<aliases>
  <alias
   match="test"
   enabled="y"
   expand_variables="y"
   send_to="2"
   sequence="100"
  >
  <send>Total Health @total_health</send>
  </alias>
</aliases>

This trigger runs some Lua code using the wildcards in the trigger to print out total and current health.
<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="health: *\*"
   send_to="12"
   sequence="100"
   variable="total_health"
  >
  <send>
total_health = "%2"
current_health = "%1"

Note("Current: "..current_health)
Note("Total: "..total_health)</send>
  </trigger>
</triggers>

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.

Template:post=9626
Please see the forum thread: http://gammon.com.au/forum/?id=9626.

Template:post=9616
Please see the forum thread: http://gammon.com.au/forum/?id=9616.

Amended on Tue 27 Oct 2009 02:58 AM by Blainer
#2
This trigger catches the line above (I made a few assumptions in the match) and calls the function "print_wildcards" in the script file passing the name, line and a table of wildcards.
<triggers>
  <trigger
   enabled="y"
   match="H:*% [*/*] M:*% [*/*] B:*% [*/*] Exp:*% [] [eb]H:*% [*/*] M:*% [*/*] B:*% [*/*] Exp:*% [] [*]"
   script="print_wildcards"
   send_to="12"
   sequence="100"
  >
  </trigger>
</triggers>

The function in the script file looks like this.
function print_wildcards (name, line, wildcards)
 for i,v in ipairs(wildcards) do
   Note(v)
 end
end

I didn't test this but it should give you the idea.
Amended on Tue 27 Oct 2009 03:11 AM by Blainer
Netherlands #3
.. Oh, there's two topics. See my reply in the other topic, too. :)