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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

C# Script unexpected 'int' error

Discussion in 'Editor & General Support' started by Damlo, Jul 16, 2015.

  1. Damlo

    Damlo

    Joined:
    Jul 16, 2015
    Posts:
    2
    Hey everyone, i recently have had an unexpexted error.
    I'm using C# and need help on this script, why is this 'int' unexpected.


    public class Deck : MonoBehaviour
    {
    List<int>cards;

    public void Shuffle()
    {

    if (cards == null)
    {
    cards = new List<int>();
    }
    else
    {
    cards.Clear();
    }
    for(int i = 0; i<52; i++)
    cards.Add(i)


    int n = cards.Count;

    while (n > 1)
    {
    n--;
    int k = Random.Range(0, n + 1);
    int temp = cards[k];
    cards[k] = cards[n];
    cards[n] = temp;
    }


    }
    }

    Unity doesn't want this markered int, it always says error, doesn't matter what i try.
    (Just saying, im a C# starter, and i made this with a youtube tutorial)
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You forgot a semicolon.
    cards.Add(i);

    unexpected xxx does normally means that the compiler is awaiting something different in hat place. in this case the compiler awaits the semicolon but finds your int.

     
  3. Damlo

    Damlo

    Joined:
    Jul 16, 2015
    Posts:
    2
    thank you very much :D