I've tried to make a control panel for my mining turtle, so I got into using Lua coroutines, because I needed the turtle to listen even if it's currently mining, but every time I call function round() it won't continue. I tried to place print('test') in between every near lines of code and I found that the round() function works untill the turtle.turnLeft() part.
The turtle has following code:
rednet.open('right')
local status = 'None'
io.output(io.stdout)
io.input(io.stdin)
io.write('Control Panel ID: ')
local baseId = tonumber(io.read())
io.write('Blocks: ')
local blcks = tonumber(io.read())
function round()
turtle.dig()
--- Here the function stops ---
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.digDown()
turtle.down()
turtle.dig()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
sleep(0.2)
end
function listen()
if true then
id, message = rednet.receive()
if message == 'down' then
print('Down!')
coroutine.resume(downCo, blcks)
elseif message == 'up' then
coroutine.resume(upCo, blcks)
elseif message == 'refuel' then
turtle.refuel()
elseif message == 'status' then
rednet.send(baseId, status)
elseif message == 'stop' then
print('Lol')
elseif message == 'fuel' then
rednet.send(baseId, turtle.getFuelLevel())
end
end
end
downCo = coroutine.create(function(blcks)
local a = 0
print('Going down! '..blcks)
status = 'Going down'
while a <= blcks do
a = a + 1
round()
end
local status = 'Done'
end)
upCo = coroutine.create(function(blcks)
local status = 'Going up'
for i = blcks,1,-1 do
turtle.digUp()
turtle.up()
end
local status = 'Done'
end)
while true do
listen()
end
I couldn't find any information about that the coroutines can't support turtle movement or anything like that
I tried to turn it into coroutine too, but it just happened to stuck at the same point.