this post was submitted on 07 Feb 2025
546 points (98.4% liked)

Gaming

20616 readers
241 users here now

Sub for any gaming related content!

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] Lifter@discuss.tchncs.de 2 points 1 day ago (1 children)

Plus all the lines to update the state, when the menu is closed, when the game is closed (i.e should it be true or false at startup), when the game is saved obviously.

That's at least three more lines plus the one you mentioned for no extra value. And again it's easier to screw it up e.g. while refactoring.

[–] JustAnotherKay@lemmy.world 1 points 1 day ago (1 children)

I think we write our code in different enough ways that we're not seeing eye to eye.

Tracking the state of the game being paused, when the menu is open and when the game is saved can all be a single match statement on a current "game state" variable which just holds "running/paused/paused and saved/exit" and when it becomes exit, it checks the save time. Only 2 lines of code and adding an enumerated state to the variable to add this functionality. Since the variable is enumerated, it's really difficult to mess it up when refactoring because if you can't pass the wrong code or else your game doesn't save or close

[–] Lifter@discuss.tchncs.de 2 points 1 day ago (1 children)

Ok, I mentioned a state machine in another sub thread. It's not as bad if you already have a state machine.

It's still adding more complexity though - again when the value is updated. You still need to change the state when saving. You need to decide which state to use when starting the game.

There is still risk of screwing that up when refactoring. And still the value is nearly none.

Regarding state mchines, it's a complexity in itaelf to add random flags ro the state machine. Next time you want to add another flag you need to double all the states again, e.g. PAUSED, PAUSED_AND_SAVED, PAUSED_AND_MUTED, PAUSED_AND_SAVED_AND_MUTED. I would never add mute to the logic of the menu but that's the pnly example I could come up with. Maybe you see my point there, at least?

[–] JustAnotherKay@lemmy.world 1 points 1 day ago (1 children)

Complexity being added at updating also feels wrong to me. Let me pseudo code some rust (just the language I know best off the top of my head right now) at you, cause it feels like maybe I'm just not understanding something that's making this seem easier than it is.

Enum Game_State
    Paused
    Paused_Saved
    Running
    Loading
    Exit
 
///Technically you could make Menu() part of the enum but I'd probably leave it elsewhere

Match Game_State
    Paused => Menu()
    Paused_Saved => Menu()
    Running => Main_Loop()
    Exit => Exit()

And then your other functions always return a game_state. You're right that adding that return would be a huge undertaking if it's not handled in the initial building of the game, but it's a QoL for the user that's easily maintainable and is therefore worth doing IMO. But these two things, defining the possible game states and then always routing decisions through that game state, makes this kind of feature relatively doable

[–] Lifter@discuss.tchncs.de 1 points 14 hours ago (1 children)

I'm sorry I don't getting your point . You start off by agreeing that you don't like the extra complexity that the update statements give. Then do some pseudo code of something entirely different where we all already agree is not an issue.

Then at the end your conclusion is that it is totally feasible. Why? You still didn't adress the problem of updating the state

[–] JustAnotherKay@lemmy.world 1 points 14 hours ago

My point was "are state machines really that complicated? Isn't it just something like this pseudo code and a return value from your functions?"

Basically I feel like this is a 2 step process but you seem like you either know more than I do or have a different philosophy about how this would be implemented, so I want to understand what I'm missing