Godot Version
4.5.1
Question
As a sort of general question, what are some best practices for handling the current game state of a game?
For example, let’s consider a sort of rogue-like where you travel through rooms defeating enemies. Every time you clear a room, you get the choice to upgrade your character.
Arbitrarily, let’s say that this specific game has the following game states:
enum GameStates {
WANDERING, # Player isn't in an active battle, freely wandering the map
IN_ROOM, # Player is in an active battle
ROOM_CLEARED, # The room has been cleared
UPGRADE, # The Player gets to choose an upgrade
DEATH, # The Player has just died
LOSS_SCREEN, # The Player is viewing the loss screen, with options to replay or exit to main menu
PAUSED # The Game is Paused
}
var current_state: GameStates
These may or may not be the perfect or even only states to include for such a game, but for the sake of this question, let’s just say that these are the states chosen for the game
What is the best way to manage changing from state-to-state when it concerns the game state as a whole? I know there are situations where using Nodes or Enums are good for state machines, but if it concerns the game as a whole, would something like an autoload to serve as a sort of “hub” work?
My best guess is that, in the ideal world, there would be one singular location that keeps track of the current state and what states are available, while every other node and script at most will be in charge of sending signals to change the game state and keeping track of the current state, but I don’t know if that’s the best practice.
In my own research, I’ve found a very wide range answers that conflict with each other or assume something that wouldn’t apply to most scenarios, so I come here to be able to properly ask this question in the hopes of narrowing the range of conflicting and/or unique answers so I can more easily choose which answer is right for whatever I’m currently working on.