Jump to content


Photo

Grids Driving Me Insane!


  • This topic is locked This topic is locked
6 replies to this topic

#1 Rikrok

Rikrok

    GMC Member

  • New Member
  • 12 posts

Posted 07 March 2008 - 05:05 PM

I hope someone can help, it's a bit long winded but bear with me..
Here's what I'm trying to do and it should be simple- sort a list of scores. I don't want to use the inbuilt score table, it's nasty and my table includes other information such as level achieved. I can't simply use a list and use the sort function because it won't sort the corresponding owners of the scores etc.

So here's my thinking; use a grid.
(There are four columns(0-3). 2 is where the score is held)
Check if the score in the row below is smaller than in the current row
If it is swap them: copy the current row to a temporary grid
Copy the row below to the current row
Copy the row from the temporary grid to the row below
Now check the score 2 rows below, 3, etc. After this you have the highest score in the top row. Then repeat the process for every subsequent row

 // Order by scores
  for (j=0; j<=8; j+=1) {
   for (k=j+1; k<=9; k+=1) {
    if (ds_grid_get(grd_scores,2,j) < ds_grid_get(grd_scores,2,k)) {
     ds_grid_set_grid_region(grd_scorescopy,grd_scores,0,j,3,j,0,0);
     ds_grid_set_grid_region(grd_scores,grd_scores,0,k,3,k,0,j);
     ds_grid_set_grid_region(grd_scores,grd_scorescopy,0,0,3,0,0,k)};
  }};


The first problem was copying to the temporary grid:
ds_grid_set_grid_region(grd_scorescopy,grd_scores,
0,j,3,j,0,0);
It would only do it once, from then on when retrieving what should have been new values from grd_scorescopy I just got the first one that had been copied there.

Bizarrely this got slightly better when I changed the height of the temporary gird to 2, even though I'm only ever copying one row it. It seems completely fine when I set it's height to the same as grd_scores and instead of pasting in at ypos 0 using j.

So surely no more problems (even if the last solution doesn't really make sense)?

The scores are nicely sorted until position 6, where the sorting process just seems to have given up! I have no idea why. I've wasted so much time trying to sort this now and am wondering whether grids are just a steaming pile of *&!£. Any ideas?

Edited by Rikrok, 07 March 2008 - 05:48 PM.

  • 0

#2 xot

xot

    GMC Dismember

  • GMC Elder
  • 4785 posts
  • Version:GM:Studio

Posted 07 March 2008 - 05:43 PM

This is a little-known, but absolutely confirmed, Game Maker 7 bug.

http://gmc.yoyogames...howtopic=338408

The work around is to replace ds_grid_set_grid_region() with your own version. You can even keep it the same name and your script will be used instead of the built-in function. That's a useful feature that simplifies code updates when the bug is finally fixed; you only need to remove your replacement and everything that uses ds_grid_set_grid_region() will be updated automagically.

// ds_grid_set_grid_region(dst,src,x1,y1,x2,y2,xpos,ypos)
// NOTE: This is a replacement for the buggy GM7 function of the same name.
var xoff,yoff,i,j;
xoff = argument6-argument2;
yoff = argument7-argument3;
for (i=argument2; i<=argument4; i+=1) {
    for (j=argument3; j<=argument5; j+=1) {
        ds_grid_set(argument0,i+xoff,j+yoff,ds_grid_get(argument1,i,j));
    }
}

  • 0
GMLscripts.com, rise from your grave!

If any of my posts contain broken images or links, I can probably supply them for you. PM with a link to the post.

#3 Rikrok

Rikrok

    GMC Member

  • New Member
  • 12 posts

Posted 07 March 2008 - 05:51 PM

Thank you so much xot! You've made me very happy, no more tearing my hair out.
  • 0

#4 xot

xot

    GMC Dismember

  • GMC Elder
  • 4785 posts
  • Version:GM:Studio

Posted 07 March 2008 - 05:56 PM

:) Believe me, I know the feeling. I spent hours struggling with this stupid bug.
  • 0
GMLscripts.com, rise from your grave!

If any of my posts contain broken images or links, I can probably supply them for you. PM with a link to the post.

#5 Big J

Big J

    GMC Member

  • GMC Member
  • 2853 posts
  • Version:GM8.1

Posted 10 March 2008 - 01:03 AM

Wow, a Game Maker 7 bug? Did this bug exist in Game Maker 6.x?

I wonder...
  • 0

Get your GM 8.1 Anti-Aliasing here!

2712265.png

http://www.youtube.com/Sporkinator


#6 xot

xot

    GMC Dismember

  • GMC Elder
  • 4785 posts
  • Version:GM:Studio

Posted 10 March 2008 - 01:17 AM

This function doesn't exist in GM6, so no. But there are at least two bugs in GM6 concerning grid data structures.

ds_grid_value_exists() - Does not detect strings, it can only find the existence of numbers.

ds_grid_resize() - This function will cause a crash if the width of the grid is increased in any way.

These two bugs were fixed for GM7.

Edited by xot, 10 March 2008 - 02:01 AM.

  • 0
GMLscripts.com, rise from your grave!

If any of my posts contain broken images or links, I can probably supply them for you. PM with a link to the post.

#7 Big J

Big J

    GMC Member

  • GMC Member
  • 2853 posts
  • Version:GM8.1

Posted 10 March 2008 - 01:45 AM

I've never worked with a grid data structure, so I didn't realize that the function wasn't in GM6.

Your own script works better than a built-in function. I find that a bit funny.
  • 0

Get your GM 8.1 Anti-Aliasing here!

2712265.png

http://www.youtube.com/Sporkinator