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

rednet.receive() won't receive

Started by mono15591, 30 September 2012 - 11:46 AM
mono15591 #1
Posted 30 September 2012 - 01:46 PM
SO happy to see that a computer is in minecraft. Just found out two days ago. I already have many ideas for this game :)/>/>


The point of this little test program is to turn the redston coming from the back of the computer on or off depending on the message. If the message is for the computer than turn redstone on if not and redstone is on then turn redstone off. The computers ID is 2 while the computers ID I'm sending information from is 3

rednet.open("right")
state = true
while state == true do
	  write("waiting...")
	  id, message = rednet.receive()
	  message = tonumber(message)
	
	 if message = os.computerID then
		  rs.setOutput("back", true)
	 elseif rs.getInput("back") == true then
		  rs.setOutput("back", false)
	 end
end

The problem it's not going into the if statement at all. It just loops back to "waiting…". This is the code I'm sending it
rednet.open("right")
rednet.send(2,"2")
ardera #2
Posted 30 September 2012 - 02:56 PM
You're problem is in this line:

if message = os.computerID then

I know the os.computerID should return the id, but you have to add () to call the function.
so


if message = os.computerID then
should be


if message = os.computerID() then

Next Issue (in the same line):

the == is the equals operator, not =
so the = in this line has to be a ==

I think the rest is ok
mono15591 #3
Posted 30 September 2012 - 09:20 PM
Sorry "=" is "==" in my game. I don't know how to copy past from the game. But when I write "os.computerID()" instead of "os.computerID()" I get an error "attempt to call nil"
Lyqyd #4
Posted 30 September 2012 - 09:46 PM
If you're getting an error calling os.computerID(), you've screwed something else up somewhere.
BrolofTheViking #5
Posted 01 October 2012 - 02:21 AM
I suggest checking to make sure all the capitalizations are where they need to be, and make sure you spelled receive correctly, I frequently type it as recieve accidentally.

if any function is typo'd, then Lua will see it as a variable, and will thus report an attempt to call NIL, since the variable hasn't been defined yet.
mono15591 #6
Posted 01 October 2012 - 08:22 AM
I suggest checking to make sure all the capitalizations are where they need to be, and make sure you spelled receive correctly, I frequently type it as recieve accidentally.

if any function is typo'd, then Lua will see it as a variable, and will thus report an attempt to call NIL, since the variable hasn't been defined yet.

yep accidentally capitalized the "c" in os.computerID. Works perfectly now.