Input.get_mouse_mode() is returning 32767. Why?

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

Hi all,

This code:

func input(event):
        if (event.type==InputEvent.MOUSE_BUTTON and event.is_action_released("mouse_clicked") and !event.is_echo()):
            print("yup, you clicked it")
            print("Mouse mode: ", str(Input.get_mouse_mode()))

prints the following:

yup, you clicked it
Mouse mode: 32767
yup, you clicked it
Mouse mode: 32767

I just don’t understand that. I though that based on this:Input — Godot Engine (stable) documentation in English it would be 0, 1 or 2.

Any help would be really appreciated.

Which OS are you on?

Zylann | 2017-02-09 03:22

OS X sorry. Godot 2.1 stable.

Robster | 2017-02-09 03:23

:bust_in_silhouette: Reply From: Zylann

You get 32767 because… mouse_mode was not initialized in the engine :stuck_out_tongue:
https://github.com/godotengine/godot/blob/master/platform/osx/os_osx.mm#L1767
So you just get garbage. That’s a nice bug!
I opened an issue since I’m about to fall asleep, it will be fixed quickly in next version OS.get_mouse_mode() returns garbage on OSX · Issue #7766 · godotengine/godot · GitHub

ahhhh, is there a way… I can work around it?

Robster | 2017-02-09 03:34

I think the default should have been MOUSE_VISIBLE, so you could call OS.set_mouse_mode(MOUSE_VISIBLE) when your game starts (or whatever value you want) so it gets an initial value.

Zylann | 2017-02-09 03:39

Thank you. I tried to add OS.set_mouse_mode(MOUSE_VISIBLE) to my func _ready(): but got this error:

Parser Error: Identifier not found: MOUSE_VISIBLE

EDIT: I also tried MOUSE_MODE_VISIBLE and 0 with the same issue

Robster | 2017-02-09 03:42

Sorry, the constant is Input.MOUSE_MODE_VISIBLE.
If the returned mouse mode is higher than the maximum one, just assume it’s Input.MOUSE_MODE_VISIBLE.

Zylann | 2017-02-09 03:46

Thank you, adding Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) to the func _input(event): worked. I really appreciate your help. I’d have never figured that one out!

Robster | 2017-02-09 03:52

No, don’t put it in _event, put it in _ready or some other place it would run only at game start ;).

Bojidar Marinov | 2017-02-09 07:38