'GetComponent' is not a member of 'Object'... who said I was using an Object??

I clearly defined a variable as a GameObject, yet I cannot use GetComponent on it. I can’t figure out what’s wrong with my code. I need to be able to resize the arrays, so built-in arrays won’t help. Any help would be greatly appreciated :smiley:

#pragma strict

var InDialogue = 0;
var InBattle = 0;

// Battle vars
var battleArray : Array;
var ent1 : GameObject; // << The actual GameObject.  Clearly defined as GameObject.
var ent1e : Entity; // Entity script that contains all movement and battle variables
var en = 0;
var fr = 0;
var NumActiveBt = 0;

function Start () {
	battleArray = new Array();
}

function InitBattle() {
	// Initial splash screen?
	
	// Find out who's in this battle...
	battleArray.Push(gameObject.FindGameObjectsWithTag("Player"));
	var npclist : GameObject[] = GameObject.FindGameObjectsWithTag("NPC");
	for (var npc1 : GameObject in npclist)
	{
		if ((npc1.GetComponent(Entity).HP > 0) && ((npc1.GetComponent(Entity).Si > 0)))
		{
			battleArray.Push(npc1);
			//NumActiveBt += 1;
		}
	}
	InBattle = 1;
}

function Update () {
	if (InBattle == 1)
	{
		en = 0;
		fr = 0;
		//NumActiveBt = bt.length;
		//InBattle = 0;
		NumActiveBt = 100;
		for (ent1 in battleArray)
		{
			ent1e = ent1.GetComponent(Entity); // THIS IS THE LINE THAT RETURNS AN ERROR
			NumActiveBt = 200;
			if (ent1e.HP > 0)
			{
				//NumActiveBt++;
				if (ent1e.Si == 1)
				{
					fr ++;
				}
				if (ent1e.Si == 2)
				{
					en ++;
				}
			}
		}
		NumActiveBt = 300;
		if (fr == 0)
		{
			// LOSE GAME
		}
		if (en == 0)
		{
			// WON BATTLE
			// Loot screen?
			InBattle = 0;
		}
	}
}

This error should not happen, since ent1 is a member variable declared as GameObject. The only thing I can think is that the compiler is creating a temporary variable ent1 in the for…in loop - since it’s not typed, the compiler assumes the generic object type.
You could try the following:

    for (var ent1: GameObject in battleArray)

Your iteration variable has the same name as your member variable. Change the iterator (ent1) variable to a different name.