Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ What's wrong with this script?
|
What's wrong with this script?
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Rivius
(99 posts) Bio
|
| Date
| Sat 25 Sep 2010 12:16 AM (UTC) |
| Message
| 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.... | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Sat 25 Sep 2010 12:41 AM (UTC) |
| Message
| 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
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Rivius
(99 posts) Bio
|
| Date
| Reply #2 on Sat 25 Sep 2010 01:20 AM (UTC) |
| Message
| 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! | | Top |
|
| Posted by
| Nick Gammon
Australia (23,165 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Sat 25 Sep 2010 01:31 AM (UTC) |
| Message
| Well that was shorthand. You can do it like this:
if arm == nil then
arm = 0
end -- if
However the original was shorter. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
14,083 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top