Posted 17 September 2014 - 10:04 PM
My code (found in the spoiler below) is meant to basically do what find does (Sort peripherals) in a version of computercraft that dosen't have peripheral.find. I simply need to run these functions in ok, err = pcall(). When I do so, they still return the error and end the program. The goal is to have it NOT do that. If someone could work out this error or explain it to me, I'd be very grateful (Also, if you use the latest version of Tekkit main, getting it to work would be even better :)/> ) The error I get is 4: attempt to call nil
Spoiler
--Start of setup
local function isReactor(input)
local tempReactor = peripheral.wrap(input)
local checkReactor = tempReactor.getConnected()
return checkReactor
end
local function whatIs(input)
local reactor = peripheral.wrap(input)
local whatIsIt = reactor.isActivelyCooled()
if whatIsIt then
table.insert(activeReactors, input)
else
table.insert(passiveReactors, input)
end
end
bigReactors = {}
passiveReactors = {}
activeReactors = {}
turbines = {}
--End of setup
--Sorting peripherals
foundPeripherals = peripheral.getNames()
for i=1,#foundPeripherals do
ok, err = pcall(isReactor(foundPeripherals[i]))
if ok then
table.insert(bigReactors, foundPeripherals[i])
else
print(foundPeripherals[i].." Is not a reactor!")
end
end
foundPeripherals = nil
ok = true
for i=1,#bigReactors do
ok, err = pcall(whatIs(bigReactors[i]))
if not ok then
table.insert(turbines, bigReactors[i])
end
end
print("Turbines found: "..#turbines)
print("Active reactors found: "..#activeReactors)
print("Passive reactors found: "..#passiveReactors)
Edited on 17 September 2014 - 08:05 PM