Wombat wrote:Ok, can you tell me a way to solve my problem then?
I am afraid still nobody here understands your problem (certainly I do not), but let me make some guesses.
In lua (or any other interpreted language) you can have variable assignments (like "a=1"), function definitions (like "function love.load() end") and commands (like "print (2)") within a file. The "sane way" is to put all your logic within defined functions (like function stage1() ...end, function stage2() ...end), then, after each function is defined (and every file has been read in), you call every function in order (stage1(); stage2()). This is how you write a manageable code.
It is possible that you skipped the "define function" step, and execute the commands "as you go", reading and executing files one after another (dofile("stage1.lua"); dofile("stage2.lua")), and it could work in your previous game. But this is a bad style, and if you went this way, it will show up just now.
Love is not "execute as you go" environment, instead it runs its own mainloop, and calls a callback functions which you need to define in advance. So you need to define all your functions first (do all "require()'s"), and only after the main.lua script is read in and "executed", the mainloop starts working, calling your functions. So if you do (dofile("stage1.lua"); dofile("stage2.lua")) inside main.lua, you are executing your functions before the mainloop runs (i.e., the game system does not yet work).
The hackish solution would be to convert content of a script to a function (or, encapsulating a script body within a function), lets say, convert:
Code: Select all
-- file: stage1.lua
print("stage 1")
to:
Code: Select all
-- file: stage1.lua
function stage1()
print("stage 1")
end
then you could call your newly defined stage1(), stage2(), ... functions at the desired moments (within love.update() most probably).
Still, I doubt it will work, because writing for love (or for a system with its own mainloop) is different than providing your mainloop (or not using a mainloop at all, in case of sequential executing dofile()).
Sorry for this long post, especially while I still do not understand your problem. I just hope it was close enough.