shared.lua local


I have a shared.lua, and in my cl_.lua I include it at line 1.
Why can’t I use local variables defined in shared.lua, in the client file?


include( "autorun/sh_test.lua" ) 
-- if I type here, local variable = 1, then it works
local function test()



local variable = 1

variable is nil in the test function.

Local variables only exist within the scope they are defined. Different file = different scope.

Because that’s how Lua works. local variables can’t be accessed from outside of the file or scope they are created in. That’s the point o their existence. If you want to access that variable or function, you’ll have to make it global.