Search Unity

hello programers im quiet new and i have a problem its an cs1003 but i dont see a problem

Discussion in 'Scripting' started by kentaronareswara, Jan 25, 2021.

  1. kentaronareswara

    kentaronareswara

    Joined:
    Oct 6, 2020
    Posts:
    1
    Code (CSharp):
    1. ublic class movement : MonoBehavior
    2. {
    3.     public float moveSpeed 10f;
    4.     public float turnSpeed 50f;
    5.  
    6.  
    7.     // Update is called once per frame
    8.     void Update()
    9.     {
    10.         if (input.GetKey(KeyCode.UpArroww))
    11.             transform.translate(Vector3.forward * moveSpeed * Time.deltaTime);
    12.  
    13.         if (input.GetKey(KeyCode.DownArroww))
    14.             transform.translate(-Vector3.forward * moveSpeed * Time.deltaTime);
    15.  
    16.         if (input.GetKey(KeyCode.LeftArroww))
    17.             transform.translate(Vector3.forward * -TurnSpeed * Time.deltaTime);
    18.  
    19.         if (input.GetKey(KeyCode.RightArroww))
    20.             transform.translate(Vector3.forward * TurnSpeed * Time.deltaTime);
    21.  
    note =
    Assets\movement.cs(7,28): error CS1003: Syntax error, ',' expected
    Assets\movement.cs(8,28): error CS1003: Syntax error, ',' expected
    using 2019-4 12F1
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    And there seems to be the very first character 'p' missing in the very first line.
     
  3. mopthrow

    mopthrow

    Joined:
    May 8, 2020
    Posts:
    348
    Lots of spelling errors, gotta be careful with programming. It's gotta be exactly right.

    You missed the 'p off of 'public' on line 1.
    MonoBehaviour is miss-spelled on line 1. You forgot the u.
    Arrow should have a single w, not two on lines 10, 13, 16 and 19
    Input is a class, it should have a capitalised i. 10, 13, 16 and 19
    Translate is a function, should have capital first letter. 11, 14, 17 and 20
    You declared turnSpeed, but you reference TurnSpeed. Match that capitalisation.
    You forgot the equals signs for moveSpeed and turnSpeed when assigning them a value.
    You need to close the Update function's code block by adding a close curly brace } on line 23
    You need to close the class with a close curly brace at the end of the file.
    You need to add using UnityEngine at the top for MonoBehaviour to work.
    Your class name should capitalise the letter of every word (though it won't break if you don't)
    If you change your class name, make sure to change your file name to match.

    If you get an error, try to understand why and fix it before moving on, otherwise you'll end up with a pile of them like this if you're new :)
     
    Last edited: Jan 25, 2021
    Bunny83 likes this.
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,981
    You have to learn basic C# syntax. Also when you get an error, including the error code is generally useful but we are not machines. We don't work with numerical error codes. The C# compiler always gives you a written error message which should be the first thing you should quote and not the error code.

    Next thing is if you get a compiler error you have done something wrong. The compiler tells you the exact line and column where it thinks the error is. The error is generally at this exact location or before that location. The compiler does not know what you may have intended since the code does not follow the syntax rules. So the compiler / parser may suggest things that you actually don't want.

    When you post such issues here, please put some efford into solving the issue yourself and provide all the information you got. The compiler tells you the exact line and column numbers. You either should tell us which lines the compiler complains about or at least include the whole script from the very beginning. Otherwise the line numbers do not match. Just as we can see in your case here. The errors are in line 7 and 8. However in your posted code that's line number 3 and 4 because you did not copy all code. You just make our lives harder. You are the one who is looking for assistance, so make sure you put enough efford into your post.

    Finally lets get to your issue(s). Those two lines do not represent valid C# syntax:

    Code (CSharp):
    1.     public float moveSpeed 10f;
    2.     public float turnSpeed 50f;
    The compiler does not know what that means. It reads the code character by character from the beginning. So it recognises that you want to declare a public float variable with the name moveSpeed. However after the name of the variable there's suddenly an invalid character. Specificaiiy there's a "1". This makes no sense syntactically. After the name of a variable you could either declare another variable by seperating the different variable names with a comma, or you can initialize that variable to a value with an equal sign "=". As I said the compiler does not know what you want to do, so it tells you that he would expect a comma after the name. However in your case you most likely want to initialize the variable to the value 10f. So you don't need or should put a comma there but an equal sign.

    Code (CSharp):
    1.     public float moveSpeed = 10f;
    2.     public float turnSpeed = 50f;
    Apart from that we can immediately see a couple of other errors. Since you only copied a fragment of your script we don't know anything about the parts you did not copy. I guess the missing "p" at the very beginning is a copy & paste error and you just did not copy it. Though actual errors are:

    The method in the Transform class is called "Translate" and not "translate". Likewise you named your variable "turnSpeed" when you declared it, however in your code you used "TurnSpeed". C# is, like most programming languages, case sensitive. So the casing of any identifer has to match exactly. When you use a proper IDE like VisualStudio it should help you with those issues as the IDE will suggest the variable, method and class names it already knows about. So do yourself a favor and use it ^^.

    edit
    Ahh, I missed a couple of other mistakes. Though those are all mistakes I would never expect. You almost never need to write "MonoBehaviour" yourself as it's usually already part of the template. So if you rewrite everything from scratch you just makes it more complicated for yourself. Same thing with the KeyCode enum values. Intellisense of VS should have autocompleted the names. As I said above, not using a proper IDE is just a waste of time.
     
    mopthrow likes this.