Okay, this is my first attempt at Robot Repair… I’ve got errors on lines 41,59 91. Below is my script. If anyone can help me get this resolved I will be extremely thankful!
var cols:int = 4;
var rows: int = 4;
var totalCards:int = cols*rows; //16 cards total
var matchesNeededToWin:int = totalCards * 0.5; //if there are 16 cards you need 8 to win and clear the board
var matchesMade:int = 0; //at the start there have no been any matches made
var cardW:int = 100; // 100pixels wide
var cardH:int = 100; //100 pixels tall
var aCards:Array; //we'll store the cards we collect here
var aGrid:Array; //keeps track of shuffeled and delt cards
var aCardsFlipped:ArrayList; //stores cards the player has flipped
var playerCanClick:boolean; //we'll use this to prevent the player fromclicking buttons when we dont want him to.
var playerHasWon:boolean = false; //stores whether or not a player has won should start at false.
function Start ()
{
playerCanClick = true; // we should let the player press play
BuildDeck();
aCards = new Array (); //initialize the array as an empty list
aGrid = new Array ();
aCardsFlipped = new ArrayList();
for (var i=0; i<rows; i++)
{
aGrid[i] = new Array(); //creates a new empty array at index i
for (var j: int=0; j<cols; j++)
{
var someNum:int = Random.Range(0, aCards.length);
aGrid[i][j] = aCards[someNum];
aCards.RemoveAt(someNum);
}
}
}
function OnGUI ()
{ //possible error on my end..change function back to update?
GUILayout.BeginArea(Rect(0,0,Screen.width, Screen.height));
BuildGrid();
GUILayout.EndArea();
print("Building Grid!");
}
function BuildGrid()
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
for (var i=0; i<rows; i++)
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
for (var j=0; j<cols; j++)
{
var card:Object = aGrid[i][j];
if (GUILayout.Button(Resources.Load(card.img),GUILayout.Width(cardW)))
{
Debug.Log(card.img);
}
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
function BuildDeck () {
var totalRobots : int = 4; // We have 4 robots
var card : Object; // stores a reference to a card
var id : int = 0;
for (var i=0; i<totalRobots; i++)
{
var aRobotParts:Array = ["Head", "Arm", "Leg"];
for (var j=0; j<2; j++)
{
var someNum:int = Random.Range(0, aRobotParts.length);
var theMissingPart:String = aRobotParts[someNum];
aRobotParts.RemoveAt(someNum);
card = new Card("robot" + (i+1) + "Missing" + theMissingPart, id);
aCards.Add(card);
card = new Card("robot" + (i+1) + theMissingPart, id);
aCards.Add(card);
id++;
}
}
}
class Card extends System.Object
{
var isFaceUp : boolean = false;
var isMatched : boolean = false;
var img : String;
var id : int;
function Card (img:String, id:int)
{
this.img = img;
this.id = id;
}
}