L
lohtangclan
Guest
after a few hours of scratching my head and restarting my scripts I just have to ask here! I'm a bit new to Gamemaker, but have a little experience with C and other 3d-software-scripting languages.
I'm just trying to make sense of where and how I should be calling ds_sort_grid.
In my Create event I have the following code, which puts random values into my grid
I have a Draw event which displays my 4 x 5 grid -
and finally two keypress checks in a Step event, to sort and randomise-
For some reason, when I hit "s" to sort the values, they are never actually sorted, but jumbled around.. And when I specify only one column for ds_grid_sort , it seems to do something to the entire grid..
When I initialise the grid to value j, and hit "s", the values seem to be sorted as I expect.. Does ds_grid have a problem with random values? Or am I doing something incredibly wrong somewhere?? (enclosed two images to show the random number example)
Ultimately I was working on a Scorched Earth/Tank Wars terrain system, but I was finding my ds_grid_sort was affecting areas of the grid that I had not specified, so went back to a much simpler test...which is driving me a little nuts!!
Thanks for any help!
<-images
I'm just trying to make sense of where and how I should be calling ds_sort_grid.
In my Create event I have the following code, which puts random values into my grid
Code:
mygrid=ds_grid_create(4,5);
for(var i=0;i<4;i++){
for(var j=0;j<5;j++){
val=floor(random(4));
ds_grid_set(mygrid,i,j,val);
}
}
Code:
for(i=0;i<4;i++){
for(j=0;j<5;j++){
draw_text(30+i*100,30+j*100,string(ds_grid_get(mygrid,i,j)));
}
}
Code:
if(keyboard_check_pressed((ord("S")))){
for(i=0;i<4;i++){
ds_grid_sort(mygrid,i,false);
}
}
if(keyboard_check_pressed(ord("R"))){
for(var i=0;i<4;i++){
for(var j=0;j<5;j++){
val=floor(random(12));
ds_grid_set(mygrid,i,j,val);
}
}
}
When I initialise the grid to value j, and hit "s", the values seem to be sorted as I expect.. Does ds_grid have a problem with random values? Or am I doing something incredibly wrong somewhere?? (enclosed two images to show the random number example)
Ultimately I was working on a Scorched Earth/Tank Wars terrain system, but I was finding my ds_grid_sort was affecting areas of the grid that I had not specified, so went back to a much simpler test...which is driving me a little nuts!!
Thanks for any help!
<-images
Last edited by a moderator: