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

[ANSWERED] Crashing with no apparent reason

Started by Fluffy977, 09 August 2012 - 07:47 AM
Fluffy977 #1
Posted 09 August 2012 - 09:47 AM
Computer 1:

rednet.open("back")
rednet.broadcast("Farm Computer Online")
print("Farm Computer Online")
print("Welcome, would you like to open the floodgate")
answer = read()
if answer == "yes" then
	rednet.send(2,"gate")
	sleep(15)
end
Computer 2:

rednet.open("top")
rednet.broadcast("Floodgate Computer Online")
print("Floodgate Computer Online")
term.clear()
term.setCursorPos(1, 1)
redstone.setOutput("right", true)
redstone.setOutput("left", true)
active = rednet.receive()
while true do
if active == true then
  redstone.setOutput("right", false)
  redstone.setOutput("left", false)
  print("Recieved")
  sleep(30)
  redstone.setOutput("right", true)
  redstone.setOutput("left", true)
end
end

So, when I open the 2nd one, then run back to the first to run the 1st program. It turns off the other computer and in server console it says
'Warning! Failed to abort a Computer. Dangling lua threads could cause errors.' When I go back to the 2nd computer, and start it up, it crashes with the same error, without me even starting up the program. Can someone explain? <3
Pharap #2
Posted 09 August 2012 - 10:36 AM
Computer 1:

rednet.open("back")
rednet.broadcast("Farm Computer Online")
print("Farm Computer Online")
print("Welcome, would you like to open the floodgate")
answer = read()
if answer == "yes" then
	rednet.send(2,"gate")
	sleep(15)
end
Computer 2:

rednet.open("top")
rednet.broadcast("Floodgate Computer Online")
print("Floodgate Computer Online")
term.clear()
term.setCursorPos(1, 1)
redstone.setOutput("right", true)
redstone.setOutput("left", true)
active = rednet.receive()
while true do
if active == true then
  redstone.setOutput("right", false)
  redstone.setOutput("left", false)
  print("Recieved")
  sleep(30)
  redstone.setOutput("right", true)
  redstone.setOutput("left", true)
end
end

So, when I open the 2nd one, then run back to the first to run the 1st program. It turns off the other computer and in server console it says
'Warning! Failed to abort a Computer. Dangling lua threads could cause errors.' When I go back to the 2nd computer, and start it up, it crashes with the same error, without me even starting up the program. Can someone explain? <3

Looks to me like the neverending loop you have is crashing lua somehow.:


while true do
if active == true then
  redstone.setOutput("right", false)
  redstone.setOutput("left", false)
  print("Recieved")
  sleep(30)
  redstone.setOutput("right", true)
  redstone.setOutput("left", true)
end
end

If active isn't true, it will never be true and the loop will never end because there is no break or return.
Luanub #3
Posted 09 August 2012 - 10:56 AM
And active will never be true. rednet.receive() returns a couple different params. A true/false boolean is not one of them.

It returns, id of the sending computer, the message sent, and the distance it was transmitted.

If you are wanting to check for a message indicating that something is on do something like this

while true do
local id, msg = rednet.receive() -- the message is the second param sent
if msg == "Farm Computer Online" then
  redstone.setOutput("right", false)
  redstone.setOutput("left", false)
  print("Recieved")
  sleep(30)
  redstone.setOutput("right", true)
  redstone.setOutput("left", true)
end

end
Fluffy977 #4
Posted 09 August 2012 - 07:36 PM
Thank you so much!