# Help me problem solve drawing a chunk of my grid?

#### AnotherHero

##### Member
Hiya all!

I'm making a sudoku game. The player can only see one block of the 3x3 grid at a time. The way I draw the numbers looks like this:

GML:
``````    switch scene {

case 1:
for (var _x = 0; _x < 3; ++_x) {
for (var _y = 0; _y < 3; ++_y) {
if (sudoku.givens[_x,_y] == 0) continue;
draw_text((map_width / 3 * _x) + (screen_center_x) - (map_width / 3),(map_width / 3 * _y) + (screen_center_y) - (map_width / 3), string(sudoku.givens[_x,_y]));
}
}
break;``````

(the "scene" is the block of the grid the player is viewing)

This works fine when drawing the top left block, as seen:

I want the player to be able to view any one of the blocks. The full puzzle is only there in the bottom right for debug purposes. The problem is, when I have _x and _y offset for, say, 4-7 instead of 0-3, to get the center block, the numbers are drawn offset so much they are off screen.

I know it's because _x and _y not only multiply the number positions, but it's also used as the locator to find out which numbers to draw. I've tried using four nested for loops and just changing what sudoku.givens[i,j] we're looking for, but it causes every digit, 0-9, to draw in every tile.

If anybody needs more clarification or code, I'm happy to provide.

Thank you

Last edited:

#### TheouAegis

##### Member
What does your array for sudoku_givens[] actually look like?

the numbers are drawn offset so much they are off screen.
So if that image in your screenshot is what the player can ever only see -- one cell at a time -- then what you need to do is mod _x by 3 and mod _y by 3 for the drawing coordinates.
Code:
``draw_text((map_width / 3 * (_x mod 3)) + (screen_center_x) - (map_width / 3),(map_width / 3 * (_y mod 3)) + (screen_center_y) - (map_width / 3), string(sudoku.givens[_x,_y]));``

#### AnotherHero

##### Member
What does your array for sudoku_givens[] actually look like?

So if that image in your screenshot is what the player can ever only see -- one cell at a time -- then what you need to do is mod _x by 3 and mod _y by 3 for the drawing coordinates.
Code:
``draw_text((map_width / 3 * (_x mod 3)) + (screen_center_x) - (map_width / 3),(map_width / 3 * (_y mod 3)) + (screen_center_y) - (map_width / 3), string(sudoku.givens[_x,_y]));``
This code worked! Wow thank you. I have been stumped on this all day and I can't believe the answer was so simple!! THANK YOU!

I'm using a modified version of a marketplace asset for the sudoku puzzle