Trigger to call a function to get info to see if ok to fire trigger

Posted by Warbit on Fri 19 Aug 2011 07:57 AM — 2 posts, 12,896 views.

USA #0
I have been looking on forum for information on how to do this for 4 hours.

I found this
http://www.mushclient.com/forum/?id=6030

I tried this

<triggers>
  <trigger
   enabled="y"
   match="You are thirsty."
   script="my_stats"
   send_to="12"
   sequence="100"
  >
  <send>if cma &gt; 20 then

Send ("cast 'freshwater'")

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


<triggers>
  <trigger
   enabled="y"
   match="&lt;*/*hp */*ma */*mv&gt;"
   script="my_stats"
   send_to="12"
   sequence="100"
  >
  </trigger>
</triggers>


function test_alias (name, line, wildcards)
  Note "Hello, world!"
end -- function test_alias


function my_stats (name,line,wildcards)
local chp = wildcards [1]
local mhp = wildcards [2]
local cma = wildcards [3]
local mma = wildcards [4]
local cmv = wildcards [5]
local mmv = wildcards [6]


end--function my_stats

How I wanted it to work was. It would see You are thirsty. It for check my_stats. It would see if I had 20 or more mana available. If the answer was yes, then it would cast the freshwater spell.

I get:

Error number: 0
Event:        Run-time error
Description:  [string "Trigger: "]:1: attempt to compare number with nil

stack traceback:

	[string "Trigger: "]:1: in main chunk
Called by:    Immediate execution


Amended on Fri 19 Aug 2011 08:03 AM by Warbit
Australia Forum Administrator #1
Here's one problem:

function my_stats (name,line,wildcards)
local chp = wildcards [1]
local mhp = wildcards [2]
local cma = wildcards [3]
local mma = wildcards [4]
local cmv = wildcards [5]
local mmv = wildcards [6]


end--function my_stats


Variables declared "local" like that cease to exist at the end of that function. But from what you described you want global variables. So delete the word "local" from each line.

Local means "local" like "only here".