GML Basic For loop for displaying 2D array not working when # of columns do not equal # of rows


Just started using GML and am somewhat new to coding. I wanted to try to make a game menu that changes the color of the option you want to select if you used the arrow keys. I cannot for the life of me figure out why my For loops only work if the columns and rows are the same value (a 3x3 matrix works totally fine, but a 3x2 doesn't). Can anyone figure out what I'm doing wrong? I'd greatly appreciate it. Attached is all the code and the error I get, and I circles the For loops in question. Create.pngDraw.pngError.PNG


The error is indicating the runner is trying to read an index that is out of range of the array 'name'. Looking at your for loop, it looks like you should be addressing it as
'j' in your case is referring to the height (or number of rows).

Also, from 2.3+, the array_*_2d functions are considered depreciated, and it's instead recommended to just use the array_length function with the new syntax (which you seem to already be using for your arrays).