Search Unity

error CS1513: } expected

Discussion in 'Scripting' started by Fawful10, Jun 7, 2019.

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

    Fawful10

    Joined:
    Aug 6, 2017
    Posts:
    5
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Paddle : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.        
    11.     }
    12.  
    13.     public void Init(bool isRightPaddle) {
    14.  
    15.         Vector2 pos = Vector2.zero;
    16.         if (isRightPaddle)
    17.         {
    18.             pos = new Vector2(GameManager.topRight.x, 0);
    19.             pos -= Vector2.right * transform.localScale.X;
    20.         }
    21.         else
    22.         {
    23.             pos = new Vector2(GameManager.bottomLeft.x, 0);
    24.             pos += Vector2.right * transform.localScale.X;
    25.         }
    26.         transform.position = pos;
    27.         //place paddle on the right
    28.  
    29.  
    30.         // Update is called once per frame
    31.         void Update()
    32.     {
    33.        
    34.     }
    35.  
    36. }
    37.  
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    put a } on line 28
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Stop enabling this kind of lazy behavior.
    OP, you could have easily seen what's wrong, you even see that it says " } expected".
    what angers me most is the fact you didn't even say nothing, error message on title and only code in post (atleast you used the tags)
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Your code editor will point out these errors. VS for example will have put a red squiggly mark near the error. When possible, such as this instance, the error will even tell you exactly what to fix.

    Frankly, you should be able to fix these kinds of errors on your own. This isn't a Unity issue. It is a first 5 minutes of any C# book or tutorial issue. If you can't you should stop with Unity for now, and focus on the fundamentals of C#, and come back to Unity at the appropriate time.
     
    elcionap, TaleOf4Gamers and SparrowGS like this.
  6. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
    I wasn't going to respond to this further, but what the hell? Who do you think you are talking to me like that and singling this thread out for special treatment? (This is a rhetorical question).

    I've seen quite literally dozens of posts like this over the years that receive similar responses to that which I gave.

    At least my post addressed the problem, whereas yours isn't likely to do anything except to piss me off!
     
    davidnibi likes this.
  7. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    I dunno why you got offended, I took your previous reply as a joke rather then you being actually insulted.

    I've seen a lot of posts from both sides of the table, people asking nicely about something they genuinely don't understand and people (including me) replying with an explanation, and people like here, where they copy past something from a tutorial and just go "hey unity forums! fix whatevers wrong here for me so it works like I want it to!" and people (again, including me) Gordon-Ramsaying them.

    I still think my post actually addresses the problem here, I didn't mean to piss you off and I don't really understand why you're so offended by this, it wasn't personal towards you, it was for everyone answering this kind of questions.
    Take it easy dude.
     
  8. Deleted User

    Deleted User

    Guest

    Understandable but @SparrowsNest (as well as @Joe-Censored) has a point. Too many people do not do their homework before asking for help. This behaviour tires the community and people who could help end up giving up.
     
    SparrowGS likes this.
  9. alexb2008

    alexb2008

    Joined:
    Mar 16, 2022
    Posts:
    34
    This is just so I am not ignored (as this is a year old forum)
    @Munchy2007
    @Joe-Censored

    Yeah I am having the same problem... but with SparrowGS roaming this forum, I'm not sure if I even want to ask! i am new to C# and have loked through this dam piece of code for the error many times.

    # STARTS #

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class DialogueManager : MonoBehaviour
    7. {
    8.     public NPC npc;
    9.    
    10.     bool isTalking = false;
    11.  
    12.     float distance;
    13.     float currentResponseTracker = 0;
    14.  
    15.     public GameObject player;
    16.     public GameObject dialogueUI;
    17.  
    18.     public Text npcName;
    19.     public Text npcDialogueBox;
    20.     public Text playerResponse;
    21.  
    22.     // Start is called before the first frame update
    23.     void Start()
    24.     {
    25.         dialogueUI.SetActive(false);
    26.     }
    27.  
    28.     void OnMouseOver()
    29.     {
    30.         distance = Vector3.Distance(player.transform.position, this.transform.position);
    31.         if(distance <= 2.5f)
    32.         {
    33.             if(Input.GetAxis("MouseScrollWheel") < 0f)
    34.             {
    35.                 curResponseTracker++;
    36.                 if(curResponseTracker >= npc.playerDialogue.Length - 1)
    37.                 {
    38.                     curResponseTracker = npc.playerDialogue.Length -1;
    39.                 }
    40.             }
    41.             else if(Input.GetAxis("MouseScrollWheel") > 0f)
    42.             {
    43.                 curResponseTracker--;
    44.                 if(curResponseTracker <0)
    45.                 {
    46.                     curResponesTracker = 0;
    47.                 }
    48.             }
    49.  
    50.             if(Input.GetKeyDown(KeyCode.E) && isTalking == false)
    51.             {
    52.                 StartConversation();
    53.             }
    54.             else if(Input.GetKeyDown(KeyCode.E) && isTalking == true)
    55.             {
    56.                 EndDialogue();
    57.             }
    58.  
    59.             if(curResponesTracker == 0 && npc.playerDialogue.Length >= 0)
    60.             {
    61.                 playerResponse.text = npc.playerDialogue[0];
    62.                 if(Input.GetKeyDown(KeyCode.Return))
    63.                 {
    64.                     npcDialogueBox.text = npc.dialogue[1];
    65.                 }
    66.             }
    67.             else if(curResponesTracker == 1 && npc.playerDialogue.Length >= 1);
    68.             {
    69.                 playerResponse.text = npc.playerDialogue[1];
    70.                 if(Input.GetKeyDown(KeyCode.Return))
    71.                 {
    72.                     npcDialogueBox.text = npc.dialogue[2];
    73.                 }
    74.             }
    75.             else if(curResponesTracker == 1 && npc.playerDialogue.Length >= 2);
    76.             {
    77.                 playerResponse.text = npc.playerDialogue[2];
    78.                 if(Input.GetKeyDown(KeyCode.Return))
    79.                 {
    80.                     npcDialogueBox.text = npc.dialogue[3];
    81.                 }
    82.             }
    83.         }
    84.     }
    85.    
    86.     void StartConversation()
    87.     {
    88.         isTalking = true;
    89.         currentResponseTracker = 0;
    90.         dialogueUI.SetActive(true);
    91.         npcName.text = npc.name;
    92.         npcDialogueBox.text = npc.dialogue[0];
    93.     }
    94.  
    95.     void EndDialogue()
    96.     {
    97.         isTalking = false;
    98.         dialogueUI.SetActive(false);
    99.     }
    100. }
    # ENDS #

    It says:

    Assets\DialogueManager.cs(74,14): error CS1513: } expected

    No clue why. I have removed the } then i get the same message for line 100. then the same for line 99. one about there being no end to the loop for line 98... It makes no sense what it wants me to do. it feels like im being stupid but I erally do not know! if anyone is still on this forum, please let me know where I am missing something.
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    Please don't necro-post to old threads just to have others find your typing mistakes.

    For one, it's against forum rules, and for two, this is just a fatfinger typo.

    In your case you have at least TWO places you have added semicolons that should not be present.

    This is causing the actual error you report.

    You may even have other errors.

    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.

    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.
     
  11. alexb2008

    alexb2008

    Joined:
    Mar 16, 2022
    Posts:
    34
    if you are going to diss me, at least let me know where I have gone wrong. as I said, I am new to this! I started last Saturday! And this is my first time on this website. don't need to be rude. Explain things first because being a bit of a, won't help.
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    If you don't necro threads then you're more likely to get help and just starting isn't a good reason to necro.

    So this is just a typo. Look at the incorrect semi-colon you've put on line 67 and line 75. Kurt already told you this even if he didn't give you the specific lines. All you have to do is look though. ;)
     
  13. alexb2008

    alexb2008

    Joined:
    Mar 16, 2022
    Posts:
    34
    New to all this so not too sure how to make new threads and stuff! will look into it. And thanks.
     
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    No problem. Good luck with your new journey.
     
Thread Status:
Not open for further replies.