Attempting to retrieve the button name from a group but in one situation the name prints as @b@4 instead of b.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LunarBeach

Relevant code:

func _input(event):
buttons = get_tree().get_nodes_in_group(“Buttons”)
for button in buttons:
button.connect(“pressed”, self, “_some_button_pressed”, [button])
ready = Input.is_action_just_released(“accept”)

other function…
…for opt in turn_text.keys():
buttons[i].name = opt
i += 1

func _some_button_pressed(button):
branch =
return branch

The JSON file it is pulling from:

{“name”:“Nat”, “expression”:“neutral”, “text”:{“a”:“Dean you are so cool and I love you so much.”}, “xp”:5 },
{“name”:“You”, “expression”:“neutral”, “text”:{“a”:“Pshh. What a nerd.”, “b”:“BBBBBBBBBBBBBBBBBBBBBB?”, “c”:“Wow look another option!”} },
{“name”:“Nat”, “expression”:“neutral”, “text”:{“a”:“abracadabra”, “b”:“Barn Yard”} },
{“name”:“You”, “expression”:“nervous”, “text”:{“a”:“Go away weirdo.”, “a1”:“I love you, Nat”} },
{“name”:“You”, “expression”:“neutral”, “text”:{“b”:“Barnicles!”, “b1”:“Butts and butts”} },
{“name”:“You”, “expression”:“neutral”, “text”:{“b”:“Lets eat a fancy dinner.”, “b1”:“I hate you.”} },
{“name”:“Nat”, “expression”:“neutral”, “text”:{“a”:“okay King, I love you.”, “a1”:“I hate you.”} }

It happens when I click “Barnicles!”

This happens when you have multiple instances of the same node with the same name at the same node path

So i suppose you could do branch = str(name.replace("@", "").replace(str(int(name)), ""))

Wakatta | 2020-12-22 20:45

That explains a lot. I was very curious as to why this was happening.

LunarBeach | 2020-12-22 23:46

:bust_in_silhouette: Reply From: Lopy

Two sibling nodes cannot have the same name. @b@4 is Godot renaming your buttons to resolve the conflict.
You could make sure that no two nodes ever have the same name, but I would recommend storing your information elsewhere.

You can either make a script extending button, with an “option” variable :
class_name LunarButton extends Button
var option: String

Or use the “meta” functions :
buttons[i].set_meta("option", opt)
branch = button.get_meta("option")

This fixed it! I used the second technique because it looked like it would work better with the larger scheme of what I had going on.

Thank you so much!

LunarBeach | 2020-12-22 23:47