Search Unity

Bug Error CS1002: ; expected

Discussion in 'Scripting' started by matidevelop, May 29, 2023.

  1. matidevelop

    matidevelop

    Joined:
    May 29, 2023
    Posts:
    2
    So, I have this weird bug that I cannot solve, somewhere in the code I missed ";" and I cannot found where
    Assets\scripts\Movement.cs(29,53): error CS1002: ; expected
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Movement : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     Vector2 moveDirection;
    9.     [SerializeField] float moveSpeed;
    10.  
    11.     bool speedUp;
    12.     [SerializeField] float speedUpMultiplier;
    13.  
    14.  
    15.     void Start()
    16.     {
    17.        
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.    
    24.        
    25.      moveDirection.x = Input.GetAxisRaw("Horizontal");
    26.      moveDirection.y = Input.GetAxisRaw("Vertical");
    27.      speedUp = Input.GetButton("SpeedUp");        //create SpeedUp axis in input manager and bind it to L/R shift
    28.  
    29.      transform.position; Time.deltaTime * moveSpeed * (speedUp ? speedUpMultiplier : 1) * moveDirection.normalized;
    30.        
    31.  
    32.     }
    33. }
    34.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Well clearly something is wrong on line 29 as the error states. Indeed, looking at that line, it makes no sense. I mean just look at the first part of it:
    Code (CSharp):
    1. transform.position;
    What does this mean? You're just kind of shouting
    transform.position
    into the wind.

    Statements in C# must generally either be a function call or an assignment. e.g.:

    Code (CSharp):
    1. x = something;
    2. // OR
    3. SomeFunction();
    and what you have there is neither.
     
    matidevelop and angrypenguin like this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    That's not a bug. That's a typing mistake. You do not need us to fix your typing mistakes!!!

    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.

    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.
     
    matidevelop and angrypenguin like this.
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,145
    C# has a habit of incorrectly identifying missing or erroneous symbols as a missing semicolon, but it's typically able to find the correct line even if it gets the error wrong. In this case the first semicolon on line 29 is supposed to have been an equals sign.

    Before:
    Code (csharp):
    1. transform.position; Time.deltaTime * moveSpeed * (speedUp ? speedUpMultiplier : 1) * moveDirection.normalized;
    After:
    Code (csharp):
    1. transform.position = Time.deltaTime * moveSpeed * (speedUp ? speedUpMultiplier : 1) * moveDirection.normalized;
     
    matidevelop and angrypenguin like this.