This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I have a container that has other control elements in it that when I scroll it will scroll through the contents smoothly, for the most part when I start the program the scrolling works fine, but after a while or in some cases almost immediately it will crash with the error:
Invalid get index 'button_index' (on base: 'InputEventMouseMotion').

I am assuming that the problem has something to do with vectors conflicting with the x and y values that are apart of InputEvenMouseButton.

I am still not very sure what match is or what it does, but without it, it doesn't seem to work any other way.

Thank you in advance :)

Here is my code:

extends Container

var v = Vector2(0,0) #current velocity
var just_stop_under = 1
var multi = -4 #speed of one input
var is_grabbed = false


func _process(delta):
    v *= 0.9
    if v.length() <= just_stop_under: v = Vector2(0,0)
    $Origin.rect_position += v

    if $Origin.rect_position.y < -709.8:
        $Origin.rect_position.y = -709.8
    if $Origin.rect_position.y > 0:
        $Origin.rect_position.y = 0


func _gui_input(event):

    #if event is InputEventMouseButton:
        #match event.button_index:
            #BUTTON_MIDDLE:  is_grabbed = event.pressed

    if event is InputEventMouseButton and $Origin.rect_position.y > -709.9 or $Origin.rect_position.x < 0.1:
        match event.button_index:
            BUTTON_WHEEL_DOWN:  
                v.y += multi
                continue
            BUTTON_WHEEL_UP:    
                v.y -= multi
                continue
Godot version version 3.4
in Engine by (58 points)
edited by

1 Answer

0 votes

I think the logic here isn't working as you intend due to a lack of parens:

if event is InputEventMouseButton and $Origin.rect_position.y > -709.9 or $Origin.rect_position.x < 0.1:

I assume that needs to be:

if event is InputEventMouseButton and ($Origin.rect_position.y > -709.9 or $Origin.rect_position.x < 0.1):

Note, I just added a set of parens. Without those around the position checks, you'll get inside that if block unexpectedly...

Specifically, your logic is essentially this:

if thing_one and thing_two or thing_three

Without parens, that'll be TRUE in either of these cases:

  • thing_one and thing_two are TRUE -or-
  • thing_three is TRUE

With the parens, the logic only returns true in this one case:

  • thing_one is TRUE and (either thing_two or thing_three is TRUE)
by (22,704 points)
edited by
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.