ObjectTables | Live object-based tables!

Please read: This is a module that was for fun and not to fit any use, if anyone finds an use, sure, I’ll update it to include new features, and fix glitches, but if not, I won’t. I’ll only fix glitches. I can’t find use specifically in this, but it’s cool to mess around with, and it’s also cool to code. I made this today and just liked it, so that’s really it, it’s completely fine if you can’t find use with it.

Link to download:

https://www.roblox.com/library/6480763439/ObjectTables

No github for now.

How does this work?

This is a module which will make and update, and mess with tables using values. These types of values:

image

All of the above are supported, plus SUB-TABLES. Meaning, you can have a table, inside a table… inside another table… inside yet another table. You get what I mean.

Because of the limitations of newproxy() like not being able to list how many things are in a table, I included support for that and some other stuff.


How does one get an object-based table?

First, require the module, then, you can do objectTable.new() to get a table object.

Now, you can set, get, anything from it.

objectBasedTable.Players = game:GetPlayers()
print(objectBasedTable.Players)

How slow is this compared to normal tables?

It is slower. It isn’t painfully slow. It’s fine slow. It’s not gonna break any of your systems.
I can’t really compare it, since I’m not good with math, and it uses that type of format: “6.54122340e-6” which I’m dumb and can’t calculate, but it is slower, that’s usually what you need to know. If you wanna do some bench marking, this can be useful:

Benchmarking script
local objectTable = require(game.ReplicatedStorage:WaitForChild("ObjectTables"))

wait(15)

local start = os.clock()

local End = os.clock()

local Table

print("ObjectTable: ")

Table = objectTable.new()

start = os.clock()

Table["cool"] = 100

End = os.clock()

local actionTimeWrite = End-start

print("Writing to: ", actionTimeWrite)

start = os.clock()

print(Table["cool"])

End = os.clock()

local actionTimeGet = End-start

print("Getting: ", actionTimeGet)

print("Is writing slower than getting: ", actionTimeWrite >= actionTimeGet)

local executionTime1 = actionTimeGet + actionTimeWrite

print("--------- \n Normal Table: ")

Table = {}

start = os.clock()

Table["cool"] = 100

End = os.clock()

actionTimeWrite = End-start

print("Writing to: ", actionTimeWrite)

start = os.clock()

print(Table["cool"])

End = os.clock()

actionTimeGet = End-start

print("Getting: ", actionTimeGet)

local executionTime2 = actionTimeGet + actionTimeWrite

print("Is writing slower than getting: ", actionTimeWrite >= actionTimeGet)

print("Winner: ")

if executionTime1 <= executionTime2 then

print("Object Table!")

else

print("Normal table!")

end

Why did you make this?

Mainly for fun, and that’s pretty much it, I didn’t have anything to do today, I was tired, and I felt like this could be a cool thing to do.

How safe is this, since it uses Instances/Objects?

I woudn’t recommend as of now, to use it on the client. And don’t keep sensitive data inside of that either.
Right now, I don’t have an option to not parent it to the storage folder inside the script.

Any uses?

Currently I can’t think of much, but I guess you can use it to limit yourself from using values that might be incompatible in some other system.

Documentation?

I can talk about is calling the table you made, as a function. Example: objectBasedTable(), this will return you an actual table, a copy from the object version. This can be used in for loops, and such. If you do objectBasedTable(true), it will clean up the storage on which the table was made on. Don’t call anything from this table once you do that, you can also give it a table argument, objectBasedTable({coolright = 3}), this will replace the current table with the new table you gave it.


Thanks for reading!

6 Likes

I don’t really know why, I just really like to mess with tables and object conversion for no reason.
This just felt good to make, I don’t know, it is superseding TTO, there’s also ToInstance for anybody who wants similar job to TTO.

3 Likes

I’d love to see a full use example, from requiring the module, to adding and removing values, and clearing the table.

1 Like

I can give you a better example. I’m almost finishing updating something right now.

Alright. Looking forward to it. I’ve been trying to do this for a while

I’m going to use _G here, which is just a shared storage you can acess from any script. I’m going to do it via the console, since it’s easier to see what is going on.

First to get a object-based table, you need to do .new() on the module.
I’m going to keep the variable of the module as module.

Now you have a table, now I’ll be using the console, but it would be the same on a normal script.

This is kind of a table handler, when doing .new() you get a newproxy() object, which is basically a fake table, it only allows you to see what is being requested and set to it, then the module will handle getting it from the objects and such.

To set a value, set it to whatever you want. As long as it’s supposed as a Object based value, meaning an of these:

image

Anything else won’t work.

Example:

image

You’ll also notice that there’s a storage thing on the module, that’s used to keep the tables, when you set a value, a new value will be created. Unless there’s already a value there which is the same type.

image

image

Updating a value will replicate fine.

To remove a value, set it to nil, so:

image

Nothing inside anymore.

image

Once you’re done with a table like this, you need to garbage collect it. (Empty it, clean it.)

How do that? You’re gonna call the table, kind of as a function, yeah, you need to pass “true” inside to wipe it.

image

image

Garbage collected!

You can get an actual table copy from that by not passing through true. It will give you an actual table you can use for loops on and such.

Make sure you don’t call anything from that table anymore.

I found a little glitch, I’m going to fix it lol, I recommend you to update it right now; I fixed it;

How do I get the table from another different script?

1 Like

You have to deploy your own solution, you can use the _G table if you prefer.
I might have something coming up to allow stuff like that, like table naming, because as of now, tables are handled using a unique id.