#Got this error on my grid-movement code

1 messages · Page 1 of 1 (latest)

chilly comet
#

Array index must be +'ve
at gml_Object_oPlayer_StepNormalEvent_2 (line 93) - if (oCamera.cells[(x div 32) - 1, y div 32 + 1] == 0)

Player Step Event:

chilly comet
#

I know this code sucks BAD, and i'm trying to make it way better

#

also, oCamera create event

var i, j; // Not required but helps speed up 'for loop'

// Use the room's height and width divided by grid size (32) to
// initialize grid with 0
for (i = 0; i <= (room_width div 32); i += 1)
{
for (j = 0; j <= (room_height div 32); j += 1)
{
cells[i,j] = 0;
}
}

// This 'with()' statement will cycle through all pSolid instances
// within our rooms and use their relative x/y properties
with(pSolid)
{
// Use block's x/y divided by grid size to set relative location
// in cells[x,y] array to 1
other.cells[x div 32, y div 32] = 1; // 'other' refers to oCamera

// For performance, we can remove the instance
instance_destroy();
}

#

you can see i'm a rookie, feel free to judge me

chilly comet
#

I'm looking for better ways to do that or anything