How would I store a ternary tree within a game?

I am making a game about mazes, and I would like to store an entire ternary tree representing the maze within… somewhere.
I’ve thought about storing my maze as JSON in a string attribute, but I fear when my mazes get too large the JSON string might become absurdly long and there might be problems with roblox truncating data.
I don’t think module scripts will work either since they aren’t changable at runtime.
Roblox’s parent-child system is itself a tree, however I think having thousands of folders would be really data-heavy.
Anyone has any ideas?

1 Like

Ok-y first off this should be in #help-and-feedback:scripting-support, not Code Review but that’s okay!

Now moving on to your question, could you use a DataStore instead?

1 Like

Firstly, apologies for the mistag, and secondly,
DataStore is not an ideal solution as it is primarily used for storing data over long periods of time, while I would like my maze data to be quickly accessible by script without too much calculation (akin to the registries on a computer).

Well, you don’t have many options, either as @Midnightific stated (DataStores) or you will have to use JSON files. Storing them in a script?.. You can try ObjectValues, as they can store instances.

JSON seems good, but I fear there is a possibility of a string that is too long to fit in a string attribute/value.

Is it per person, is the json string/ternary tree changing??

You could store them in an external datastore especially if the string wont ever change. Even if it will change it is possible to still do this.

That way all the data is stored outside of roblox so youre reducing the negative impact of performance on your game

edit
roblox string limit is 200,000 characters, surely thats enough? you could potentially split them into multiple strings though if needed

Indeed, the string is changing since maze generation is handled in-game randomly. I do like the split string idea though.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.