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. Dismiss Notice

Bug I'm new to Unity and have been struggling with a Syntax error for the past 5 hours

Discussion in 'Scripting' started by wasted_peonies, Aug 23, 2023.

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

    wasted_peonies

    Joined:
    Aug 23, 2023
    Posts:
    7
    Hey, sorry for the long intro but I'm pretty new to Unity and I've been dealing with this error coming up

    Assets\Impossible Odds\Toolkit\Runtime\Core\ReflectionCaching\ReclectionCachingException.cs(7,49): error CS1003: Syntax error, ',' expected

    I've been trying to fix it and I've been looking through every thread but nothing is working

    This is the full code:

    using UnityEngine;
    using System.Collections;

    namespace ImpossibleOdds.ReflectionCachingExeption

    {
    public class ReflectionCaching : ImpossibleOdds;
    {
    public ReflectionCaching()
    { }

    public ReflectionCaching(string errMsg) : base(errMsg)
    { }

    public ReflectionCaching(string errMsg, params object[] format) : base(errMsg, format)
    { }
    }
    }
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    Welcome.

    I guess you mean you're new to C#? So you know, C# isn't exclusive to Unity and there are thousands of places at your fingertips that detail the language syntax.

    The compiler error (not a "Bug" as tagged) is saying that on Line 7, Column 48 it expected a comma so you made a mistake there or somewhere before it.

    You've put a ";" at the end of the class definition i.e. "public class ReflectionCaching : ImpossibleOdds;" which is wrong.

    If you search online on how to define a class in C#, you'd not need to spend 5 hours at it. :)

    I searched "C# class" and the following site is one of many that came up:
    https://www.w3schools.com/cs/cs_classes.php
    https://www.w3schools.com/cs/cs_inheritance.php

    The forums do assume a basic working knowledge of C# TBH.
     
  3. wasted_peonies

    wasted_peonies

    Joined:
    Aug 23, 2023
    Posts:
    7
    Hello, thank you for the links but even though I checked them, it didn't work, I'm still trying and looking around but nothing is working.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    You checked the link "and it didn't work"? I told you what the problem was above.

    Please read what I wrote again.
     
  5. wasted_peonies

    wasted_peonies

    Joined:
    Aug 23, 2023
    Posts:
    7
    Yes I read it many times, I checked every place where the comma could be, and before it. Also reading through the links and checking if they would help in the code (i did change the names in them so it wouldn't be the example given) but it still isn't working.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    I'll repeat, you've put a ";" at the end of the class definition i.e. "public class ReflectionCaching : ImpossibleOdds;" which is wrong.

    If you don't understand the above then I don't know what to say so here it is explicitly typed for you:

    Incorrect.
    Code (CSharp):
    1. public class ReflectionCaching : ImpossibleOdds;
    Correct.
    Code (CSharp):
    1. public class ReflectionCaching : ImpossibleOdds
     
    Yoreki likes this.
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    ^ ^ ^ ^ ^ I have no idea what the above is but it cannot possibly be beginner material.

    Reflection and Caching and Exceptions are all EXTREMELY advanced topics.

    You should be doing stuff like Flappy Birds for your first 10 or 20 game projects, not something involving reflection and caching!!!

    Imphenzia: How Did I Learn To Make Games:



    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!


    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

    Finally, when you have errors, don't post here... just go fix your errors! Here's how:
     
    Yoreki likes this.
  8. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    431
  9. TheNullReference

    TheNullReference

    Joined:
    Nov 30, 2018
    Posts:
    222
    You might need to send a screenshot of the code at this point. I'm very curious what the issue could be.
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Sometimes compile errors are directly useful and tell you exactly what you need to do. Sometimes, especially with syntax errors, the compiler is so far from making sense of what you're trying to do that it can't suggest the actual correction. This is an example of the latter.

    You are not missing a comma. There are ways in which inserting a comma (and some other things) could fix it, but us other coders (as humans with brains) can tell that that is not your intention. The compiler doesn't have a brain, it can't work that out, so it gives you the first thing in its list of things it might expect to be there.

    The actual problem is a semicolon that shouldn't be there. It seems like you skimmed the replies for links to read but didn't read the actual comments themselves, because this was in the first reply and you never mention trying it:
     
  11. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    :eek: SWEET MOTHERBOARD OF SILICON!!!

    I think you are confused on how classes work and for some reason think:
    Code (CSharp):
    1. namespace ImpossibleOdds.ReflectionCachingExeption { }
    Is somehow a class... which it's not by the way...

    A class looks like this:
    Code (CSharp):
    1. public class ReflectionCaching : ImpossibleOdds { }
    IF in fact your class of
    ReflectionCaching.cs
    is supposed to Inherit from the
    ImpossibleOdds.cs
    ?

    So why you type it as:
    Code (CSharp):
    1. namespace ImpossibleOdds.ReflectionCachingExeption
    2. {
    3.    public class ReflectionCaching : ImpossibleOdds ; { }
    4. }
    Is beyond me, the compiler, and anyone else who looked into this post.. Actually a squirrel looked into my window just now and he dropped his nut...
     
  12. wasted_peonies

    wasted_peonies

    Joined:
    Aug 23, 2023
    Posts:
    7
    Yes I know. I DID that one as well. I STILL get the message
     
  13. wasted_peonies

    wasted_peonies

    Joined:
    Aug 23, 2023
    Posts:
    7
    Thing is I didn't write this at all. I opened a new project and imported assets I had. And When this error popped up I tried locating the script to delete it since it wasn't mine but it doesn't even show up. Therefore I'm forced to find the error and try to fix it
     
  14. wasted_peonies

    wasted_peonies

    Joined:
    Aug 23, 2023
    Posts:
    7
    I did remove that because It didn't work. I tried to see what effect it would have because of a Workshop I had taken for unity. I remember sth my professor told me there and just tried it out but it didn't work. I have removed it and have very carefully read the messages. I just can't solve it.
     
  15. wasted_peonies

    wasted_peonies

    Joined:
    Aug 23, 2023
    Posts:
    7
    This is the ONLY error I haven't resolved yet
     

    Attached Files:

  16. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,082
    You've declared ImpossibleOdds as a namespace but you're trying to inherit from it. You can't do both.
     
    SisusCo likes this.
  17. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    By my reading, so far absolutely NOTHING in this thread has been related to C# under Unity3D.

    There's nothing in here that relates in anyway to the UnityEngine and UnityEditor namespaces.

    Are you even sure you are even posting in the right forum here??

    I mean you're always welcome to be here of course, but it's a little bit like you brought your car into the supermarket to see if they could fix it.

    How about: what are you TRYING to do. Use this template and everybody here will save a LOT of wasted spinning time, now that we're up to 17 responses.

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, log output, variable values, and especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

    The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven't put effort into finding the documentation, why should we bother putting effort into replying?



    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    - Do not TALK about code without posting it.
    - Do NOT post unformatted code.
    - Do NOT retype code. Use copy/paste properly using code tags.
    - Do NOT post screenshots of code.
    - Do NOT post photographs of code.
    - ONLY post the relevant code, and then refer to it in your discussion.
     
    Yoreki and wideeyenow_unity like this.
  18. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    As you can see, you don't get the same messge, you get another one as described above.
     
    Yoreki likes this.
  19. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,588
    • Please use code tags so we have syntax highlighting and line numbers
    • Please use a .. viable.. IDE so YOU have syntax highlighting and line numbers
    • As others said: You fixed the original error. Now you get a different one.
    • As others said: ImpossibleOdds is not a type. You can not inherit from it.
    • You are clearly a beginner. Whatever you do is not a beginner topic. WHY are you doing this?
    TL;DR: Stop torturing yourself. Set up an environment in which you can work properly, pay attention to what people actually tell you, and work on a topic appropriate to your skill level to build experience. What you are doing now is not helping you in any way, shape or form.
     
    Ryiah, Bunny83 and Kurt-Dekker like this.
  20. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,955
    Closing.
    You need to go through some beginning tutorials for C#. This forum is not for that. You cannot build a game without learning the basics, and expect to others to hold your hand through very basic typos and structure.
    There are links above that have been posted to start your journey.
     
    Ryiah and Bunny83 like this.
Thread Status:
Not open for further replies.