Hello. I’ve been trying to learn coroutine but I’ve seem to be in a pickle. I have the following code as an example.
local StartTimer = coroutine.wrap(function()
for i = 1,10,1 do
wait(1)
print("Starting in "..10-i)
end
print('Start!')
coroutine.yield()
end)
while true do wait(20)
StartTimer()
print('Started Timer')
end
When I do StartTimer() twice, it doesn’t seem to fire on the second time for some reason. Could someone help please? I don’t know if I’m just being dumb.
Oh thanks, sorry I didn’t know yield was the problem.
Does this work efficiently?
local StartTimer = coroutine.create(function()
while true do
for i = 1,10,1 do
wait(1)
print("Starting in "..10-i)
end
print('Start!')
coroutine.yield()
end
end)
while true do wait(20)
coroutine.resume(StartTimer)
print('Started Timer')
end