Search Unity

what does this error mean CS1003

Discussion in 'Scripting' started by kancelarija12, Sep 17, 2019.

Thread Status:
Not open for further replies.
  1. kancelarija12

    kancelarija12

    Joined:
    Sep 17, 2019
    Posts:
    15
    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;

    }
    }

    }
    }
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    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.
     
    Ryiah and kancelarija12 like this.
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    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.
     
    Ryiah likes this.
  4. kancelarija12

    kancelarija12

    Joined:
    Sep 17, 2019
    Posts:
    15
    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.
     
    carlitos272010 likes this.
  5. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    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
     
    Ryiah likes this.
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    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.
     
    Ryiah and kancelarija12 like this.
  7. kancelarija12

    kancelarija12

    Joined:
    Sep 17, 2019
    Posts:
    15
    what is a coroutine?
     
    faithfulolushkin likes this.
  8. kancelarija12

    kancelarija12

    Joined:
    Sep 17, 2019
    Posts:
    15
    Assets\Jump.cs(5,34): error CS1003: Syntax error, ',' expected
    whoops sorry i thought it was a dot
     
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
  10. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    I see lots of issues:

    Code (csharp):
    1. public class Jump : MonoBehaviour;
    No need for that ;

    Code (csharp):
    1.  
    2.     void Start()
    3.     {
    4.         bool jump = false;
    5.     }
    6.  
    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:

    Code (csharp):
    1. if (jump == false)
    'jump' is not in scope here.

    Code (csharp):
    1. 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<Rigidbody>()' if you expect the Rigidbody attached to the same GameObject as this script.

    Code (csharp):
    1. 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:

    Code (csharp):
    1. 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.
     
    Last edited: Sep 17, 2019
    Bunny83 and Ryiah like this.
  11. kancelarija12

    kancelarija12

    Joined:
    Sep 17, 2019
    Posts:
    15
    that is the only error i get idk why the other ones dont appear
     
  12. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    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;


    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.
     
    Ryiah likes this.
  13. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    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.
     
    Ryiah likes this.
  14. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    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!
     
    Ryiah and StarManta like this.
  15. sardarovgabriell

    sardarovgabriell

    Joined:
    Apr 11, 2020
    Posts:
    6
    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;
    }
     
  16. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    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:
    Code (CSharp):
    1. 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 {}:
    Code (CSharp):
    1. // Update is called once per frame
    2. 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:
    Code (CSharp):
    1. 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.
     
  17. sardarovgabriell

    sardarovgabriell

    Joined:
    Apr 11, 2020
    Posts:
    6
    thank you really much,i will do it now
     
  18. sardarovgabriell

    sardarovgabriell

    Joined:
    Apr 11, 2020
    Posts:
    6
    i have a question,i really like learning game dev-ing .but can you recommend me more people on youtube for learning game dev?
     
  19. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    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.
     
    sardarovgabriell likes this.
  20. jakeman300012

    jakeman300012

    Joined:
    Sep 19, 2020
    Posts:
    2
    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);

    }
    }
    }
     
  21. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Did you read any of the answers? Useful replies for now include:
    • Use code tags
    • Post the full error message
    • There should be no semicolon after Monobehavior
    If you had the time to ask a question in the correct thread, you could have at least read the first 4 replies, which may have completely removed the need to ask a question.
     
  22. jakeman300012

    jakeman300012

    Joined:
    Sep 19, 2020
    Posts:
    2
    Ok thank you
     
Thread Status:
Not open for further replies.