Jump to content




Rednet refuses to work (Bug?)


5 replies to this topic

#1 ToxicC00kie1001

  • Members
  • 9 posts

Posted 16 May 2018 - 05:04 AM

Ok so I'm new to using lua and all I'm trying to do is make a simple program that wirelessly enables and disables the lights. The only problem is how stupidly complex rednet is rednet won't work. Every time I tell it to turn on or off, computer 1 shows the appropriate response to my inputs while computer 2 is still waiting for input from computer 1. I tried searching for examples and stuff online and the wiki to no avail so this is my last resort. Am I doing something wrong or have I discovered a bug?

Computer 1's code (Sender):

--Computer id is 1

print("Lamp on or off?")
print("1=On 0=Off")

rednet.open("back") --modem is indeed here and within range

ans = io.read() -- ans is what the user requested

if ans == ("1") then
rednet.send(1, "1")
print("Turned it on!")

elseif ans == ("0") then
rednet.send(1, "0")
print("Turned it off!")

else
print("Invalid Input")
end

Computer 2's code (Receiver):

--Computer id is 4

rednet.open("back") --modem is indeed here and within range

ans = rednet.receive()

if ans == ("1") then
redstone.setOutput("left", true) --Lamp is indeed here

elseif ans == ("0") then
redstone.setOutput("left", false) --Lamp is indeed here

else
print("Invalid Input!")
end

#2 Luca_S

  • Members
  • 407 posts
  • LocationGermany

Posted 16 May 2018 - 05:11 AM

1. Put your code in Codeblocks when posting on the Forum or, if the code is large, publish it on Pastebin
2. Your send program sends the rednet message to the computer it is currently running on and not to the computer that runs the receive script.

EDIT: Also rednet is not really "stupidly complex" I would suggest that you read the documentation

Edited by Luca_S, 16 May 2018 - 05:14 AM.


#3 ToxicC00kie1001

  • Members
  • 9 posts

Posted 16 May 2018 - 05:14 AM

View PostLuca_S, on 16 May 2018 - 05:11 AM, said:

1. Put your code in Codeblocks when posting on the Forum or, if the code is large, publish it on Pastebin
2. Your send program sends the rednet message to the computer it is currently running on and not to the computer that runs the receive script.

1. Noted
2. How do I correct this?

#4 Luca_S

  • Members
  • 407 posts
  • LocationGermany

Posted 16 May 2018 - 05:17 AM

View PostToxicC00kie1001, on 16 May 2018 - 05:14 AM, said:

View PostLuca_S, on 16 May 2018 - 05:11 AM, said:

1. Put your code in Codeblocks when posting on the Forum or, if the code is large, publish it on Pastebin
2. Your send program sends the rednet message to the computer it is currently running on and not to the computer that runs the receive script.

1. Noted
2. How do I correct this?

Check the documentation for rednet.send it requires you to give the ID of the receiving computer as the first argument. So in both cases where you are using rednet.send replace the 1 with the ID of the receiving computer(4)

#5 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 16 May 2018 - 05:20 AM

View PostToxicC00kie1001, on 16 May 2018 - 05:14 AM, said:

View PostLuca_S, on 16 May 2018 - 05:11 AM, said:

...
2. Your send program sends the rednet message to the computer it is currently running on and not to the computer that runs the receive script.
...
2. How do I correct this?

Change rednet.send(1, "1") and rednet.send(1, "2") to rednet.send(4, "1") and rednet.send(4, "2") respectively. (EDIT: :ph34r: 'd)

Also, you're missing a variable for rednet.receive() and only capturing the sender ID - rednet.receive() returns the sender id and the message.
id, ans = rednet.receive()

Edited by Dog, 16 May 2018 - 05:23 AM.


#6 ToxicC00kie1001

  • Members
  • 9 posts

Posted 16 May 2018 - 05:23 AM

View PostLuca_S, on 16 May 2018 - 05:17 AM, said:

View PostToxicC00kie1001, on 16 May 2018 - 05:14 AM, said:

View PostLuca_S, on 16 May 2018 - 05:11 AM, said:

1. Put your code in Codeblocks when posting on the Forum or, if the code is large, publish it on Pastebin
2. Your send program sends the rednet message to the computer it is currently running on and not to the computer that runs the receive script.

1. Noted
2. How do I correct this?

Check the documentation for rednet.send it requires you to give the ID of the receiving computer as the first argument. So in both cases where you are using rednet.send replace the 1 with the ID of the receiving computer(4)

Worked perfectly! Many thanks. :lol:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users