Furniture backup system creation

To add to this, each decimal is treated as another character, which wastes potentially valuable space. It only upsets my OCD. Aside from not being able to store specific value types directly, this is also a great time to use binary to convert numbers into characters to save on space.

1 Like

I clamp positions like in my example to prevent long unnecessary strings. You can turn:
"x25.502501y5.294z6.0603" to "x25.5y5.3z6.1" which is way shorter when dealing with lots of objects.

Less string = less data.

Can you expand on this? Is binary conversion just compression?

Well yes, if you’re serializing them as strings. But if you serialize them as tables you wouldn’t have this issue. Also CMIIW, but serializing numbers as strings is less efficient because you’re storing them in base 10, rather than base 2, even if doubkes take up more space than ints.

E.g. 827377229 would be saved as 9 bytes as a string, but only 8 as a double. If yoh really want to save space, you could serialize it as a short, but you would need your own function to convert the number to a binary string

That depends on how you are saving it. If you run:

print(game:GetService('HttpService'):JSONEncode(1.1245))

You’ll find that it prints exactly what you put in. JSON isn’t doing any magic to save space, it’s just converting arrays and tables into a string format.

As a JSON, yes. JSON, I suppose, is meant to be more human readable than space efficient. But why wouldn’t you just save it as a table? I’m sure it would take up less space than a JSON representation of the same thing…

So basically, each character is a byte and a byte is 8 bits. You can store a surprising amount of data in one byte, but I won’t get into the details unless you really want me to (using Minecraft as an example). But the main thing here is that you can convert a large number into only a few string characters that still exactly represent that longer number.

1 Like

I encourage you to print your JSONEncode output to see how your data is actually being saved. A table isn’t a special datatype, it’s still just text.

Would you recommend having my serialized plot data (all objects) fit into one string? Then one big de/serializer function to deal with it?

It would ultimately save on space for sure, but it depends on if that’s worth it to you. The amount of optimization I’m referring to is really only needed for large scale data saving, such as saving entire sets of chunks (like block data in Minecraft). But arrays still add additional things like brackets and commas that aren’t entirely needed data wise, if you really need to be that efficient on space.

1 Like

But, as I said, you don’t have to use JSON. JSONEncode would encode it to JSON, yes, that’s pretty obvious.

What I mean is save it on the DataStore via :SetAsync passing the value as a table instead of serialized JSON.

By this, I’m assuming you mean JSON objects, not Lua(u) tables.

You can only save a string. We use JSONEncode to convert arrays/tables to a string format.

Technically yes, but ultimately everything outside of objects are strings, or can at least be saved as such (with JSONEncode or perhaps some other method).

You don’t have to use JSONEncode by any means, but you’ll have to write your own method to store datatypes that aren’t standard datatypes like numbers or strings are. But now I’m over-complicating things, so don’t worry about that part.

Excuse me if I’ve misunderstood the documentation, but as far as I know, you can save numbers, strings, arrays, and even dictionaries just fine.

Take this example from another thread:

I cannot speak for how Roblox saves its tables internally, as I have never worked there. However, I would have to assume they are serialized similar to how they are saved into bytecode in plain Lua 5.1, which, by the way, isn’t JSON.

I don’t believe this would work as data is saved exclusively as a string as far as I’m aware. But the documentation does show that the saved value is a Variant (Tuple):


Source

Perhaps an array is automatically converted to a Tuple, but I believe that everything is saved as a string at the end of the day. It also says that you can see the data size by using JSONEncode:


Source

1 Like

Oh, I see. I had no idea. That’s useful to know.

Thanks for correcting me.

1 Like

Yo stop replying to me please yo

After they place the furniture, you can serialize a limited amount of data, or more specifically the minimum needed to recreate the item.

I would suggest lowering the quality of certain aspects, such as rounding the position and orientation of the furniture after placed. You should also implement a limit to how much furniture you should save.

Data stores are limited to 4 megabytes, which is not very much if you serialize every instance.

Thanks for replying me.
Do you know a tutorial to setup it?

No, and I don’t believe there is any suitable tutorial, since this is a very specific topic. Whatever works for you will be the solution.

I’m not, it’s the forum that’s having notification issues.

2 Likes

I’m not sure if this video will help, it’s just the first I found and I briefly skipped through it, but perhaps it will give you a foundation to work with:

Here’s another that seems a bit better and has a playlist:

But please don’t just copy code, it’s better to learn how it works so you can create your own systems without help in the future. Plus the ones above seem to still be a bit over-complicated over-engineered, but it should at least be easier to follow a video than a written guide, depending on your skill level (plus the videos at least seem to cover everything from start to finish).