Arrays and Calculation.

Posted by Jerm on Sun 31 Jul 2005 08:45 PM — 3 posts, 14,734 views.

#0
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!
Australia Forum Administrator #1
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"))

Amended on Mon 01 Aug 2005 07:31 AM by Nick Gammon
#2
Thanks a bunch!