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

GameMaker Can't Set the Ds Grid to a value Out of Range Error

Ç

Çağrı

Guest
Insıde obj_RoomState;

-Create-
RoomGrid = ds_grid_create(5, 5);
ds_grid_set_region(RoomGrid,0,0,4,4,"aaa")
//RoomGrid[1, 0] = "aaa";
RoomGrid[2, 2] = room1;
RoomGrid[3, 2] = room3;
RoomGrid[3, 3] = room2;
RoomGrid[2, 3] = room4;

-Draw-
draw_text(x,y,RoomGrid[1, 0])

When i run the game i get this error:



But when i run it like this:

-Create-
RoomGrid = ds_grid_create(5, 5);
ds_grid_set_region(RoomGrid,0,0,4,4,"aaa")
RoomGrid[1, 0] = "aaa";
RoomGrid[2, 2] = room1;
RoomGrid[3, 2] = room3;
RoomGrid[3, 3] = room2;
RoomGrid[2, 3] = room4;

It works...



Im somewhat new to game maker so my question is this

ds_grid_set_region(RoomGrid,0,0,4,4,"aaa")
RoomGrid[1, 0] = "aaa";

Shouldn't First line set All the grid and RoomGrid[1,0] to "aaa" why it gives an error when i delete the second line
 

jo-thijs

Member
Insıde obj_RoomState;

-Create-
RoomGrid = ds_grid_create(5, 5);
ds_grid_set_region(RoomGrid,0,0,4,4,"aaa")
//RoomGrid[1, 0] = "aaa";
RoomGrid[2, 2] = room1;
RoomGrid[3, 2] = room3;
RoomGrid[3, 3] = room2;
RoomGrid[2, 3] = room4;

-Draw-
draw_text(x,y,RoomGrid[1, 0])

When i run the game i get this error:



But when i run it like this:

-Create-
RoomGrid = ds_grid_create(5, 5);
ds_grid_set_region(RoomGrid,0,0,4,4,"aaa")
RoomGrid[1, 0] = "aaa";
RoomGrid[2, 2] = room1;
RoomGrid[3, 2] = room3;
RoomGrid[3, 3] = room2;
RoomGrid[2, 3] = room4;

It works...



Im somewhat new to game maker so my question is this

ds_grid_set_region(RoomGrid,0,0,4,4,"aaa")
RoomGrid[1, 0] = "aaa";

Shouldn't First line set All the grid and RoomGrid[1,0] to "aaa" why it gives an error when i delete the second line
Hi and welcome to the GMC!

When you use:
Code:
RoomGrid[1, 0] = "aaa";
you're telling GameMaker that RoomGrid is a 2D array, rather than a grid, to which the error reports that the variable is not a 2D array.
For grids, you need to use accessors like so:
Code:
RoomGrid[# 1, 0] = "aaa";
 
Ç

Çağrı

Guest
Hi and welcome to the GMC!

When you use:
Code:
RoomGrid[1, 0] = "aaa";
you're telling GameMaker that RoomGrid is a 2D array, rather than a grid, to which the error reports that the variable is not a 2D array.
For grids, you need to use accessors like so:
Code:
RoomGrid[# 1, 0] = "aaa";
I wasted such a long time on this simple thing lol. Thank you
 
Top