Error CS 1002: ; expected

Hi! I’m stuck. My code is really short and im missing that > “;” symbol.

Hi Pius,

Welcome to our community! :slight_smile:

The error messages usually tell you what the problem is. Sometimes, they are misleading, though. Please double click on the error message. To which line in your code does it refer? Is there a semicolon missing in that line or another line? Also make sure that all methods are declared within the code block of the class. A code block is defined by { code block }.

Remember you can also look at the lecture code changes via the link in the Resources of each lecture.


See also:

Everything is rewrited 1:1 with lecture. I did it 3 times so far :frowning:

I cannot see any problem in your screenshot but code on screenshot is almost as hard to read as in videos. For this reason, it is better to share it as formatted text.


See also:

1 Like
using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Movement : MonoBehaviour

{

    // Start is called before the first frame update

    void Start()

    {

       

    }

    // Update is called once per frame

    void Update()

    {

        ProcessTrust();

    }

    void ProcessTrust()

    {

        if (Input.GetKey(KeyCode.SPACE))

        {

            Debug.Log("Pressed SPACE - Thrusthing");

        }

        if (Input.GetKey(KeyCode.A))

        {

            Debug.Log("Pressed A - Rotate LEFT");

        }

        if (Input.GetKey(KeyCode.D))

        {

            Debug.Log("Pressed D - Rotate RIGHT");

        }

    }

}

Very odd. There does not seem to be any problem in your code.

You saved your script, didn’t you? If so, have you already tried to restart Unity and Visual Studio Code?

If so, Please go to Edit > Preferences > External Tools (in Unity) and click ‘Regenerate project files’.

Did this work?

If not, rename your class and your script. Save your script. Then go to Unity and test your game again. If it works, and if you don’t see that error message anymore, rename your class and script to Movement again. In rare cases, Unity has got internal problems.

Sadly it didn’t but accidently i changed “SPACE” into single “E”

And it works, i dont know why.

Thank you for your time!

The KeyCodes are case sensitive, the code for the space key is “Space” rather than “SPACE”

2 Likes

Good job on modifying your code to test something. Sometimes, the mistake is so obvious, that it is easy to miss.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms