• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Legacy GM Cant Find The Infinite Loop In this code

N

NotMe

Guest
I got this code


///Setting up the level
// Set the grid width and height
var width = room_width div CELL_WIDTH;
var height = room_height div CELL_HEIGHT;

// Create the grid
grid = ds_grid_create(width, height);

// Fill the grid with the void
ds_grid_set_region(grid, 0, 0, width, height, VOID);
for(var yy = 0; yy < height; yy++) {
for(var xx = 0; yy < height; xx++) {
if(tile_layer_find(10000000, xx, yy) != -1) {
grid[# xx, yy] = WALL;
}
}
}
for(var yy = 0; yy < height-1; yy++) {
for(var xx = 0; yy < height-1; xx++) {
if(grid[# xx, yy] == WALL) {
instance_create(xx, yy, obj_wall);
}
}
}

to setup the walls
but the game wont run because there's an infinite loop that i cant fine
thanks if u can help me :)
 
N

NotMe

Guest
oh sorry wrong forum iam so sorry i didnt notice
 
Last edited by a moderator:
Both of your nested for loops are incorrect.
This one:
Code:
for(var xx = 0; yy < height; xx++) {
and this one:
Code:
for(var xx = 0; yy < height-1; xx++) {
should be:
Code:
for(var xx = 0; xx < width; xx++) {
and:
Code:
for(var xx = 0; xx < width-1; xx++) {
What you were doing was incrementing xx, but accidentally checking that yy< height instead of checking that xx<width. So as yy was not being incremented, it was always going to be <height, and therefore never getting out of the for loop.
 
Top