• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

ds_grid_get_sum() - having an issue - SOLVED

  • Thread starter Dennis Ross Tudor Jr
  • Start date
D

Dennis Ross Tudor Jr

Guest
I am supplying a script and the output it produced. The issue I am having is that the output shows that it's adding a value to the grid, but when the script sums of the region of the grid it found no values. Is there something wrong with the ds_grid_get_sum() function or am I not seeing something here? I've been up for more than a few hours now :p

Code:
show_debug_message("AssignExplodeGrid script --> assigning horizontal explodes");
var row,col;
// assign horizonal values to explode board
for(row=topRow;row<NUM_OF_ROWS;row++){
    for(col=0;col<NUM_OF_COLS-2;col++){
        var b1,b2,b3;
        b1=ds_grid_get(Board,row,col);
        b2=ds_grid_get(Board,row,col+1);
        b3=ds_grid_get(Board,row,col+2);
        if(b1.stoneType==b2.stoneType && b1.stoneType==b3.stoneType){
        show_debug_message("AssignExplodeGrid script --> match horizontal");
            b1.explode=true;
            b2.explode=true;                // TODO: remove redundancy
            b3.explode=true;                //             by advancing 'col'
            ds_grid_set(ExplodeBoard,row,col,1);
            ds_grid_set(ExplodeBoard,row,col+1,1);
            ds_grid_set(ExplodeBoard,row,col+2,1);
        }
    }
}
show_debug_message("AssignExplodeGrid script --> assigning vertical explodes");
// assign vertical values to explode board
for(row=topRow;row<NUM_OF_ROWS-2;row++){
    for(col=0;col<NUM_OF_COLS;col++){
        b1=ds_grid_get(Board,row,col);
        b2=ds_grid_get(Board,row+1,col);
        b3=ds_grid_get(Board,row+2,col);
        if(b1.stoneType==b2.stoneType && b1.stoneType==b3.stoneType){
        show_debug_message("AssignExplodeGrid script --> match vertical");
            b1.explode=true;
            b2.explode=true;
            b3.explode=true;
            ds_grid_set(ExplodeBoard,row,col,1);
            ds_grid_set(ExplodeBoard,row+1,col,1);
            ds_grid_set(ExplodeBoard,row+2,col,1);
        }
    }
}
var value;
value=ds_grid_get_sum(ExplodeBoard,0,topRow,NUM_OF_COLS,NUM_OF_ROWS);
show_debug_message("AssignExplodeGrid script --> value of sums: "+string(value));
Code:
AssignExplodeGrid script --> assigning horizontal explodes
AssignExplodeGrid script --> match horizontal
AssignExplodeGrid script --> match horizontal
AssignExplodeGrid script --> assigning vertical explodes
AssignExplodeGrid script --> match vertical
AssignExplodeGrid script --> value of sums: 0
The grid is actually twice the size of the board(16x8), hence the topRow variable (which == 8 by the way)
NUM_OF_ROWS=16
NUM_OF_COLS=8
When the Explode grid is viewed or printed out there are 1's where exploded cells should be so the region should add up to more than zero.

the last line of the output should have produced
AssignExplodeGrid script --> value of sums: 6+ (at least 6 but at most 9 -> depending how the 3 triplets were lined up.
 

Bukmand

Member
I think there is something wrong with your regions!
Manual: This function can be used to get the value (either a real number or a string) from any cell within the given ds_grid. If you pass invalid grid coordinates to the function, then the value returned will be 0.
 
D

Dennis Ross Tudor Jr

Guest
EDIT: new code with debug showing range and data structure

Code:
// REVAMPED WITH DEBUG MESSAGE SHOWING DATA STRUCTURE
show_debug_message("AssignExplodeGrid script --> assigning horizontal explodes");
var row,col;
show_debug_message("AssignExplodeGrid script --> topRow: "+string(topRow));
// assign horizonal values to explode board
for(row=topRow;row<NUM_OF_ROWS;row++){
    for(col=0;col<NUM_OF_COLS-2;col++){
        var b1,b2,b3;
        b1=ds_grid_get(Board,row,col);
        b2=ds_grid_get(Board,row,col+1);
        b3=ds_grid_get(Board,row,col+2);
        if(b1.stoneType==b2.stoneType && b1.stoneType==b3.stoneType){
        show_debug_message("AssignExplodeGrid script --> match horizontal");
        show_debug_message("AssignExplodeGrid script --> match grid location ["+string(row)+","+string(col)+"]");
            b1.explode=true;
            b2.explode=true;
            b3.explode=true;
            ds_grid_set(ExplodeBoard,row,col,1);
            ds_grid_set(ExplodeBoard,row,col+1,1);
            ds_grid_set(ExplodeBoard,row,col+2,1);
        }
    }
}
show_debug_message("AssignExplodeGrid script --> assigning vertical explodes");
// assign vertical values to explode board
for(row=topRow;row<NUM_OF_ROWS-2;row++){
    for(col=0;col<NUM_OF_COLS;col++){
        b1=ds_grid_get(Board,row,col);
        b2=ds_grid_get(Board,row+1,col);
        b3=ds_grid_get(Board,row+2,col);
        if(b1.stoneType==b2.stoneType && b1.stoneType==b3.stoneType){
        show_debug_message("AssignExplodeGrid script --> match vertical");
        show_debug_message("AssignExplodeGrid script --> match grid location ["+string(row)+","+string(col)+"]");
            b1.explode=true;
            b2.explode=true;
            b3.explode=true;
            ds_grid_set(ExplodeBoard,row,col,1);
            ds_grid_set(ExplodeBoard,row+1,col,1);
            ds_grid_set(ExplodeBoard,row+2,col,1);
        }
    }
}
var value,t;
for(row=topRow;row<NUM_OF_ROWS;row++){
    t="";
    for(col=0;col<NUM_OF_COLS;col++){
        t+=string(ds_grid_get(ExplodeBoard,row,col));
    }
    show_debug_message(t);
}
show_debug_message("X1: "+string(0)+" Y1: "+string(topRow)+" X2: "+string(NUM_OF_COLS)+" Y2: "+string(NUM_OF_ROWS));
value=ds_grid_get_sum(ExplodeBoard,0,topRow,NUM_OF_COLS,NUM_OF_ROWS);
show_debug_message("AssignExplodeGrid script --> value of sums: "+string(value));
Code:
 OUTPUT
AssignExplodeGrid script --> assigning horizontal explodes
AssignExplodeGrid script --> topRow: 8
AssignExplodeGrid script --> match horizontal
AssignExplodeGrid script --> match grid location [9,4]
AssignExplodeGrid script --> match horizontal
AssignExplodeGrid script --> match grid location [10,3]
AssignExplodeGrid script --> match horizontal
AssignExplodeGrid script --> match grid location [10,4]
AssignExplodeGrid script --> assigning vertical explodes
AssignExplodeGrid script --> match vertical
AssignExplodeGrid script --> match grid location [8,7]
AssignExplodeGrid script --> match vertical
AssignExplodeGrid script --> match grid location [12,2]
00000001
00001111
00011111
00000000
00100000
00100000
00100000
00000000
X1: 0 Y1: 8 X2: 8 Y2: 16
AssignExplodeGrid script --> value of sums: 0
You'l notice that I am calling the range that is with in the scope of the grid where a sum should produce a positive integer. (in this case 13)
 
Last edited by a moderator:
D

Dennis Ross Tudor Jr

Guest
I did edit the line in case I was checking out of bounds with NUM_OF_COLS and NUM_OF_ROWS as X2 and Y2 but the output is still the same
Code:
value=ds_grid_get_sum(ExplodeBoard,0,topRow,NUM_OF_COLS-1,NUM_OF_ROWS-1);
Code:
AssignExplodeGrid script --> assigning horizontal explodes
AssignExplodeGrid script --> topRow: 8
AssignExplodeGrid script --> match horizontal
AssignExplodeGrid script --> match grid location [13,0]
AssignExplodeGrid script --> assigning vertical explodes
AssignExplodeGrid script --> match vertical
AssignExplodeGrid script --> match grid location [10,5]
AssignExplodeGrid script --> match vertical
AssignExplodeGrid script --> match grid location [13,2]
AssignExplodeGrid script --> match vertical
AssignExplodeGrid script --> match grid location [13,6]
00000000
00000000
00000100
00000100
00000100
11100010
00100010
00100010
X1: 0 Y1: 8 X2: 8 Y2: 16
AssignExplodeGrid script --> value of sums: 0
index The index of the grid.
x1 The left cell column of the region.
y1 The top cell row of the region.
x2 The right cell column of the region.
y2 The bottom cell row of the region.
 
D

Dennis Ross Tudor Jr

Guest
I thought I would add that I set up the grid this way

Code:
ExplodeBoard = ds_grid_create(NUM_OF_ROWS,NUM_OF_COLS);
I think I see it now.. a mixup I create a wide, short grid, but check a skinny tall grid... :)


thx
 
Top