Falling blocks not behaving correctly [Solved]

So I'm making this falling block game but I've hit a snafu. Basically, after blocks have matched with neighbours and been destroyed I can't get the blocks above to fall down into their new spots like I want them to.

The "cube_list_pop" script populates a list with all the instances of blocks on the playing field and puts them into "global.cube_list".
The "check_empty_vert" script checks how many empty squares there are below the current square within the playing field and returns that number.
Alarm[5] only contains "y = y+50"

Code:
        script_execute(cube_list_pop);
        
        for (i = 0; i < ds_list_size(global.cube_list); i += 1)
        {
            inst = global.cube_list[| i];
            with (inst)
            {
                dropAmount = script_execute(check_empty_vert);
                
                for (ii = 0; ii < dropAmount; ii +=1)
                {
                    alarm[5] = global.drop_speed;
                }
            }
        }
When using this code I get "hanging" blocks in the air. I'm guessing that having an alarm in a for loop doesn't work as I intended. It seems as if the alarm is only called once, the block hangs in the air after falling one square down.

If I instead use this code...

Code:
        script_execute(cube_list_pop);
        
        for (i = 0; i < ds_list_size(global.cube_list); i += 1)
        {
            inst = global.cube_list[| i];
            with (inst)
            {
                dropAmount = script_execute(check_empty_vert);
                
                if (dropAmount > 0)
                {
                    y = y + (50*dropAmount)
                }
            }
        }
...all of the blocks end up in the right places but they do it instantly. Using alarms I want to get that old school effect of the blocks moving one square at a time using "global.drop_speed" as how fast they drop from one square to another.

Any tips or solutions?
 

3dgeminis

Member
I would check if you can move, and the motion itself in the alarm event of each cube.
I would activate it in the Create event and then only use the alarm event.
 
I solved it this way.

Code:
        script_execute(cube_list_pop);
        
        for (i = 0; i < ds_list_size(global.cube_list); i += 1)
        {
            inst = global.cube_list[| i];
            with (inst)
            {
                dropAmountLocal = script_execute(check_empty_vert);
                alarm[5] = global.drop_speed;
            }
        }
Where the alarm looks like this:

Code:
if (dropAmountLocal > 0)
{
    y = y+50;
    dropAmountLocal -=1;
    
    if (dropAmountLocal > 0)
    {
        alarm[5] = global.drop_speed;   
    }
}
dropAmountLocal is a local variable stored in the blocks. My new problem is trying to have all of the "dropping" done before the player regains controls. Sort of waiting for the alarms to stop. But that's another topic.
 
Top