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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Counting items and dividing
Counting items and dividing
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Solara
USA (59 posts) Bio
|
Date
| Wed 01 Aug 2012 01:13 AM (UTC) |
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
USA (59 posts) Bio
|
Date
| Reply #1 on Wed 01 Aug 2012 01:22 AM (UTC) |
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
USA (59 posts) Bio
|
Date
| Reply #2 on Wed 01 Aug 2012 01:30 AM (UTC) |
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,257 posts) Bio
|
Date
| Reply #3 on Wed 01 Aug 2012 04:08 AM (UTC) |
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.
15,213 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top