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

help with rednet

Started by joshua1234, 26 May 2012 - 09:01 PM
joshua1234 #1
Posted 26 May 2012 - 11:01 PM
I need some help with my code. I'm not sure what's wrong it tells me expected positive number, I'm tyring to send a message to my turtle and if the message is str it will move forward here's the code for the sending computer
–send

write ("which side is your modem:")
ms = io.read()
rednet.open(ms)
write ("id of turtle:")
idt = io.read()
idt = tonumber(idt)

while true do
event, param1 = os.pullEvent()
if param1 == "w" then
rednet.send("str", idt)
end
end

And here's the code for the receiving turtle
–receive

write ("which side is your modem:")
ms = io.read()
rednet.open(ms)
while true do
Id, message = rednet.receive()
if id == "str" then
turtle.forward()
end
end

Please could any1 help , this is hopefully going to be remote control program thanks.
Any help will be appreciated
Cloudy #2
Posted 26 May 2012 - 11:11 PM
You've got the arguments swapped in your rednet.send. Should be ID THEN message.
Lyqyd #3
Posted 27 May 2012 - 01:37 AM
You also need to then check message instead of id in the receiving program.
joshua1234 #4
Posted 27 May 2012 - 07:21 AM
I tried that it still says positive number expected!but thanks for your reply
joshua1234 #5
Posted 27 May 2012 - 07:32 AM
Never got it to work thanks a lot !
joshua1234 #6
Posted 27 May 2012 - 07:46 AM
Never mind I meant
Maarten551 #7
Posted 27 May 2012 - 09:56 AM
I think I know what the problem is.

You send a string what needs to be an Int.

This can simple be solved with this code :
tonumber([string]) and the output will be in int format, and ready for use.

Also :

if param1 == "w" then
rednet.send("str", idt)
end

Needs to be


if param1 == "w" then
rednet.send(15[The computerID, not the message], "str"[Here needs to be the message])
end

Also have a look at this :

while true do
Id, message = rednet.receive()
if id == "str" then
turtle.forward()
end

Needs to be :

while true do
Id, message = rednet.receive(1[A timeout is always nice])
if message == "str" then
turtle.forward()
end

this can be changed in multply places in your code.

If you have more question, just send a message to me, and I will be glad to help.
Dirkus7 #8
Posted 27 May 2012 - 11:00 PM
Also, you don't have to ask on which side the modem is on the turtle, it's always on the right side.