Strange child behaviour

Godot Version

Godot v4.6.2.stable (001aa128b)

Question

Came across this weird behaviour while following a fps tutorial, relating to an ammo pickup updating the label. I managed to make an MRP of it here. similar hierarchy, node implementation, and logic.

It has 3 scripts shape.gd, shape_switch.gd, shape_handler.gd.

2 shapes that inherit from a shape scene and _shape.gd. spacebar to give tribute to each shape.

shape_switch.gd handles displaying and switching between shapes with 1 and 2 keys to switch between a cube and ball shape.

shape_handler.gd stores the tributes given to each shape, has a boolean flag to tell whether the shape is currently being displayed or not, and updates the label for each shape accordingly.

press the spacebar, add exclamation marks to the dictionary of tributes for each shape. simple. however, when pressing the spacebar when the 1st child is displayed, the label doesn’t update, but it updates as expected when the 2nd child is displayed. the label for the 1st child will update when swapping back to it, but not when pressing the spacebar.

the issue appears to happen in shape_switch.gd in the else block of the display_shape() function, it sets the boolean variable of both children to false, when it’s supposed to set one.

I don’t know why it behaves the way it does, and maybe someone here can spot something about my code that i missed.

Seems to work, what are you expecting to happen?

Maybe you are confusing your per-child code with this switch maker node

func display_shape(active_shape: Node3D) -> void:
	for child in get_children():
		if child == active_shape:
			child.visible = true
			child.switchmaker.shape_active = true
			child.set_process(true)
			child.switchmaker.flaunt_tribute(child.shape_type)
		else:
			child.visible = false
			child.switchmaker.shape_active = false
			child.set_process(false)

all childs point to the same .switchmaker so setting .shape_active only matters for what the last child is.

Pressing the spacebar when the first child is displayed doesn’t update the label, the same way it updates on the label when the second shape is displayed, as demonstrated here. the label only updates after i switch back to the first shape. same thing happens when i reorder the children.

What do you want to happen?

to press the spacebar while the first shape is displayed, and for exclamation marks to be appended to the label text in real time, the same way it works when the second shape is displayed.

figured out what the problem is with the code. i was using both children to set the same flag, so the second child would always overwrite the flag after the first child set it.