i have a new error
i finally figured out for the most part why my grid was not working but after i changed the numbers it popped out a error that i am having a hard time figuring out what it wants me to do
if there is any one who can help me i would appreciate it very much
here is the error
ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
0
System.Collections.ArrayList.ThrowNewArgumentOutOf RangeException (string,object,string) <IL 0x00008, 0x00064>
System.Collections.ArrayList.get_Item (int) <IL 0x00023, 0x00083>
UnityScript.Lang.Array.get_Item (int) <IL 0x00007, 0x0003b>
(wrapper dynamic-method) UnityScript.Lang.Array.Array$get_Item$System.Int32 (object,object[ ]) <IL 0x00017, 0x00082>
Boo.Lang.Runtime.RuntimeServices.GetSlice (object,string,object[ ]) <IL 0x00056, 0x00137>
Grid.BuildGrid () (at Assets/scripts/Grid.js:94)
Grid.OnGUI () (at Assets/scripts/Grid.js:37)
var cols:int = 6; // number of columns
var rows:int = 6; // number of rows
var totalCards:int = cols*rows; // number of cards
var matchesNeededToWin:int = totalCards*0.5; // number of matching to win
var matchesMade:int = 0; // current matching number
var cardW:int = 100; // card width
var cardH:int = 100; // card height
var aCards:Array; // We will store all the cards we create in this array
var aGrid:Array; // This array will keep track of the shuffled, dealt cards
var aCardsFlipped:ArrayList; // This array will store the two cards that the player flips over
var playerCanClick:boolean; //We will use this flag to prevent the player from clicking buttons when we don't want them to
var playerHasWon:boolean = false; //Store whether or not the player has won.
var addScore:boolean;
var JumpS : AudioClip;
function Start(){
playerCanClick = true;
aCards = new Array(); //Initialize the array as empty list
aGrid = new Array();
aCardsFlipped = new ArrayList();
BuildDeck(); // ********************** My own function to generate a list of cards
for (i = 0; i<rows; i++){
aGrid[i] = new Array(); // Create a new, empty array at index i
for (j = 0; j<cols; j++){
var someNum:int = Random.Range(0, aCards.length);
aGrid[i][j] = aCards[someNum];
aCards.RemoveAt(someNum);
}
}
}
function OnGUI () {
GUILayout.BeginArea (Rect (0,0, Screen.width, Screen.height)); // define the area
BuildGrid(); // ************ My Own Function
if(playerHasWon) LoadLevel();
GUILayout.EndArea();
print ("Grid is made");
}
/*
class Card extends System.Object
{
var isFaceUp:boolean = false;
var isMatched:boolean = false;
var img:String;
function Card(){
img = "robot";
}
}
function Start(){
playerCanClick = true;
aCards = new Array(); //Initialize the array as empty list
aGrid = new Array();
aCardsFlipped = new ArrayList();
for (i = 0; i<rows; i++){
aGrid[i] = new Array(); // Create a new, empty array at index i
for (j = 0; j<cols; j++){
aGrid[i][j] = new Card(); // ****** Call Constructor of "Card"
}
}
}
function BuildGrid(){
GUILayout.BeginVertical();
for (i =0 ; i<rows; i++){
GUILayout.BeginHorizontal();
for (j=0; j<cols; j++){
var card:Object = aGrid[i][j]; // aGrid (array of cards) has been made in "Start()"
// If there is an image named (card.img= "robot"), and its width == cardW
if (GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW))){
Debug.Log(card.img);
}
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
*/
//********** Step2
function BuildGrid(){
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
for (i =0 ; i<rows; i++){
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
for (j=0; j<cols; j++){
var card:Object = aGrid[i][j]; // aGrid (array of cards) has been made in "Start()"
var img:String;
if (card.isFaceUp) img = card.img;
else img = "wrench";
if (GUILayout.Button(Resources.Load(img), GUILayout.Width(cardW))){
if (playerCanClick) {
FlipCardFaceUp(card); // ***** My own function to flip the card.
}
Debug.Log(card.img);
}
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
function BuildDeck(){
var totalStick:int = 6; //We've got four robots to work with
var card:Object; // this store a reference to a card
var id:int = 0;
for (i = 0; i<totalStick; i++){
var aStickParts:Array = ["Head", "Arm", "Leg"];
for (j = 0; j<2; j++){
var someNum:int = Random.Range(0, aStickParts.length); //Get some random integer
var theMissingPart:String = aStickParts[someNum]; //Get the name in the random id
aStickParts.RemoveAt(someNum); // remove the name from the list
// Look at the Resouce folder images. The goal is to match "robot1MissingHead" and "robot1Head"
card = new Card("Stick"+(i+1) + "Missing"+theMissingPart, id);
aCards.Add(card);
card = new Card("Stick"+(i+1)+theMissingPart, id);
aCards.Add(card);
id++;
}
}
}
function FlipCardFaceUp(card:Card){
card.isFaceUp = true;
aCardsFlipped.Add(card); // Store the flipped card in the list
if(aCardsFlipped.Count ==2){
playerCanClick = false; // cannot flip
yield WaitForSeconds(1); // Wait a second
if (aCardsFlipped[0].id == aCardsFlipped[1].id) {
aCardsFlipped[0].isMatched = true;
aCardsFlipped[1].isMatched = true;
matchesMade ++;
if(matchesMade >= matchesNeededToWin) playerHasWon = true;
}
else {
aCardsFlipped[0].isFaceUp = false;
aCardsFlipped[1].isFaceUp = false;
}
aCardsFlipped = new ArrayList(); // Next turn
playerCanClick= true;
}
}
function LoadLevel(){
Application.LoadLevel("WinnerScreen");
}