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

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


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.


while true do
    local enemy = hero:findNearestEnemy()

Introduction for LUA

Practice using a parameter passed into a function:

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

local enemy = hero:findNearestEnemy()
-- 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!")

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