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.
+1 vote

Whenever I use a while loop, doesn't matter what is in it or what is the condition, it crashes the game. I even tried creating a new project and only adding the code below to _proccess(delta) but it crashed too. Is this only with me? I'm using the Steam Version v3.0.6.stable.official.8314054 (latest version avaliable for Steam today)

while true:
in Engine by (519 points)

2 Answers

+1 vote

You should add the following line at the end of the while loop:

yield(get_tree(), "idle_frame")
by (47 points)

Perhaps, but this doesn't answer "why", and isn't a good solution to what's probably a fundamental misunderstanding of how the engine operates. Better to understand the main loop execution before diving into coroutines.

Add the following line like this?

    while y == true and yield(get_tree(),"idle_frame"):
    movement.y += 1

Like that right?

When y is true and yield get tree idle frame:
movement y += 1

+1 vote

A while loop like that is infinite - it never exits. If it never exits, then the _process() function can never end. Since _process() is called every frame, you have now locked up the application and no more frames will ever be executed.

This is the case in most graphical applications, where you already have a central loop running the core processes of the application. Instead of using a while loop you should ask yourself what you're trying to accomplish. For example, if you just wanted to print "test" over and over again, you could just do this:

func _process(delta):

Now when you run the game, your output panel will be flooded with "test" prints every 1/60 of a second.

by (22,191 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 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.