Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


GameState is a bad method nowadays ?

  • You cannot reply to this topic
5 replies to this topic

#1 Alundra   Members   -  Reputation: 1307

Like
0Likes
Like

Posted Yesterday, 07:48 PM

Hi,

I'm still using game state to have different state like menu and in-game for example.

The modern way is to use only scene and code actor to do something for this actual scene.

Is it a bad method nowadays to use game state ?

Thanks


Edited by Alundra, Yesterday, 07:48 PM.


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 21429

Like
9Likes
Like

Posted Yesterday, 08:22 PM

It’s equally relevant as it ever has been, and largely a matter of choice.
When you set up your engine to use states, there are no downsides. If you ultimately end up wanting to use only 1 state for the whole game, then just make one GameState class and do it all that way. It has the flexibility to work in any system, so there is no reason not to do it.

I personally still choose to use game states, as they are still the best way to isolate sections of code in your game.


L. Spiro

#3 sigvatr   Members   -  Reputation: 161

Like
0Likes
Like

Posted Today, 08:51 PM

Generally speaking it is a bad idea because you may want to be making use of multiple states at the same time. Imagine a game where you can drop down a console to read logging info and enter commands while the game is running. Perhaps it could even have a game menu opened at the same time on top of all that other stuff. A good example of this is Valve's Source engine. Team Fortress 2 can have the game running while a console, title screen, server browser and options window are all open at the same time, and that's not the end of it.



#4 frob   Moderators   -  Reputation: 31463

Like
1Likes
Like

Posted Today, 09:33 PM

State machines, including nested state machines, are an incredibly powerful tool both inside computer science generally and inside games specifically.

While you can use scenes to implement some of those things, and tools like Unity do this, there is also nothing inherently wrong with using state machines to track and flow through the system. It is not "a bad method". It is one method of many.

State machines are the correct tool to use when you flow through states. That is what they are for, that is what they do. If that is what you need part of your game to do, then it is the right tool for the job. When you need to flow from state to state to state, using transition rules along the way, you use a state machine.

For the example of having multiple pieces open at once, that is composition rather than state. Each component is engaged in states. The console is using states to indicate its drawing mode and display status. The option windows are a hierarchy defined by state and state machines. The title screen and menus are a state machine defined by state and state machines. Most of the AI in TF2 is powered by state machines. Most game objects and spawners and other parts are run by state machines.

You don't need to use state machines for everything, and there may be other tools available for various tasks, but still embrace the fact that state machines are found practically everywhere in computer programming, including concepts like the lowly switch statement and if/else trees.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I occasionally write about assorted stuff.


#5 sigvatr   Members   -  Reputation: 161

Like
0Likes
Like

Posted Today, 09:34 PM

Threading is important, too.



#6 L. Spiro   Crossbones+   -  Reputation: 21429

Like
0Likes
Like

Posted Today, 09:40 PM

Generally speaking it is a bad idea because you may want to be making use of multiple states at the same time. Imagine a game where you can drop down a console to read logging info and enter commands while the game is running. Perhaps it could even have a game menu opened at the same time on top of all that other stuff. A good example of this is Valve's Source engine. Team Fortress 2 can have the game running while a console, title screen, server browser and options window are all open at the same time, and that's not the end of it.

Solution: Stack of states.
This is what we use on devices such as Nintendo Wii that have the potential to force menus/notifications over your game (low battery on a controller, etc.)

Threading is important, too.

Threads are unrelated to states.


L. Spiro

Edited by L. Spiro, Today, 09:41 PM.






PARTNERS