Sharing vars around .lua files
Posted: Fri Nov 21, 2014 9:30 pm
I would ask this question to be sure I'm not doing a best practice on how I should share a specific information around game lua files.
For example, I would share the game name "Super Generic Adventure" around my code for various reasons, for example the window title, or the name of the folder with the save games inside.
I didn't started seriously to code with lua, but reading examples around make me think I should share these data with functions so something like this:
I never programmed a video game and I never worked with lua, but I'm pretty sure it's easy to became crazy on organize it's code if it isn't organized as it should be, so is that a good practice or does exist better ways to do that?
I've noticed lua supports classes, so I suppose this is a must for who would write a well organized video game.
For example, I would share the game name "Super Generic Adventure" around my code for various reasons, for example the window title, or the name of the folder with the save games inside.
I didn't started seriously to code with lua, but reading examples around make me think I should share these data with functions so something like this:
Code: Select all
-- File A
function getGameName()
return "Super Generic Adventure"
end
-- File B
function saveGameFile()
local gameName = getGameName()
-- do code to save game
end
-- File C
function setWindow()
local gameName = getGameName()
-- do code to set window size and title
end
I've noticed lua supports classes, so I suppose this is a must for who would write a well organized video game.