#Optimal way to store lots of BoolValues

1 messages · Page 1 of 1 (latest)

hollow turtle
#

Hi everyone. Basically I plan on adding “titles” to my game, and I need a way to see what titles a player owns and I need it to load/save. I know how to do this, I would just make a ton of boolvalues (with the name of the title as the name of the value, and it’s set to true or false to see id the player owns it) but I feel this is not efficient, especially if there ends up being hundreds of titles. So, what’s a better way to do this? I would use tables but I want to be able to see what titles the player owns in other scripts and the client/server.

So, how would I efficiently save tons of boolvalue-like values?

scarlet heart
#

first of all

#

if you really care about optimization, there are several levels to consider

#

you can represent a boolean in a singular bit, and there are 8 bits in a byte; a byte can store 256 distinct values

#

Lua integers have 8 bytes

#

you can, therefore, store 64 booleans in a singular number (like a number value instance)

#

the next level up is refraining from using instances for this purpose, primarily for the reason that not everyone needs to know about it (instances on the server will, unless placed in certain locations not public to the client, always automatically replicate even if you don't need them to)

#

instead, rely on remotes and tables or otherwise

#

the next level from there is to realize that you don't have that many titles, and you don't really need 8 bytes to store 16384 different titles (or up to 64 booleans representing the state of each, individually) and resort to using bit-packing using buffers

#

After that, consider all about culling, if you haven't already with remotes

compression is obviously overkill for something so small