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.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
local MyModule = {}
 
local myVariable = "foo"
local function myFunction()
  print("myFunction()")
end
 
function getMyVariable()
   return myVariable
end
 
MyModule.myFunction = myFunction
 
return MyModule

Thanks!

views:1628 update:2011/11/26 9:01:35
corona forums © 2003-2011