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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Counting items and dividing

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Counting items and dividing

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Solara   (13 posts)  [Biography] 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.
[Go to top] top

Posted by Solara   (13 posts)  [Biography] 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.
[Go to top] top

Posted by Solara   (13 posts)  [Biography] 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))
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] 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
[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.


726 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]