A script crashes the engine
Posted: Thu Jan 30, 2014 3:24 am
When I run this code, the game crashes.
Explanation:
There are actors called "badshot" flying around the screen--they're created every so often. The code above is supposed to figure out which "badshot" is closest to it. They and it are constantly moving, so the code is put in the Draw Actor event. If the code above is hopeless, what's another way do figure out which "badshot" is closest?
- Code: Select all
int badshots = ActorCount("badshot");
int i;
char*clonename;
Actor*clone;
Actor*closestshot;
int smalldist;
for (i = 0; i < badshots; i++) {
sprintf(clonename, "badshot.%d", i);
clone = getclone(clonename);
if (distance(x,y,clone->x,clone->y) < smalldist) {
closestshot = clone;
smalldist = distance(x,y,clone->x,clone->y);
}
}
Explanation:
There are actors called "badshot" flying around the screen--they're created every so often. The code above is supposed to figure out which "badshot" is closest to it. They and it are constantly moving, so the code is put in the Draw Actor event. If the code above is hopeless, what's another way do figure out which "badshot" is closest?