This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes
func _ready():
        while $Start.time_left >= 1.0:
                print(str($Start.time_left))

is not working. The program does not react and it does not even write time_left one single time! With if, it is working but I need it with while! Of course, I have the timer on autostart.

Godot version 3.2.3.stable
in Engine by (382 points)
edited by

Hmmm... since ready() is run once, after the scene is ready, this also means you forgot to check autostart on Timer properties.

Haha no, I wrote that I enabled it ;)

I have nearly no idea what is going on but my complete code that has anything to do with this issue is as follows.

func _ready():
    get_tree().paused = true # Timer's pause_mode is process, SceneChanger's pause_mode is process
    yield(SceneChanger, "scene_changed")
    countdown()

func countdown():
    while $Start.time_left >= 1.0:
        print(str($Start.time_left))
        $CanvasLayer/Time.text = str(round($Start.time_left)) # Time's pause_mode is process.

Script of SceneChanger-autoload:

signal scene_changed

func change_scene(scene_to_load_path, delay = 0):
    if scene_to_load_path == "res://game/game.tscn":
        $AnimationPlayer.play("fade")
        yield($AnimationPlayer, "animation_finished")
        assert(get_tree().change_scene(scene_to_load_path) == OK)
        $Control/ColorRect.modulate.a = 0
        emit_signal("scene_changed")
        return

What i know is that countdown() is never called because this scene waits until "scene_changed" was emitted but for some reason, it thinks it is never being emitted!? Maybe the problem was this from the beginning upsi xD.

Okay, it's not. When I remove the yield line, it starts freezing again :/.

1 Answer

0 votes

The _ready() function is executed only when the node is ready to do its thing, and it is only run once. It may be better to check the status of the timer in the _process() function.

by (3,164 points)

But if there is a (while-)loop, the function in which the loop exists does not have to be and is not called, that would be extremely weird!

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 Frequently asked questions and 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 [email protected] with your username.