Search Unity

Resolved I'm getting an error CS1002 for a line that already has a semicolon. Can someone help?

Discussion in 'Scripting' started by artistsftwbro, Dec 8, 2022.

  1. artistsftwbro

    artistsftwbro

    Joined:
    Dec 7, 2022
    Posts:
    1
    I am new to C# and scripting and I have a script that keeps getting an error CS1002 for line 14 though it already has a semicolon. The error is for line 14 which is

    playerInput = GetComponent PlayerInput();


    Code (CSharp):
    1.  {
    2.         playerInput = GetComponent PlayerInput();
    3.         OnFootActions = playerInput.OnFootActions;
    4.         motor = GetComponent<playermotor>();
    5.     }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,744
    Artists FTW indeed.

    Rather than being creative, go look at the docs for what a typical GetComponent<T>() method looks like.

    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.
     
    artistsftwbro likes this.