Help me with my memory game ( I'm new developer)

In first place, I want to apologize because of my English. I’m not native speaker.

I’m learning Unity 3D by a book called Game Development by Examples. I have a lot of issues because of my Unity Version: 3.4.2. (I think The book teaches in another version).

I’m in chapter 6. (Memory Card Game, you won when you get all the pairs)

This fist code is to start

var cols:int = 4; // the number of columns in the card grid
var rows:int = 4; // the number of rows in the card grid
var totalCards:int = cols*rows; // I think the answer is 16, but I was
//never good with numbers.
var matchesNeededToWin:int = totalCards * 0.5; // If there are 16
//cards, the player needs to find 8 matches to clear the board
var matchesMade:int = 0; // At the outset, the player has not made any
//matches
var cardW:int = 100; // Each card's width and height is 100 pixels
var cardH:int = 100;
var aCards:Array; // We'll 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'll use this flag to prevent the
//player from clicking buttons when we don't want him to
var playerHasWon:boolean = false; // Store whether or not the player
//has won. This should probably start out false :)


class Card extends System.Object
{
	var isFaceUp:boolean = false;
	var isMatched:boolean = false;
	var img:String;
	function Card()
	{
	img = "robot";
	}
}


function Start()
{
	playerCanClick = true; /* We should let the player play,
	dont you think?*/
	// Initialize the arrays as empty lists:
	aCards = new Array();
	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();
		}
	}
	
}

Then, the code for drawing the table of robots is ( another script)

function OnGUI () {

	

	GUILayout.BeginArea (Rect (0,0,Screen.width,Screen.height));

	BuildGrid();

	GUILayout.EndArea();

	print("Game Working..");



}



function BuildGrid()

{

	GUILayout.BeginVertical();

	for(i=0; i<rows; i++)

	{

		GUILayout.BeginHorizontal();

		for(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.EndHorizontal();

	}

	GUILayout.EndVertical();

}

According the book, this is correct.
The problem is that second script doesn’t identify the first script’s variables ( like rows).

Thank for your help:)

I did a search for “cardW” on this page, and found that it is in both scripts… This tells me that these are not two scripts but one. Put them together. :wink:

I havent read the book , and i jus barely skimmed the code itself , but why not put all that into a single script … its not to big, and seems it would fix the problem, if its just a case of no access.

Thank you for your help. I found the solution by myselft some minutes ago.

BTW, THANK YOU.

That’s an except from the book?

Because wow, there’s so much in there that scream ‘BAD’ to me!