|
Counting items and dividing
|
Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Solara
(13 posts) bio
|
| Date |
Wed 01 Aug 2012 01:13 AM (UTC) [ quote
] |
| Message |
Hi, this should be an easy script but I don't know how to do basic math with Lua.
I want to count some items (herbs), and then divide them by 4. I basically want to split all my herbs into 4 piles.
Trigger to capture number of total herbs: (works fine)
The last count reached *
SetVariable ("herbcount", string.format ("%i", %1))
Note (GetVariable ("herbcount"))
Here's the script to divide: NOT working (I want to set the herbcount divided by 4 to a variable so that I can then send to the game "put X herb in backpack, drop X herb on ground" etc.
require "wait"
wait.make (function ()
Send ("count colocrasses")
wait.time (10)
SetVariable ("divided", (bc.div (Getvariable ("herbcount"), 4)))
Note (GetVariable ("divide"))
end)
So how do I go about dividing the variable "herbcount" by 4, and then setting that to a new variable "divided"? I know this must be easy. | top |
|
| Posted by |
Solara
(13 posts) bio
|
| Date |
Reply #1 on Wed 01 Aug 2012 01:22 AM (UTC) [ quote
] |
| Message |
Bah, I knew it was easy. This did it:
SetVariable ("divided", GetVariable ("herbcount")/4)
Now I just need to round it down to lower number. | top |
|
| Posted by |
Solara
(13 posts) bio
|
| Date |
Reply #2 on Wed 01 Aug 2012 01:30 AM (UTC) [ quote
] |
| Message |
Okay so this divides it, rounds it down, and sets it to variable "divided":
SetVariable ("divided", string.format ("%i", GetVariable ("herbcount")/4))
| top |
|
| Posted by |
Twisol
USA (2,229 posts) bio
|
| Date |
Reply #3 on Wed 01 Aug 2012 04:08 AM (UTC) [ quote
] |
| Message |
Kudos for bending string.format() to your needs, but math.floor() was made for that purpose. ~_^
SetVariable ("divided", math.floor (GetVariable ("herbcount")\/4))
|
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | 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.
726 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )