Override add_child function for custom container type.

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

I have created a custom UI Container that implements a radial menu. Currently I am using a custom function ( add_button(node) ) to add_child 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 remove_child function. Not the other half because add_child 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.

:bust_in_silhouette: Reply From: wombatstampede

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”. :wink:

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. >.<

DomtronVox | 2019-04-06 00:20