🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Where Is The Error Here?

Started by
2 comments, last by thecapl 3 years ago

Ok so to start off I'm not sure if I'm in the right forum or not but here is my question. I am following this tutorial on making pong in 6 minuets and I'm stuck on a few things. First when I tried to make player 2 work, player 2 would not move so I moved on to the next part thinking I could just make it one player. So then I moved on to making the ball move. I copied all the code he wrote went over it several times and kept getting this error message.( [21:01:26] Assets\ball.cs(26,56): error CS1002: ; expected ). I do not know what it means and I can not find where the error is located at. I would like to know how to understand the message and figure out how to fix it and below is my code.

____________________________________________________________________________________________________________________________

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class ball : MonoBehaviour

{

public float speed;

public Rigidbody2D rb;

// Start is called before the first frame update

void Start()

{

Launch();

}

// Update is called once per frame

void Update()

{

}

private void Launch()

{

float x = Random.Range(0, 2) == 0 ? -1 : 1;

float y = Random.Range(0, 2) == 0 ? -1 : 1;

rb.velocity = new Vector2(speed * x, speed * y)

}

}

____________________________________________________________________________________________________________________________

Advertisement

thecapl said:
… kept getting this error message.( [21:01:26] Assets\ball.cs(26,56): error CS1002: ; expected ). I do not know what it means and I can not find where the error is located at. I would like to know how to understand the message and figure out how to fix it and below is my code.

It literally means what it says. The computer expects a semi-solon at some point (I guess “(26,56)” are line and column numbers), and you didn't give a semi-colon.

The thing to watch out for here is that errors get line and column numbers at the spot where lack of the the semi-solon is detected. That may or may not be the spot where you forgot to add it. Often the code line before is also a good suspect to check in these cases. In more complicated cases, the culprit may be somewhere else entirely.

In this case “rb.velocity = new Vector2(speed * x, speed * y)” doesn't seem to have a semi-solon at the end, maybe that's the culprit.

I know it's tempting to copy code and get it to run. However by skipping the basic tutorial and writing simpler code by yourself by typing it first, you don't quite understand what things mean nor do you know common patterns like always end a statement with a semi-colon. That makes trying to get code run much harder.

I'd suggest you start reading and experimenting with a C# tutorial for a while, and by all means do try things that are not in the book. Exercise your brain to think in this language by working with your own code. You'll find things get much simpler in finding errors like the above.

thank you and I don't usually copy code but when I was following this tutorial I wanted to make it exact so thank you for the help!

This topic is closed to new replies.

Advertisement