Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

BACK-TO-BACK level lua


#1

On level ‘Back to back’ in forest I get ReferenceError: enemy is not defined when my code looks like:

while true do
    enemy = hero:findNearestEnemy()
    if enemy then
        hero:attack(enemy)
        hero:attack(enemy)
    else
        hero:moveXY(40, 34)
    end
end

#3

@szymex73

It should be:

local enemy = hero:findNearestEnemy()