is_action_just_pressed is gone, what to use now?

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

EDIT:
it appears is_action_just_pressed comes from a development version, but the below chess game doesn’t load into the v3 alpha development version, it must have been made for some other development version… in any case, it doesn’t load into version 3 even after renaming editor.cfg to project.godot

I downloaded a chess project from here:

the godot project did not run because it used

if (Input.is_action_just_pressed("ui_select")):

to determine if you just clicked a place on the board, the game would then would highlight the possible places to move on the board by coloring the squares differently

unfortunately Input.is_action_just_pressed appears to be removed from the engine, only Input.is_action_pressed remains. Using the latter causes the highlighted squares to rapidly toggle and most of the time, the squares don’t remain highlighted after a mouse click.

So what do we use now when we need to do something only once when ui_select is triggered?

The “just_pressed/released” is on the 2.2-legacy (unreleased) version too, that project may be using that one.

eons | 2017-07-19 11:28

:bust_in_silhouette: Reply From: aozasori

Suggestion one:

var ui_select_pressed = false

func _process(delta):

	if Input.is_action_pressed("ui_select"):
		if not ui_select_pressed:
			ui_select_pressed = true
			## done once when the key is pressed

	elif ui_select_pressed:
		ui_select_pressed = false
		## done once when the key is released

Suggestion two:

var pressed = {}

func is_action_just_pressed(action):

	if Input.is_action_pressed(action):
		if not pressed.has(action) or not pressed[action]:
			pressed[action] = true
			return true
	else:
		pressed[action] = false
	return false

func _process(delta):

	if is_action_just_pressed("ui_select"):
		## done once when the key is pressed
:bust_in_silhouette: Reply From: st_phan

For people finding this, there is also is_echo() (Godot docs) that “Returns true if this input event is an echo event” which might be handy.

if event.is_action_pressed("some_action") and not event.is_echo():
	# Do something now