Hello demiGod,
You were so close.. A little bit more, and you'd figure this out yourself
. But oh well, here you go..
Code:
function test_ITERATE_ENTITIES()
{
var iDist;
var i;
you = 0;
while( i < ds_numberOfEntities)
{
if(ds_scan_array_list[i] == 0)
{
i += 1;
continue;
}
temp_ITERATE_ENT = ptr_for_handle(ds_scan_array_list[i]);
my=temp_ITERATE_ENT;
i += 1;
if(!temp_ITERATE_ENT)
{
continue;
}
if(my._ds_OpponentClosestDIST > iDist)
{
you = temp_ITERATE_ENT;
iDist = my._ds_OpponentClosestDIST;
}
}
ds_MOST_FREE_ENTITY = you;
return (iDist);
}
You just never defined my, and suddently you use it to compare distances. You can skip that temp entity pointer all together, and just use my instead.
Note, that continue; is not a very safe command, and should only be used when absolutely nessecery (it's very much similar to the very hatred GOTO command from the Basic language. It can lead to errors if you're not very carefull).
I re-wrote your algorithm without using continue. If these are your first steps into coding, better get it right from the start, than having to correct bad habits later on..
Code:
function test_ITERATE_ENTITIES()
{
var MaxDist;
var i;
while (i<ds_numberOfEntities)
{
if (ds_scan_array_list[i])
{
my=ptr_for_handle(ds_scan_array_list[i]);
if (my)
{
if (my._ds_OpponentClosestDIST>MaxDist)
{
ds_MOST_FREE_ENTITY=my;
MaxDist=my._ds_OpponentClosestDIST;
}
}
}
i+=1;
}
return(MaxDist);
}
Good luck with your AI.
Cheers,
Aris