Unknown Identifier 'i'

I was scripting a gamescript and following the instructions of a beginner’s guide to Unity, until I ran into a problem to which I cannot find a fix for.

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

I will post the entire code if needed.


var cols:int = 4;
var rows:int = 4;
var totalCards:int = cols*rows;
var matchesNeededToWin:int = totalCards * 0.5;
var matchesMade:int = 0;
var cardW:int = 100;
var cardH:int = 100;
var aCards:Array;
var aGrid:Array;
var aCardsFlipped:ArrayList;
var playerCanClick:boolean;
var playerHasWon:boolean = false;

function Start () {
	playerCanClick = true; // We should let the player play, don't you think? XD
	
	//Initialize the arrays as empty lists:
	aCards = new Array();
	aGrid = new Array();
	aCardsFlipped = new ArrayList();
	
	for(i=0; i<rows; i++)
	{
	 aGrid *= new Array(); // Create a new, empty array at index i*
  • for(j=0; j<cols; j++)*
  • {*
    _ aGrid*[j] = new Card();_
    _
    }_
    _
    }*_

}

function Update () {

}

class Card extends System.Object
{
* var isFaceUp:boolean = false;*
* var isMatched:boolean = false;*
* var img:String;*

* function Card()*
* {*
* img = “robot”;*
* }*
}

function OnGUI()
{
* GUILayout.BeginArea (Rect (0, 0, Screen.width, Screen.height));*
* BuildGrid();*
* GUILayout.EndArea();*
* print(“Building grid!”);*
}

function BuildGrid()
{
* GUILayout.BeginVertical();*
* for(i=0; i<rows; i++)*
* {*
* GUILayout.BeginHorizontal();*
* for(j=0; j<cols; j++)*
* {*
_ var card:Object = aGrid*[j];
if(GUILayout.Button(Resources.Load(card.img),
GUILayout.Width(cardW)))
{
Debug.Log(card.img);
}
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}*_

It should be:

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

Or if you need ‘i’ to live beyond the for() statement you can do:

var i : int;
for(i=0; i<rows; i++)

I don’t know javascript but in c# you have to declare the variable BEFORE you start the loop so:

for(int i=0; =<rows; i++)
{
////blah
}

or (as fafase correctly stated)

int i = 0;

for (i=0;i<rows;i++)
{
//blah
}

without the int declaration, the program doesn’t know what ‘i’ is. maybe you have to

var i

or something