I’m using Terrain:ReadVoxels() to save terrain chunks to an external realtime database. Saving the occupancies works great, but as soon as I try to encode the materials using JSONEncode(), it deletes a large portion of the array.
If your table has numeric indexes and dictionaries, then this must be the problem. At least in the datastore it does not accept numeric indexes and dictionaries, and from what I know when saving in the datastore the tables are converted to json.
converts the table into a problem.
Apologies if I misunderstand what you mean. I’m just trying to find a solution where I can encode the array into a string and decode it back into an array. Does that make sense?
So, what I meant about the datastore is that when you save a table in the datastore, they are converted to json, so the problem of the datastore not saving numeric indexes and dictionaries may be a limitation of the conversion of the table to json.
In short, check if your table has a numeric index and a dictionary, this may be the problem. Use only one, either a numeric index or a dictionary.
If I were to guess, it’s probably because Enums aren’t JSON serializable (you’re trying to serialize an Enum.Material in this case). You should iterate over the array and serialize it in some way (I would save the Material.Value as ints are generally shorter than strings), then to deserialize, use Enum.Material:FromValue(storedValue)
Not sure if this is related to your problem at any way but from my personal testing Roblox’s JSONEncode and Decode do have a max to the amount of data they can handle. It’s around 200,000 characters iirc, and you can try paginating data if you want to use more than that.
Okay, I imported it but I’m super confused on how to actually use it. This seems like a super high-profile module and I’m just not even sure where to start.
Do you think it would be possible for you to give me some code snippets of what I should do?
Thanks so much for all the help, seriously awesome
Nevermind, created my own serialization system. Here’s the code for those who need it in the future:
local function SerializeMaterials(Materials)
for _, D1 in Materials do
if type(D1) == "table" then
for _, D2 in D1 do
for Iteration, D3 in D2 do
D2[Iteration] = D3.Value
end
end
end
end
return Materials
end
local function DeserializeMaterials(Materials)
for _, D1 in Materials do
if type(D1) == "table" then
for _, D2 in D1 do
for Iteration, D3 in D2 do
D2[Iteration] = Enum.Material:FromValue(D3)
end
end
end
end
return Materials
end