Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

error CS1010: Newline in constant

Discussion in 'Scripting' started by Hfciwk73755kddwd, Apr 24, 2022.

  1. Hfciwk73755kddwd

    Hfciwk73755kddwd

    Joined:
    Jan 8, 2022
    Posts:
    3
    I'm desperate. I started programming and therefore watched a tutorial for a main menu. However, I get error messages every time and even though I've looked at my script 100 times, I can't find the errors:

    -Assets\Scrips\LoadPrefs.cs(42,61): error CS1010: Newline in constant
    -Assets\Scrips\LoadPrefs.cs(42,67): error CS1003: Syntax error, ',' expected
    -Assets\Scrips\LoadPrefs.cs(43,49): error CS1026: ) expected

    And here the code:



    I know that others had the same error and that there is a solution somewhere on the internet. However, it didn't work and I'm really desperate and just don't know what to do next
     

    Attached Files:

    Last edited: Apr 25, 2022
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,620
    It's just a typo. If you're following a tutorial then you need to follow it more carefully and exactly. The errors tell you the lines of your typo so all you have to do is look at the tutorial and check those lines or the lines in that area.

    Also, when posting code, please don't use plain-text, use code-tags and ensure the errors you have (which give you line/column numbers) match up to the lines in your editor. Just post the full script and they will.

    Without this, you're asking someone here to read through the unformatted plain-text and manually count the line numbers and even assume they are the same thing. You can edit your post above to include code-tags.
     
    Bunny83 likes this.
  3. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,596
    If you use a good IDE, errors like this will be extremely obvious, as it colors your syntax. Even if you just use the code-tags as MelvMay mentioned above, you can usually see clearly where you made an error, as it does the same coloring as an IDE would (supposing you use the left code-tag, not the right one).
     
    MelvMay likes this.
  4. Hfciwk73755kddwd

    Hfciwk73755kddwd

    Joined:
    Jan 8, 2022
    Posts:
    3
    Ohh.. I didn't know that the errors lines indicate where the problem is. I looked at the lines with the code again, but couldn't find any errors, especially since I don't know what the hell is wrong with line 42
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,620
    Or how to use code-tags as asked TBH. Nobody wants to download source files to look at a snippets of source where someone has a typo.

    What IDE are you using? Any IDE will show you the error as already stated above.

    Line 42:
    Code (CSharp):
    1.  volumeTextValue.text = localVolume.ToString("0.0);
    You cannot see that the string above that needs to be enclosed in double-quotes just like all the other strings you've specified in your code.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    Believe it or not, the compiler is your friend and is trying desperately to help you fix you typo.

    You need to learn how the compiler tells you things. Here's a handy guide:

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.
     
  7. Hfciwk73755kddwd

    Hfciwk73755kddwd

    Joined:
    Jan 8, 2022
    Posts:
    3
    Thanks to both of you :D