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

Wireless Modem Fun

Started by applesauce10189, 09 January 2014 - 11:20 AM
applesauce10189 #1
Posted 09 January 2014 - 12:20 PM
I'm new to coding and I felt like playing around with wireless modems and I think I messed up, I'm wondering what I'm doing wrong it says on line 4 there's a "then" expected but it's already there,



rednet.open("right")
id, message = rednet.recieve()
while true do
  if message = 1 then
    rs.setOutput("down", true)
  elseif message = 2 then
    rs.setOutput("down", false)
  end
end
wieselkatze #2
Posted 09 January 2014 - 12:26 PM
Should be:


rednet.open("right")
id, message = rednet.recieve()
while true do
  if message == 1 then
	rs.setOutput("bottom", true)
  elseif message == 2 then
	rs.setOutput("bottom", false)
  end
end

Same mistake: if you want to check if something matches something, use ==
Edited on 17 June 2014 - 09:29 PM
applesauce10189 #3
Posted 09 January 2014 - 12:26 PM
Thanks, guess I forgot,
edit, now it says on line 2 attempt to call nil.
another edit, I misspelled receive, fixed it.
Edited on 09 January 2014 - 11:28 AM
Lyqyd #4
Posted 09 January 2014 - 12:29 PM
This is covered under the Common Errors section of the sticky post titled Read This Post Before Asking Questions. You should try using the resources available to you rather than immediately running off to post a question. We have that sticky for exactly this sort of easy to solve, common error.
LBPHacker #5
Posted 09 January 2014 - 01:16 PM
Also, I'm not sure if "down" is a valid side. Use "bottom".
applesauce10189 #6
Posted 09 January 2014 - 02:00 PM
Also, I'm not sure if "down" is a valid side. Use "bottom".
Tried bottom. Didn't seem to work either so I moved the computer and put redstone in the back and using "back" didn't work either.
LBPHacker #7
Posted 09 January 2014 - 02:41 PM
Oh so there's another bug. Yeah, I see. receive will never be a number, since you can't send numbers over rednet, only strings.
applesauce10189 #8
Posted 09 January 2014 - 03:20 PM
Oh so there's another bug. Yeah, I see. receive will never be a number, since you can't send numbers over rednet, only strings.
Still doesn't work. I changed 1 into "on" and 2 into "off" both with and without quotation marks. What am I doing wrong?
6677 #9
Posted 09 January 2014 - 03:44 PM
elseif message == 2 then

change the 2 to "2"
applesauce10189 #10
Posted 09 January 2014 - 04:18 PM
elseif message == 2 then

change the 2 to "2"
Thank you, I feel stupid for making so many mistakes in so little amounts of code,
Lyqyd #11
Posted 09 January 2014 - 04:32 PM
Oh so there's another bug. Yeah, I see. receive will never be a number, since you can't send numbers over rednet, only strings.

You can send numbers over rednet. Tables, too.
TheOddByte #12
Posted 09 January 2014 - 08:14 PM
It seems that the OP put Ignore this :P/>

id, message = rednet.recieve()
It should be

id, message = rednet.receive()

To print the valid sides do this

for _, side in ipairs( rs.getSides() ) do
	print( side )
end
Edited on 09 January 2014 - 07:19 PM
Bomb Bloke #13
Posted 10 January 2014 - 02:35 AM
You can send numbers over rednet. Tables, too.
… depending on the version of ComputerCraft installed.
Lyqyd #14
Posted 10 January 2014 - 11:16 AM
True, though for unqualified statements of what one can or cannot do, the current version is the one to base things off of. :P/>