I am currently coding my first turtle mining programm, which scanns the environment and displays all
the given information about it(the blocks around the turtle) and the turtle(FuelLevel) out on a Monitor.
Now i am trying to make a programm, who allows the user to move the turtle when he
click on one of the printet Blocks.
The programm i made for that works fine, if i start it alone, but whenever i try to open it with
shell.run("ProgrammName")
the programm just hang up and i need to terminat it.
The code whit which i have trouble with:
Spoiler
--Programm Name movement
while true do
local event, side, x, y = os.pullEvent()
if event == "monitor_touch" then
--Move Down
if (x == 9 and y == 13) or (x == 10 and y == 13) then
rednet.send(5, "Down")
break
end
--Move Right
if (x == 15 and y == 8) or (x == 16 and y == 8) then
rednet.send(5, "Right")
break
end
--Move forward
if(x == 9 and y == 8) or (x == 10 and y == 8) then
rednet.send(5, "Forward")
break
end
--Move Left
if (x == 3 and y == 8) or (x == 4 and y == 8) then
rednet.send(5, "Left")
break
end
--Move UP
if (x == 9 and y == 3) or (x == 10 and y == 3) then
rednet.send(5, "Up")
break
end
--Move Back
if (x == 8 and y == 17) or (x == 9 and y == 17) or (x == 10 and y == 17) or (x == 11 and y == 17) then
rednet.send(5, "Back")
break
end
end
end
an here the code i use to run the code above:
Spoiler
--Programm Name Viewer
-- #4 Cpu // Turtel #5
rednet.open("back")
monitor = peripheral.wrap("left")
term.setBackgroundColor(32)
term.clear()
term.setCursorPos(1,1)
monitor.setTextScale(1)
while rednet.isOpen("back") == true do
local ID, MSG, PORT = rednet.receive()
if MSG == "Detect" then
shell.run("draw")
end
if MSG == "FuelLevel" then
shell.run("getTank")
end
if MSG == "End" then
rednet.close("back")
end
if MSG == "Move" then
shell.run("movement")
end
end
The Problem i have, is that it seems like the code hang up at
local event, side, x, y = os.pullEvent()
And if it is helpful here's the main "Turtelcode" which is used to call the different functions:
Spoiler
--Programm Name TView
rednet.open("right")
--Functions
function mMovement()
rednet.send(4,"Move")
shell.run("mMovement")
end
function getFuelLevel()
rednet.send(4, "FuelLevel")
local TANK = turtle.getFuelLevel()
if TANK == 0 then
shell.run("refuel")
else
rednet.send(4, TANK)
end
end
function detect()
rednet.send(4, "Detect")
--detect top
shell.run("detectt")
--detect Left
turtle.turnLeft()
shell.run("detectf")
--detect forward
turtle.turnRight()
shell.run("detectf")
--detect Right
turtle.turnRight()
shell.run("detectf")
--turn normal
turtle.turnLeft()
-- detect bottom
shell.run("detectb")
end
--Main
local bRunning = true
while bRunning == true do
detect()
getFuelLevel()
mMovement()
bRunning = false
end
rednet.send(4, "End")
And the code which actually moves the turtle:
Spoiler
--Programm Name mMovement
local ID, MSG, PORT = rednet.receive()
if MSG == "Forward" then
if turtle.detect() == true then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if MSG == "Back" then
turtle.turnRight()
turtle.turnRight()
if turtle.detect() == true then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if MSG == "Left" then
turtle.turnLeft()
if turtle.detect() == true then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if MSG == "Right" then
turtle.turnRight()
if turtle.detect() == true then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
if MSG == "Up" then
if turtle.detectUp() == true then
turtle.digUp()
turtle.up()
else
turtle.up()
end
end
if MSG == "Down" then
if turtle.detectDown() == true then
turtle.digDown()
turtle.down()
else
turtle.down()
end
end
I'll already stuck at this problem since 5 hours now and still haven't found the reason why it behave like this especially because it does work, when i start the programm(movement) separately.
Thanks in advance