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

Program closes when still needed to recive message from rednet.

Started by Zambonie, 14 January 2013 - 05:45 AM
Zambonie #1
Posted 14 January 2013 - 06:45 AM
Yes,I kinda found out the problem,but how can I fix it?I am making an program called the FLC(Fishing Lounge Control) for my bro.And to make it im using rednet.One of my options is to spawn a boat at the boat deck.Ive got a computer next to a dispenser there with a modem conected to it.I got to the part were the computer by the deck can notice that it found the flc computer,but when I want to give the computer a comand from the flc,I check at the computer at the boat deck and it exited the program.It didnt clear the screen or anything,it just shows the ">_" in the shell.Here are the codes I use:

FLC:

rednet.open("right")
rednet.broadcast("Signal")
v = (1.0)
a = ("Fishing Lounge Control.")
b = ("--------------------------------------------------")
term.clear()
term.setCursorPos(15,9)
term.setTextColor(colors.blue)
textutils.slowPrint("Fishing Lounge Control")
sleep(3)
term.clear()
term.setCursorPos(1,1)
print(a)
print(B)/>
print("Press the # before the thing you want to do to do it.")
print(B)/>
print("1:Spawn boat at boat deck.")
local input = read()
if input == "1" then
rednet.broadcast("Boat")
end

Computer by boat deck:

term.clear()
term.setCursorPos(1,1)
rednet.open("left")
a = ("FLC BC")
b = ("--------------------------------------------------")
c = ("Found signal from FLC. FLC BC can now take commands from FLC")
d = ("Spwaning Boat...")
print(a)
print(B)/>
print("Finding signal from FLC...")
id,message = rednet.receive()
if id == 6 and message == "Signal" then
print(c)
id,message = rednet.receive(10)
if message == "Boat" then
print(d)
redstone.setOutput("right", true)
sleep(1)
redstone.setOutput("right", false)
end
end
huettner94 #2
Posted 14 January 2013 - 07:04 AM
The Problem is in the Code for your computer on the boat deck:

the parameter of rednet.receive is the timeout. So your program will wait 10 seconds for a command and then exit.
If you just replace rednet.receive(10) with rednet.receive() everything should work fine.
Check the Wiki (http://www.computercraft.info/wiki/Rednet.receive) for more information
Zambonie #3
Posted 15 January 2013 - 12:42 PM
Ok,thanks!
remiX #4
Posted 15 January 2013 - 05:21 PM
Also, this will just run once, use a while true do loop between the main parts for it to run forever