Hi,
I use GUI nodes for a puzzle game, where a “block” can have a “selected” state, visualized by another child node with a texture.
All block nodes are created dynamically without assigning an individual id to them. I store only the reference to each node in an array.
Now I want to clone a block node with gui.clone_tree( block_node ).
Since I don’t have any ids to access the resulting table of this function, I use next() for getting the first node (the root I assume).
The block is then cloned a the same position but without showing the “selected” state texture.
When I then assign a position to the root node reference, nothing changes visually, even though internally the correct position is stored, if I print out gui.get_position():
local new_pos = vmath.vector3(100, 100, 0)
local node_tree = gui.clone_tree(node)
local _, root_block_node = next(node_tree)
gui.set_position(root_block_node, new_pos)
print(gui.get_position(root_block_node)) -- correct position
Things become even less comprehensible (to me) when I test assigning a parent node to the root block like so:
local blocks_node = gui.get_node("blocks") -- the parent of all created blocks
gui.set_parent(root_block_node, blocks_node, true)
Then the child node (the node for state “selected”) will be set to the position I want instead. But the cloned block node remains in its position!
The examples and code in the forum I have found of clone_tree() always involve the use of the id string. But it would be great if you could solve it without.
How can this behavior be explained and how can I solve the problem? Thanks!