Trying to get a chip count using modulo (%)

I am trying to decipher a method to determine how many chips I will place on table based on the bet amount which will be ‘bet index’  I saw something similar and tried to use it for how many of each chips will be used for each bet.

For example I have 25, 100, and 500 chip and  bet amount of $250 should give me 2 ‘$100’ chips and 2 ‘$25’  chips.  So I tried unsuccessfull like this:

bet_index=250

   chip_500=math.floor(bet_index/500)

   bet_index=math.floor(500%bet_index)

  chip_100=math.floor(bet_index/100)

   bet_index=math.floor(100%bet_index)

   chip_25=math.floor(bet_index/25)

   bet_index=math.floor(25%bet_index)

but my result will be zero.  Would anyone know how to use the modulo correctly?

If I understand what you are doing correctly, try something like this:

bet_index = 250

chip_500 = math.floor(bet_index/500)

bet_index = math.fmod(bet_index, 500)

chip_100 = math.floor(bet_index/100)

bet_index = math.fmod(bet_index, 100)

chip_25 = math.floor(bet_index/25)

bet_index = math.fmod(bet_index, 25)

print( chip_25 … " 25s ,"… chip_100… " 100s ,"… chip_500 … " 500s")

I tested this and it works.  Hope this helps.

Wonderful, Thank You!

Hi again, 

To further this I have set up  an ‘up’ and a ‘down’ button that would increment a number bet display on the blackjack table by 25 each time pressed.

I also 3 variables for the chips #'s that represent an image of that # chip.  chip_25_image=display.newImage…, chip_100_image=display.newImage…,  chip_500_image=display.newImage…, 

I want to have an image of the number of chips that we have deciphered in the above code.  But i want it to change on the fly between the number of coin images as the bet_index goes up or down.  So as bet_index went from 275 to 300 the table would show (2 100’s, 3 25’s) then 3 100 chips.

Can you please provide me with assistance on how you would implement this?  Thank you  

So, if I were doing this, I would probably set the image up with a series of sprites with one for each of the chip values.  Given that you have 3 chip types (25, 100, 500) you would only need to set up a few frames for each (except for the 500 depending on what/if you were to have a chip maximum that could be achieved).  So, I would set up 4 frames for the 25 chips (0 chips, 1 chips, 2 chips and 3 chips), 5 frames for the 100 chip (0 chips, 1, 2, 3, and 4 chips) and however many you would want to have for the 500 chips.

Doing it this way, you wouldn’t have to keep swapping out and replacing graphics - you could just take the number of chips we determined above and tell the sprite to go to the corresponding sequence.  Does that make sense?

Yes it does,  very interesting approach which I had not considered.  I think I am capable of doing this.  Thank you!

If I understand what you are doing correctly, try something like this:

bet_index = 250

chip_500 = math.floor(bet_index/500)

bet_index = math.fmod(bet_index, 500)

chip_100 = math.floor(bet_index/100)

bet_index = math.fmod(bet_index, 100)

chip_25 = math.floor(bet_index/25)

bet_index = math.fmod(bet_index, 25)

print( chip_25 … " 25s ,"… chip_100… " 100s ,"… chip_500 … " 500s")

I tested this and it works.  Hope this helps.

Wonderful, Thank You!

Hi again, 

To further this I have set up  an ‘up’ and a ‘down’ button that would increment a number bet display on the blackjack table by 25 each time pressed.

I also 3 variables for the chips #'s that represent an image of that # chip.  chip_25_image=display.newImage…, chip_100_image=display.newImage…,  chip_500_image=display.newImage…, 

I want to have an image of the number of chips that we have deciphered in the above code.  But i want it to change on the fly between the number of coin images as the bet_index goes up or down.  So as bet_index went from 275 to 300 the table would show (2 100’s, 3 25’s) then 3 100 chips.

Can you please provide me with assistance on how you would implement this?  Thank you  

So, if I were doing this, I would probably set the image up with a series of sprites with one for each of the chip values.  Given that you have 3 chip types (25, 100, 500) you would only need to set up a few frames for each (except for the 500 depending on what/if you were to have a chip maximum that could be achieved).  So, I would set up 4 frames for the 25 chips (0 chips, 1 chips, 2 chips and 3 chips), 5 frames for the 100 chip (0 chips, 1, 2, 3, and 4 chips) and however many you would want to have for the 500 chips.

Doing it this way, you wouldn’t have to keep swapping out and replacing graphics - you could just take the number of chips we determined above and tell the sprite to go to the corresponding sequence.  Does that make sense?

Yes it does,  very interesting approach which I had not considered.  I think I am capable of doing this.  Thank you!