"orangeball" + (i + 1) as String
seems wrong. Try str("orangeball" + (i + 1))
.
How you're accomplishing what you're trying to do doesn't make use of the tools built into the engine very well. I would recommend attaching a script to your number nodes (0-12) and making them spawn the balls. Attaching a script that contains this:
func _physics_process(_delta):
var new_ball = get_node("orangeball").duplicate()
get_parent().add_child(new_ball)
new_ball.global_position = self.global_position
To any of your numbered nodes will accomplish what you were trying to accomplish in a much more decoupled manner. Attach that script to 0, then simply duplicate that node in the editor and it will work.
It's generally bad practice to refer to nodes by their name. It's preferable to use groups or class names instead. add_node_to_group()
and get_tree().get_nodes_in_group()
is generally how you want to refer to nodes that you instance at runtime.
https://docs.godotengine.org/en/latest/tutorials/scripting/groups.html
Adding class_name MyNode
to a node's script allows you to make comparisions like if some_node is MyNode:
. This is useful for collisions and other scenarios where you want to know if a unknown node is a specific type of node that you created at runtime.