Trying to make my code modular from the outset, I have functions related to map generation in the file map.lua, like this:
Code: Select all
map = {}
function map.createMap()
...
return map
Code: Select all
player = {
["xPos"] = 10,
["yPos"] = 20
}
return player
Code: Select all
local mapModule = require("map")
local playerModule = require("player")
Code: Select all
mapModule.createMap()
My other question is about global variables. In my game I'd like to make a small number of variables (well, really pseudo constants) accessible to all modules, for example the size of the map, MAPSIZE. Where's the best place to define such things? I read something about _G, the environment table but not sure if that's a good idea.