-snip
There is a handful of problems with the test code posted, mostly having to do with the use of coroutines.
coroutine.create(func) – This function will return what I am going to call a thread. I will touch on threads in a second.
coroutine.resume(thread, arg1, arg2, etc…) – This function will resume a thread. It will run the passed thread until it reaches a coroutine.yield (os.pullEvent and os.pullEventRaw both call coroutine.yield). The arguments passed after the thread in coroutine.resume will be what will be received by coroutine.yield.
coroutine.yield(filter) – This will cause the thread to yield allowing you to come back to it later without the requested information in the filter. The filter is returned by the coroutine.resume that resumed the thread.
example for create, resume, and yield:
function hello()
print("hi")
coroutine.yield("filter example")
print("hello")
coroutine.yield("hello")
print("another message")
end
local co = coroutine.create(hello)
local filter = coroutine.resume(co) --# the first time you resume a coroutine it starts from the very beginning, it doesn't need args.
print(filter) --# will print "filter example"
filter = coroutine.resume(co,"filter") --# this is resuming at the point of the first yield
print(filter) --# will print("hello")
coroutine.resume(co,"hello")
print(coroutine.status(co)) --# will print dead because it is at the end of the function
For what you are wanting though, it would be easier to just use parallel api, as you would need to make a full coroutine manager to do it.
Try something like this as a test:
function testLoop()
term.setCursorPos(1,1)
term.write(math.random(1, 50))
end
function loopMe(n)
lm = true
term.setCursorPos(1,2)
turtle.forward()
turtle.up()
turtle.down()
turtle.down()
turtle.turnLeft()
turtle.turnRight()
turtle.turnRight()
turtle.turnLeft()
turtle.up()
term.setCursorPos(1,2)
if i == n then lm = true end
str = str + 1
end
parallel.waitForAny(function() loopMe(3) end,function() while true do testLoop() sleep(.05) end)
I haven't tested that but I believe it should work for what you are wanting.