Compiler Error Learn to Code by Making games

It says I have a compiler error when I need to test if it works after I do the freedom part. It is near the end of lecture 32.

Hi Allan,

Can you post your code please. Also, please the Unity course related questions in the appropriate category, you are more likely to get relevant help that way. :slight_smile:

Hi Allan,

In your first screen shot you have an error message which states that the method named “state_mirror” is already defined.

If you look at your code you can see that you have a method named “state_mirror” at line number 40, and then you have the same named method again at line 83. This is why you have the error method.

Most likely you have used a previous code block and copy and pasted it ready to build the next state method, but because you haven’t changed the name of the method the compiler is not happy with you. It cannot have methods with the same signature in the same class, it would cause ambiguity.

As an example, if the method at line 40 set the screen colour to red, and the same named method at line 83 set it to blue - when the program ran - which colour should be displayed?

Your choices are…

  • delete the duplicate method at line 83
  • comment out the method at line 83
  • rename the method at line 83

After this, that specific error message should go away.

For this specific section of the course, it is advisable to add the corresponding method for the specific state you are adding to the enum one at a time, that way you know that you don’t have any methods missing, or any extra that you don’t need.

Please note, when sharing code it is must easier for the person trying to help you if you copy and paste the code in your post (see the link below), screenshots are useful for things like showing the state of the Unity editor, or for specific settings from a component within the Unity editor, but for code, pasting it directly into your post and formatting it accordingly is typically preferred :slight_smile:

I hope this helps :slight_smile:


See also;

There is a another error above. With my code.

Hi Allan,

Did you read my previous reply regarding the posting of code?

Privacy & Terms