[Solved] I don't understand what is going on with the enum part

I read the microsoft documentation and watched the enum part of the video where the text is moved to void state_cell. I understand nearly everything until this point. If someone could break it down for me for what is going on in this part of the video, that would be great! Thanks!

An enum is basically just a way to give a list of integers meaningful names.

Here we have a list of all the possible states the game can be in, so we could attach a number to each of those states to keep track of them. We could make an int variable called state and say that the initial state where we’re in the cell is 0, looking at the mirror is 1, looking at the sheets is 2, etc.
Then our code would look something like:

if (state == 0) {
// Handle initial cell state
} else if (state == 1) {
// Handle looking at mirror
}…

The problem with that is that those integers are arbitrary and don’t really mean anything. So we make an enum to give names to them, such that 0 is now called “cell”, 1 is called “mirror”, 2 is called “sheets_0” etc. That’s all an enum does.

Now we can use those names in the code to make it easier to read and keep track of what state we are in.
Hopefully that was helpful to you :wink:

4 Likes

Thanks for the quick response and yes, that helped!