1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Game Freezes thanks to enemy Spawner

Discussion in 'Programming' started by LanderMiskolczi, Apr 27, 2019.

  1. LanderMiskolczi

    LanderMiskolczi Member

    Joined:
    Feb 20, 2019
    Posts:
    15
    So My game freezes, Idk if my game is stuck in a loop or something else, Can I have help?
    It only freezes when enemyCount is equal to 7
    OB_SPAWNER
    Create
    Code:
    /// Varabiles
    enemyCount = 0;
    ranX = 2;
    ranY = 2;
    Alarm[0] (Only has a comment)
    Step
    Code:
    /// Spawn Enemys
    if (enemyCount <= 25)
    {
        if (alarm[0] <= 0)
        {
            do
            {
                ranX = irandom_range(0, room_width);
                ranY = irandom_range(0, room_height);
            }
            until (!collision_point(ranX, ranY, ob_wall, true, true))
           
            instance_create(ranX, ranY, ob_enemy);
            enemyCount++;
           
            alarm[0] = room_speed*2;
        }
    }
    Draw
    Code:
    /// Draw enemyCount
    draw_text(room_width-98, 16, 'Enemys: ' + string(enemyCount));
    draw_text(room_width-226, 32, 'RANX/RANY: ' + string(ranX) + '/' + string(ranY));
    I think this is the problem but I have no idea, There is another do loop in my game, but I dont think thats the problem if you want to see it tho, here it is
    SCRIPT I MADE
    Code:
    /// sc_choose_movement_type
    alarm[1] = room_speed;
    dir = choose(0, 1);
    do
    {
        randomX = irandom_range(0, room_width);
        randomY = irandom_range(0, room_height);
    } until (!collision_line(x, y, randomX, randomY, ob_wall, true, true))
    enemyType = enemyMovement[irandom_range(0, 3)];
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,650
    It's both, probably.

    Your first code checks if there is not a wall at a particular point. If there's no wall at that point, it creates the enemy there. Your code does not say, "Don't create the enemy at the specified coordinates if it will place it on a wall", it just says, "Don't create an enemy if there is a wall at the specified coordinates." So then your enemy is getting created so close to a wall that it is now inside the wall.

    Then your other code is trying to find random coordinates such that there's no line collision with a wall from (x,y) to the specified coordinates. ...Except since the enemy is IN a wall, there's ALWAYS a line collision, so it freezes.

    Your spawner code needs to take into consideration the enemy's mask before finalizing its spawn coordinates.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice