Traffic Light State Machine Dictionary Issues
If someone could assist I was building my State Machine for my college class and for some reason I ran into an issue with creating my dictionary for each colored light in my scene. Here is what it looks like.
//State in which the bulb turns green
enum BulbGreen
{
ON,
OFF,
NUM_STATES
}
//State in which the bulb turns yellow
enum BulbYellow
{
ON,
OFF,
NUM_STATES
}
//State in which the bulb turns red
enum BulbRed
{
ON,
OFF,
NUM_STATES
}
//Keeping track of Current Bulb Color State
private BulbGreen curStateGreen = BulbGreen.ON;
private BulbYellow curStateYellow = BulbYellow.ON;
private BulbRed curStateRed = BulbRed.ON;
private Dictionary<curStateGreen, Action> gsm = new Dictionary<curStateGreen, Action> ();
private Dictionary<curStateYellow, Action> ysm = new Dictionary<curStateYellow, Action> ();
private Dictionary<curStateRed, Action> rsm = new Dictionary<curStateRed, Action>();
The private Dictionary curStateGreen, Yellow, and Red come up with an error stating.
Assets/LaPinska_Brandon_Lab1/TrafficLightStateMachine.cs(44,28): error CS0118: TrafficLightStateMachine.curStateRed' is a
field' but a `type' was expected
I also have to set up a timer on these lights to circulate from green to yellow to red back to green. If anyone can help I would greatly appreciate it.
If you cant help with this or know where to find out to allow me to learn why this is an issue I would also appreciate that as well.
Thank You fellow Unity3d'ers!
Answer by Glurth · Oct 30, 2016 at 02:22 AM
Confused by why you use 3 different enums that are identical: why not just have "enum LightState"?
Regarding the Error: When you define which generic version of the dictionary you want to use, you must specify an actual TYPE or class into the , rather than a variable.
So
private Dictionary<curStateGreen, Action> gsm;
is an invalid declaration, but
private Dictionary<BulbGreen , Action> gsm;
Would be a valid declaration
Answer by brandon_lapinska · Oct 30, 2016 at 02:49 PM
I am new to dictionaries and how many enums I am actually supposed to have. The practice that they had us doing was just a light that turns on and off. I was just trying to piece things together. Thanks for the help.
Your answer
Follow this Question
Related Questions
Pulling and printing a random entry from a dictionary of a list of strings. C#. 1 Answer
Have a method accept generic methods for a in-game console 0 Answers
Getting KeyNotFoundException and I can't understand why 1 Answer
Assigning a script as a game object in Dictionary 1 Answer
dictionary of functions? 1 Answer