I changed it around, but it's still not working… I have tried everything I can think of….to no avail. I'm just going to have to post my entire code, huh? well, here you go…again. :P/>/>
--Made by Craniumkid22
--This code is free to use, under a few conditions:
--1. DO NOT claim this as your own work!
--2. If you change this code, feel free to contact me on the CC forums, user-Craniumkid22.
--3. if you have questions about any of this code, feel free to contact me as well.
--Huge thanks to Lyqyd for pounding the necessity of local variables into my thick skull.
--screen functions
function title()
term.clear()
term.setCursorPos(1,1)
print(" Welcome to Master Control initialization!")
print(" Please read each selection carefully.")
print(" If you mess up, press CTRL + T")
print(" And run the wizard again.")
term.setCursorPos(1,9)
end
--end screen functions
-- variables
colorOpt={
"Redstone/Red alloy wire",
"White",
"Orange",
"Magenta",
"Light Blue",
"Yellow",
"Lime",
"Pink",
"Gray",
"Light Gray",
"Cyan",
"Purple",
"Blue",
"Brown",
"Green",
"Red",
"Black"
}
eType={
"None",
"BatBox",
"MFE",
"MFSU"
}
pType={
"None",
"Generator",
"Geothermal Generator",
"Water Mill",
"Wind Mill",
"Solar Panel",
"Nuclear Reactor",
"Redstone Engine",
"Steam Engine",
"Combustion Engine"
}
--end variables
function yN()
local n=1
while true do
local x, y=term.getCursorPos()
term.clearLine()
if n==1 then write(">YES< NO") else write (" YES >NO<") end
term.setCursorPos(x, y)
a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent() end
if b==203 and n==2 then n=1 end
if b==205 and n==1 then n=2 end
if b==28 then print("") break end
end
if n==1 then return "true" end
if n==2 then return "false" end
return false
end
function opt(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
function colorConvert(color)
if color > 1 then return 2^(color - 2)
else return 0
end
end
function eConvert(e,m)
if e == "1" then r = m[1]
elseif e == "2" then r = m[2]
elseif e == "3" then r = m[3]
elseif e == "4" then r = m[4]
elseif e == "5" then r = m[4]
elseif e == "6" then r = m[6]
elseif e == "7" then r = m[7]
elseif e == "8" then r = m[8]
elseif e == "9" then r = m[9]
elseif e == "10" then r = m[10]
end
return tostring(r)
end
local function saveState(saveTable)
local file = fs.open("status", "w")
if file then
for eNum, eInfo in ipairs(saveTable) do
file.writeLine(eInfo.type..","..eInfo.color..","..eInfo.status)
end
file.close()
end
end
local function saveProfile(saveTable)
local file = fs.open("profile", "w")
if file then
for eNum, eInfo in ipairs(saveTable) do
file.writeLine(eInfo.type..","..eInfo.name..","..eInfo.pass)
end
file.close()
end
end
local function loadState()
local loadTable = {}
local file = fs.open("status", "r")
if file then
readLine = file.read("*l")
while readLine do
local lineTable = {}
lineTable.type, lineTable.color, lineTable.status = string.match(readLine, "(%a+),(%a+),(%a+)")
if lineTable.type then
table.insert(loadTable, lineTable)
end
readLine = file.read("*l")
end
file.close()
end
return loadTable
end
--code start
local controlTable = {}
while true do
title()
local deviceTable = {type="Admin"}
while true do
print("Please enter Administrator name:")
deviceTable.name = read()
if deviceTable.name == "" then
print("Admin name cannot be blank")
sleep(1)
title()
else break
end
end
title()
while true do
while true do
print("Please enter Administrator password:")
tempadmin = read("*")
if tempadmin == "" then
print("Password cannot be blank")
sleep(1)
title()
else break
end
end
title()
while true do
print("Please re-enter password:")
tempadmin2 = read("*")
if tempadmin2 == "" then
print("Password cannot be blank")
sleep(1)
title()
else break
end
end
title()
if tempadmin ~= tempadmin2 then
print("Passwords do not match. Please try again.")
sleep(1)
title()
elseif tempadmin == tempadmin2 then
deviceTable.pass = tempadmin break
end
end
title()
print("Thank you. Admin profile created.")
sleep(1)
table.insert(controlTable,deviceTable)
saveProfile(controlTable)
tempadmin = nil
tempadmin2 = nil
break
end
local deviceTable = {type="User"}
while true do
title()
print("Please enter User name:")
tempusername = read()
if tempusername == adminname then
print("Cannot have User name the same as Administrator name.")
sleep(1)
title()
elseif tempusername == "" then
print("User name cannot be blank.")
sleep(1)
title()
else
deviceTable.name = tempusername
break
end
end
while true do
title()
while true do
while true do
print("Please enter User password:")
tempuser = read("*")
if tempuser == "" then
print("Password cannot be blank.")
sleep(1)
title()
else break
end
end
title()
while true do
title()
print("Pleas re-enter password:")
tempuser2 = read("*")
if tempuser2 == "" then
print("Password cannot be blank.")
sleep(1)
title()
else break
end
end
title()
if tempuser ~= tempuser2 then
print("Passwords do not match. Please try again.")
sleep(1)
title()
elseif tempuser == tempuser2 then
deviceTable.pass = tempuser break
end
end
title()
print("Thank you. User profile created.")
sleep(1)
break
end
table.insert(controlTable,deviceTable)
saveProfile(controlTable)
tempuser = nil
tempuser2 = nil
--removed
local deviceTable = {type="Lights"}
title()
print("Do you have lighting that you want to control?")
deviceTable.status = yN()
if deviceTable.status == "true" then
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt))
deviceTable.status = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
else deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
end
title()
while true do
local deviceTable = {type="Power"}
print("What type of power are you using?")
sleep(2)
deviceTable.type = tostring(opt(pType))
if deviceTable.type == "7" then
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
local deviceTable = {type="Reactor"}
title()
print("Do you want this computer to control your reactor?")
deviceTable.status = yN()
if deviceTable.status == "true" then
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt))
table.insert(controlTable,deviceTable)
saveState(controlTable)
else
local deviceTable = {type="Reactor"}
deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
end
local deviceTable = {type="Coolant"}
deviceTable.type = "Coolant"
title()
print("Do you have an independant coolant system?")
deviceTable.status = yN()
if deviceTable.status == "true" then
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt))
table.insert(controlTable,deviceTable)
saveState(controlTable) break
else
deviceTable.status = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
end
elseif deviceTable.type == "1" then
local deviceTable = {type="Power"}
deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
local deviceTable = {type="Reactor"}
deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
local deviceTable = {type="Coolant"}
deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
else
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt))
deviceTable.status ="false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
local deviceTable = {type="Reactor"}
deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
local deviceTable = {type="Coolant"}
deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
end
break
end
while true do
local deviceTable = {type="Energy"}
title()
print("What type of energy storage are you using?")
sleep(2)
deviceTable.type = tostring(opt(eType))
if deviceTable.type ~= "1" then
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt))
deviceTable.status = "nil"
table.insert(controlTable,deviceTable)
saveState(controlTable)
else
deviceTable.color = "false"
deviceTable.status = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
end
break
end
while true do
local deviceTable = {type="Macerator"}
title()
print("Would you like to control an IC2 Macerator?")
deviceTable.status = yN()
if deviceTable.status == "true" then
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt))
deviceTable.status = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
break
else deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
break
end
end
while true do
local deviceTable = {type="Furnace"}
title()
print("Would you like to control an IC2 Furnace?")
furnace = yN()
if furnace == "true" then
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt))
deviceTable.status = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
break
else deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
break
end
end
while true do
local deviceTable = {type="Compressor"}
title()
print("Would you like to control an IC2 Compressor?")
deviceTable.status = yN()
if deviceTable.status == "true" then
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt))
deviceTable.status = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
break
else deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
break
end
end
while true do
local deviceTable = {type="Extractor"}
title()
print("Would you like to control an IC2 Extractor?")
extractor = yN()
if extractor == "true" then
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt))
deviceTable.status = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
break
else deviceTable.status = "false"
deviceTable.color = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
break
end
end