0
\$\begingroup\$

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.traderoutes[0,0]="x1";
global.traderoutes[1,0]="y1";
global.traderoutes[2,0]="x2";
global.traderoutes[3,0]="y2";

//global.traderoutes coordinates length, +1 everytime a set is added
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.traderoutes[0,R1]=global.planetinfo[1,i];
       global.traderoutes[1,R1]=global.planetinfo[2,i];
       global.traderoutes[2,R1]=global.planetinfo[1,j];
       global.traderoutes[3,R1]=global.planetinfo[2,j];

       global.a1=dist;
       global.R1+=1;  
    }
    else if (dist<=global.a2){
       global.traderoutes[0,R1]=global.planetinfo[1,i];
       global.traderoutes[1,R1]=global.planetinfo[2,i];
       global.traderoutes[2,R1]=global.planetinfo[1,j];
       global.traderoutes[3,R1]=global.planetinfo[2,j];

       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.

\$\endgroup\$

closed as off-topic by wolfdawn, MichaelHouse Jan 25 '14 at 15:44

  • This question does not appear to be about game development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ 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. \$\endgroup\$ – wolfdawn Jan 25 '14 at 9:24
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – wolfdawn Jan 25 '14 at 9:27
0
\$\begingroup\$
for (i=1;i=global.TT;i+=1){

i=global.TT: isn't that supposed to be <= instead?

same here?

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

Even if you intend to use the assignment operator in a loop, it makes no sense and should be well commented but it appears that it was not the intention.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.