Guys iam making a Power simulator game, and like ALL simulators you Will have BIG values on Stats (like 10Trilion endurance), How that IS possible, that NUMBERS are insane for a DataStore
If you wanted to you could convert the numbers into scientific notation, if there are a lot of zeros this will greatly reduce the amount of characters needed.
Lua will do this automatically.
Instead of storing the whole number, store the logarithm of the number. An n-digit number becomes a log(n)-digit number. Precision is lost but you aren’t using those digits.
I was thinking on doing that
["Stats"] = {
["Strength"] = {
["Value"] = 0;
["Suffix"] = "";
["Multiplier"] = 0;
["Boost"] = 0;
};
["Endurance"] = {
["Value"] = 0;
["Suffix"] = "";
["Multiplier"] = 0;
["Boost"] = 0;
};
["Mind"] = {
["Value"] = 0;
["Suffix"] = "";
["Multiplier"] = 0;
["Boost"] = 0;
};
["Jump"] = {
["Value"] = 0;
["Suffix"] = "";
["Multiplier"] = 0;
["Boost"] = 0;
};
["Speed"] = {
["Value"] = 0;
["Suffix"] = "";
["Multiplier"] = 0;
["Boost"] = 0;
}
};
["Leard"] = {
["Reputation"] = 0;
["Rank"] = "Innocent";
};
["Missions"] = {
};
["Skills"] = {
};
}
I was think save the value divided and save the suffix, so the max value Will be 999, but to make a global rank Will be hard, and increase values too since iam increasing on that way
local function increaseStats(player,Amount,Stat)
while true do
wait(1)
if AutoTraining[player.UserId]["Training"] == false then return end
ServerData[player.UserId]["Stats"][""..Stat]["Value"] = ServerData[player.UserId]["Stats"][""..Stat]["Value"] + 50
print(ServerData[player.UserId]["Stats"][""..Stat]["Value"])
end
end
If I use prefix i Will need get the number, multiplier to get the max, add and after / again to make the suffix and save, this isnt a good deal
I dont know man, see my DataStore ^
I guess you should try out DataStore 2
No thanks, i Will make a backup system with Firebase
This happens because Lua uses double-precision floating-point for numbers.
In Lua, decimals have a precision of 13, however, this should not influence at all what you’re looking for. Precision is simply how many digits beyond the decimal place start the number can go.
Take, for example, 0.123456789123456789. This number would only actually store up to 13 houses, becoming 0.1234567891234.
This is not an issue when doing a Simulator, mainly because, well, you’re looking at integers (well, at least, their format… they’re basically whole numbers with no decimal place - IntValue stands for Integer Value, for example), and therefore don’t need to worry about precision.
10 trillion is a small number. It actually only has 4 spaces, if you separate it by unit.
10 000 000 000 (4)
If we were to use Int64 (64-bit integer), the maximum value supported would be much, much higher.
High as 9 223 372 036 854 775 807 (7).
This means that you can actually store normal values up to that much when taking into consideration full numbers.
But decimals are special.
You can go even higher with these… around
79 228 162 514 264 337 593 543 950 335 (10).
Therefore the amount and the number shouldn’t be an issue. That’s why it supports up to that much.
But if even that becomes an issue, you may work around using a logarthm alternative, as @1waffle1 has mentioned in this topic.
Therefore, you shouldn’t need to worry about how big the number is when overall working with Lua for a Simulator Game. And yeah, that’s how Datastores can store that big of a number.
This is a common misunderstanding. I’d like to clarify that each object (or so I like it call it – too used to OOP) has their own data type. A quote ("Hello World!"
) is a string, while a number 15
is, well, a number. This can be checked using the built-in type(obj)
function.
You’re confusing the physical string limit with the number, which a lot of people do.
Datastore saves exactly what you put in to save, and doesn’t convert it automatically into a string. This means that even though Datastore supports up to that much data, what you put in will ultimately influence the result.
EDIT: Forgot to note: 100,000,000,000,000 is the highest number you can reach with Lua using decimals and while keeping full precision. Any number above that will result in rounding errors.
DataStore automaticly save NUMBERS as decimal ? Or i need instance ?
DataStore will automatically save the data you put in as it is. If you put in a string, it will save a string. If you put in a number, it will save that number as it is. And so on.
Ik but iam saving like that value = 0, so i need use value = Instance.new(“Decimal”)?
Decimal is not an Instance, it is a type of value used in programming.
In Lua, decimals are simply called number (data type).
If you’d like to save a number, you’d have to :SetAsync()
, UpdateAsync()
or IncrementAsync()
.
For example:
local yes = 1337
DataStore:SetAsync("cool", yes)
So my Value = 0 is decimal?(is the first data when player Join and dont have DataStore )