Help with Game Dev level 5 Chokepoint, Lua

I am back again with an issue on Level 5 of Game Dev Chokepoint. I have the proper code I believe, but it appears when the game runs the 1st soldier will kill 1 enemy then do nothing, the 2nd and 3rd soldiers do nothing at all from the start, and the 4th soldier appears to be working fine. Here is my code:

      -- <%= else_unit2 %>
-- <%= ogres_advancing %>
-- <%= spawn_soldiers %>

function defendLane(event)
    -- <%= remember_unit %>
    unit = event.target
    -- <%= start_x %>
    startX = unit.pos.x
    while true do
        enemy = unit:findNearestEnemy()
        -- <%= if_unit %>
        if enemy then
            -- <%= use_attack %>
            unit:attack(enemy)
        else
            -- <%= else_unit2 %>
            unit:moveXY(startX, 16)
        end
    end
end        

game:spawnXY("soldier", 9, 16)
game:spawnXY("soldier", 30, 16)
game:spawnXY("soldier", 54, 16)
game:spawnXY("soldier", 75, 16)

-- <%= set_action %>
game:setActionFor("soldier", "spawn", defendLane)

I have discovered my issue. I did not set the variables as local variables which I assume caused the game to not understand what they were.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.