Hi,
I'm having trouble with entity pointers, which leads to an error stating that I have an empty pointer and it prevents my AI opponents from working properly. I do try to filter out empty pointers by using a simple if-statement, but it still seems to slip through regardless of how I change the code around.
The problem occurs in this function, and only this function, even though I have a couple of similar functions that work perfectly fine.
function findClosestTeamPlanet(VECTOR* pos,team) {
var count = 0;
var dist1 = 0;
var dist2 = 65535;
ENTITY* temp_ent = NULL;
ENTITY* temp_ent2 = NULL;
for (count = 0; count < 255; count ++) {
if (planets[count] != 0) {
temp_ent = ptr_for_handle(planets[count]);
if (temp_ent != NULL) {
dist1 = vec_dist(temp_ent.x,pos);
if (dist2 > dist1 && temp_ent.skill18 == team) {
dist2 = dist1;
temp_ent2 = temp_ent;
}
}
}
}
return temp_ent2;
}
The error is thrown at the line 'dist1 = vec_dist(temp_ent.x,pos);', which I would expect to be prevented by the line just before that - but it isn't. Anyone have any idea why that might be?
Thanks in advance!
~TehV
EDIT: Changed the title. Problem was solved.