How to assign a key which when pressed it disables one function or line of code ??

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

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 == "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

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“Ball” to “if gameover and == “Ball”” then at the end of the function “gameover = true”

ArthurER | 2020-10-03 03:46

Code and show me

Siddharth Pushkar | 2020-10-03 03:53

:bust_in_silhouette: Reply From: K1ll3rM

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")):

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.