Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Following tutorial and gettings errors the tut is not. Help?

Discussion in 'Scripting' started by danielquasar, Jan 8, 2023.

  1. danielquasar

    danielquasar

    Joined:
    Nov 4, 2022
    Posts:
    4
    I've been following this tutorial to learn the basics of making a CCG in Unity:


    Just trying to learn some fundamentals from it so I can apply them to my own game, at least start somewhere. Anyway, I am on video 3 (the one linked) and when I try to attach the CardDatabase script like he does at the top of the video, I get 5 errors and a popup preventing me from attaching it to the object. Below is my code and the 5 errors.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CardDatabase : MonoBehaviour
    6. {
    7.     public static List<Card> cardList + new List<Card>();
    8.  
    9.  
    10.     void Awake()
    11.     {
    12.        
    13.         cardList.Add(new Card(0, "None", 0, 0, "None"));
    14.         cardList.Add(new Card(1, "Human", 2, 1, "This is a human"));
    15.         cardList.Add(new Card(2, "Elf", 3, 3, "This is a elf"));
    16.         cardList.Add(new Card(3, "Dwarf", 4, 4, "This is a dwarf"));
    17.         cardList.Add(new Card(4, "Troll", 5, 5, "This is a troll"));
    18.  
    19.  
    20.  
    21.  
    22.     }
    23. }
    24.  
    ERRORS
    • Assets\Scripts\CardDatabase.cs(7,39): error CS1003: Syntax error, ',' expected
    • Assets\Scripts\CardDatabase.cs(7,41): error CS1002: ; expected
    • Assets\Scripts\CardDatabase.cs(7,55): error CS1519: Invalid token '(' in class, record, struct, or interface member declaration
    • Assets\Scripts\CardDatabase.cs(7,56): error CS8124: Tuple must contain at least two elements.
    • Assets\Scripts\CardDatabase.cs(7,57): error CS1519: Invalid token ';' in class, record, struct, or interface member declaration

    They all pertain to line 7.

    Code (CSharp):
    1. public static List<Card> cardList + new List<Card>();
    I am not knowledgeable enough to know how to fix these properly, and since the tutorial doesn't have these errors, I don't know how he would fix them. Any advice, solutions, whatever, would be helpful so I can move forward. I want to know what is wrong here and how to fix it cause I'm more than baffled. :(
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    If you're following a tutorial then you need to follow it more closely. If this is code you've typed that's not in the forum then you need to follow a basic C# tutorial first.

    Code (CSharp):
    1. public static List<Card> cardList + new List<Card>();
    This shows that you should not be following complex tutorials but instead be following a basic C# tutorial. The "+" should be an assignment "=". Typically they are on the same key on the keyboard so I get a sense that this is a typo following a tutorial.

    Again, you need to follow the tutorial and be 100% accurate if you don't know what you're doing at all.
     
  3. danielquasar

    danielquasar

    Joined:
    Nov 4, 2022
    Posts:
    4
    Thanks for pointing out that it was a typo. I didn't realize I had done that. A simple mistake and I can move forward now. That particular key has been an issue for me before and a habit I'm still trying to break. Haha

    Not new to programming but new ish to Unity and C#. This is how I learn, by doing something that holds my interest. I actually am also working on fundamentals but I wanted to work on something a bit more engaging as well. So I figured a simple card game might be worth it, and the tutorial seems to be well received. ¯\_(ツ)_/¯ I figured, why not.

    I will say, your tone is somewhat condescending. You might not have meant it that way, tone is difficult with text I know, but it came across that way. I'd suggest wording your replies in ways that won't give off the wrong vibe. :) It would certainly help me feel more welcome to reach out again if I need to.

    Thanks again! Appreciate it.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    This sounds like you might be focusing on the wrong thing. This is engineering and the compiler and computer are RELENTLESSLY INDIFFERENT to emotions and condescension. You have made some minor typing errors and you need to fix them and that is where the story ends.

    I urge you to dissociate yourself from any feelings about reading technical guidance documentation because it WILL NOT HELP YOU LEARN.

    It doesn't sound like you're doing it properly. If you are not, you may be completely wasting your time, so make sure to get your "tutorial following" strategy on track. It's easy, it's only two steps:

    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:

    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.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    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.

    Best of luck in your gamedev journeys!
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    You received it as condescending but it was not written to be condecending. Everything I wrote above is good advice. I have no idea of your actual skill level and have no way to know it. We have hundreds of posts each day for general typos, responding to indicate you should follow a basic C# tutorial is good advice for most.

    Sorry if you felt it wasn't appropriate in your case.

    Note that there is a Getting Started forum you might find useful too.
     
    Kurt-Dekker likes this.
  6. danielquasar

    danielquasar

    Joined:
    Nov 4, 2022
    Posts:
    4
    Thanks to the both of you. As Kurt suggested, I will not bring my issues or questions to the forum. You're right, it's best to follow the error description and if I get stuck there, Google the error for assistance.

    Should Google bring up the forum like it did this time, I'll know it best not to post here. My apologies for wasting time.
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    I am a moderator here so I can see that you have reported me and I'm not sure I understand why.

    <Edited>

    Some people want advice, some people just want the answer. Maybe you just want the answer and not any advice. No offense is meant here.
     
  8. danielquasar

    danielquasar

    Joined:
    Nov 4, 2022
    Posts:
    4
    Less bothered by your tone on the original reply. Sorry, let me rephrase, perceived tone. But now I am actually disturbed that you would take the time to call me out publicly in my thread for reporting your reply.

    As someone who has experience moderating groups and forums, you take this stuff to DMs. It's inappropriate for a mod to pull a private report out and discuss it publicly with the person reporting. That's an aggressive move, and kinda proves my point.

    For what it's worth, I consulted a few programming friends to see if I had mistaken anything or was in the wrong but they too also felt you were being kinda rude. Not wrong with your advice but your execution in delivering it, and suggested I report the reply in question.

    Now I feel even less inclined to come to the Unity forums for advice or help, if a moderator is going to act in this way.

    I'm sorry that you feel like I misunderstood you so badly that I felt like reporting was the correct decision, but I don't feel like I should be chastised for it in my own thread.
     
    MelvMay likes this.
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    I am not trying to chastise you and I can remove the quote of what you said if you would like that to be private. I would ask that we DM in private so we can have a friendly chat because I do not wish for you to feel unhappy about coming to the forums.

    I'll modify the thread above.
     
  10. TheCodingWizard

    TheCodingWizard

    Joined:
    Jun 27, 2020
    Posts:
    1
    Please do not take this one interaction and leave the forums. This place has millions of members who all want to help.

    Please reach out through DM if you ever need anything.
     
    danielquasar likes this.
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    I agree.

    I too spend a lot of my personal time helping users here because it's important and it's unfortunate that this conversation went so wrong. Lots of success, occasionally something like this.

    I've just reached out to @danielquasar by DM too.