Why are these nodes sharing the same position in parent?

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

I have a scene setup like these:


(each one being a Node2D)

Each child of Parent has the same scrpit:

extends Node2D

var timer: = Timer.new()

func _ready():
	timer.autostart = true
	timer.wait_time = 1.0
	timer.connect("timeout", self, "on_timeout")
	print(get_path(), " is at position ", get_position_in_parent())

func on_timeout():
	if get_position_in_parent() == 0:
		print(get_path(), "'s turn")
        get_parent().move_child(self, get_parent().get_child_count()-1)
		print("is not ", get_path(), "'s turn")

In the first frame, the print output is okey:
(Pepe is at position 0,
Juan is at position 1,
Pedro is at position 2
Luisa is at position 3)

However, when the on_timeout function gets called every second, every node has the condition get_position_in_parent() == 0 set to true. How can the have the same position in the same parent?

:bust_in_silhouette: Reply From: vanyousee

Because script is execute in order. First node runs first, so it would be putted in bottom, then the second node becomes the first one when its script runs.
If you put your node from bottom to up it would run well.