[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Arrays and Calculation.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Arrays and Calculation.

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


Posted by Jerm   (2 posts)  [Biography] 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!
[Go to top] top

Posted by Nick Gammon   Australia  (21,405 posts)  [Biography] 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
[Go to top] top

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


2,896 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]