Code: Select all
_G.GlobalData = {}
MainWaiting = false
MainWaitingTimer = 0
_G.wait = function(sTime)
MainWaitingTimer = sTime or 1 / 30
MainWaiting = true
coroutine.yield()
end
function love.load(arg)
GlobalData.MainThread = coroutine.create(function() -- This will separate the game from the main thread calling love.update and love.draw.
wait(2)
require("MainMenu")()
end)
coroutine.resume(GlobalData.MainThread)
end
function love.update(deltaTime)
if MainWaiting then
MainWaitingTimer = MainWaitingTimer - deltaTime
if MainWaitingTimer < 0 then
MainWaiting = false
coroutine.resume(GlobalData.MainThread)
end
end
end
Code: Select all
return function()
print("Hello, World!")
end
However, when I try waiting inside the main menu file, rather than inside main.lua, it will give me this error:
Error: Attempt to yield across C-call boundary.
Debugging the traceback of the callstack, I've pinpointed the problem. The problem, I found was that that the require() function is a C function, meaning when I try yielding, it will halt the thread past a C function.
Is there any good way to get around this? I want to be able to use multiple files in order to organize my game efficiently. And I also want to run the game's thread separate from the thread that love.draws and love.updates in order to time my game into a certain sequence (For cutscenes and such) within the same function.