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
Messaging Library ('messaging')
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-
OR
OR
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?
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?