Very interesting & useful articles.
About global variables, I don’t use _G to define them in my game project. I’ve been puzzling over whether it’s important to use _G, or not-to-add “local” in front of a variable to declare it as global. Is there any difference?
For the time being, all global variables are declared in my main.lua, and just to make sure I don’t end up modifying any exiting global variables that the system uses, I set up mine to a table in main.lua, like this:
[lua]-- just to make sure I know what global variables are added, insert them to the list up top as I go
gamedata = {}
gamedata.fontName1 = nil;
gamedata.fontName2 = nil;
gamedata.fontSize = nil;
.
.
.
– later on, the global variables are defined where they are used the first time around (and once defined, it never gets changed)
– I’m considering to move these definition up top where the global variables are first declared (but not implemented yet).
gamedata.fontName1 = “some custom font1”;
gamedata.fontName2 = “some custom font2”;
gamedata.fontSize = 10;
– as an example, I use the gamedata.fontSize as the anchor, and use it like this in my code
textObject1.size = gamedata.fontSize;
textObject2.size = gamedata.fontSize;
textObject3.size = gamedata.fontSize +10;
.
.
.[/lua]
I’m wondering what might be the reason to declare variable as local in main.lua. I could be totally wrong, but I’m thinking/guessing that main.lua is always in memory/present throughout the runtime session, so whatever is local to main.lua is available to any module my project may access. And if so, what might be the point of declaring variables as local in main.lua – is my train of thought totally mistaken? [import]uid: 67217 topic_id: 16282 reply_id: 60646[/import]