• 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 [SOLVED] Adding a sprite to a DSGrid

F

Frolacosta

Guest
A function I am working on requires a sprite index to be put intoa DSGrid I have created. I have attempted it like so.
Code:
ds_grid_set(grid, 3, 0, spr_coin);
My issue is, the sprite index is not going into the data structure. When I look at that cell in the debugger, it just holds 0.

If I use this code:
Code:
ds_grid_set(grid, 3, 0, string(spr_coin));
The cell holds "0".


Does anyone know where I am going wrong? As I have put sprites into data grids in the past without any issue, so I don't understand what could be going wrong.
 

Simon Gust

Member
A function I am working on requires a sprite index to be put intoa DSGrid I have created. I have attempted it like so.
Code:
ds_grid_set(grid, 3, 0, spr_coin);
My issue is, the sprite index is not going into the data structure. When I look at that cell in the debugger, it just holds 0.

If I use this code:
Code:
ds_grid_set(grid, 3, 0, string(spr_coin));
The cell holds "0".


Does anyone know where I am going wrong? As I have put sprites into data grids in the past without any issue, so I don't understand what could be going wrong.
The grid is showing the correct value (or text).
You have to understand what sprites actually are or any resource in the resource tree. Essentially they're just numbers, starting from 0.
I am assuming spr_coin is the first sprite in your resource tree. The names for the resources are replaced by their numbers on compile and only have names so you know what you're dealing with.
So, instead of a string just put spr_coin into it. Or keep the string and call asset_get_index() on it but I don't recommend that.
 
F

Frolacosta

Guest
The grid is showing the correct value (or text).
You have to understand what sprites actually are or any resource in the resource tree. Essentially they're just numbers, starting from 0.
I am assuming spr_coin is the first sprite in your resource tree. The names for the resources are replaced by their numbers on compile and only have names so you know what you're dealing with.
So, instead of a string just put spr_coin into it. Or keep the string and call asset_get_index() on it but I don't recommend that.
I never really considered that it would be putting a 0 into the data structure because that is the sprite position in the resource tree! Interestingly, moving the sprite further down the tree so it is not in position 0 has fixed the issue!

I have no idea why it was causing an issue being at position 0, but thank you for explaining how the resource tree works!
 

TheouAegis

Member
It never caused an issue. Well, it did but the issue was your fault.

A grid defaults to 0. It is your responsibility to know what values will be in the grid and clear the grid with a value of -1 first.

If testing if a value is set, it is your responsibility to know what a true false is based on the content of the cells. If you shortcut boolean checks like

if grid[#3,4]

that will return false on 0. You'd have to |1 that value to prevent 0 from being false, or simply check if the value is greater than -1.

if grid[#3,4] | 1

or

if grid[#3,4] > -1
 
Top