How to get the string out of hash from gui.get_id?

Hi everyone, I see that gui.get_id is presented like this on API:

local id = gui.get_id(node)
print(id) --> hash: [my_node]

since I can print the “my_node” here, I suppose there is a way to turn the id into a string. How can I achieve this?

You can’t get strings out of hash by design.

1 Like

I understand it but I thought since I can actually print the hash and it has the string I am looking for visible, there would be a way to get the string out :frowning:

That’s possible in debug builds but not in release. Trips people up a lot.

2 Likes

Thank you for letting me know
Would you happen to know any way to get the name/id of a gui node as a string?

A better question I believe is to ask: what are you trying to achieve?

1 Like

On my gui, I have mulypile buttons and text. They are structured like:
xbutton
xtext (child of x button)
ybutton
ytext (child of y button)

I saved all buttons on a table and am using the table to check what button is hovered on dynamically instead of hardcoding them.
Currently using gui.pick_node() I am able to tell what button I am currently on with cursor.
My goal is using the name of the button, I will delete the button and add text to get the correct text so when button is clicked, I can change the text as needed.
I know I can resoze the text so it will cover the button and using the logic for finding the current button, I can find the text too. But being able to find the name in string would help for additional game logic. It is not difficult to find a way around but still want to know for sure if getting a button’s id/name as string is possible.
(I am not on my pc so cannot share the code directly)

I’m not sure I understood your usecase but:
If all your nodes are defined in your GUI scene, you could save their id as string in the table and then do gui.pick_node(gui.get_node(id)) .
If you create nodes dynamically, you can set their id with gui.set_id() .

1 Like

You cant get a string from a hash/node id.

But you dont really need a string…what you need is a way to identify and associate a button node with some data.
You should define a table with the buttons data, which are indexed by the buttons names hash. What i do is something like that.

local ids = {
 XBUTTON = hash("xbutton"),
 YBUTTON = hash("ybutton")
}
local buttons_data = {
  [ids.XBUTTON] = { name="XBUTTON", text="X BUTTON", otherdata= 1},
 [ids.YBUTTON] = {....}
}

local buttons = {}
for k, v in pairs(buttons_data) do
  node = gui.get_node(k)
  buttons[node] = k
End

-- then when you have a node
buttons_data[buttons[mynode]].text

I am on my phone so this is probably wrong..
I use a ids table so I can use autocompletion everywhere never typing strings again.
Maybe there is too much indirection, but you get the idea.

1 Like

Thank you for the answers and suggestions @Mathias , @a-daniel :slight_smile:
I already had a workaround idea but wanted to know if could use a string based approach to the problem :sweat_smile: