var cols : int = 4; // no of columns
var rows : int = 4; //no of rows
var totalCards : int = 16; //columns*rows
var matchesNeededToWin : int = totalCards * 0.5; // need 8 matches to win
var matchesMade : int = 0; //no matches made at beginning of game
var cardW : int = 100; //card width then height below
var cardH : int = 100;
var aCards : Array; //all cards stored in this array
var aGrid : Array; //this array keeps track of shuffled and dealt cards
var aCardsFlipped : ArrayList; //this keeps track of the chosen cards by player
var playerCanClick : boolean; //used to prevent player clicking when not wanting him/her to
var playerHasWon : boolean = false; //stores whether the player has won or not
function Start()
{
playerCanClick = true; //lets the player play
//initialise arrays as empty lists
aCards = new Array();
aGrid = new Array();
aCardsFlipped = new ArrayList();
BuildDeck();
for(var i=0; i<rows; i++) //added var to give i it's variable use
{
aGrid *= new Array(); //create new empty array at index i*
-
for(var j=0; j<cols; j++) //added var to give j it's variable use*
-
{*
-
var someNum : int = Random.Range(0, aCards.length);*
_ aGrid*[j] = aCards[someNum];_
_ aCards.RemoveAt(someNum);_
_ }_
_ }_
_}_
_ function BuildGrid()_
_{_
_ GUILayout.BeginVertical();_
_ GUILayout.FlexibleSpace();_
_ for(var i : int=0; i<cols; i++) //added var to give i it’s variable use*_
* GUILayout.BeginHorizontal();*
* GUILayout.FlexibleSpace();*
* for(var j : int=0; j<cols; j++) //added var to give j it’s variable use*
var Card : Object = aGrid _[j];_
* if(GUILayout.Button(Resources.Load(Card.img), GUILayout.Width(cardW)))*
* //Debug.Log(Card.img);*
* GUILayout.FlexibleSpace();*
* GUILayout.EndHorizontal();*
* GUILayout.FlexibleSpace();*
* GUILayout.EndVertical();*
}
function OnGUI()
{
* GUILayout.BeginArea(Rect(0,0, Screen.width, Screen.height));*
* BuildGrid();*
* GUILayout.EndArea();*
* print (“building grid!”);*
*} *
class Card extends System.Object
*{ *
* var isFaceUp : boolean = false;*
* var isMatched : boolean = false;*
* var img : String;*
* function Card(img : String)*
* {*
* this.img = img;*
* }*
}
function BuildDeck()
{
* var totalRobots : int =4; //we have 4 robots to work with*
* var Card : Object;*
* for (var i : int=0; i<totalRobots; i++) //added var to this line*
* {*
* var aRobotParts : Array;*
* aRobotParts = new Array();*
* for(var j : int=0; j<2; j++) //added var to this line*
* {*
* var someNum : int = Random.Range(0, aRobotParts.length);*
_ var theMissingPart : String = aRobotParts[someNum];_
* aRobotParts.RemoveAt(someNum);*
* Card = new Card(“Robot” + (i+1) + “Missing” + theMissingPart);*
* aCards.Add(Card);*
* Card = new Card(“Robot” + (i+1) + theMissingPart);*
* aCards.Add(Card);*
* }*
* }*
}
Ok, this one is stumping me! I’m still learning but please don’t assume I’m an idiot and shouldn’t be learning this! It’s probably something small that i’m overlooking and the only way to learn is to make mistakes.
According to Unity, the code is ok but when you run the script it throws up :
ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
both separate lines by the way, first 1 just once and the second multiple times.
It points to :
var theMissingPart : String = aRobotParts[someNum]; (1 error)
and
var Card : Object = aGrid [j]; (Multiple errors)
As always, any help gratefully accepted.