Re: Lua local question
Posted: Mon Aug 22, 2011 4:20 pm
In Kurosuke, I require "scenes" from the main file, the first of which has this line in it:
This startup file has tons of variable like this in it:
Most of these variables don't get mentioned again until we're two more scenes into the game (ie, two more requires deep).
If a variable is not defined as local, it is global to the entire game. It doesn't matter which file it is defined in. Think in terms of functions, not files.
Edit: following statement is false, apparently.
So, if you want a variable to be local to a file, you have to make sure that file's contents are inside a big function, otherwise it is effectively global again (it's effectively local will refer to the whole program, if I remember correctly).
Code: Select all
require "subclass/startup"
Code: Select all
currentLevel = "level_1"
multiplayer = 1
players = {}
If a variable is not defined as local, it is global to the entire game. It doesn't matter which file it is defined in. Think in terms of functions, not files.
Edit: following statement is false, apparently.
So, if you want a variable to be local to a file, you have to make sure that file's contents are inside a big function, otherwise it is effectively global again (it's effectively local will refer to the whole program, if I remember correctly).