Fixer90
Member
So I have this code in the Room Start event, and the object is persistent:
What this does is makes it to where every tile in every room that has a depth of 999990 gets its own collision object. This works perfectly... but if I have a room with no tiles at that depth, the game crashes and gives me an error message. I tried putting an if check before the for check:
but even this didn't work. The same error message pops up: "Tile does not exist. Yada-yada-yada, instance_create(tilet_get_x(walls), tile_get_y(walls), obj_collision);"
TL;DR: The code works great, but if I don't have tiles on that depth, it crashes the game. How do I make it work even if there are no tiles on that depth?
Code:
var walls = tile_get_ids_at_depth(999990);
for(var w = array_length_1d(walls), i = 0; i < w; i ++)
{
instance_create(tile_get_x(walls[i]), tile_get_y(walls[i]), obj_collision);
}
Code:
if(array_length_1d(walls) >= 1)
TL;DR: The code works great, but if I don't have tiles on that depth, it crashes the game. How do I make it work even if there are no tiles on that depth?