Local variables across files and functions?

So as I have understood you should have as many local variables as possible, right?
My problem is that my game is level based with one main lua file named level.lua and then I have one file for each level that says which setups that specific level by changing things in level.lua.
Currently all those things that are changed in level.lua are global variables, is it possible to have local variables and access them from another file? The same question about functions. [import]uid: 24111 topic_id: 18206 reply_id: 318206[/import]

Hi,

Local variables are private, so they’re inaccessible outside of the current scope. If you want both the speed benefits of local variables plus accessibility from outside your module, you can do something like this in your module:

[lua]local MyModule = {}

local myVariable = “foo”
local function myFunction()
print(“myFunction()”)
end

function getMyVariable()
return myVariable
end

MyModule.myFunction = myFunction

return MyModule[/lua]

Now, whenever you need to access your variable or function from within the module, you can reference myFunction or myVariable.

If you need to access these from outside the module, you can call moduleName.myFunction() or moduleName.getMyVariable().

Of course, if the only purpose of these variables is to be accessed from outside of the module, then there’s really no point in going through these extra steps, since I don’t think you’ll get any benefits from declaring the references as local. [import]uid: 1294 topic_id: 18206 reply_id: 69565[/import]

Thanks! [import]uid: 24111 topic_id: 18206 reply_id: 69569[/import]