0
\$\begingroup\$

I'm trying to set it up so that there are three buttons but only one can be toggled at a time. So when one button gets toggled it makes sure that the other two are not toggled.

The code is trying to set the toggled status however since it can't find the node I'm at a loss.

var vec = Vector2(0,1000)
var ori = Vector2(0,0)
func _ready():
    pass

func _on_Ally1_Button_toggled(button_pressed):
    if button_pressed:
        set_position(ori)
        $Player_Button.set_pressed(false)
    else:
        set_position(vec)

This is what the tree looks like.

enter image description here

The Player_Ally1_ui is trying to access Player_Button but as stated it can't seem to find it and just returns null.

Any help is greatly appreciated, thank you in advance.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

$Player_Button refers to the child of the current Node called Player_Button, not the sibling. You actually want get_node(../Player_Button) (as the $ syntax doesn't support ..).

A better option might be connecting these nodes via signals in the Editor. One of the advantages of this is that you can move the nodes around in the tree and the Editor will handle updating the singal connections for you. If you use hard-coded node paths, you'll have to update your code every time you move nodes around (which I find happens frequently in Control nodes).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .