Jump to content




[Solved] Trying to understand coroutine


  • You cannot reply to this topic
2 replies to this topic

#1 darkrising

  • Members
  • 234 posts
  • LocationScotland

Posted 11 May 2013 - 10:22 AM

I've been trying to learn how coroutine work, but with not much success. Below is my testing code, what have I done wrong?

function one()
  while true do
	print("one")
	sleep(1)
	print("two")
	sleep(1)
  end
end

function two()
  while true do
	print("three")
	sleep(1)
	print("four")
	sleep(1)
  end
end

o = coroutine.create(one)
co = coroutine.create(two)

while true do
  coroutine.resume(o)
  coroutine.resume(co)
end

--print(coroutine.status(co))
print("\nThe end.")


#2 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 11 May 2013 - 11:13 AM

The thing is the infinite loop. You cannot resume a coroutine wich is dead. If you dont know the term coroutine and death together, you should read this tutorial by Bubba.

#3 darkrising

  • Members
  • 234 posts
  • LocationScotland

Posted 11 May 2013 - 12:19 PM

Thank you for passing me that, it has helped immensely!





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users