LUA code patch for - Forest - Seek-and-Hide - posted intro/ overview / and default code

Default code for LUA - - Copy-Paste into the editor to start


-- Gather 4 lightstones to defeat the Brawler.
-- If you find a lightstone, hide.

local checkTakeHide = function(item)
    if item then
        -- The item is here, so take it.
        hero:moveXY(item.pos.x, item.pos.y)
        -- Then move to the center of the camp (40, 34)
        
    end
end    

while true do
    -- Move to the top right X mark.
    hero:moveXY(68, 56)
    -- Search for a stone there.
    local stone = hero:findNearestItem()
    -- Call checkTakeHide() with the argument: stone
    checkTakeHide(stone)
    
    -- Move to the top left mark.
    
    -- Search for a stone.
    
    -- Call the checkTakeHide() function.
    -- Pass in the result of your search as an argument.
    
end

Overview for LUA


You can use a function parameter as a variable inside the function. But also you can add additional instructions, which are not related to the parameter. For example:
local checkAndHit = function(unit)
    if unit then
        hero:attack(unit)
        -- An additional instruction without 'unit'.
        hero:say("I'm dangerous!")
    end
end

Also, don’t forget you can call the same function as many times as you want.

hero:moveXY(10, 10)
local enemy = hero:findNearestEnemy()
checkAndHit(enemy)
-- Next point.
hero:moveXY(70, 10)
enemy = hero:findNearestEnemy()
checkAndHit(enemy)

Please feel free to use this to help you with the level until the patch is applied.

My student is trying to do the “Seek-and-Hide” lesson in Lua but every time he starts the level he gets the following error message( I’m hoping that your solution above helps him out):

“Expected “#”, “(”, “-”, “–”, “–[”, “…”, “0”, “;”, “[”, “break”, “debugger”, “do”, “false”, “for”, “function”, “if”, “local”, “nil”, “not”, “repeat”, “return”, “that”, “true”, “while”, “{”, [\r\t\n], [’’], [’], [0-9] or end of imput but “/” found.”