Question

I am learning from a book on unity and it used this array to store cards.

var aGrid:Card[,];

I understand that :Cards means that it will only hold instances of the Cards class, but I don't understand what the comma in the "[,]" means. There are no "," in my Card class. Can anyone explain to me what this does?

Here is the full code if you need it:

#pragma strict

class Card extends System.Object {
    var isFace:boolean = false;
    var isMatched:boolean = false;
    var img:String;

    function Card() {
        img = "robot";
    }
}
import System.Collections.Generic;
var cols:int = 4; //number of collumbs
var rows:int = 4; //the number of rows in a card grid
var totalCards;int = 16;//4*4=16, there are sixteen slots in our grid for 16 cards
var matchesNeededToWin:int =  totalCards * 0.5;//two cards is one match
var matchesMade:int = 0;//At the outset, the player has not made any matches
var cardW:int = 100; // Each card is 100px by 100px
var aCards:List.<Card>;//We'll store all the cards we created in this list.
var aGrid:Card[,];//2d array to keep track of the shuffled, dealt cards
var aCardsFlipped:List.<Card>;//stores flipped cards
var playerCanClick:boolean;//prevent players from clicking wrong buttons
var playerHasWon:boolean = FalseString;//store wether or not the player has won
Was it helpful?

Solution

It would appear from the comment that the [,] notation is to create a 2D array, where presumably [] creates a single-dimension array.

For more information, see How to Write a 2d Array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top