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

[Question] Rednet broadcast not working?

Started by Mightygod27, 01 May 2012 - 05:12 PM
Mightygod27 #1
Posted 01 May 2012 - 07:12 PM
I created a simple program to have two turtles place blocks to create a door, and a second to mine them to open the door. I have them hidden behind a wall and want to activate them using a rednet signal. I also have a simple startup program to load the programs on the turtles and prep them.

startup:

fs.copy("disk/dooropen","dooropen")
fs.copy("disk/doorclose","doorclose")
rednet.open("right")
x=os.computerID()
print("My name is ", x)

open door:

x, message = rednet.receive()
print(message)
if message == "Open" then
turtle.dig()
turtle.forward()
turtle.turnLeft()
turlte.dig()
turtle.up()
turtle.dig()
turtle.turnleft()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
turtle.place()
end

close door:

x, message = rednet.receive()
print(message)
if message == "Close" then
turtle.dig()
turtle.forward()
turtle.turnLeft()
turlte.place()
turtle.up()
turtle.place()
turtle.turnleft()
turtle.forward()
turtle.turnRight()
turtle.place()
turtle.down()
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
turtle.place()
end



The startup works, but for some reason, when I broadcast the signal, the turtle doesn't run the program :/ any suggestions?
MysticT #2
Posted 01 May 2012 - 07:51 PM
You should run the programs in a loop, cause now they just listen for 1 message and if it's the "Open" or "Close" then do something, then the program ends.
Try with a while loop:

while true do
  -- your code here
end