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

Rednet Issues

Started by LewisTehMinerz, 18 February 2014 - 08:46 AM
LewisTehMinerz #1
Posted 18 February 2014 - 09:46 AM
I'm having issues when trying to use rednet for messaging other computers.

Senders Code:


rednet.open("back")
while true do
write("Positioned? Write yes if you are: ")
answer = read()
  if answer == "Yes" or "yes" then
	rednet.send(24, "order")
   end
end

Receivers Code:


rednet.open("back")
while true do
id, message, bd = os.pullEvent("rednet_message")
if message == "order" then
rs.setOutput("bottom", true)
rs.setOutput("bottom", false)
sleep(10)
rs.setOutput("bottom", true)
rs.setOutput("bottom", false)
end


The problem is: The sender sends the message, but the receiver doesn't collect it. Please Help!


--Lewis
Edited on 18 February 2014 - 11:34 AM
Anavrins #2
Posted 18 February 2014 - 11:29 AM
Since you are using os.pullEvent() to get the message, you must do the same as you would do with other types of events, that is that the first parameter must be the name of the event.

"event, id, message, bd = os.pullEvent()"
CometWolf #3
Posted 18 February 2014 - 12:10 PM
Your sender will always send "order" regardless of what you input.
When you compare something, you must specify what to compare everytime. just "yes" will always equate to not nil, and thus the condition will be considered true.

if answer == "Yes" or answer == "yes" then

a simple way of dealing with capitalization, would be to use string.lower(). This will turn whatever string you pass it into lowercase.

if answer:lower == "yes" then -- This is just a syntactic sugar method of calling string.lower on the variable answer
Edited on 18 February 2014 - 11:11 AM
LewisTehMinerz #4
Posted 18 February 2014 - 12:42 PM

Since you are using os.pullEvent() to get the message, you must do the same as you would do with other types of events, that is that the first parameter must be the name of the event.

"event, id, message, bd = os.pullEvent()"


——————————————————————————————-

Your sender will always send "order" regardless of what you input.
When you compare something, you must specify what to compare everytime. just "yes" will always equate to not nil, and thus the condition will be considered true.

if answer == "Yes" or answer == "yes" then

a simple way of dealing with capitalization, would be to use string.lower(). This will turn whatever string you pass it into lowercase.

if answer:lower == "yes" then -- This is just a syntactic sugar method of calling string.lower on the variable answer

Both will be put in my code.

Ah snap!

Put in the ideas and on the sender it errors:


bios:399: [string "send"]:5: function augments expected

:angry:/>/>
MKlegoman357 #5
Posted 18 February 2014 - 01:24 PM
Also, you set rs output to true and then immidiately to false. I don't think there will be a rs pulse when you toggle it that fast. If I am correct then a simple sleep for about 0.1 second between the rs functions should be ok.
LewisTehMinerz #6
Posted 18 February 2014 - 01:43 PM
Download My Code For Receiver:

pastebin get iSza1YxT

Download My Code For Sender:

pastebin get vkT03Lyw
Bomb Bloke #7
Posted 18 February 2014 - 04:44 PM
Sender / receiver

The number "5" in the error indicates the line where it's expecting the function arguments.

I see that for now you've commented that second line Comet gave you out, replacing it with the first - the problem with that commented line is that "answer:lower" is a function (which returns a lower-case version of the answer variable), and Lua's expecting the function to be called, rather then just referred to.

Long story short, it should be:

if answer:lower() == "yes" then
surferpup #8
Posted 18 February 2014 - 04:48 PM
Also, you set rs output to true and then immidiately to false. I don't think there will be a rs pulse when you toggle it that fast. If I am correct then a simple sleep for about 0.1 second between the rs functions should be ok.

I think you have to have the sleep be at the very least 0.08 seconds for a pulse. If anyone knows better, please advise.
Lyqyd #9
Posted 18 February 2014 - 05:09 PM
It's usually best to leave it on for a full redstone tick (0.1s). Shorter durations can be unreliable.
CometWolf #10
Posted 18 February 2014 - 05:11 PM
Sender / receiver

The number "5" in the error indicates the line where it's expecting the function arguments.

I see that for now you've commented that second line Comet gave you out, replacing it with the first - the problem with that commented line is that "answer:lower" is a function (which returns a lower-case version of the answer variable), and Lua's expecting the function to be called, rather then just referred to.

Long story short, it should be:

if answer:lower() == "yes" then
Whops, my bad.
LewisTehMinerz #11
Posted 19 February 2014 - 04:19 AM
I set my redstone to:


sleep(1)

to make sure that it would pulse.

EDIT: I fixed up all the code with the sender but still, no receive. :(/>
Edited on 19 February 2014 - 03:32 AM
CometWolf #12
Posted 19 February 2014 - 05:37 AM
Im guessing the pastebin is still up to date, so… The ID of the receiver is 24, right? Or did you just chose a random number?
LewisTehMinerz #13
Posted 21 February 2014 - 11:11 AM
Im guessing the pastebin is still up to date, so… The ID of the receiver is 24, right? Or did you just chose a random number?

Need to paste a new program. the things outdated.

Im guessing the pastebin is still up to date, so… The ID of the receiver is 24, right? Or did you just chose a random number?

yes
LewisTehMinerz #14
Posted 06 March 2014 - 04:25 PM
New Codes:
Send:
pastebin get ULy8v6Hn
Receive:
pastebin get neAqHfcb
CometWolf #15
Posted 06 March 2014 - 05:09 PM
I see nothing wrong with your code, so how far apart are these computers located? Also, try opening the lua console on the receiver and write the following

rednet.open"back" while true do print(os.pullEvent"rednet_message") end
Then go to the sender and write this into the console

rednet.open"back" rednet.send(24,"test")
If nothing appears on the receiver, they're not able to reach eachother.
Bomb Bloke #16
Posted 06 March 2014 - 11:31 PM
I'd stick some "print" statements into both scripts - on the sender, to make sure it's not somehow misinterpreting your text input, and on the receiver, to see what messages it's actually receiving.

Also, silly question, but what sort of modems are you using? You haven't accidentally hooked up some wired modems instead of wireless ones, or somesuch? It's getting to the stage where screenshots may be helpful.
LewisTehMinerz #17
Posted 07 March 2014 - 03:53 PM
I'd stick some "print" statements into both scripts - on the sender, to make sure it's not somehow misinterpreting your text input, and on the receiver, to see what messages it's actually receiving.

Also, silly question, but what sort of modems are you using? You haven't accidentally hooked up some wired modems instead of wireless ones, or somesuch? It's getting to the stage where screenshots may be helpful.
Wireless Modems are the modems i'm using.
LewisTehMinerz #18
Posted 14 April 2014 - 04:08 PM
Is anyone there? I'm using wireless modems Bomb Bloke.
Bomb Bloke #19
Posted 14 April 2014 - 11:43 PM
How'd you go with those "print" statements?
LewisTehMinerz #20
Posted 25 April 2014 - 01:40 PM
How'd you go with those "print" statements?
I think i'll go with print statements, I'll do some editing of my code