Devyn
Devyn

Reputation: 2275

Lua function range

I got error if I do like this. What should I do?

local function one()
    local function two()
        local function three()
            callMe() -- got error here
        end
    end
end

local function callMe()
    print ("can't call :(")
end

callMe()

Upvotes: 1

Views: 729

Answers (2)

daurnimator
daurnimator

Reputation: 4311

locals have to be declared before used:

local callMe
local function one()
    local function two()
        local function three()
            callMe() -- got error here
        end
    end
end
function callMe()
    print ("can't call :(")
end
callMe()

Upvotes: 6

Jasmijn
Jasmijn

Reputation: 10452

As well as the missing () for one, two and three, like Bart Kiers said, calling three() would error, as callMe is a local function outside of three's scope, so it doesn't know that function.

Upvotes: 4

Related Questions