This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
darkrising's profile picture

[Solved] Trying to understand coroutine

Started by darkrising, 11 May 2013 - 09:22 AM
darkrising #1
Posted 11 May 2013 - 11: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.")
Engineer #2
Posted 11 May 2013 - 12:13 PM
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.
darkrising #3
Posted 11 May 2013 - 01:19 PM
Thank you for passing me that, it has helped immensely!