0 votes

I'm very new to the engine and encountered something that I don't think is normal. I did this very small bit of code.

var activationKeyReleased : bool = false

func _physics_process(delta):

func fall_down(delta):
    if activationKeyReleased == true:
        self.rotation_degrees += 70 * delta
        if self.rotation_degrees >=90: 
            activationKeyReleased = false 

func _input(ev):
    if Input.is_key_pressed(KEY_SPACE) and ev.echo == true: 
        self.scale.y += 0.15
    elif ev.is_action_released("ACTIVATEINCREASE"):
        activationKeyReleased = true

I get the message in the debugger "Invalid get index 'echo' (on base: 'InputEventMouseMotion')
Sometimes it works and sometimes it doesn't when I run the code. When I exported it, it worked fine everytime thought. Maybe its to do with mouse movement but I don't know why.

I fixed it, figured out _input(ev) detects all inputs which include mouse movement, so if I'm holding space and moving the mouse thats new input and mouse movement is not .echo I don't think.

func _input(ev):
    if Input.is_key_pressed(KEY_SPACE) and ev is InputEventKey: 
        if ev.echo == true:
            self.scale.y += 0.15
in Engine by (20 points)
edited by

1 Answer

+1 vote

Yes, _input receives all kinds of events, and using Input is not really the expected way to use this function. Take a read of all this article: http://docs.godotengine.org/en/3.1/tutorials/inputs/input_examples.html

is_echo() is specific to keyboard inputs (related to key repeats when you hold a key for more than 1 second), so you should check if ev is a keyboard event before calling it. In your first code, you were not doing that.

by (28,731 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.
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 webmaster@godotengine.org with your username.