• shared.lua local
    2 replies, posted
Hi 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? client: [CODE]include( "autorun/sh_test.lua" ) -- if I type here, local variable = 1, then it works local function test() end[/CODE] sh_test: [CODE] local variable = 1 [/CODE] 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.
Sorry, you need to Log In to post a reply to this thread.