Counting items and dividing

Posted by Solara on Wed 01 Aug 2012 01:13 AM — 4 posts, 19,832 views.

USA #0
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.
USA #1
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.
USA #2
Okay so this divides it, rounds it down, and sets it to variable "divided":

SetVariable ("divided", string.format ("%i", GetVariable ("herbcount")/4))
USA #3
Kudos for bending string.format() to your needs, but math.floor() was made for that purpose. ~_^

SetVariable ("divided", math.floor (GetVariable ("herbcount")\/4))