+1 vote

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 (101 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 (399 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 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.