ID:1624769
 
Code:
Problem description:
I'm trying to put together a money system in this format.

1 Coin=1000 bits
1 Byte=100 bits
Bits=1

I want it so that whenever the player gets bits, say if they get 1000 bits, that it will automatically be transferred over into the highest currency to hold it efficiently.
In other words in this example,

If I got 1000 bits, it would convert into 1 Coin.

If I then got 750 bits, it would convert into 7 bytes and 50 bits.

In total I'd have 1 Coin, 4 bytes and 50 bits.

For a real world example of this- Dragon Age Origins money system is basically what I'm trying to recreate.

However the "roll over" process is what is confusing me, I'm a little foggy on the best way to approach it. Any ideas?

This is what I have thus far : (though I feel it's not exactly correct)

GainAyo(var/cc)
var/image/x=image('Items.dmi',"coinup",src)
src<<x
x.pixel_x=-8
animate(x,pixel_y=48,time=15)
spawn(15)
del(x)
//src<<sound('Music_Sfx/FX/coinjingle.ogg',0,0,0,client.vol)
src.ayo=max(0,ayo+round(cc))
if(ayo>=1000)
var/f=dyo%1000
GainRyo(round(ayo/1000))//coins
ayo=f
if(ayo>100)
var/f=dyo%100
GainDyo(round(ayo/100))//bytes
ayo=f
src<<"got [cc]"
src<<"Money :Ryo [ryo],Dyo:[dyo],Ayo:[ayo]"//ayo is bits.

You can deal with it in decimals:

proc
GainMoney(var/amount)
var/offset = round(amount)
//deal with coins
src.coins += offset
amount -= offset
amount *= 1000
//deal with bytes
src.bytes += round(amount)
//deal with bits
amount *= 100
src.bits += round(amount)
if(src.bits>100)
offset = round(src.bits/100)
bits -= offset*100
bytes += offset
if(src.bytes>1000)
offset = round(src.bytes/1000)
src.bytes -= offset*1000
src.coins += offset


I'd argue your denominations are a bit wonky, but that's up to you.
In response to Ter13
You're right. I already changed the values and made it 100 bits=1 byte, 100 bytes = 1 coin

GainAyo(var/cc)
var/image/x=image('Items.dmi',"coinup",src)
src<<x
x.pixel_x=-8
animate(x,pixel_y=48,time=15)
spawn(15)
del(x)
//src<<sound('Music_Sfx/FX/coinjingle.ogg',0,0,0,client.vol)
src.ayo=max(0,ayo+round(cc))
if(ayo>=1000)
var/c=0
while(ayo>=1000)
c++
ayo-=1000
GainRyo(c)
if(ayo>100)
var/c=0
while(ayo>=100)
c++
ayo-=100
GainDyo(c)//bytes
src<<"got [cc]"
src<<"Money :Ryo [ryo],Dyo:[dyo],Ayo:[ayo]"//ayo is bits.



This is ultimately what I came up with. The approach I took was to have the value of all items measured in the smallest amount. But to be honest I'd prefer not having to loop through so I will probably convert it to your method.

I think using your method I can also set up a spending proc as well.