Godot Version
4.2.1
Question
My program creates a turn order for players. Each member block contains their name and their current delay count that ticks with time until 0, and then it’s their turn (similar to Trails series). The member block is a scene, and the important node is Member → Color Rect → Color Rect → SpinBox, which holds the value of the delay.
The parent node creates instances of each member scene. I’m trying to write a function that will organize the child nodes so that the lowest value is on top when the turn order is displayed (below).
I get an error on the “if get_child(minimumIndex)” line, and it says “Invalid get index ‘value’ (on base: ‘null instance’)” The Errors tab also says “Node not Found.”
I’m not sure what I’m doing wrong, though it’s probably obvious to someone more familiar. In another function, I preload the scene, but I was under the impression that I would only need to do that once for the whole program? Any help is appreciated, since the only programming I’ve done before this was on assignments in class.
Tangential question: does move_child insert the child node at the given index, and push the other child nodes up an index, or does it swap the child with whatever node was there?
If I need to provide more info, please ask.
func memberSort():
if get_child_count() == 0:
return
var childCount = get_child_count()+1
for i in childCount:
var minimumIndex = i
for j in range(i+1, childCount):
if get_child(minimumIndex).get_node("$ColorRect/ColorRect/SpinBox").value < get_child(j).get_node("$ColorRect/ColorRect/SpinBox").value:
minimumIndex = j
if (i != minimumIndex):
swapMember(i, minimumIndex)