what does this error mean CS1003

So this is my script and i get 1 CS1003 error and dont know what it means:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Jump : MonoBehaviour;
{
// Start is called before the first frame update
void Start()
{
bool jump = false;
}

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (jump == false)
{
Rigidbody.AddForce(transform.up * 200);
jump = true;
WaitForSeconds(0x5);
jump = false;

}
}

}
}

Hi and welcome.
It would help if you posted the error message, but i’d assume that the problem is that you are trying to use WaitForSeconds on the main thread. Also, while your code is properly formatted, we have code tags you can use to add syntax highlighting. It’s the first sticky on this subforum.

2 Likes

Copy and paste the actual error. We don’t have error codes memorized, plus the error will include more information like line numbers that will help us narrow it down quickly and easily.

But yeah, WaitForSeconds doesn’t work like that. It has to be in a coroutine.

1 Like

Thanks but would you mind explaining what is a main thread and how to avoid this error?
The error message is Assets/Jump.cs(5.34): error CS1003: syntax error . expected.

1 Like

You have a number of errors there.

  • There shouldn’t be a ; after MonoBehaviour
  • Your jump bool is declared within the start method so isn’t available in the update method
  • WaitForSeconds can only be used in a coroutine
1 Like

Oh, there shouldn’t be a semicolon after MonoBehaviour.

And when we say copy and paste, we literally mean copy and paste. You can select the error and just ctrl-C to copy. Don’t try and retype it, as that will introduce random little mistakes. Like, you typed a period in the quotes, when (looking at your code) it should be a semicolon.

2 Likes

what is a coroutine?

1 Like

Assets\Jump.cs(5,34): error CS1003: Syntax error, ‘,’ expected
whoops sorry i thought it was a dot

2 Likes

I see lots of issues:

public class Jump : MonoBehaviour;

No need for that ;

    void Start()
    {
        bool jump = false;
    }

You’ve declared ‘jump’ inside of Start. This should be at class level, not inside the method ‘Start’, if you expect to access it elsewhere in the class. Like here:

if (jump == false)

‘jump’ is not in scope here.

Rigidbody.AddForce(transform.up * 200);

Rigidbody is a class name, AddForce is an instance method… WHICH Rigidbody to you expect to be accessing? You need a reference to it… maybe ‘this.GetComponent()’ if you expect the Rigidbody attached to the same GameObject as this script.

WaitForSeconds(0x5);
  1. WaitForSeconds is a class for a coroutine yield instruction. You usually say “yield return new WaitForSeconds(5f);” if you expect to wait 5 seconds.

  2. Furthermore this is being done in Update, and not a Coroutine, so it’s not going to work correctly.

  3. And why are you using the hex prefix? I mean 5 and 0x5 are technically the same since the value is < 16. But Like say you said 0x10, that’s not the same as 10.

And lastly, you’re also setting unscope 'jump’s again before and after this WaitForSeconds.

…

As for the CS1003 error you’re getting. It honestly has nothing to do with anything at this point. Your code has so many syntax errors that the compiler is likely just confused by the ; after the MonoBehaviour that it can’t make heads or tails and is just throwing an expectation error…

Likely it’s saying ‘,’ (comma) since if you follow a inheritance declaration with anything, you generally separate them with commas. Like so:

public class SomeClass : SomeParentClass, IDisposable, IEnumerable

this is me generically implementing multiple interfaces.

But that’s not your problem… you just inadvertently put a ‘;’ in there. As well as other mistakes.

2 Likes

that is the only error i get idk why the other ones dont appear

You seem to be new, so dont worry if this goes a bit over your head for now. A thread is a basically a process, but not quite. The cpu can run one thread per logical cpu core. A programm by default always only runs on one thread, thus called the main thread. On that thread, all the code in your programm is executed sequentially.
However, one programm can make use of multiple threads and thus multiple cpu cores, in order to parallelize the wordload. But that’s where programming gets complicated, and you dont really have to worry about it now.
A Coroutine is similar, but it does not parallelize work, instead it makes use of concurrency by running a second workload on the same thread. For example, if you want to execute something and then wait 5 seconds and then execute something again and so on, then you could use a Coroutine for that. In a Coroutine you can then use “WaitForSeconds” to make it wait. While the Coroutine is waiting, the other workload (the “normal” main thread code) will be executed, until the Coroutine wakes up again and so on.

I just thought i’d explain it, but again, you dont really have to deal with this topic until way later, potentially never depending on the kind of programs you write. It is not related to your problem, as you dont have to create another thread or a coroutine, or even call WaitForSeconds, in order to make something jump.

As for your actual problem i suggest you watch some tutorials on basic movement and jumping, to get an idea for how it’s done. There are plenty of such tutorials, i’ll just link one;

https://www.youtube.com/watch?v=QGDeafTx5ug

Also

sometimes some errors only appear after fixing others, since the compiler doesnt bother to compile the entire program if it cant make sense of the start already.

1 Like

When you fix one, others will show up. Right now the compiler basically just sees the first one and then can’t make sense of the file at all, and so doesn’t know that they’re issues.

1 Like

see:

When your syntax errors are in the realm where the compiler can’t make sense of anything following it, there’s not a whole lot it can do. You ended a class declaration with a ‘;’, it doesn’t know what anything following that would be. It doesn’t know you continue on declaring a class.

It’d be like if I just randomly started speaking boom tangle nut bag squeezy nuggets with a chirp chirp fully norte gimp bugket, chip, whoseit?!..

…

Sure, I have spelling mistakes in there, and grammatical misuse of commas and questions marks. But I mean… how can you tell me that? What if I meant to say ‘norte’ and ‘bugket’? It’s all nonsense anyways!

2 Likes

I have this problem too heres my code,pls help

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
private readonly Debug.Log input.AxisRawHorizontal;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update();

private Debug.Log GetInput.AxisRawHorizontal() => input.AxisRawHorizontal;
}

There is plenty wrong with your code. You should really start at the very, very beginning of learning to code.

First of all, you define a variable:

private readonly Debug.Log input.AxisRawHorizontal;

This does nothing. Debug.Log is not a returntype. Log() is a function of the Debug type. You also tried to name your variable input.AxisRawHorizontal, which is first of all not a valid name, and secondly i believe you didnt even intend to use it as a name but instead … print its value or something along those lines.

You then removed the body of your update function by adding a semicolon and removing the {}:

// Update is called once per frame
void Update();

This means, ‘Update()’ literally executes no code. I’m not even sure if this compiles for non abstract methods either.

Last but not least, you wrote:

private Debug.Log GetInput.AxisRawHorizontal() => input.AxisRawHorizontal;

Which i assume is supposed to be a method declaration, but then again, Debug.Log is not a type, and GetInput.AxisRawHorizontal is not a valid name, not to mention that the rest of the method declaration is also incorrect.

Coming back to my first statement, i’d really recommend you to start learning coding at the very bottom. There are a few good tutorials to help you. I would recommend you looking into the youtube tutorial series on C# + Unity by Sebastian Lague.

thank you really much,i will do it now

i have a question,i really like learning game dev-ing .but can you recommend me more people on youtube for learning game dev?

Not really. Brackeys and a couple others are rather popular, but mostly for beginner topics imho. I personally like Sebastian Lague since he cuts into a lot of really interresting topics and breaks them down in an interrestingly educational and entertaining way. For getting started i dont think you need more than his series on gamedevelopment. If you ever feel like you need to learn more about a topic, google that specifically and learn about it. After you went through that series, or any other, you’ll need to properly start ‘learning by doing’ anyways, where you set yourself incremental goals you try to solve / develop, and as such improve your skills. One advantage of the series i recommended is that he already offers little projects (fit for your skill level according to that tutorial series) while teaching you.

1 Like

Can you guys help me I am getting error code 1003; expected my code is:
using UnityEngine;
public class playermovment : MonoBehaviour;
{
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
// Update is called once per frame
void FixedUpdate()
{
rb.AddForce(0, 0, 500 * Time.deltaTime);

if( Input.GetKey(“d”) )
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if( Input.GetKey(“a”) )
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);

}
}
}