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

SOLVED Generate unique ds_grid per instance

trippity

Member
Hi all,

Problem:
I have a 'chest' object with the following code in the create event:

GML:
_chest_main_inventory = ds_grid_create(inv_slots, 2);
I would have thought that upon instantiation the logic would be:
chest_1.<Its own grid>
chest_2.<Its own grid>

However what is happening is chest_1 & 2 are sharing the "_chest_main_inventory" grid. ie, if I put an object in chest 1 and walk over to chest 2, its teleported.

Question:
How do I create unique grids per chest object?
 

Simon Gust

Member
How are you accessing the ds_grid?
You should not be doing it like this
Code:
ds_grid_get(obj_chest._chest_main_inventory, x, y)
The grids can be only as unique as their chest objects. If you always access the same chest object, you will only access one grid of the many.
To get the correct chest object, use collision functions that return an id.
 

trippity

Member
Originally I was doing
item_id = oChest._chest_main_inventory...

and then realized the object name is not exactly 'pointing' to a new grid. So like you mentioned I switched to:
item_id = chest_ID._chest_main_inventory...
 
Last edited:
Top