Posted 23 October 2012 - 08:27 PM
So I posted on here a day or two ago and got some help with my turtle receiver code, as it kept throwing an error due to some mis-typed code, and it was working… I thought. I didn't test it very thoroughly at the time (read: hardly any) because I had some other obligations to attend to. I got back to it about an hour ago, and realized that they will excavate in synchronous, and will go upward, but no other direction. I suspect this is an issue with my for loops, but am honestly not sure.
Computer Broadcasting Code
Computer Broadcasting Code
while true do
rednet.open("top")
print("Opened modem...")
print("What would you like the turtle to do?")
input = string.lower(read())
if input == "excavate" then
print("Broadcasting excavate to all turtles.")
rednet.broadcast("excavate")
elseif input == "go left" then
print("Relocating turtles...")
rednet.broadcast("left")
elseif input == "go right" then
print("Relocating turtles...")
rednet.broadcast("right")
elseif input == "go up" then
print("Relocating turtles...")
rednet.broadcast("up")
elseif input == "go down" then
print("Relocating turtles...")
rednet.broadcast("down")
elseif input == "go forward" then
print("Relocating turtles...")
rednet.broadcast("forward")
elseif input == "go back" then
print("Relocating turtles...")
rednet.broadcast("back")
end
rednet.close("top")
print("Broadcast complete.")
end
Turtle Receiver Code
rednet.open("right")
while true do
event, id, text = os.pullEvent()
if event == "rednet_message" then
if text == "excavate" then
shell.run(""..text, "5")
elseif text == "up" then
for x = 0, 5 do
if turtle.detectUp() then
turtle.digUp()
end
x=x+1
turtle.up()
end
end
elseif text == "right" then
turtle.turnRight()
for x = 0, 5 do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
x=x+1
end
turtle.turnLeft()
elseif text == "left" then
turtle.turnLeft()
for x = 0, 5 do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
x=x+1
end
turtle.turnRight()
elseif text == "down" then
for x = 0, 5 do
if turtle.detectDown() then
turtle.digDown()
end
turtle.down()
x=x+1
end
elseif text == "back" then
turtle.turnRight()
turtle.turnRight()
for x = 0, 5 do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
x=x+1
end
turtle.turnLeft()
turtle.turnLeft()
elseif text == "forward" then
for x = 0, 5 do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
x=x+1
end
end
end