• 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 Instance Create at end of Repeat

A

AquaticChaos

Guest
So I've been following a Youtuber's tutorials on random generation (Name can be discussed if needed) and finished it up, but now I want to add a bit to a line of code.
Code:
//Create level using 1000 steps;
repeat(500) {
    //Place floor tile at controller position
    grid[# cx, cy] = FLOOR;
    
    //Randomize direction of controller
    if(irandom(odds) == odds) {
        cdir = irandom(3);
    }
    
    //Move controller
    var xdir = lengthdir_x(1, cdir*90);
    var ydir = lengthdir_y(1, cdir*90);
    cx += xdir;
    cy += ydir;
    
    //Make sure we don't move outside grid
    cx = clamp(cx, 1, width-2);
    cy = clamp(cy, 1, height-2);
}
This small line of code was put immediately after the previous code, but it didn't work.
Code:
            //Add stairs
            var sx = cx*CELL_WIDTH+CELL_WIDTH/2;
            var sy = cy*CELL_HEIGHT+CELL_HEIGHT/2;
            instance_create(sx, sy, obj_Stairs);
Any suggestions would be absolutely helpful to my cause.
 
I don't see anything immediately wrong, but I think you should use the debugger to trace through your loop and code and see why it doesn't work. Does the code never get hit? Does it get hit but just doesn't do what you expect? Get comfortable with the debugger and you won't have to rely on the forums to help (which means you don't get stuck as often and can move forward more rapidly)
 
A

AquaticChaos

Guest
The problem with using the debugger is that this code is in the Create event. And since the object's already in the room this action will occur immediately following the game opening. Heck, it doesn't take time at all to do it.

Still, I'll try to resolve the problem.
 
A

AquaticChaos

Guest
I've done just that, but I still seem stuck. Fortunately the object does appear sometimes. Other times it's nowhere to be seen. My guess is that the code was put in the wrong spot.
 
A

AquaticChaos

Guest
Aaand the problem seemed easier than I expected. Just had to put the small code INSIDE the repeat statement (And to make sure it doesn't loop, add a switch) rather than directly outside it.
 
Top