+1 vote

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?

asked Jul 18, 2017 in Engine by unknown_one (15 points)
edited Jul 18, 2017 by unknown_one

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
answered Jul 19, 2017 by aozasori (460 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 How to use this Q&A? before posting your first questions.