0 votes

I have a scene setup like these:

Parent
 Pepe
 Juan
 Pedro
 Luisa

(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
    add_child(timer)
    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)
    else:
        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?

in Engine by (28 points)

1 Answer

0 votes

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.

by (25 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.