Hello, today I made a module which can transform tables into objects. Or vice-versa.
As you can see in this example:
Also as you can see, you can store tables, inside of tables using this module;
)
You can convert them back to a table, and it keeps the tables inside of tables too.
You could also technically make your own object based table if you know how this works;
Ok! Here’s how to use it:
First of all there’s a variable inside of this module called storage:
This variable is the variable which holds the place on where you wanna store these object-based tables.
You can change them which another script by doing:
module.storage = (location)
I recommend doing it on a folder inside of either ReplicatedStorage or ServerStorage
If you want you can have only one location, and change it on the module too.
If you have multiple scripts using this system all the time, you might wanna request a module.storage change when you’re calling one of it’s functions.
So let’s go to the functions!
module.CreateObject(table, tableName)
This function is responsible by creating the object-based table;
To use it, do
module.CreateObject(table, tableName)
the “table” variable is the one who holds the table you wanna convert to object-based.
the tableName variable is the name you wanna have for your table. This would be similar to a identifier; When calling a convert object-based table to an actual table you NEED to input this name. Please use a string.
This function will create a folder inside the module.storage variable that you have set up.
module.CreateTable(tableName)
This will return the table back in it’s original table format, and not object-based.
You will need the tableName which you sended before to the module.
If it doesn’t find any object-based table inside of the storage, it will not continue the code and will simply not run.
Now, modules from my understanding do not support “returning” values from their functions to actual scripts, so I had to go around that with a variable inside of this script;
This is not true, I thought it could like that, but no, you IN FACT can return from a Module.
Something about my old modules did not let me return;
The old method is not available anymore; Trying to call it will result in nil.
To get the table value, you would have to do
local data = ds.CreateTable(tableName)
print(data)
the module.Returned variable contains the table, that you requested;
If you requested a table and there was no object-based table, then the script will set that to nil.
This function will return nil if there is no object-based table. So be sure to do:
if data then
everytime you call this function.
Any questions, if I forgot to explain something, please reply to this topic
I currently need feed-back. I’m a new developer, and I do not know if someone already made this;
This is the link for the module:
This is open-source and can be modified by you in anyway you want;
Edit: This was my attempt for a “TableValue” in Roblox Studio;