Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Lazulily |
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