[SOLVED] Understanding Question about private enum State {...} & private State myState;

Hello! :slight_smile: ,

I am currently doing the “Building your Game Engine” Lecture and a question arose regarding the following part:

private enum Phase {…};
private Phase myState;

Is it right that the variable Phase has to have the same name as the enum name (Phase)? [I hope that it is right if I say “enum name” :slight_smile:]

I wanted to give the enum a different name than the variable. This is what I tried which however, did not work:

private enum State {cell, sheets_0, mirror, lock_0, sheets_1, cell_mirror, lock_1, freedom};
private Phase myState;
	
	
	void Start () {
		myState = State.cell;
	}

Phase in “private Phase myState” appears red and I cannot run it. Why is that so? I thought State.cell would refer back to the enum name and had no connection to the variable type “Phase”. Why would I have to call the variable “State” as well?

Please tell me if the question is clear or not with all these States and Phases and Variables. In case it is not I will do my best to ask the question in a better form.

Thank you very much!
Bryan

Phase is just the name the instructor gave to the enumeration. You’re certainly welcome to change the enum to any name you want.

remember that the second line is creating a variable, myState, to be a private type, in this case the enumeration Phase.

so your code would be:
private enum State {};
private State myState;

Hope that helps :wink:

Great! Thank you very much