What's wrong with this script?

Posted by Rivius on Sat 25 Sep 2010 12:16 AM — 4 posts, 16,165 views.

#0
Trigger Line is:

^You have recovered balance on your (right|left) arm\.$

and my script is:


arm=arm+1

if arm==2 then

ColourNote("white", "black", "*********************************************")

ColourNote("black", "orange", "You have recovered balance.")

ColourNote("white", "black", "*********************************************")

arm=0

end -- if


What I've been trying to do is make it so that once both arm balances are back, it sends me the note, since my class needs both arms to attack anyway.

I get this error message:


Run-time error
World: Treant
Immediate execution
[string "Trigger: "]:1: attempt to perform arithmetic on global 'arm' (a nil value)
stack traceback:
[string "Trigger: "]:1: in main chunk


Bahhh....
Australia Forum Administrator #1
Variables default to nil (no value) and you can't add 1 to nil.

Add an extra line to make arm zero if nil (ie. the first time):


arm = arm or 0  -- make zero if doesn't exist

arm = arm + 1  -- now you can add to it
#2
Thanks, I didn't know that you had to set it like that. I thought I might have been stuck setting it to 0 everytime then.

Thanks! My script seems to be working now!
Australia Forum Administrator #3
Well that was shorthand. You can do it like this:


if arm == nil then
  arm = 0
end -- if


However the original was shorter.