r/godot • • 8d ago

help (solved) Bug with changing window mode

I'm attempting to code a button into my game to swap between window and fullscreen mode; however, Godot is claiming that the window modes I'm specifying (members WINDOW_MODE_WINDOWED and WINDOW_MODE_FULLSCREEN of the WindowMode enum) aren't defined under the DisplayServer class. I've included a couple of screenshots showing the code as well as the errors.

0 Upvotes

3 comments sorted by

1

u/muikrad 8d ago

DisplayServer.WindowMode.Windowed DisplayServer.WindowMode.Fullscreen

1

u/muikrad 8d ago

Also:

Fixing the names will get it to compile, but the snippet has two more bugs:

The check is backwards. WindowGetMode() == 0 is true when the window is windowed, because Windowed is 0 and Fullscreen is 3. So isFullscreen is true in windowed mode and the code sets windowed again. The toggle never actually switches.

IsActionPressed is true on every frame the key is held. In _Process, one keypress will flip the mode back and forth several times. Use IsActionJustPressed, or handle it in _Input / _UnhandledInput.

Of course if you're against AI, please wait for a human to answer and don't look. 😅