+1 vote

I have created a custom UI Container that implements a radial menu. Currently I am using a custom function ( addbutton(node) ) to addchild then recalculate each child's position. However, I should just run the reposition function whenever a change to the container's immediate children happens.

I found this question and answer which half works for me. Half because I am able to override the removechild function. Not the other half because addchild gives me an error

My code:

#update positioning whenever a child node changes
func add_child(node):
    .add_child(node)
    position_buttons()
func remove_child(node):
    .remove_child(node)
    position_buttons()

The error it gives:
Function signature doesn't match the Parent. Parent signature is 'void add_child(Node node, bool=default)'.

in response I tried the following change:

func add_child(node, bool=default):
    .add_child(node)
    position_buttons()
func remove_child(node):
    .remove_child(node)
    position_buttons()

However this obviously gives an error since the argument's name is a reserved keyword type. At least that is how I'm interpreting the error message:

Expected identifier for argument

I'm wondering if this is either a bug in godot or I'm just an idiot.
Any help would be much appreciated. Thanks ahead of time.

asked Apr 5, 2019 in Engine by DomtronVox (28 points)

1 Answer

+1 vote
Best answer

How about:
func add_child ( Node node, bool legible_unique_name=false ):

or
func add_child ( node, legible_unique_name=false ): (without typing)

The declaration you tried used a reserved identifier (bool) for a variable name. Like you already noticed.

..and we're all idiots one time or the other when it comes to programming "challenges". ;-)

answered Apr 5, 2019 by wombatstampede (3,193 points)
selected Apr 6, 2019 by DomtronVox

Thanks! That's what I needed. For some reason in my head I was sure I shouldn't rename the argument.

#update positioning whenever a child node changes
func add_child(node, legible_unique_name=false):
    .add_child(node, legible_unique_name)
    position_buttons()

And this is what I meant by idiot. I really should have checked the "add_child" function in the docs more closely. It plainly names the argument "legible_unique_name" not "bool. >.<

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.