Gui.clone_tree - identifying table elements

#1

In many ways this question follows on from my previous one. On reflection I felt that what I really wanted to do was to show league table with the scores + handles of the “best” players and then the current player followed by the scores + handles of the players immediately below the current player.

To that end I am getting my server-side code to return a table with up to nine entries - between 0 and 4 from the “best players”, the current player and then between 0 and 4 below the current player.

In order to do this I decided to clone the nodes required to show each league table entry on-the-fly. The node in question has the following structure

  • A containing box
  • Two inner boxes each containing a text node which I desiginate as my score and *handle * text nodes.

For arguments sake le t us call the outer box boxLeagueTableRow and the two text nodes txtScore & txtHandle

This approach allows for much flexibility and I can show the position of the current player in the league table in all possible circumstances - better players exist, no better players exist, worse players exist… .

The problem I have is this: gui.clone_tree returns a table containing the hashes for the items it has cloned. Very good. But having cloned the node I now need to update the text content of the two text nodes I have just cloned. I have the league table data sent down by my servers to do so. However, the order of the hashes returned in clones table is not guaranteed. So how do I go about establishing which of the hashes match the two freshly created text nodes?

0 Likes

#2

I am going to leave this question here with my answer. Suppose you clone a node bearing the id parent_node which in turn contains a node tree with the nodes

  • child_node_A

  • grand_child_node_A_1

  • grand_child_node_A_2

  • child_node_B

  • grand_child_node_B_1

  • grand_child_node_B_2

Then the table returned by gui.clone_tree will be a sequence of hashes with the keys being parent_node, child_node_A, child_node_B etc.

So now to manipulate the attributes of any of these nodes you simply use the relevant gui methods. e.g. gui.set_text(clones[“child_node_1”],“I love Defold”) :star_struck:

0 Likes