• 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!

drawing with 2D arrays[solved]

W

Wild_West

Guest
I keep getting an out of range error when I try to do this


draw_text(view_xview, view_yview + 32 * loop,
"WRATH Deck " +string(loop) + " : " +string(global.player1_wrath_symbol_set[loop,1]) )

How do I adjust string_width and height for a 2D array?
 

Mr Magnus

Viking King
The only array I see is player1_wrath_symbol_set. Are you sure that loop is a 2D array and that loop never goes below 0 or that player1_wrath_symbol_set is not smaller than the maximum value of loop (and has at least size 2 in the second index)
 
W

Wild_West

Guest
The only array I see is player1_wrath_symbol_set. Are you sure that loop is a 2D array and that loop never goes below 0 or that player1_wrath_symbol_set is not smaller than the maximum value of loop (and has at least size 2 in the second index)
Yeah actually the player1_wrath_symbol_set only has 5 columns starting at 1, and one extra row for each column.

I used clamp in the controller object's step event (where this draw event is also)
but I'm not sure I set it up right.

//scroll the deck
menu_position = clamp(global.player1_wrath_symbol_set[1,1], 1, 5);

and there's the symbol set array

global.player1_wrath_symbol_set[1,1] = "";//Title of the symbol in that type category
global.player1_wrath_symbol_set[1,2] = 0;//The amount of that symbol held

global.player1_wrath_symbol_set[2,1] = "";
global.player1_wrath_symbol_set[2,2] = 0;

global.player1_wrath_symbol_set[3,1] = "";
global.player1_wrath_symbol_set[3,2] = 0;

global.player1_wrath_symbol_set[4,1] = "";
global.player1_wrath_symbol_set[4,2] = 0;

global.player1_wrath_symbol_set[5,1] = "";
global.player1_wrath_symbol_set[5,2] = 0;
 

Mr Magnus

Viking King
a ) be careful, arrays start at 0, so you have a whole column per index that's undefined. That array has 6 columns: 0,1,2,3,4,5

b ) what is the rest of the code, because on a quick tired glance I can't see that this should throw an error

c ) Draw functions don't work in the step event (except when drawing to surfaces), only in the draw event
 
W

Wild_West

Guest
a ) be careful, arrays start at 0, so you have a whole column per index that's undefined. That array has 6 columns: 0,1,2,3,4,5

b ) what is the rest of the code, because on a quick tired glance I can't see that this should throw an error

c ) Draw functions don't work in the step event (except when drawing to surfaces), only in the draw event
Oh I know, sorry I said that wrong, what I meant was the draw event code is in the same object that this step event code is in.
But I thought you could just skip over an array index if you wanted, since my loop starts at 1 also
 

Mr Magnus

Viking King
You absolutely can, it just comes with the caviat to be careful since it's easy to forget you have an index that's undefined.

Anyhow, what is the code surrounding that draw_text statement? I can't see a reason why that specific code should fail
 
W

Wild_West

Guest
You absolutely can, it just comes with the caviat to be careful since it's easy to forget you have an index that's undefined.

Anyhow, what is the code surrounding that draw_text statement? I can't see a reason why that specific code should fail

if (show_WRATH_deck == true)
{
for(loop = 0; loop < 5; loop ++)
{
draw_text(view_xview, view_yview + 32 * loop,
"WRATH Deck " +string(loop) + " : " +string(global.player1_wrath_symbol_set[loop,0]) )
}

draw_rectangle
(view_xview, view_yview,
view_xview+string_width( global.player1_wrath_symbol_set[loop,0] ),
view_yview+string_height( global.player1_wrath_symbol_set[loop,0] ), true );
}

I reset the array to 0 - 4

and the error is :

Execution Error - Variable Index [5,0] out of range [5,-1] - -5.player1_wrath_symbol_set(100000,160000)
at gml_Object_controller_obj_DrawEvent_1 (line 15) - view_yview+string_height( global.player1_wrath_symbol_set[loop,0] ), true );
 

Mr Magnus

Viking King
Game maker is complaining that you're trying to treat a 1D array like it was a 2D array meaning the second dimension does not exist for that array. Are you sure that the script that initializes the second dimension of the array has actually executed before this drawing code runs?
 
W

Wild_West

Guest
Game maker is complaining that you're trying to treat a 1D array like it was a 2D array meaning the second dimension does not exist for that array. Are you sure that the script that initializes the second dimension of the array has actually executed before this drawing code runs?
The second dimension initializes with the first when you make the array doesn't it?
It is in the create event after all.
 

Mr Magnus

Viking King
ah, ah, I see the problem.

See the draw rectangle code? it is not in the loop. It's outside the loop, so the variable 'loop' at that point has the value 5 which is indeed outside of the
array (since it only has slots 0,1,2,3,4).

Either move the rectangle code inside the loop, or subtract 1 from 'loop' before trying to draw it.

for loops always end up with a counter that violates the condition (in this case loop < 5 , meaning loop = 5 so the loop stops).
 
W

Wild_West

Guest
ah, ah, I see the problem.

See the draw rectangle code? it is not in the loop. It's outside the loop, so the variable 'loop' at that point has the value 5 which is indeed outside of the
array (since it only has slots 0,1,2,3,4).

Either move the rectangle code inside the loop, or subtract 1 from 'loop' before trying to draw it.

for loops always end up with a counter that violates the condition (in this case loop < 5 , meaning loop = 5 so the loop stops).
Wow, and I literally just had an issue with not making sure code was put in the loop I did like the start of last week too. Well I definitely won't forget to make sure NOW lol
Thanks for the help.
 
Top