Hey! So, the serializing I’m doing in the article will probably not be good in your case, since as you already said, you all the parts in seperate folder, which will help in the long run and in our scenario, and you have a preset part for each type of blocks. If I were to quote myself:
Note that, for games that have the same type of objects being used again and again (e.g. a building game, where you just have 3 (or more) types of building parts, like brick, dirt and plastic) you can simply save a table containing table where the key is each object’s name, and that table will hold a long list of Vector3
s that indicate where each block of that certain type is placed. And when unloading, loop through the table, and each time just :Clone()
the original object of the current type (assuming it’s stored in ServerStorage
or ReplicatedStorage
) and position it at the current position. This is better than having to save properties and extra info we don’t need. Of course this depends on the structure of your game, you might need to store additional info such as color maybe.
A better serializing technique would be like this, when saving, have a table, where each key is the type of the block, and each key holds a table with a lot of serialized positions. When you load the data back, loop through each key, for each key you’re gonna be looping, copying and placing the corresponding preset part for each position. This is a good strategy.
local toSave = {
Dirt = {loop through all dirt blocks, put the position of each one here},
Stone = {loop through all dirt stone put the position of each one here},
...
}
As for the positions, this is a 2D game, all you need to save is an X and a Y, which could simply be a string containing two numbers seperated by a comma or something else. "x,y"
.
So, efficiency does matter in your game. When you save something, that something gets JSONEncoded, so the length of the generated JSON string is the limit. Recently, the limit was increased to 1 MB, a character is 1 byte, meaning you can save approxiametly a million character long string. I doubt the game has more than 10 tousand blocks, and for each block you’re gonna need to save a 6 or 7 characters long string, which is its position, you have the comma, and I assume the Y and X directions will go hundreds of blocks in that direction, that’s 7. 10000 * 7
, that’s 70000, we’re not even close to the limit. Of course there is more overhead like the [
and ,
found in the JSON string, let’s just say another extra 20000. Again, these are just my expectations, you can count and see for yourself, if you find issues with hitting the limit, then you would need to do some form of serialization.