I have the error CS1002 although I placed a Semicolon.

Hello, i am a bloody beginner in Unity. I wrote the script like a guy in a tutorial but it wont work because of the error: “Assets\Player.cs(72,49): error CS1002: ; expected”. Here the code:

private void OnCollisionEnter2D(Collision2D collision)
    {
        if(collision.gameObject.tag == "ground")
        {
            isgrounded = true;
        }
        if (collision.gameObject.tag == "Enemy")
        {
            HealthManager.health HealthManager.health; //this is line 72
            if (HealthManager.health <= 3)
            {
                StartCoroutine(GetHurt());
            }
        }
    }
HealthManager.health HealthManager.health; //this is line 72

lets say HealthManager.health is equal to 5. what you have written is

        if (collision.gameObject.tag == "Enemy")
        {
            5 5; //this is line 72
            if (HealthManager.health <= 3)
            {
                StartCoroutine(GetHurt());
            }
        }

If i were the compiler, my error message would be " what do you mean 5 5? what do you want me to do with this?"

i imagine it expects a “;” because

HealthManager.health

is a complete statement, and complete statements end with semicolons (or are continued into some other complete statement, which isnt the case here)

Well a bloody good morning to you from the Unity forums then!

This is where you went slightly wrong. Go back and check, he certainly didn’t write what you have above.

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.
Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

Finally, when you have errors, don’t post here… just go fix your errors! Here’s how:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

1 Like

So, thanks for your Help! I wrote it first only one time but then another error appeared. So i searched for the error and a solution from a forum question was to write it two times. It solved the error but the error above appeared.

Thank you for your help!
I did both steps. I searched the sh** out of google and i wrote the script again and again and again. What can maybe cause the problem is, that the guy in the tutorial already made a “Game over” screen but i wanted to make it later. The “if” ribbon (i guess thats the word for it… i am german) should trigger the game over screen. There was an “else” ribbon which should trigger the “GetHurt” but I deleted the else and changed the if ribbon. Maybe this triggered the error.

Well, the code you posted does not contain anything related to a game over screen. Maybe it’s in the GetHurt coroutine that you start, but since you didn’t include it here, it’s probably not relevant to the question? The line that contains the error just serves no purpose at all, as @TzuriTeshuba already pointed out. So you probably should just delete that line completely.

Nope :slight_smile: you looked up the wrong word for “Schleife”. A ribbon is a physical “Schleife” or “Band”. It’s called an “if statement” as it’s not a loop at all. if statements (If - Anweisung) a just a branch (“Verzweigung”) or conditional block (“bedingter Block”). “Ribbon” is much closer to “Band”. “Schleife” is only used as a synonym for Band (bei einer Zierschleife). Ribbon is actually used in IT, but it’s used for a special kind of menu-bar. See Ribbon(wikipedia de) for more details.

Wow, hats off you both for learning this stuff in two or more languages and keeping the terminology straight so you can search efficiently!!

1 Like