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

Can't make this code work

Started by X3ME, 08 November 2014 - 08:52 PM
X3ME #1
Posted 08 November 2014 - 09:52 PM
Hi, i have developed this code to a remote door loking system, but i don't know why it doesn't work, help please?

PS: Computer ID is 4, he wants to receive from computer 3, door is on the right side, modem is in the back, it gives the following error:
rednet:68: Expected number
I was thinking if it was 68th line, but the code doesn't even have that line!

os.pullEvent = os.pullEventRaw
while true do

message = (rednet.receive("westerndigital")) —-random protocol_just for safety
password = changeme

if "message" = "password" then

rednet.open("back")
rs.setOutput("right", true)
sleep(5)
rs.setOutput("right", false)
os.reboot()

end
end
valithor #2
Posted 08 November 2014 - 10:01 PM
Going to point out a few things.

You do not open rednet until after you try to receive the message.

rednet.return does not only return the message, and it does not return the message first. Because of this where you define the message variable it will actually be equal to the senders id not the message. I suggest looking at the suggestion on this page. http://computercraft.../Rednet.receive

The reason that it says line 68 and your program does not have that line is because the error is from how you used rednet.receive, which is defined on line 68 in the rednet api.

What version of Computercraft are you using. I am assuming that you are using a version before 1.6, which means that protocol is not implemented.
Edited on 08 November 2014 - 09:05 PM
X3ME #3
Posted 08 November 2014 - 10:05 PM
I am using FTB Ultimate…Whats the version on that?
X3ME #4
Posted 08 November 2014 - 10:15 PM
I am sorry, i did not understand your english, can you be more specific?
valithor #5
Posted 08 November 2014 - 11:30 PM
Feed the Beast uses computercraft version 1.5. This means that you can not use a protocol when using rednet. Protocol was not implemented until computercraft version 1.6+.


os.pullEvent = os.pullEventRaw
while true do
(1) senderId, message = (rednet.receive((2)"westerndigital")) —- Protocol is not implemented in the version you are using so you can not use it
password = (6)changeme
if (5)"message" = (5)"password" then
(3)rednet.open("back")
rs.setOutput("right", true)
sleep(5)
rs.setOutput("right", false)
(4)os.reboot()
end
end


1. Rednet.receive() returns 2 values. The id of the computer that sent the message, and the message that is sent. The order that they are returned is senderid, message. In order for you to get the message you have to assign the first value (the senderid) to a variable. (NOTE: In computercraft 1.6+ rednet.receive() returns 3 things with the 3rd value being protocol)

2. Protocol for the rednet api is not implemented in the version of computercraft that feed the beast uses. Using a protocol is what caused the error.

3. You have to open rednet before you use it. Move the rednet.open("back") to somewhere before you use rednet.

4. It is also bad practice to use os.reboot() to restart a program. It would be better to put "message = nil" there and remove os.reboot(). That will make it to where the message varialble equals nothing, so it no longer equals password.

5. You need to remove the quotation marks "" around message and password. When you put quotation marks around something it is considered a string not a variable. Because of this it is litterally checking to see if the word message equals the word password.

6. You need quotation marks around this. As it is trying to set the password variable to a variable called changeme, which does not exist.

os.pullEvent = os.pullEventRaw
while true do
  rednet.open("back")
  senderId, message = (rednet.receive()) ---- Protocol is not implemented in the version you are using so you can not use it
  password = "changeme"
  if message = password then
	rs.setOutput("right", true)
	sleep(5)
	rs.setOutput("right", false)
	message = nil
  end
end




The error msg you got rednet:68: Expected number was caused by how you used rednet.receive(). The error occured on line 68 of the rednet api not your program. Since protocol was not added in the version you are using the only argument that you can pass to rednet.receive is a number, so when you inputed the protocol (a string) it errored.

edit: Sorry would have put the original code in a code block like the corrected code, but I could not color the errors then.
edit2: Sorry that a few of them are out of order. They were in order at first, but I found a couple more after i did the original post.
Edited on 08 November 2014 - 11:16 PM