+2 votes

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?

in Engine by (16 points)
edited by

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

1 Answer

0 votes

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
        pressed[action] = false
    return false

func _process(delta):

    if is_action_just_pressed("ui_select"):
        ## done once when the key is pressed
by (468 points)
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.