Game Dev 2 / Stick Shift / C++

Hey, what am I doing wrong? The “ogre-f” variable is not counted towards the goal, so the boss never gets defeated, the hero does not say his sucess line and the level is not finished sucessfully.

// Now you can create a custom goal for your game
// using the game.addManualGoal(description) method!

// Enemy Behavior
auto onSpawn(auto event) {
    auto unit = event.target;
    while(true) {
        auto enemy = unit.findNearestEnemy();
        if(enemy) {
            unit.attack(enemy);
        }
    }
}

// Update our manual goals whenever an enemy is defeated.
// This is an example of an algorithm using if-statements.
auto onDefeat(auto event) {
    auto unit = event.target;
    if (unit.type == "scout") {
        scoutsDefeated += 1;
        hero.say("Scout down!");
    }
    if (scoutsDefeated >= 3) {
        // Use setGoalState to mark scoutGoal complete.
        game.setGoalState(scoutGoal, true);
        hero.say("All Scouts down!");
    }
    if (unit.type == "ogre-f") {
        // Use game.setGoalState to mark bossGoal complete.
        // Don't forget about the second parameter.
        if (ogresDefeated >= 1){
        hero.say("Defeated the big boss!");
        }
    }
}




auto hero = game.spawnPlayerXY("captain", 12, 56);

auto generator = game.spawnXY("generator", 41, 13);


auto scoutGoal = game.addManualGoal("Defeat all scouts");




auto scoutsDefeated = 0;

int main() {
    // Spawn a few scouts, a boss, and a maze.
    game.spawnMaze(5);
    game.spawnXY("scout", 60, 58);
    game.spawnXY("scout", 28, 29);
    game.spawnXY("scout", 61, 24);
    auto ogref = game.spawnXY("ogre-f", 60, 12);
    // Spawn and configure the hero.
    hero.maxHealth = 550;
    hero.maxSpeed = 10;
    hero.attackDamage = 1000;
    // Spawn a munchkin generator.
    generator.spawnDelay = 5;
    generator.spawnType = "munchkin";
    // Survive goal.
    game.addSurviveGoal();
    game.spawnXY("potion-medium", 28, 12);
    // addManualGoal adds an incomplete goal with a description
    // The description will be shown to players.
    // NOTE that we save it in a variable called scoutGoal
    // Use addManualGoal to add a goal to defeat the boss
    // Save it in a variable called bossGoal
   auto bossGoal = game.addManualGoal("Defeat the boss");
    game.setActionFor("scout", "spawn", onSpawn);
    game.setActionFor("ogre-f", "spawn", onSpawn);
    // Count how many scouts are defeated.
    float scoutsDefeated = 0; 
    float ogresDefeated = 0;
    // Assign the onDefeat handler to the ogres" "defeat"
    // NOTE that munchkins don't count toward success!
    game.setActionFor("scout", "defeat", onDefeat);
    game.setActionFor("ogre-f", "defeat", onDefeat);
    
    return 0;