Game crashes when using 'while' loop in '_ready()'

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

I’m trying to make a small game, with a ball that move right and left, and I want the game to begin only when we press the right or the left key to start moving the ball. I tried using a while loop in the _ready() function that run until we press one of the keys, but it always crashes the game.
Is there another way I could this ?

:bust_in_silhouette: Reply From: Asthmar
var Startedgame = false

func StartGame():
	 #In here goes code that starts game

func _process(delta):
    if Input.is_action_just_pressed('Start_Key'):
      if Startedgame == false: ## did game start yet?
           StartGame()
           Startedgame = true
	

hope that helps!

Thanks for answering so fast ! That should work.

Coconut35 | 2023-02-13 15:55