TraversableTable - Tables like Instances!

TraversableTable

Traverse through tables like you’re using Instances!

This module allows you to use properties like Parent to traverse through a table, no matter how complex.

Usage

local TraversableTable = require(path.to.TraversableTable)

local tbl = TraversableTable.new({
	key = {
		value = 8,
		another = {
			name = 'hi'
		},
		third = {
			1,
			2,
			3
		}
	}
})

print(tbl.key.value.Parent:Get())

Docs

TraversableTable.new(tbl: Table|Dictionary) : Node

Create a new TraversableTable instance (a Node object)

Node[key] : Node

Just like using table[someKey], it will return the Node of the child element in the table

Node:Any(): { ForEach: function, Connect: function }

Allows you to apply a function to all children of the Node, or Connect a callback function to all RBXScriptSignal children of the Node.

Node:Construct() : Table|Dict

Constructs the Lua table from a Node and it’s children (like conversion from Nodes back to vanilla table form)

Node:Get() : any

Returns the raw value of the Node. Keep in mind, however, that if you change a Node’s value, any ancestor Nodes that are 2 or more levels up will not have updated raw values - this is why :Construct() exists.

Node:List() : any

List all the keys of the children (more of a utility function tbh)

Node:Set(new: any) : any

Reconstruct the current Node to hold new value instead. This will update its direct parent Node but nothing higher.

Links

Roblox Model: TraversableTable - Roblox
GitHub Repo: GitHub - R0bl0x10501050/TraversableTable

Closing

I know tables aren’t really meant for traversing, but in certain scenarios, this can be useful.

Hope you enjoy!

13 Likes

YES! I needed those, I’m not sure why didn’t Roblox add this??

Because the additional overhead on tables for a niche use case would dramatically reduce performance for people who don’t need this functionality. That doesn’t mean this module doesn’t have a use, because it can, but the amount of people who use it will be outweighed by the number of people who don’t which would make it not the best to add to vanilla tables.

2 Likes

From what I understand, you can read and use the parent to navigate through the table structure,however, does this also allow you to set the parent?

No, I didn’t think of that for some reason. I’ll add that in with the next update.

This is great! I used this to make a explorer similar to the roblox studio one.

1 Like