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

Rednet Problem!

Started by Frederiken23, 14 July 2012 - 11:33 AM
Frederiken23 #1
Posted 14 July 2012 - 01:33 PM
Hey guys. I'm all new here, so sorry if this thread is posted the wrong place!

Now, I have a problem. Obviously.
I recently made some password protected doors, with a code to unlock them. Nothing special!

However, I also added an alarm feature which would set off an alarm. I then thought, "It could be awesome if the computer would notify another computer that security had been attempted breached.
So I added some lines of code, and then stuff went wrong.

Here is the code for the two computers.
1. (The lock-computer)

password = "rootbeer"

print ("Ocelot Industries lock terminal")
write ("Password:")
input = read ("*")
if input == password then
redstone.setOutput ("left", true)
rednet.open ("top")
rednet.send ("4", "Acces granted to main hall")
sleep(5)
os.shutdown()
else
print ("Wrong password!")
redstone.setOutput ("bottom", true)
rednet.open ("top", "Security breach attempted!")
sleep(10)
os.shutdown

Ok that's the code for computer 1. The reciever have a super simple code:
rednet.recieve()
print (message)

However, then the reciever makes this error: startup:1: attempt to call nil,
and suddenly the door won't close again!
Please help me, I'm utterly confused! :P/>/>
Kolpa #2
Posted 14 July 2012 - 01:47 PM
1. post this in ask a pro
2. u need to define the message that you print

id,message = rednet.receive()
print(message)
3. ur code is pretty messed up anyways

password = "rootbeer"
rednet.open ("top")

while true do
	print ("Ocelot Industries lock terminal")
	write ("Password:")
	input = read ("*")

	if input == password then
		redstone.setOutput ("left", true)
		rednet.send (4, "Acces granted to main hall")
		sleep(5)
		redstone.setOutput("left",false)
	else
		print ("Wrong password!")
		redstone.setOutput ("bottom", true)
		rednet.send(4, "Security breach attempted!")
		sleep(10)
		redstone.setOutput("bottom",false)
	end

end
4. use the
 tag
Frederiken23 #3
Posted 14 July 2012 - 02:16 PM
Ok thanks :P/>/>
naz42 #4
Posted 18 July 2012 - 03:17 AM
Ok that's the code for computer 1. The reciever have a super simple code:
rednet.recieve()
print (message)

However, then the reciever makes this error: startup:1: attempt to call nil

you misspelled receive
in lua, if you use a variable which does not exist (in this case "rednet.recieve")
lua treats it as if it were a variable, but has the value nil
and of course you cant call a function with an id of nil