LUA code patch for - Forest - Tomb Ghost - posted intro/ overview / and default code


#1

default code for LUA - - Copy-Paste the code below into the editor


-- The only exit is blocked by ogres.
-- Hide from the skeletons and defeat the ogres one by one.

-- This function should attack an enemy and hide.
local hitOrHide = function(target)
    --  If 'target' exists:
    
        -- Attack 'target'.
        
        -- Then move to the red mark.
        

end

while true do
    local enemy = hero:findNearestEnemy()
    hitOrHide(enemy)
end

Introduction for LUA


Practice using a parameter passed into a function:

local hitAndRun = function(target)
    if target then
        hero:attack(target)
        hero:moveXY(10, 20)
    end
end

local enemy = hero:findNearestEnemy()
hitAndRun(enemy)
-- Call hitAndRun() with target set to enemy

Overview for LUA


Remember that a parameter is a way of passing information into a function. It is a predefined variable containing whatever was put between the () when the function was called.

Just use the target parameter like you would any variable:

local checkAndDefend = function(target)
    if target then
        hero:say("I see an enemy! I should defeat them!")
    end
end

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


Tomb Raider - code help - what are functions - lua default code for level