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

Pocket Computer to Advanced Computer Rednet Connection Not Working

Started by TMCCarnage, 10 August 2017 - 01:55 AM
TMCCarnage #1
Posted 10 August 2017 - 03:55 AM
So basically I have a edited startup on my Advanced Computer. Basically what the code is supposed to do is it is supposed to be waiting for a rednet signal to be received.

rednet.open("back")
while true do
id, message = rednet.receive()
end
if message == "LPA1OpenClosed" then
shell.run("LPA1OpenClosed")
end
if message == "LPA1COpenOpen" then
shell.run("LPA1OpenOpen")
end
if message == "LPA1ClosedClosed" then
shell.run("LPA1ClosedClosed")
end
if message == "LPA1ClosedOpen" then
shell.run("LPA1ClosedClosed")
end

Then I also have a code written on my pocket computer that is supposed to be sending the rednet signal and message.

rednet.open("back"
rednet.send(7, "LPA1OpenClosed")
print("Opening North LP. Closing South LP.")
sleep(3)
term.clear()
term.setCursorPos(1,1)
print("TMC OS V1.0.0")
rednet.close("back")

By the way in the "rednet.send(7, LPA1OpenClosed)", 7 is the ID of the advanced computer.

In the first code that I showed you, when there was only one if statement the message was getting sent and received fine. But now that I added more if statements, nothing is getting received and the Advanced Computer is frozen until I ctrl + T to terminate the startup program.

Also I have made the programs on the Advanced Computer for the shell.run("LPA1OpenClosed") etc.

Any reasons as to why the Advanced Computer isn't receiving a signal and running the program it's supposed to based of the message received?
SquidDev #2
Posted 10 August 2017 - 07:16 AM
You're jolly nearly there, you've just got an end in the wrong place. If you indent your code, it becomes a little clearer:

rednet.open("back")
while true do
	id, message = rednet.receive()
end
if message == "LPA1OpenClosed" then
	shell.run("LPA1OpenClosed")
end
if message == "LPA1COpenOpen" then
	shell.run("LPA1OpenOpen")
end
--# etc...
As you can see, it's just continually receiving events, but never doing anything with them. By moving the if statements inside the loop, everything should work:

rednet.open("back")
while true do
	id, message = rednet.receive()
	if message == "LPA1OpenClosed" then
		shell.run("LPA1OpenClosed")
	end
	if message == "LPA1COpenOpen" then
		shell.run("LPA1OpenOpen")
	end
	--# etc...
end
Edited on 10 August 2017 - 05:17 AM
TMCCarnage #3
Posted 10 August 2017 - 01:45 PM
You're jolly nearly there, you've just got an end in the wrong place. If you indent your code, it becomes a little clearer:

rednet.open("back")
while true do
	id, message = rednet.receive()
end
if message == "LPA1OpenClosed" then
	shell.run("LPA1OpenClosed")
end
if message == "LPA1COpenOpen" then
	shell.run("LPA1OpenOpen")
end
--# etc...
As you can see, it's just continually receiving events, but never doing anything with them. By moving the if statements inside the loop, everything should work:

rednet.open("back")
while true do
	id, message = rednet.receive()
	if message == "LPA1OpenClosed" then
		shell.run("LPA1OpenClosed")
	end
	if message == "LPA1COpenOpen" then
		shell.run("LPA1OpenOpen")
	end
	--# etc...
end
Thank you so much! I wish I had discovered this Ask a Pro thing before I sat there for 4 hours unsure of what isn't working xD