how to use get_button_index in Godot 3.0 Alpha

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By swipis
:warning: Old Version Published before Godot 3 was released.

Hello,
I trying Godot 3.0 Alpha and want to get mouse wheel scroll

If InputEventMouseButton.get_button_index ==BUTTON_WHEEL_UP:
      Print('wheel up!')

and getting error

Invalid get index 'get_button_index' (on base: GDNativeClass)

what I’m doing wrong?

Thank you in advance

:bust_in_silhouette: Reply From: kidscancode

First of all, if and print shouldn’t be capitalized (I’m guessing that’s a typo in your question, not in your code).

In 3.0 the event API has changed a bit (and hasn’t yet been documented fully). An InputEvent is an object, and you check its type to see what it is. Depending on its type, you can access its members. For example:

func _input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_WHEEL_UP:
            print("wheel up!")

You can also use get_button_index() like in your question, but you would need the () because it’s a function.

now it is working. Thank you very much!

swipis | 2017-08-19 07:11

:bust_in_silhouette: Reply From: asaber

This is the way to capture wheel mouse in Godot from C#.

public override void _UnhandledInput(InputEvent @event){
    if (@event is InputEventMouseButton){
        InputEventMouseButton emb = (InputEventMouseButton)@event;
        if (emb.IsPressed()){
            if (emb.ButtonIndex == (int)ButtonList.WheelUp){
                GD.Print(emb.AsText());
            }
            if (emb.ButtonIndex == (int)ButtonList.WheelDown){
                GD.Print(emb.AsText());
            }
        }
    }
}