1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Question - Code Game Bug I Can't Figure Out, Please Help

Discussion in 'GameMaker Studio 2 Community Tech Support' started by twalkerp, Aug 12, 2019.

  1. twalkerp

    twalkerp Member

    Joined:
    Oct 12, 2018
    Posts:
    29
    I am almost done with my Tower Defense game, but cannot seem to figure out this annoying and game breaking bug.

    When I press the Combine(upgrade) button on my towers, if I press it as the same time as a monster from the current monster wave is being spawned to my path, one monster from my very first level of monsters(goblin) will appear at cursor/button position.

    It's always a Goblin, known in code as enemies[0.0];

    My towers then will go nuts shooting the top left of screen.

    Image of Issue:
    https://imgur.com/xzKgjZ6

    Here is the code for spawning my enemies: Alarm[0]
    Code:
    if(timer_set == false){
        if(enemies[arraySpot, 1] <= 0){
        arraySpot = clamp(++arraySpot, 0, array_height_2d(enemies) -1);   
        }
    
    displayWaveTimer = false;
    var enemy = instance_create_layer(x, y, layer, enemies[arraySpot, 0]);
    
        with(enemy){
        path_start(other.myPath, enemy.mySpeed, path_action_stop, true);
        }
    
    
    ++currentEnemies;
    ++currentLevelEnemies; //just for printing text
    enemies[arraySpot, 1] -= 1;
    
    if(currentEnemies < maxEnemies )
        alarm[0] = spawnRate;
    }
    
    if(enemies[arraySpot, 1] <= 0)
    {
    timer_set= true;
    }
    
    Here is the code for my upgrade(Combine Tower) button On Tap event:
    Code:
    drawInfo = true;
    
    if(instance_number(myTower.object_index) >=2)
    {
      var _x = myTower.x;
      var _y = myTower.y;
      var _rand_inst = myTower;
       while(_rand_inst == myTower)
        {
            _rand_inst = instance_find(myTower.object_index, irandom(instance_number(myTower.object_index)-1));   
        }
           
        var randomAdvancedTower = random(array_height_2d(objTowerMaker.atowers));
        var randomRareTower = random(array_height_2d(objTowerMaker.raretowers));
       
            if(myTower.towerTier == 1)
            {
       
            instance_create_layer(_x,_y,"Instances",objTowerMaker.atowers[randomAdvancedTower,0]);
            instance_destroy(myTower);
            instance_destroy(_rand_inst);
            instance_destroy(objUpgradeParent);
            }
            else if(myTower.towerTier == 2)
            {
               
            instance_create_layer(_x,_y,"Instances",objTowerMaker.raretowers[randomRareTower,0]);
            instance_destroy(myTower);
            instance_destroy(_rand_inst);
            instance_destroy(objUpgradeParent);
            }
            else
            {
            exit;
            }
       
    }
    
     

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