how do i disable a input in the InputMap in code

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lynn_Len
:warning: Old Version Published before Godot 3 was released.

im currently working on a project that needs to disable input key in the InputMap when said key becomes false; but i don’t know how to do can someone help me.

here’s my code if you need.

extends KinematicBody2D

export var motion_speed = 300

var ray

var aim = preload("res://Scenes/Entities/Player_Extensions/Aiming_Reticle.tscn")

export (bool) var is_aiming = false 

onready var r = get_node("Aiming_Reticle")

func _ready():
	set_fixed_process(true)
	set_process_input(true)

	ray = get_node("Ray")

func _fixed_process(delta):
	var motion = Vector2()

	if Input.is_action_pressed("ui_up"):
		motion += Vector2(0, -1)
		ray.set_rotd(180)
	if Input.is_action_pressed("ui_down"):
		motion += Vector2(0, 1)
		ray.set_rotd(0)
	if Input.is_action_pressed("ui_left"):
		motion += Vector2(-1, 0)
		ray.set_rotd(-90)
	if Input.is_action_pressed("ui_right"):
		motion += Vector2(1, 0)
		ray.set_rotd(90)

	motion = motion.normalized()*motion_speed*delta
	move(motion)

func _input(event):
	var s = aim.instance()

	if event.is_action_pressed("ui_event 1"):
		is_aiming = true
		add_child(s)
		s.set_pos(Vector2(0, -64))
		placed()

	if event.is_action_released("ui_event 1"):
		is_aiming = false
		r.queue_free()
		placed()

    func placed():
    	if is_aiming == false:
    		print("FALSE!!!!!")
    
    	if is_aiming == true:
    		print("TRUE!!!!!!") 

In func input(event): I made it so if event.is_action_pressed(ui event 1): would spawn in a aiming reticle, it also make a (bool) variable called is_aiming = true. I also have a if statement called if event.is_action_released(ui event 1): that despawns the aiming reticle and also makes is_aiming = false. I have it so that you can spawn four aiming reticle using the 8, 5, 6, 4 and despawn upon releasing those keys. Having multiple aiming reticles seems to not work saying that it attempt to call queue_free in base null instance on a null instance so what i want is to make it so while i pressed one of the keys make it so i can’t spawn another from the other keys.

Lynn_Len | 2017-12-06 07:46

I actually misread your question, and have since hidden my comment. Sorry. Let me get back to you.

Edit:

So the aiming reticle is meant to be visible as long as you’re holding either 8, 5, 6, or 4.

You have the reticle node r as an onready variable, so it’d already be a child of the scene. Meanwhile, when event.is_action_pressed("ui_event 1") is true you add a node s to the scene. Did you perhaps mean r - which would be redundant since r is already be a child - or is this a different node entirely? Finally, when event.is_action_released("ui_event 1") is true you delete r; that’s what queue_free is for. Referencing r after that would get you null.

If all you want to do is show and hide the reticle the methods show() and hide() would be more appropriate.

Aaron | 2017-12-06 21:18

Thank you, i did what you said and it work like i wanted to.

Lynn_Len | 2017-12-06 23:23

:bust_in_silhouette: Reply From: Aaron

Turning my comment into the answer:

As you explained, you want to show and hide the aiming reticle node (r) depending on whether certain inputs are pressed or released ("ui_event 1").

You were attempting to do this by adding and removing the reticle node to your scene in response to inputs. There was a bug though where you called queue_free on the node when removing it, which would cause it to become unavailable when you want to re-add it to the scene later.

As I suggested, a better approach would be to not add and remove the node but to show and hide it, using the show() and hide() methods.