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

Legacy GM Scanning a room's objects, storing them in a grid, reproducing different objects based on grid value

A

AnimusRex

Guest
So I have a design room wherein I am scanning all my placeholder block objects, and saving them in a grid.

The code is as follows;
Code:
//Making design room invisible
if background_exists(bg_roomdesign)
{background_delete(bg_roomdesign)}

//Setting block size
blocksize = 32

var width = room_width div blocksize; //Number of columns
var height = room_height div blocksize; //Number of rows

// Creating the grid
blockgrid = ds_grid_create(width, height)

// Iterate through every cell in the grid
for (var i = 0; i < width; ++i)
{
    for (var j = 0; j < height; ++j)
    {
        var translatedx = (i*blocksize)+(blocksize/2);
        var translatedy = (j*blocksize)+(blocksize/2);
        var thisobject = collision_point(translatedx, translatedy, all, false, false);
        ds_grid_set(blockgrid, i, j, (thisobject));
    }
}
Then I'm trying to create objects based on the objects found in the design room, using the following code:
Code:
for (var i = 0; i < width; ++i)

{
    for (var j = 0; j < height; ++j)
    {
    if ds_grid_get(obj_arraycontroller.blockgrid,i,j)!= noone //As long as the grid value at i and j isn't zero
    //Create an instance at i*blocksize, j*blocksize to convert it to the real gcoords
        {
        instance_create(i*blocksize, j*blocksize, obj_block1) //Call the object based on what was saved in the grid cell
        }
    }
}
What am I doing wrong?
 
A

AnimusRex

Guest
You can use show_debug_message, and run it through every step in your code.
I don't really know how to debug in GM; is there a way to at least confirm that I'm populating my grid with values? Every time I've used show_debug_message it either does nothing, or I'm using it improperly.
 
W

whale_cancer

Guest
I don't really know how to debug in GM; is there a way to at least confirm that I'm populating my grid with values? Every time I've used show_debug_message it either does nothing, or I'm using it improperly.
All show_debug_message does is pass a string to the compile window. You need to pass useful strings that let you know what is happening to get any use out of it. How have you been using it?

Edit; You seen to be storing the IDs of the objects. You can't use those IDs to create objects. You could store the object_index of an object to recreate them. Personally, I use an ini file with dynamic section names to do what you are trying to.

Edit2: Yeah, the error message you are getting would be super useful.
 
Last edited:
A

anomalous

Guest
What indicated it was wrong, an error or which thing wasn't occurring?

this line:
if ds_grid_get(obj_arraycontroller.blockgrid,i,j)!= noone //As long as the grid value at i and j isn't zero

I'm use to seeing two things here.
1. when you create the grid, you may want to set all grid cells to a default value using ds_grid_clear (clear to noone looks like you want)
2. noone has a specific value, yet you wrote "isn't zero". If you want to check 0 check 0. If you want to check noone check noone. noone is -4 I believe. But in any case, simply check what you expect. Your code would be true if that value was 0...
 
Top