Register forum user name Search FAQ

Gammon Forum

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.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Arrays and Calculation.

Arrays and Calculation.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Jerm   (2 posts)  Bio
Date Sun 31 Jul 2005 08:45 PM (UTC)
Message
I'm trying to make on key in my table(of numerical values) be a specific number less than another. Here's what I wrote..(doesn't work).

function calculate_stats()
ArraySet ("stats", "siphp", "(ArrayGet ("stats", "truemaxhp) -350)")
note (ArrayGet ("stats", "siphp"))
end


What I want is to make the siphp key 350 less than the truemaxhp key.

Thanks!
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 01 Aug 2005 07:29 AM (UTC)

Amended on Mon 01 Aug 2005 07:31 AM (UTC) by Nick Gammon

Message
Your quotes are a bit strange. You have quoted "(ArrayGet ..." which means it is just a string, not a function that will be called. Also you don't close the quotes for "truemaxhp) .

Last, the function is Note not note (note capitals).

This will work better:


ArraySet ("stats", "siphp", ArrayGet ("stats", "truemaxhp") - 350)
Note (ArrayGet ("stats", "siphp"))


However even this will fail with "attempt to perform arithmetic on a nil value" if you don't put a numeric value into the "stats" array item initially (to say nothing of having to create the array before you do that).

My full test, which worked for me was:


ArrayCreate ("stats")
ArraySet ("stats", "truemaxhp", 10)
ArraySet ("stats", "siphp", ArrayGet ("stats", "truemaxhp") - 350)
Note (ArrayGet ("stats", "siphp"))


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jerm   (2 posts)  Bio
Date Reply #2 on Mon 01 Aug 2005 11:11 AM (UTC)
Message
Thanks a bunch!
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.


11,190 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.