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

Rednet send and receive

Started by lewanator1, 21 October 2012 - 12:32 PM
lewanator1 #1
Posted 21 October 2012 - 02:32 PM
ok so i have got a turtle and a computer that are both wireless and working (i can see the red band on the modem) on the turtle i type rednet.receive() and then the cursor disapears and waits for a signal like it should i think so i then move to my computer and type rednet.broadcast("go forward") i get back true but then i realise the turtle hasnt moved and on the turtle i get 2.236068?


thanks

lewanator1
faubiguy #2
Posted 21 October 2012 - 02:35 PM
rednet.receive doesn't automatically run commands. You have to set up a program that makes it run commands when it receives messages. For example:
while true do
    local sender, message = rednet.receive()
    if message == "go forward" then
        turtle.forward()
    end
end
casr144 #3
Posted 21 October 2012 - 02:36 PM
The turtle receives the message from the computer as the string "go forward" but it doesn't execute this as a command.
Lettuce #4
Posted 21 October 2012 - 02:37 PM
Try rednet.receive(5) so it listens for a longer period. And I assume you have a program to read strings for the turtle? If this doesn't work, show us your code.
lewanator1 #5
Posted 21 October 2012 - 02:37 PM
The turtle receives the message from the computer as the string "go forward" but it doesn't execute this as a command.
rednet.receive doesn't automatically run commands. You have to set up a program that makes it run commands when it receives messages. For example:
while true do
	local sender, message = rednet.receive()
	if message == "go forward" then
		turtle.forward()
	end
end

ah ok thanks guys messed that up abit :)/>/> this is going to take some messing to get it working :)/>/>
casr144 #6
Posted 21 October 2012 - 02:38 PM
You'll need to write a loop or if statement in order for this to execute something:
Example:

id, message = rednet.receive()

if message == "go forward" then
– code to move the turtle forwards
else
– code to make the turtle do something else like move backwards
end

np
lewanator1 #7
Posted 21 October 2012 - 02:45 PM
hmm i have some code i copied from somwhere that uses a gps tower the one that you type goto (cords here) how would i make a program for that so i can send the cords for my turtle to go to from my computer in my house?

thanks
lewanator1 #8
Posted 21 October 2012 - 02:50 PM
.
cheekycharlie101 #9
Posted 21 October 2012 - 03:19 PM
im about to upload a turtle remote control system, il post a link here as soon as its done.
lewanator1 #10
Posted 21 October 2012 - 04:17 PM
im about to upload a turtle remote control system, il post a link here as soon as its done.

Aww sweet dude thanks very much!
cheekycharlie101 #11
Posted 21 October 2012 - 05:03 PM
here ya go, heres the link: http://www.computercraft.info/forums2/index.php?/topic/5270-turtle-control-v20/

make no changes to the turtle code but on the client code find out where the to notes are, to find these look for "–" and the end of a line and read them. they will tell you what to change the values to.
thanks -Cheeky