If your stages can simply be “numbered” progressively, from main.lua, simply do a “for” loop requiring each level_#.lua and returning its object into a table.
As an example:
[lua]game = {
basepath = “levelsdir/level_”, – root dir and basename for levels
levels = {}, – this table will contain each levels’ object and load function
numlevels = 5,
curlevel = 1 – current level. Will be incremented by “change level” management code
}
for i=1,game.numlevels do – assuming levels are from 1 to 5
game.levels[i] = require(basepath…tostring(i)…".lua")
end
– clearly you will need some management code to change levels first, somewhere
– assuming each level has a load function which creates all display objects and logics, etc.
– the next line will effectively display and run level 1
game.levels[game.curlevel]:load()[/lua]
This should give you at least the basic “main.lua -> levels” system up. [import]uid: 5750 topic_id: 1638 reply_id: 12345[/import]