0 votes

Hi,
The following code

func input(event):
# If the user press a mouse button
if event.type == InputEvent.MOUSE
BUTTON and event.pressed:
if event.buttonindex == BUTTONLEFT:

Gives throws the following error:

Invalid get index 'type' (on base: 'InputEventMouseMotion').

Please help

in Engine by (99 points)

1 Answer

0 votes

Rather than use event.type, try:

if event is InputEventMouseButton:

Place that outside the rest of the statement, though, because otherwise godot will try and check if moving the mouse is pressed, which doesn't work

func input(event):
# If the user press a mouse button
if event is InputEventMouseButton:
    if event.pressed:
        if event.buttonindex == BUTTONLEFT
by (388 points)
if event is InputEventMouseButton and event.pressed and event.buttonindex == BUTTONLEFT:
    print("this works too! because it only checks the second if the first true etc")
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.