# smallest distance randomly generated objects [closed]

For a project in gamemaker, I'm making a galaxy with several planets in it (about 30), which have random placements (there is a minimum distance between them). After the planet generating, i'm trying to figure out how to calculate the two closest planets for each individual planet, so I can make trade routes between them. So, each planet has two planets that are closest to it, and I'm trying to make an array in which the coordinates of that planet and the two closest planets are.

I'm using the following code:

///trade route making
var a1;
var a2;
var R1;
var dist;

//what each kolom is

global.R1=1;

for (i=1;i=global.TT;i+=1){

global.a1=100000000; //a1 and a2 are values to check against, larger than any distance could possibly be.
global.a2=100000000;
for (j=1+i;j=global.TT;j+=1){
dist=point_distance(global.planetinfo[1,i],global.planetinfo[2,i],global.planetinfo[1,j],global.planetinfo[2,j]);
if (dist<=global.a1){

global.a1=dist;
global.R1+=1;
}
else if (dist<=global.a2){

global.a2=dist;
global.R1+=1;
}
}
}


global.TT is the length of the planetinfo array, where all the coordinates for each planet are stored in the first (xcoordinate) and second(ycoordinate) column.

However, it doesn't work. global.traderoutes always comes out empty, it doesn't create any new rows beside the 0th one, where "x1, y1,x2,y2" are written above each kolomn. Can anyone see a mistake I made in the code? Any help would be greatly appreciated.

• You should really avoid asking on stackexchange for help with debugging your code. It is too specific and wouldn't be of value to other readers. Just got to a site where that is appropriate. I don't mind helping and I am sure others are willing to but this is not the correct place to request such help. – AturSams Jan 25 '14 at 9:24
• This question appears to be off-topic because it is a request to debug a specific piece of code the user created that will unlikely be informative to any other users. – AturSams Jan 25 '14 at 9:27

for (i=1;i=global.TT;i+=1){

i=global.TT: isn't that supposed to be <= instead?
for (j=1+i;j=global.TT;j+=1)