# Currency System that auto divides into three types?

Hello! I’m trying to create a currency system that has three forms of coinage. Copper, Silver, and Gold. I’m trying to make it so if you have 100 copper coins, it automatically indexes 1 silver, and if you have 100 silver than it automatically indexes 1 gold and so on. Anyone have any recommendations on how i should go about this?

Store a general coin type in one variable and calculate how much of all types you have each time you change the general coin variable.

local gen = 55005; -- that's how much coins you have, equivalent to 55005 copper

function calcCoins(gen)
local gold, silver, copper;
gold = math.floor(gen / 10000);
gen = gen - gold * 10000;
silver = math.floor(gen / 100);
copper = gen - silver * 100;

return copper, silver, gold;
end

local copper, silver, gold = calcCoins(gen); -- copper: 5, silver: 50, gold: 5

And now if you want to take from a Player for example one silver coin you just subtract 100 from gen and then call calcCoins() again because the amount of coins of the general type has changed.

7 Likes