+1 vote

I have made a game where you move a ball, collect coins and escape the enemies.
if you collect all 10 coins your scene will change to You Win screen But if you touched any enemy or entered any enemy body your scene will change to Game Over screen.
I want to assign a key on the keyboard (Like Shift + D) which when I press, It Disables the function or code of line in which when the ball enters the enemy body the scene changes to Game Over.

func _on_enemy_body_entered(body):
if body.name == "Ball":
    get_tree().change_scene("res://Demo menu screen/Gameover.tscn")
   # I want to disable this line of code or function when a key is pressed
in Engine by (40 points)

I have never tried something like 'shift D' with two keys , but could you not just make a variable true or false like 'var gameover = true' set it to false if a key is pressed , then change 'if body.name=="Ball" to "if gameover and body.name == "Ball"" then at the end of the function "gameover = true"

Code and show me

1 Answer

0 votes
Best answer

Go to Project Settings > Input map (at the top) and add a new action by pressing "New". Add a new key to it by pressing the plus right next to the new action and enter you key combination.

if(!Input.is_action_pressed("NAME OF ACTION")):
    CODE HERE
pass

Wrap your code in this if statement and replace the "NAME OF ACTION" with your action name. This should work for whatever you're trying to do.

by (61 points)
selected by
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.