Useful Competitors Lua help


#1

Hi community! I got stuck at this level with no idea what causes the problem. Any help appreciated.
The hero just stand around instead to move on to the next cycle at the poison check.

while true do
    local enemy = hero:findNearestEnemy()
    local item = hero:findNearestItem()
    if not enemy.type == "peon" then
        hero:attack(enemy)
    elseif not item.type == "poison" then
        local pos = item.pos
        local x = pos.x
        local y = pos.y
        hero:moveXY(x, y)
    end
end


#2

You want two if-statements at the first layer of your while-true, not an if/elseif. Check existence, then check the type.

Also, from what I can see, not in Lua comes before ==, so you want to use parenthesis to assist with the order of operations.

if not enemy.type == "peon" then -- if (not enemy.type) is peon then
end

vs

if not (enemy.type == "peon") then -- if not (enemy.type is peon) then
end

#3

Hmm… I see thanks for the quick response :slight_smile: