is it possible to create a await function?
for example..
if await(60,"my identifer") then --done end |
here is my code
function await(t,id) if not cofun[id] then --don't know how to return true here add(cofun,cocreate(function() while t>0 do t-=1 yield() end end)) else return false end end function coupdate() for c in all(cofun) do if costatus(c) then coresume(c) else del(cofun,c) end end end |
EDIT: idk if this is possible but maybe something like this..
--id is determined by function execution index if await(60) then --done end |
for example..
await(60)--await id 0 await(60)--await id 1 await(60)--await id 2 --nextframe await(60)--await id 0 await(60)--await id 1 await(60)--await id 2 |



yield cannot return value - so you need to provide a function to your await that will be triggered when done.
Something like:
function wait_async(t,fn) return cocreate(function() -- wait... for i=1,t do yield() end -- trigger user code fn() end) end c=wait_async(60,function() print("done") end) function _update() coresume(c) end |



huh odd I guess I could do this with a timer instead of coroutines.
thankyou
[Please log in to post a comment]