Why does the global function work and the local one doesn’t? It won’t recognise the “Change” but will recognise the “Method”. Also how do i access the global function from another script?
local carColor = {
Change = print
}
local function carColor:Change(a, b)
end
----------------------------------------
local someObject = {
Method = print
}
function someObject:Method(a, b)
--
end
local functions can only access anything in that is below itself, unless it is local. That is why it can only get the object method as the car color table is above the local function. Why? This is because lua reads code line by line.
Wait so how does the function only see below? Lua reads it line by line so that means that it should be able to read anything above and nothing below unless its called with arguments. And how does the function not see the table, but you can access the table from inside the function?
Apologies I may have mixed it up, you are correct it should be able to read all over above the function. I do not know the solution entirely. However I do know that functions used similarly in module scripts are always global, so similar logic could be applied to this situation.