Hello developers so i have this incremental game im working on but the problem is after it reaches 1e308 of money the game break and says “nil” anyone know how to fix this?
1 Like
because thats the max value a lua number can hold, so you have to represent the number with some other method like tables
lots of modules already do this; you can use infinite math or eternity num or omeganum
1 Like
That’s the limit of lua number. You can only fix it by implementing bignum modules and using them everywhere. It needs a whole remake in almost all of the scripts to be implemented
You’ll have to stop using regular numbers past ~1e308 or it’ll break. Either switch to log-based math or use a BigNum module.
-- cheap log-based system
local moneyExp=308
local moneyMant=1
local function add(amount)
if moneyExp>math.log10(amount) then
moneyMant += amount / (10^moneyExp)
else
local aExp=math.log10(amount)
local aMant=amount/10^aExp
if aExp==moneyExp then
moneyMant+=aMant
elseif aExp>moneyExp then
moneyMant=aMant + moneyMant/10^(aExp-moneyExp)
moneyExp=aExp
else
moneyMant=moneyMant + aMant/10^(moneyExp-aExp)
end
end
if moneyMant>=10 then
moneyMant/=10
moneyExp+=1
end
end
local function mul(factor)
moneyMant*=factor
if moneyMant>=10 then
moneyMant/=10
moneyExp+=1
end
end
local function getMoney()
return moneyMant * 10^moneyExp
end
-- usage
add(5e307)
mul(2)
print(moneyMant, moneyExp, getMoney())
omg bro how in the hell do you need a giant number with 308 zeros? ![]()
I think the problem is in core concept of the game…
1 Like
let him cook bro
3 Likes