Declared an array in Start, cant use it in Update?

So I made an array that keeps track of player lives visually, and I want it so that whenever a player is called a life token is removed from the screen. Problem is that it’s throwing an Unknown Identifier error. Here is the code:

	p1Tokens = new Array();
	
	for(i = 0; i < 6; i++){
		if( i < 3){
			x = i - 18.39797;
			y = 13;
		}
		else{
			x = (i - 3) - 18.39797;
			y = 11.5;
		}
		p1Tokens *= Instantiate(p1LifeToken, Vector3(x, y, -8.469761), Quaternion.identity);*
  • }*

  • p2Tokens = new Array();*

  • for(i = 0; i < 6; i++){*

  •  if( i < 3){*
    
  •  	x = i - 18.39797;*
    
  •  	y = 8;*
    
  •  }*
    
  •  else{*
    
  •  	x = (i - 3) - 18.39797;*
    
  •  	y = 6.5;*
    
  •  }*
    

_ p2Tokens = Instantiate(p2LifeToken, Vector3(x, y, -8.469761), Quaternion.identity);_
* }*
}

function Update () {

* if (playerOne == null && p1Lives != 0){*
* p1Lives -= 1;*
* Destroy(p1Tokens[p1Lives].gameObject);*
* playerOne = Spawn(playerOneFab);*
* }*
* if (playerTwo == null && p2Lives != 0){*
* p2Lives -= 1;*
* Destroy(p2Tokens[p2Lives].transform);*
* playerTwo = Spawn(playerTwoFab);*
* }*
The problem occurs in the call to Destroy, on the array p1/p2Tokens.
Any suggestions?

Move the def of p1/p2Tokens out of Start, to the top bit where vars are defined for entire program scope

Ecmascript, which UnityScript and Javascript are both dialogs of, has functional scope.

In normal Javascript, a variable that is referenced without a var will search upwards and end up declaring itself in the global scope
if it is not defined in any child scope.

HOWEVER UnityScript doesn’t have a Javascript style scope ‘bubbling’. So I suspect its just declaring it as if it was declared with a var.

In which case its not visible outside of that function.

(See http://wiki.unity3d.com/index.php?title=Head_First_into_Unity_with_UnityScript for more inf ion differences between Javascript and Unityscript).