What Is 'States'?

Hello! I was watching the lesson entitled “Building Your Game Engine” and found myself completely lost when he started talking about states. Did I miss something? if anyone has answer it would be much appreciated! I’m sorry it’s probably a really easy answer isn’t it and I’m being stupid haha!
~MA

Hello @Morbidly_Adorable, in this lecture it is referring to the different states of which the game can currently be in.

For example, if you consider a text adventure… you walk into a room and see a key on the floor. That may be referred to as room_0 - which, as you are developing your game you would understand means that the player at that point hasn’t done anything with the key, it is still on the floor.

If the play was to pick up the key, perhaps you would then set the state to be room_1, you would then know that the player had the key.

You can then limit other options and perhaps displayed text based on the current state of the game.

In the code, States I believe was an enum (enumerator), you add these and they serve effectively as options to differentiate something. Using the intelli-sense within MonoDevelop or Visual Studio you would then be able to type…

States dot (e.g. a full stop) and the moment you do you would be presented with a list of all of the available enums that you have configured… in my example above that would read:

Room_0
Room_1

There are alternative ways to achieve the same outcome, but for the first game could be a little overwhelming I believe.

Hope this helps.

Edit

Please don’t ever feel that something must be obvious or you’re being stupid, if there is something you are not sure about please do ask. Typically the instructors will respond to course related questions when they are posted within the Q&A section on Udemy, but you obviously post questions here to and you will invariably find someone from the rather awesome community that the course has created who will try to help you.

Remember, you may not be the first person to not understand something, but you may be the first person who asks, and by asking and getting an answer you could well be helping other people also. :slight_smile:

1 Like

Hello, @Morbidly_Adorable!!

To expand a bit on what Rob said, you can think of states as nodes in a flow chart. Well, what do I mean by that? Well, a flow chart is often used to visualize the relationships between states and their transitions. I’ve attached an image for reference. A few key things to note:

  • Paths can diverge, and become unique when they do
  • Paths can re-intersect (state_1 and state_2 both lead to state_4)
  • The same action in a different state can yield a different result (state_1 and state_3 both have “investigate chair,” but each results in a different state)
  • State transitions can be many things, not just location change (Rob also mentioned this, for example you can find a key in one room, but remain in that room – it can still be considered a separate state)!

And to reiterate, do not feel as if you’re missing something or unintelligent. We’re here to learn, and state machines are actually a very sophisticated topic in Computer Science. In fact, all computation that we can currently complete can be reduced to a Turing Machine, which is just a special type of state machine. So, if you have any more questions, or if something I’ve said is unclear, don’t hesitate to ask!

4 Likes

Great response @Gwynblade and nice diagram :slight_smile:

Privacy & Terms