Codea Coroutines Not Working

I am trying to use coroutines in an app, but the debugger is throwing errors. Below is a simple example of a coroutine and the output when the program is run.


function setup()
    -- Do your setup here
    
    local b = coroutine.create(function() print("Hello World") coroutine.yield() end)
    
    coroutine.resume(b)
end

function draw()
    background(120, 100, 30)
end

Output:

…odea.app/Frameworks/LuaKit.framework/vscode-debuggee.lua:706: table index is nil
stack traceback:
…odea.app/Frameworks/LuaKit.framework/vscode-debuggee.lua:706: in function ‘vscode-debuggee.addCoroutine’
…odea.app/Frameworks/LuaKit.framework/vscode-debuggee.lua:62: in function ‘coroutine.create’
Main.lua:4: in function ‘setup’

This doesn’t solve your problem, but it provides some perspective.

Placing your coroutine code before setup() works, so the issue might be with setup() itself.

Give this a shot. Again, it’s not a solution, but it might help narrow down where things are going wrong:

function helloworld()
    print("Hello, world!")
    coroutine.yield()
end

local c = coroutine.create(helloworld)
coroutine.resume(c)

function setup()
    print("Nothing happening in here (except this print statement)...")
end

function draw()
    background(0)
end

that’s a really interesting issue, i seem to have nailed it down a bit tighter on accident:

if you define a global variable like createCoroutine = coroutine.create before setup, then it works as expected, but if you try to use coroutine. after there is a problem, the work around should be good enough

@Beckett2000 I think judging by the stack trace it would be safe to say that this is is an issue with the recent integration of AirCode with VS Code.

I wouldn’t worry too much about something you are doing here. The example in your first post looks perfectly correct to me and should run.

I can also confirm that this is working again on the latest beta 3.8.1 (383) so once the dev team update the build on the app store this shouldn’t be a problem :slightly_smiling_face:

Any news on when this might get fixed in the version on the app store? I’ve just run into this problem, and I have the latest version which is 3.8 (382).