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

[Lua] Shell.run doesn't exit rednet.receive()

Started by Blooody750, 07 July 2012 - 02:56 PM
Blooody750 #1
Posted 07 July 2012 - 04:56 PM
I have a system setup where at floors one computer sends to a main computer which controls what floor an elevator sends you to. But I have the problem that the main program for the control doesn't stop when if receives a message.


x,y,z = rednet.receive()
if y == "1" then
shell.run("FirstFloor")
else
shell.run("ElevatorControl")
end
if y == "2" then
shell.run("SecondFloor")
else
shell.run("ElevatorControl")
end

I gets the message, then runs the program for the specific floor. If it gets anything other then a floor number is restarts. A computer sends a floor number to the computer, and it does nothing. I only works sometimes if you terminate the program, because then it decides to run FirstFloor or SecondFloor. So it seems like this program is not ending, but is queuing up the other program to run when it is terminated.
KevinW1998 #2
Posted 07 July 2012 - 05:17 PM
How about using os.run?

os.run({},"yourProgram")
Blooody750 #3
Posted 07 July 2012 - 05:35 PM
Doesn't work. I receives the number, prints it, and then won't run the other programs unless I terminate the current one.
Heres the new code, and I'll also put in the code for the other programs.

x,y,z = rednet.receive()
print(y)
if y == "1" then
os.run({},"FirstFloor")
else
os.run({},"ElevatorControl")
end
if y == "2" then
os.run({},"SecondFloor")
else
os.run({},"ElevatorControl")
end


print("Received FirstFloor")
redstone.setBundledOutput("back", colors.blue)
print("Set Output Back Blue True")
print("Waiting for 30 seconds...")
sleep(30)
redstone.setBundledOutput("back", colors.yellow)
print("Set Output Back Blue False")

And this is the one that sends the message.

term.clear()
term.setCursorPos(1,1)
rednet.open("left")
print("Please enter floor number you wish to go to...")
local second = "2"
local enteredsecond = io.read()
if enteredsecond == second then
rednet.send(8,"2")
term.clear()
term.setCursorPos(1,1)
print("Sending to Second Floor for 30 seconds...")
sleep(30)
shell.run("FirstControl")
else
print("Invalid Floor...")
sleep(3)
shell.run("FirstControl")
end
The one that sends the message works fine with shell.run. It restarts all fine, so I'm thinking it is a problem that rednet.receive won't end.
MysticT #4
Posted 07 July 2012 - 06:12 PM
What if you try not using multiple programs and shell.run?
Also, use a loop instead of running the program again.
Blooody750 #5
Posted 07 July 2012 - 08:16 PM
Thanks. I did both and it is now working.