--[[--
This program runs everything
in the folder /autorun/ once
and everything within the folder
/loop/ continously
--]]--
-- folder path
local runpath = "autorun"
local looppath = "loop"
-- if the delay between each
-- run is less than this, cancel out
-- dont touch if you dont
-- know what youre doing
local throttle = 5
--(( Functions ))--
local function checkfolder(path)
if fs.isDir(path) then
-- not empty
return #fs.list(path) > 0
else
if fs.exists(path) then
-- path is a file, not folder
error("'"..path.."' is not a folder!",0)
else
-- no file nor folder
return false
end
end
end
local function executefolder(folder)
local list = fs.list(folder)
for index,name in ipairs(list) do
local path = fs.combine(folder,name)
if fs.isDir(path) then
executefolder(path)
else
shell.run(path)
end
end
end
local function oldStartupScript()
local label = os.getComputerLabel()
local info = function(key,value)
term.setTextColor(colors.lightGray)
write(key)
if term.isColor and term.isColor() then
term.setTextColor(colors.yellow)
else
term.setTextColor(colors.white)
end
print(value)
end
info("Computer ID: ","#"..os.getComputerID())
info("Computer label: ", os.getComputerLabel() or "<unnamed>")
if turtle then
local fuel = turtle.getFuelLevel()
local limit = math.floor(100 * fuel / turtle.getFuelLimit()) .. "%"
info("Fuel level: ", fuel.." ("..limit..")")
end
end
--(( Error handleing ))--
--(( Main program ))--
oldStartupScript()
if checkfolder(runpath) then
executefolder(runpath)
end
while true and checkfolder(looppath) do
local starttime = os.clock()
executefolder(looppath)
local endtime = os.clock()
if endtime - starttime < throttle then
error("Stopping loop in case of continous erroring",0)
end
end
--(( EOF ))--
Comments