wanted to make a leaderboard but i use high numbers that are saved in scientific form (1.23e45) for example. How can i create a leaderboard that would use EternityNum module?
Not informed about this “EternityNum” module, however judging by what you said it returns you should be able to simply insert a string value in the leaderstats folder and set the value to what you receive from the EternityNum function
A way to order them is to calculate exponent*10 + mantissa assuming that the mantissa can be between 0 and 10(if the mantissa was between 0 and 2 you would do exponent*2 instead).
To show them visually it depends on how you want them to be displayed, you can keep the scientific form, or you can convert the exponent to a string(for example M for million) and the mantissa to an approximation(such as 5.34), so it displays as 5.34M) when you combine them.
Also to decode them from exponent*10 + mantissa just do:
local exponent, mantissa = n//10, n%10
Also worth mentioning that if your issue is with ordered datastores, those only accept integers. So apart from all this, you will also have to multiple n by a given amount then round to the closest integer so you can save them. Then on load divide by that same amount. Obviously there’s some information loss in the process but it should be tiny compared to the huge numbers we’re talking about(since the least significant part of the number is the one being erased, for example values way after the decimal point).
So to summarize:
--A large number we can safely multiply with
local largeNum = 0xFFFFFFFF
local function floatToInteger(x: number): number
local m, e = math.frexp(x)
local n = e*2+m
return math.round(n*largeNum)
end
local function integerToFloat(x: number): number
local n = x/largeNum
local e, m = n//2, n%2
return math.ldexp(m, e)
end
So you store the integer representations in the ordered datastore and when you load them you convert them back to floats so you can display them properly.
Issue is numbers go passt math.huge so i can not calculate via normal roblox functions rather with eternityNum function
Hey I released the following resource today:
If have a way to directly fetch the mantissa and exponent of an eternityNum object, or expose them in some way, you can pass them directly in the functions of the provided module. That way no intermediate calculations will occur and inf wont be an issue.
It also gives you decoding that gives a mantissa and exponent instead of the float, so you can use it for string representations, etc.
Well my biggest issue is i dont understand too well how to make the leaderboards. I tried modifiying a pre-made one but got lost
Basically you have to do the following:
- Create the eternityNum object for the large value you want to work with
- Extract the mantissa and exponent by using the built-in eternityNum functions in such a way so the result is identical to that of the default
math.frexpfunction. If it’s in base10, that’s okay, since my module also provides a function that works with base10 inputs and outputs. - In my module, call the respective function to encode the integer(for example
encodeBigNumBase10) and store it like that in the ordered datastore when you doSetAsync. That’s an encoded form that maintains the order of the floats. - When you load the data using
GetAsync, you will have the encoded integers. Run the reverse function(in this casedecodeBigNumBase10) to get the mantissa and exponent in base10 form(these numbers are small and wont hitinflimits). - Then use them for string calculations so you can display a proper result. For example you can cut the mantissa to two digits after the decimal point and use the exponent to define a string name(for example
Mfor million).
Just so you know this entire process removes information from the number we had at the beginning, this is in purpose so it can be stored inside ordered datastores. Specifically it removes information that you likely won’t display anyway(for example numbers way after the decimal place). So only use this for graphics/visuals and not to store actual player data(for that use their respective datastore).
eternity num objects are just tables that store the exponent and mantissa i think
but you dont have to do anything because ordered data store is already built in mind with every large number module
for eternity num a simple search shows you can use the lbencode and lbdecode methods
I seen the function needed but as i said is i dont know to make leaderboards, so i just have no clue where or how to import the special eternitynum table
just follow the tutorial for a normal leaderboard
but the value being stored in the ordereddatastore is lbencode(num) where num is an eternitynum object
and then when you display it you have to change it back with decoded = lbdecode(num) and then use whatever tostring method that eternity num has on that