Search Unity

C# Learning Methods from brackeys and when i do the code there are so many of the same errors

Discussion in 'Scripting' started by NoahsCute, Nov 24, 2020.

  1. NoahsCute

    NoahsCute

    Joined:
    Nov 22, 2020
    Posts:
    2
    So im watching a Brackeys tutorial on C# and trying to learn about methods but when i type in this code there is an error that just says "expected". and it is saying this like 5 times in a row, it just says expected and thats it. ill show you the code.(I wrote this under the update function, not in the curly brackets but like under them)

    void Start()
    {
    MeetPeople();
    }



    static void MeetPeople()
    {
    Random numberGen = new Random();
    string name = "Bob", "Martha", "Robert", "Ani";
    int age = numberGen.Next(18, 45);
    Debug.Log("Hello im " + name + " and im " + age + " years old");
    }

    I dont get why it just keeps writiong an error just saying "expected" so could someone help me out please? -Thanks!
     
  2. jbnlwilliams1

    jbnlwilliams1

    Joined:
    May 21, 2019
    Posts:
    267
    1. Please post your code using code tags. Post all the code...
    2. Please post the exact error message you see in the console. Cut and paste will work fine.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    You wrote:

    Code (csharp):
    1. string name = "Bob", "Martha", "Robert", "Ani";
    Based on what I see above, it seems you're just "sorta typing some of the stuff from the tutorial."

    That will actually NEVER work.

    Programming requires you to spell everything 100% correctly, including capitalization, punctuation, spelling, etc.

    It's NOT optional.

    Also, if you post code, please use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    How to report problems productively in the Unity3D forums:

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

    Help us to help you.
     
    Bunny83 and Vryken like this.
  4. NoahsCute

    NoahsCute

    Joined:
    Nov 22, 2020
    Posts:
    2
    yeah i was copying it then analizing then i was going to mess around with some stuff to get used to it. but do you know why the errors popped up, i know i did use correct capitlization
     
  5. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    Probably because that line that Kurt-Dekker highlighted is nonsensical and won't compile. Go back to the tutorial and check it.

    You also have not yet posted all of the script in code tags, nor have you posted the actual error messages.
     
    Bunny83, Vryken and Kurt-Dekker like this.