Parsing a dynamic GUI template node

So if I pprint a dynamically created node I’m cloning successfully I get:

{ --[[0x110e07800]]
hash: [GOOEY/template13/sealTHIN] = box@(0, 0, 0),
hash: [GOOEY/template13/sealROOT] = box@(800, 800, 1),
hash: [GOOEY/template13/sealHIGHLIGHT] = box@(0, 0, 0),
hash: [GOOEY/template13/sealCORE] = box@(0, 0, 0),
hash: [GOOEY/template13/sealTHICK] = box@(0, 0, 0)
}

I get this back from a function and lets stay I store it in MyNode and what I want to do is specifically get the string GOOEY/template13/sealROOT from MyNode… How can I do that?

You access them by simply doing a table lookup.

-- Clone the node and store the resulting nodes
local MyNode = gui.clone_tree(gui.get_node("root_node")

-- You can access nodes by doing a table lookup, 
-- the names are from the id of the clone node
local seal_root_node = myNode["GOOEY/template13/sealROOT"]

-- You can now use the node however you want
gui.set_scale(seal_root_node, vmath.vector3(2))

The issue is that I wouldn’t know the root node at the time the system is accessing this node. There’s no way for it to know its value. So I was thinking if I can parse that return value with some sort of string function I could determine it. That said I solved it a different way and I pass another variable that tells a function what this node type is, and then I have a lookup table that knows the root structure of a node object spawned from that template.

1 Like

Awesome that you fixed it!

But I would like to point out that this

Is only true if you design your system that way :slight_smile: Because we are not able to dynamically load arbitrary collections or gui files, you would always know what node you cloned at one point.

For anyone stumbling onto this later here is how you can do it.
A cloned node doesn’t have a id so you would have to give it one to be able to access it.

-- Clone the node and store the resulting nodes
local cloned_tree = gui.clone_tree(gui.get_node("root_node")

-- You can access nodes by doing a table lookup, 
-- the names are from the id of the clone node
local seal_root_node = myNode["template/sealROOT"]

If we now clone this node and print it it will show us a table with only one entry, even though the cloned tree with 6 nodes.

local cloned_seal_root = gui.clone_tree(seal_root_node)
pprint(cloned_seal_root)
--[[
{
hash: [] = box@(0, 0, 0),
}
--]]

What we want to do if we want to access our cloned clones is to first give them some ids. The table will now be two entries, one is the node we just named and the other is a “random” node (probably the last), when it tries to add the other nodes they will write over each other as they all share the same key (the key is the id).

gui.set_id(cloned_tree["template/sealROOT"], "sealROOT_clone")
local cloned_seal_root = gui.clone_tree(seal_root_node)
pprint(cloned_seal_root)
--[[
hash: [] = box@(0, 0, 0),
hash: [sealROOT_clone] = box@(800, 800, 1)
--]]

You would most likely dynamically create the node ids and store the id of the node in a table somewhere so you can later access it.

3 Likes