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

[ERROR] [Lua] parallel:22: orphaned thread

Started by Arania, 13 December 2012 - 02:09 AM
Arania #1
Posted 13 December 2012 - 03:09 AM
I've got the following code running on an autonomous machine, designed as part of an elevator system to call a minecraft to a floor using railcraft elevator tracks. It's also using the CCLan 1.2 plugin.

Startup file

dofile("messaging")
startButtonController(os.getComputerLabel())

Messaging Library ('messaging')

function startFloorController(floorNumber)
while (true) do
  local _,_,message,_ = os.pullEvent("cable_message")
   if message == floorNumber then
	redstone.setOutput("back", true)
   else
	redstone.setOutput("back", false)
   end
end
end

function startButtonController(floorNumber)
while (true) do
  if getAllRedstone() then
   sendMessage(floorNumber)
   while getAllRedstone() do end
  end
end
end

function getAllRedstone()
return redstone.getInput("front") or redstone.getInput("back") or redstone.getInput("left") or redstone.getInput("right") or redstone.getInput("top") or redstone.getInput("bottom")
end

function sendMessage(message)
if peripheral.getType("back") == "cable" then peripheral.call("back", "send", -1, message) end
if peripheral.getType("left") == "cable" then peripheral.call("left", "send", -1, message) end
if peripheral.getType("right") == "cable" then peripheral.call("right", "send", -1, message) end
if peripheral.getType("top") == "cable" then peripheral.call("top", "send", -1, message) end
if peripheral.getType("bottom") == "cable" then peripheral.call("bottom", "send", -1, message) end
if peripheral.getType("front") == "cable" then peripheral.call("front", "send", -1, message) end
end

It will work fine initially, respond to redstone pulses sent to it and direct the minecart to the appropriate floor. After some time (I'm not sure what triggers it), the computer will stop working and display one of the following errors on the terminal screen-


messaging:-1: attempt to call nil
> parallel:22: orphaned thread
Press any key to continue

OR


messaging:22: attempt to index ? (a function value)
> parallel:22: orphaned thread
Press any key to continue

OR


nil: vm error:
java.lang.ArrayIndexOutOfBoundsException
Press any key to continue

Despite the message, the terminal is unresponsive, and I need to remove and re-place the computer to get it to function again.
Have I done something entirely wrong with the code, or is something else broken here?
Doyle3694 #2
Posted 13 December 2012 - 03:15 AM
Im not sure, but is dofile() a command? try replacing it with os.loadAPI()
huettner94 #3
Posted 13 December 2012 - 08:34 AM
You shouldn't use a loop without a command. Try the following:

function startButtonController(floorNumber)
while (true) do
  if getAllRedstone() then
   sendMessage(floorNumber)
   while getAllRedstone() do
    os.pullEvent("redstone")
   end
  end
end
end

Please put this Post again (with your complete code) in the bug's section, the "vm error" shouldn't be visible