- Home /
Basic Stuff on Arrays
I am learning from a book on unity and it used this
var aGrid:Card[,];//2d array to keep track of the shuffled, dealt cards
I understand that :Cards means that it will only hold instances of the Cards class, but I don't understand what the comma in there means. There are no "," in my Card class. Can anyone explain what this does to me?
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
Answer by SirCrazyNugget · Mar 20, 2014 at 02:51 AM
It's to create a multidimensional array.
From what you've posted it looks like you're storing the address of each card, you could have an array of size 16 for each of the possible positions or a 2D array of 4x4 to supply the 16 possible addresses.
Using the 2D array enables to you to see the variable being stored at that address a lot easier Card[3,3] is the last address on the 4x4 grid instead of using Card[15].
Your answer
Follow this Question
Related Questions
Accessing a variable inside a class inside other script... 2 Answers
how to write classes 1 Answer
Array of custom class objects all return the same value? 1 Answer
Inventory Help. 2 Answers
How to create a Game Tree data structure in Unity. 0 Answers