Jump to content




Help Rednet


  • You cannot reply to this topic
4 replies to this topic

#1 tbyoran

  • Members
  • 16 posts

Posted 27 November 2012 - 04:55 AM

Why this basic program not work?

Computer:
rs.setOutput("left",true)
rednet.open("right")
write "Message: "
input = read()
rednet.broadcast(input)

Turtle:
term.clear()
print ("Write Turtle Commands From Pc")
sleep(0)
  action, senderID, text= os.pullEvent()
rednet.open("right")
if action == "rednet_message" then
  if text == "Forward" then
  turtle.forward()
  end
end


#2 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 27 November 2012 - 05:11 AM

You need to use a while true do loop for the turtle so it doesn't just run once and the program stops. Also for os.pullEvent() returns [ event, senderID, message, dist ] you have it wrong there.
This should work:

rednet.open("right") -- Does not have to be in the loop because you only need to open it once

while true do
    term.clear()
    print ("Write Turtle Commands From Pc")
    sleep(0)
    ev, senderID, msg, dist = os.pullEvent("rednet_message")
    if msg == "Forward" then
        turtle.forward()
    end
end


#3 bjornir90

  • Members
  • 378 posts
  • LocationFrance

Posted 27 November 2012 - 05:12 AM

It's maybe because on the computer you type forward instead of Forward, Lua is cass sensitive.

#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 27 November 2012 - 05:15 AM

Rednet has to be opened before receiving rednet messages. Just switch the two lines around.

rednet.open("right")
action, senderID, text= os.pullEvent()

Also, you should probably use rednet.receive() instead of os.pullEvent(), because you only want to get rednet messages.

senderID, text = rednet.receive()


#5 tbyoran

  • Members
  • 16 posts

Posted 27 November 2012 - 05:16 AM

thx a lot





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users