Posted 14 October 2014 - 10:36 AM
I was working on the script for my Operating Enviroment, I have encountered some problems. When using the table I read from a file, it's not working as I want. I am trying to use the information in the table to label the computer, please help me figure it out. (I'm not this terrible, im tired. :3)
Code
local maind = "/Luna/"
local version = "1.0"
os.version = function()
return "Luna "..version
end
if not term or not shell or not fs then
error("Luna: Not Running in CraftOS.", 0)
return
end
if not shell.getRunningProgram() == "/Luna/init" then
error("Luna: Not Running as '/Luna/init'.")
return
end
local sysd = {
prgs = maind.."Prg/",
apis = maind.."Api/",
syst = maind.."Sys/",
}
for _, v in pairs(sysd) do
if not fs.exists(v) then
error("Luna: Missing Directories, Run '/Luna/Sys/Update'", 0)
return
end
end
local apis = fs.list(maind.."Api")
for _, v in pairs(apis) do
os.loadAPI(sysd.apis..v)
print("Loaded API: "..v)
end
local prgs = fs.list(sysd.prgs)
print(#prgs.. " Programs Detected.")
if not fs.exists(maind.."Dat") then
fs.makeDir(maind.."Dat")
end
local data = { }
if not fs.exists(maind.."Dat/System") then
write("Computer Name: ")
local compname = read()
data.hostname = compname
local file = fs.open(maind.."Dat/System", "w")
file.write(textutils.serialise(data))
file.close()
end
local file = fs.open(maind.."Dat/System", "r")
local system = textutils.unserialise(file.readAll())
file.close()
system = textutils.serialise(system)
os.setComputerLabel(system.hostname)