Posted 25 August 2012 - 06:52 PM
I have a huge code I'm working on, and just added Monitor support. The problem is, I need to have the monitor running at all times, constantly updating. I thought using the parallel API would accomplish this, but I keep getting an error. I have never received this error before, but I think it's because I've got a loop being called in a parallel. This is the error I'm getting:
Edit: Strike that, it's not the loop, because I commented it out, but it's still giving me the error.
Edit 2: Wow, I'm an idiot. This was due to me calling the monTitle() within itself. Supposed to have been MCscreen()
parallel:22: mcs:1706: vm error: java.lang.ArrayIndexOutOfBoundsException: 256
And here is my code. It's quite big, so just go ahead and skip to the bottom part, since that's the relevant area.Spoiler
--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.
--CREDITS:
--Huge thanks to Lyqyd for pounding the necessity of local variables into my thick skull.
--Major credit goes to Pharap for helping me squash bugs.
--Thanks
-- variables
local controlTable = {}
local symbol = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"}
local menu = {
"Production Control",
"Reactor Control",
"Lights",
"Maintenance",
"Games",
"Shutdown"
}
local answers = {
"It is Certain ",
" Decidedly So ",
" No ",
" Yes ",
" No doubt ",
" Never ",
" Unknown ",
" Ask again ",
" Doubtful ",
" Most Likely ",
"Cannot predict",
" Probably not ",
" Stars say no ",
" For sure "
}
local gMenu = {
"Lucky Dice",
"Magic 8 Block",
"Card Slots",
"Main Menu"
}
local mMenu = {
"System Status",
"Run initialization",
"Return to Main menu"
}
local rMenu = {
"Start Reactor",
"Shutdown Reactor",
"Return to Main menu"
}
local pMenu = {
"Macerator",
"Furnace",
"Compressor",
"Extractor",
"Return to Main menu"
}
local colorOpt={
"Redstone/Red alloy wire",
"White",
"Orange",
"Magenta",
"Light Blue",
"Yellow",
"Lime",
"Pink",
"Gray",
"Light Gray",
"Cyan",
"Purple",
"Blue",
"Brown",
"Green",
"Red",
"Black"
}
local eType={
"None",
"BatBox",
"MFE",
"MFSU"
}
local pType={
"None",
"Generator",
"Geothermal Generator",
"Water Mill",
"Wind Mill",
"Solar Panel",
"Nuclear Reactor",
"Redstone Engine",
"Steam Engine",
"Combustion Engine"
}
local pTypeX={
"None",
"Generator",
"Geothermal",
"WaterMill",
"WindMill",
"SolarPanel",
"NuclearReactor",
"RedstoneEngine",
"SteamEngine",
"CombustionEngine"
}
local sSide = {
"left",
"right",
"top",
"bottom",
"back",
"front"
}
--peripheral check
for i=1,#sSide do
if peripheral.isPresent(sSide[i]) then
if peripheral.getType(sSide[i]) == "monitor" then mon = peripheral.wrap(sSide[i]) pM = true
elseif peripheral.getType(sSide[i]) == "disk" then disk = sSide pD = true
elseif peripheral.getType(sSide[i]) == "modem" then modem = sSide pW = true
end
end
end
-- 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
function newPage()
term.clear()
term.setCursorPos(1,1)
print(".-----------------------------------------------.")
print("| Welcome to Master Control |")
print("| Ver. 1.0 |")
print("+-----------------------------------------------+")
term.setCursorPos(1,6)
print(" Please select Program to run")
term.setCursorPos(1,8)
end
function nukePage()
term.clear()
term.setCursorPos(1,1)
print(".-----------------------------------------------.")
print("| Welcome to NukeOS |")
print("| Ver. 1.0 |")
print("+-----------------------------------------------+")
term.setCursorPos(1,5)
end
function prodPage()
term.clear()
term.setCursorPos(1,1)
print(".-----------------------------------------------.")
print("| Production Control |")
print("| Ver. 1.0 |")
print("+-----------------------------------------------+")
term.setCursorPos(1,6)
end
function mainPage()
term.clear()
term.setCursorPos(1,1)
print(".-----------------------------------------------.")
print("| Maintenance Access |")
print("+-----------------------------------------------+")
term.setCursorPos(1,6)
print(" Please Select Function ")
term.setCursorPos(1,8)
end
function blank()
term.setCursorPos(7,3)
print("+--------------+ +--------------+")
term.setCursorPos(7,4)
print("| | | |")
term.setCursorPos(7,5)
print("| | | |")
term.setCursorPos(7,6)
print("| Press ENTER | | to Roll |")
term.setCursorPos(7,7)
print("| | | |")
term.setCursorPos(7,8)
print("| BACKSPACE | | to Exit |")
term.setCursorPos(7,9)
print("| | | |")
term.setCursorPos(7,10)
print("| | | |")
term.setCursorPos(7,11)
print("+--------------+ +--------------+")
end
function gPage()
term.clear()
term.setCursorPos(1,1)
print(" _______ _______ _______ _______ _______ ")
print(" ( ____ \\( ___ )( )( ____ \\( ____ \\")
print(" | ( \\/| ( ) || () () || ( \\/| ( \\/")
print(" | | | (___) || || || || (__ | (_____ ")
print(" | | ____ | ___ || |(_)| || __) (_____ )")
print(" | | \\_ )| ( ) || | | || ( ) |")
print(" | (___) || ) ( || ) ( || (____/\\/\\____) |")
print(" (_______)|/ \\||/ \\|(_______/\\_______)")
end
function sTitle()
term.setCursorPos(1,15)
print(" __ __ ___ ___ __ _ ___ _____ __ ")
print(" / /' / /\\ | |_)| | \\ ( ('| | / / \\ | | ( ('")
print(" \\_\\_,/_/--\\|_| \\|_|_/ _)_)|_|__\\_\\_/ |_| _)_)")
end
function loser()
term.clear()
term.setCursorPos(1,5)
print(" __ ___ __ ____ ____ ")
print(" || // \\\\ (( \\ || || \\\\")
print(" || (( )) \\\\ ||== ||_//")
print(" ||__| \\\\_// \\_)) ||___ || \\\\")
sleep(3)
term.clear()
end
function jackpot()
for x = 1,5 do
term.clear()
sleep(.25)
term.setCursorPos(1,5)
print(" __ ___ ___ __ __ ____ ___ ______")
print(" || // \\\\ // || // || \\\\ // \\\\ | || |")
print(" || ||=|| (( ||<< ||_// (( )) || ")
print(" |__|| || || \\\\__ || \\\\ || \\\\_// || ")
sleep(.25)
end
end
function soon()
for i = 1,5 do
term.clear()
term.setCursorPos(1,1)
sleep(.25)
print(" ) ( ) ")
print(" ( ( /( ( )\\ ) ( /( ( ")
print(" )\\ )\\()) )\\))( (()/( )\\()))\\ ) ")
print(" (((_|(_)\\ ((_)()\\ /(_)|(_)\\(()/( ")
print(" )\\___ ((_)(_()((_|_)) _((_)/(_))_ ")
print(" ((/ __/ _ \\| \\/ |_ _|| \\| (_)) __| ")
print(" | (_| (_) | |\\/| || | | .' | | (_ | ")
print(" (\\___\\__)/|_| )|_|__)||_|\\_| \\___| ")
print(" ")
print(" )\\ ) ( /( ( /( ( /( ")
print(" (()/( )\\()) )\\()) )\\()) ")
print(" /(_)|(_)\\ ((_)\\ ((_)\\ ")
print(" (_)) ((_) ((_) _((_) ")
print(" / __| / _ \\ / _ \\| \\| | ")
print(" \\__ \\| (_) | (_) | .' | ")
print(" |___/ \\___/ \\___/|_|\\_| ")
sleep(.5)
end
end
-- game functions
function games()
while true do
gPage()
local input = opt(gMenu,10)
if input == 1 then
dice()
elseif input == 2 then
block()
elseif input == 3 then
slots()
elseif input == 4 then break
end
end
end
-- dice functions
function dTitle()
term.setCursorPos(1,14)
print(" __ __ ___ _ ")
print(" / / __ ______/ /____ __ / _ \\(_)______ ")
print(" / /__/ // / __/ '_/ // / / // / / __/ -_)")
print(" /____/\\_,_/\\__/_/\\_\\\\_, / /____/_/\\__/\\__/ ")
print(" /___/ ")
end
function dice()
while true do
term.clear()
dTitle()
blank()
event, p1 = os.pullEvent("key")
if p1 == 28 then
roll()
sleep(3)
elseif p1 == 14 then break
end
end
end
function die1()
local x = math.random(1,6)
if x == 1 then
term.setCursorPos(7,3)
print("+--------------+")
term.setCursorPos(7,4)
print("| |")
term.setCursorPos(7,5)
print("| |")
term.setCursorPos(7,6)
print("| |")
term.setCursorPos(7,7)
print("| O |")
term.setCursorPos(7,8)
print("| |")
term.setCursorPos(7,9)
print("| |")
term.setCursorPos(7,10)
print("| |")
term.setCursorPos(7,11)
print("+--------------+")
elseif x == 2 then
term.setCursorPos(7,3)
print("+--------------+")
term.setCursorPos(7,4)
print("| |")
term.setCursorPos(7,5)
print("| O |")
term.setCursorPos(7,6)
print("| |")
term.setCursorPos(7,7)
print("| |")
term.setCursorPos(7,8)
print("| |")
term.setCursorPos(7,9)
print("| O |")
term.setCursorPos(7,10)
print("| |")
term.setCursorPos(7,11)
print("+--------------+")
elseif x == 3 then
term.setCursorPos(7,3)
print("+--------------+")
term.setCursorPos(7,4)
print("| |")
term.setCursorPos(7,5)
print("| O |")
term.setCursorPos(7,6)
print("| |")
term.setCursorPos(7,7)
print("| O |")
term.setCursorPos(7,8)
print("| |")
term.setCursorPos(7,9)
print("| O |")
term.setCursorPos(7,10)
print("| |")
term.setCursorPos(7,11)
print("+--------------+")
elseif x == 4 then
term.setCursorPos(7,3)
print("+--------------+")
term.setCursorPos(7,4)
print("| |")
term.setCursorPos(7,5)
print("| O O |")
term.setCursorPos(7,6)
print("| |")
term.setCursorPos(7,7)
print("| |")
term.setCursorPos(7,8)
print("| |")
term.setCursorPos(7,9)
print("| O O |")
term.setCursorPos(7,10)
print("| |")
term.setCursorPos(7,11)
print("+--------------+")
elseif x == 5 then
term.setCursorPos(7,3)
print("+--------------+")
term.setCursorPos(7,4)
print("| |")
term.setCursorPos(7,5)
print("| O O |")
term.setCursorPos(7,6)
print("| |")
term.setCursorPos(7,7)
print("| O |")
term.setCursorPos(7,8)
print("| |")
term.setCursorPos(7,9)
print("| O O |")
term.setCursorPos(7,10)
print("| |")
term.setCursorPos(7,11)
print("+--------------+")
elseif x == 6 then
term.setCursorPos(7,3)
print("+--------------+")
term.setCursorPos(7,4)
print("| |")
term.setCursorPos(7,5)
print("| O O |")
term.setCursorPos(7,6)
print("| |")
term.setCursorPos(7,7)
print("| O O |")
term.setCursorPos(7,8)
print("| |")
term.setCursorPos(7,9)
print("| O O |")
term.setCursorPos(7,10)
print("| |")
term.setCursorPos(7,11)
print("+--------------+")
end
end
function die2()
local x = math.random(1,6)
if x == 1 then
term.setCursorPos(25,3)
print("+--------------+")
term.setCursorPos(25,4)
print("| |")
term.setCursorPos(25,5)
print("| |")
term.setCursorPos(25,6)
print("| |")
term.setCursorPos(25,7)
print("| O |")
term.setCursorPos(25,8)
print("| |")
term.setCursorPos(25,9)
print("| |")
term.setCursorPos(25,10)
print("| |")
term.setCursorPos(25,11)
print("+--------------+")
elseif x == 2 then
term.setCursorPos(25,3)
print("+--------------+")
term.setCursorPos(25,4)
print("| |")
term.setCursorPos(25,5)
print("| O |")
term.setCursorPos(25,6)
print("| |")
term.setCursorPos(25,7)
print("| |")
term.setCursorPos(25,8)
print("| |")
term.setCursorPos(25,9)
print("| O |")
term.setCursorPos(25,10)
print("| |")
term.setCursorPos(25,11)
print("+--------------+")
elseif x == 3 then
term.setCursorPos(25,3)
print("+--------------+")
term.setCursorPos(25,4)
print("| |")
term.setCursorPos(25,5)
print("| O |")
term.setCursorPos(25,6)
print("| |")
term.setCursorPos(25,7)
print("| O |")
term.setCursorPos(25,8)
print("| |")
term.setCursorPos(25,9)
print("| O |")
term.setCursorPos(25,10)
print("| |")
term.setCursorPos(25,11)
print("+--------------+")
elseif x == 4 then
term.setCursorPos(25,3)
print("+--------------+")
term.setCursorPos(25,4)
print("| |")
term.setCursorPos(25,5)
print("| O O |")
term.setCursorPos(25,6)
print("| |")
term.setCursorPos(25,7)
print("| |")
term.setCursorPos(25,8)
print("| |")
term.setCursorPos(25,9)
print("| O O |")
term.setCursorPos(25,10)
print("| |")
term.setCursorPos(25,11)
print("+--------------+")
elseif x == 5 then
term.setCursorPos(25,3)
print("+--------------+")
term.setCursorPos(25,4)
print("| |")
term.setCursorPos(25,5)
print("| O O |")
term.setCursorPos(25,6)
print("| |")
term.setCursorPos(25,7)
print("| O |")
term.setCursorPos(25,8)
print("| |")
term.setCursorPos(25,9)
print("| O O |")
term.setCursorPos(25,10)
print("| |")
term.setCursorPos(25,11)
print("+--------------+")
elseif x == 6 then
term.setCursorPos(25,3)
print("+--------------+")
term.setCursorPos(25,4)
print("| |")
term.setCursorPos(25,5)
print("| O O |")
term.setCursorPos(25,6)
print("| |")
term.setCursorPos(25,7)
print("| O O |")
term.setCursorPos(25,8)
print("| |")
term.setCursorPos(25,9)
print("| O O |")
term.setCursorPos(25,10)
print("| |")
term.setCursorPos(25,11)
print("+--------------+")
end
end
function roll()
local r = 1
for r = 1,50 do
parallel.waitForAll(die1,die2,sleep(.1))
end
end
-- 8block functions
function bTitle()
term.clear()
term.setCursorPos(1,1)
print(" _ _ _ __ __ _ ")
print(" ' ) ) ) ( ) / ) // / ")
print(" / / / __. _, o _. ./' /--< // __ _. /_ ")
print(" / ' (_(_/|_(_)_<_(__ (__) /___/_</_(_)(__/ <_ ")
print(" /| ")
print(" |/ ")
end
function block()
start()
while true do
local event, p1 = os.pullEvent("key")
if p1 == 28 then
shake()
sleep(2)
start()
elseif p1 == 14 then break
end
end
end
function start()
bTitle()
term.setCursorPos(1,7)
print(" .----------------. ")
print("Ask me ANY | .--------------. | Whether you ")
print("question, and | | ____ | | like it... ")
print("press ENTER | | .' __ '. | | ")
print("to receive | | | (__) | | | ")
print("your answer... | | .'____'. | | OR NOT... ")
print(" | | | (____) | | | ")
print(" | | '.______.' | | ")
print(" | | | | ")
print(" | '--------------' | ")
print(" '----------------' ")
print(" Press BACKSPACE to exit ")
end
function shake()
term.clear()
bTitle()
term.setCursorPos(1,7)
print(" .----------------. ")
print(" | .--------------. |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | '--------------' |")
print(" '----------------' ")
sleep(.2)
term.clear()
bTitle()
term.setCursorPos(1,7)
print(" .----------------. ")
print(" | .--------------. |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | '--------------' |")
print(" '----------------' ")
sleep(.2)
term.clear()
bTitle()
term.setCursorPos(1,7)
print(" .----------------. ")
print(" | .--------------. |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | '--------------' |")
print(" '----------------' ")
sleep(.2)
term.clear()
bTitle()
term.setCursorPos(1,7)
print(" .----------------. ")
print(" | .--------------. |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | '--------------' |")
print(" '----------------' ")
sleep(.2)
term.clear()
bTitle()
term.setCursorPos(1,7)
print(" .----------------. ")
print(" | .--------------. |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | '--------------' |")
print(" '----------------' ")
sleep(.2)
term.clear()
bTitle()
term.setCursorPos(1,7)
print(" .----------------. ")
print(" | .--------------. |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | '--------------' |")
print(" '----------------' ")
sleep(1.5)
ans()
end
function ans()
term.clear()
bTitle()
term.setCursorPos(1,7)
print(" .----------------. ")
print(" | .--------------. |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | |"..answers[math.random(1,#answers)].."| |")
print(" | | | |")
print(" | | | |")
print(" | | | |")
print(" | '--------------' |")
print(" '----------------' ")
end
-- slots functions
function cardtop(x,y)
term.setCursorPos(x,y)
write([[ .------------. ]])
term.setCursorPos(x,y+1)
write([[| .----------. |]])
term.setCursorPos(x,y+2)
write([[| | | |]])
term.setCursorPos(x,y+3)
write([[| | .------. | |]])
term.setCursorPos(x,y+4)
end
function cardbase(x,y)
term.setCursorPos(x,y+8)
write([[| | '------' | |]])
term.setCursorPos(x,y+9)
write([[| | | |]])
term.setCursorPos(x,y+10)
write([[| '----------' |]])
term.setCursorPos(x,y+11)
write([[ '------------' ]])
end
function numtop(n,x,y)
if symbol[n] == "10" then
term.setCursorPos(x,y+4)
write([[| | |]]..symbol[n]..[[--. | | |]])
else
term.setCursorPos(x,y+4)
write([[| | |]]..symbol[n]..[[.--. | | |]])
end
end
function numbase(n,x,y)
if symbol[n] == "10" then
term.setCursorPos(x,y+7)
write([[| | | '--]]..symbol[n]..[[| | |]])
else
term.setCursorPos(x,y+7)
write([[| | | '--']]..symbol[n]..[[| | |]])
end
end
function spade(x,y)
term.setCursorPos(x,y+5)
write([[| | | :/\: | | |]])
term.setCursorPos(x,y+6)
write([[| | | (__) | | |]])
end
function heart(x,y)
term.setCursorPos(x,y+5)
write([[| | | (\/) | | |]])
term.setCursorPos(x,y+6)
write([[| | | :\/: | | |]])
end
function club(x,y)
term.setCursorPos(x,y+5)
write([[| | | :D/>/>): | | |]])
term.setCursorPos(x,y+6)
write([[| | | ()() | | |]])
end
function diamond(x,y)
term.setCursorPos(x,y+5)
write([[| | | :/\: | | |]])
term.setCursorPos(x,y+6)
write([[| | | :\/: | | |]])
end
function slot(pos)
local c = math.random(1,4)
local n = math.random(1,13)
cardtop(pos,1)
numtop(n,pos,1)
if c == 1 then
spade(pos,1)
elseif c == 2 then
heart(pos,1)
elseif c == 3 then
club(pos,1)
elseif c == 4 then
diamond(pos,1)
end
numbase(n,pos,1)
cardbase(pos,1)
return c,n
end
function spin()
for cnt = 1, 10 do
slot(2)
slot(18)
slot(34)
sleep(cnt/30)
end
end
function allsuitsmatch(result)
return (result[1] == result[3] and result[3] == result[5] and result[5] ==result[1])
end
function allvaluesmatch(result)
return (result[2] == result[4] and result[4] == result[6] and result[6] ==result[2] )
end
function isroyalflush(result)
local Fresult = false
if result[2] > 10 and result[4] > 10 and result[6] > 10 then
if result[2] ~= result[4] and result[4] ~= result[6] and result[6] ~= result[2] then return true -- royal flush discounting Ace
end
end
if result[2] == 1 and result[4] > 11 and result[6] > 11 and result[4] ~= result[6] then return true --royal flush including ace, condition 1
elseif result[4] == 1 and result[6] > 11 and result[2] > 11 and result[6] ~= result[2] then return true --royal flush including ace, condition 2
elseif result[6] == 1 and result[2] > 11 and result[4] > 11 and result[2] ~= result[4] then return true --royal flush including ace, condition 3
end
return false
end
function testwin(results)
------------------------------
-- This function has been --
-- brought to you by Pharap --
------------------------------
local value = 0
if allsuitsmatch(results) then value = 1 end -- suits match
if allvaluesmatch(results) then value = 2 end -- values match
if allsuitsmatch(results) and allvaluesmatch(results) then value = 3 end --suits and values match
if isroyalflush(results) then value = 4 end -- royal flush
if isroyalflush(results) and allsuitsmatch(results) then value = 5 end -- royal flush of all matching suits
if isroyalflush(results) and allvaluesmatch(results) then value = "wtfiswrongwithyou,howthehelldidyoucausesuchabloodystupiderror" return "error" end-- lol, like this would actually happen
return value
end
function slots()
term.clear()
sTitle()
slot(2)
slot(18)
slot(34)
while true do
local event, p1 = os.pullEvent()
if event == "key" then
if p1 == 28 then
spin()
local s1, n1 = slot(2)
local s2, n2 = slot(18)
local s3, n3 = slot(34)
sleep(2)
local results = {s1,n1,s2,n2,s3,n3}
--local results = {3,1,3,12,3,13}
local condition = testwin(results)
if condition == 0 then
loser()
term.clear()
sTitle()
slot(2)
slot(18)
slot(34)
elseif condition == 1 then --suits
jackpot()
term.clear()
sTitle()
slot(2)
slot(18)
slot(34)
elseif condition == 2 then --values
jackpot()
term.clear()
sTitle()
slot(2)
slot(18)
slot(34)
elseif condition == 3 then --suits and values
jackpot()
term.clear()
sTitle()
slot(2)
slot(18)
slot(34)
elseif condition == 4 then --royal flush
jackpot()
term.clear()
sTitle()
slot(2)
slot(18)
slot(34)
elseif condition == 5 then --royal flush suited
jackpot()
term.clear()
sTitle()
slot(2)
slot(18)
slot(34)
end
elseif p1 == 14 then break
end
end
end
end
-- action functions
function time()
while pM do
local mX,mY = mon.getSize()
local t = os.time()
time = textutils.formatTime(t,false)
mon.setCursorPos(mX-9,3)
mon.write(time)
sleep(0)
end
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 loadState()
local loadTable = {}
local file = fs.open("status", "r")
if file then
readLine = file.readLine()
while readLine do
local lineTable = {}
lineTable.type, lineTable.color, lineTable.status = string.match(readLine, "(%w+),(%w+),(%w+)")
if lineTable.type then
table.insert(loadTable, lineTable)
end
readLine = file.readLine()
end
file.close()
end
return loadTable
end
function menuOpt()
local btn1 = {1,1,menu[1]}
local btn2 = {2,1,menu[2]}
local btn3 = {1,2,menu[3]}
local btn4 = {2,2,menu[4]}
local btn5 = {1,3,menu[5]}
local btn6 = {2,3,menu[6]}
local a1 = string.len(" ["..btn1[3].."] "..btn2[3].." ")/2
local a2 = string.len(" "..btn1[3].." ["..btn2[3].."]")/2
local a3 = string.len(" "..btn1[3].." "..btn2[3].." ")/2
local b1 = string.len(" ["..btn3[3].."] "..btn4[3].." ")/2
local b2 = string.len(" "..btn3[3].." ["..btn4[3].."]")/2
local b3 = string.len(" "..btn3[3].." "..btn4[3].." ")/2
local c1 = string.len(" ["..btn5[3].."] "..btn6[3].." ")/2
local c2 = string.len(" "..btn5[3].." ["..btn6[3].."]")/2
local c3 = string.len(" "..btn5[3].." "..btn6[3].." ")/2
local x,y = term.getSize()
local curx=btn1[1]
local cury=btn1[2]
while true do
--test for looping
if curx<btn1[1] and cury==btn1[2] then curx=btn2[1] cury=btn2[2]
elseif curx>btn2[1] and cury==btn2[2] then curx=btn1[1] cury=btn1[2]
elseif curx<btn3[1] and cury==btn3[2] then curx=btn4[1] cury=btn4[2]
elseif curx>btn4[1] and cury==btn4[2] then curx=btn3[1] cury=btn3[2]
elseif curx<btn5[1] and cury==btn5[2] then curx=btn6[1] cury=btn6[2]
elseif curx>btn6[1] and cury==btn6[2] then curx=btn5[1] cury=btn5[2]
elseif cury<btn1[2] and curx==btn1[1] then cury=btn5[2] curx=btn5[1]
elseif cury>btn5[2] and curx==btn5[1] then cury=btn1[2] curx=btn1[1]
elseif cury<btn2[2] and curx==btn2[1] then cury=btn6[2] curx=btn6[1]
elseif cury>btn6[2] and curx==btn6[1] then cury=btn2[2] curx=btn2[1]
end
-- line 1 of options
if curx==btn1[1] and cury==btn1[2] then
local x = (x/2)-a1
term.setCursorPos(x,8)
print(" ["..btn1[3].."] "..btn2[3].." ")
elseif curx==btn2[1] and cury==btn2[2] then
local x = (x/2)-a2
term.setCursorPos(x,8)
print(" "..btn1[3].." ["..btn2[3].."]")
else
local x = (x/2)-a3
term.setCursorPos(x,8)
print(" "..btn1[3].." "..btn2[3].." ")
end
-- line 2 of options
if curx==btn3[1] and cury==btn3[2] then
local x = (x/2)-b1
term.setCursorPos(x,10)
print(" ["..btn3[3].."] "..btn4[3].." ")
elseif curx==btn4[1] and cury==btn4[2] then
local x = (x/2)-b2
term.setCursorPos(x,10)
print(" "..btn3[3].." ["..btn4[3].."]")
else
local x = (x/2)-b3
term.setCursorPos(x,10)
print(" "..btn3[3].." "..btn4[3].." ")
end
-- line 3 of options
if curx==btn5[1] and cury==btn5[2] then
local x = (x/2)-c1
term.setCursorPos(x,12)
print(" ["..btn5[3].."] "..btn6[3].." ")
elseif curx==btn6[1] and cury==btn6[2] then
local x = (x/2)-c2
term.setCursorPos(x,12)
print(" "..btn5[3].." ["..btn6[3].."]")
else
local x = (x/2)-c3
term.setCursorPos(x,12)
print(" "..btn5[3].." "..btn6[3].." ")
end
e, k = os.pullEvent("key")
if k==203 then curx = curx - 1 --left
elseif k==205 then curx = curx + 1 --right
elseif k==200 then cury = cury - 1 --up
elseif k==208 then cury = cury + 1 --down
elseif k==28 then break --enter
end
end
if curx == 1 and cury == 1 then return "1" end
if curx == 2 and cury == 1 then return "2" end
if curx == 1 and cury == 2 then return "3" end
if curx == 2 and cury == 2 then return "4" end
if curx == 1 and cury == 3 then return "5" end
if curx == 2 and cury == 3 then return "6" end
end
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 login()
while true do
newPage()
term.setCursorPos(1,6)
term.clearLine()
print("Please enter User ID:")
local user = read()
controlTable = loadState()
for eNum,dInfo in ipairs(controlTable) do
if dInfo.type == "Admin" and user == dInfo.color then
newPage()
term.setCursorPos(1,6)
term.clearLine()
print("Please enter User password:")
local pass = read("*")
if dInfo.type == "Admin" and pass == dInfo.status then
return admin,true
end break
elseif dInfo.type == "User" and user == dInfo.color then
newPage()
term.setCursorPos(1,6)
term.clearLine()
print("Please enter User password:")
local pass = read("*")
if dInfo.type == "User" and pass == dInfo.status then
return user,true
end break
end
end
end
end
function opt(m,mY)
n=1
l=#m
while true do
for i=1, l, 1 do
if i==n then
local x, y = term.getSize()
local b = string.len(">"..m[i].."<")/2
local x = (x/2)-b
term.setCursorPos(x,i+mY)
term.clearLine()
print(">"..m[i].."<")
else
local x, y = term.getSize()
b = string.len(m[i])/2
x = (x/2)-b
term.setCursorPos(x,i+mY)
term.clearLine()
print(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 "redstone"
end
end
function firstRun()
while true do
if fs.exists("status") then fs.delete("status") end
title()
local deviceTable = {type="Admin"}
while true do
print("Please enter Administrator name:")
deviceTable.color = read()
if deviceTable.color == "" 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.status = tempadmin break
end
end
title()
print("Thank you. Admin profile created.")
sleep(1)
table.insert(controlTable,deviceTable)
saveState(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.color = 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.status = tempuser break
end
end
title()
print("Thank you. User profile created.")
sleep(1)
break
end
table.insert(controlTable,deviceTable)
saveState(controlTable)
tempusername = nil
tempuser = nil
tempuser2 = nil
local deviceTable = {type="Lights"}
title()
print("Do you have lighting that you want to control?")
deviceTable.status = yN()
if deviceTable.status == "true" then
--deviceTable.type = "Lights"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
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,7))
if deviceTable.type == "7" then
deviceTable.type = "Power"
deviceTable.color = "false"
deviceTable.status = "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,0))
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,0))
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)
elseif deviceTable.type == "2" then
deviceTable.type = "Generator"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
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)
elseif deviceTable.type =="3" then
deviceTable.type = "Geothermal"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
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)
elseif deviceTable.type == "4" then
deviceTable.type = "WaterMill"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
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)
elseif deviceTable.type == "5" then
deviceTable.type = "WindMill"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
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)
elseif deviceTable.type == "6" then
deviceTable.type = "SolarPanel"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
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)
elseif deviceTable.type == "8" then
deviceTable.type = "RedstoneEngine"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
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)
elseif deviceTable.type == "9" then
deviceTable.type = "SteamEngine"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
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)
elseif deviceTable.type == "10" then
deviceTable.type = "CombustionEngine"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
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 Storage"}
title()
print("What type of energy storage are you using?")
sleep(2)
deviceTable.type = tostring(opt(eType,7))
if deviceTable.type == "1" then
deviceTable.color = "false"
deviceTable.status = "false"
table.insert(controlTable,deviceTable)
saveState(controlTable)
elseif deviceTable.type == "2" then
deviceTable.type = "BatBox"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
deviceTable.status = "None"
table.insert(controlTable,deviceTable)
saveState(controlTable)
elseif deviceTable.type == "3" then
deviceTable.type = "MFE"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
deviceTable.status = "None"
table.insert(controlTable,deviceTable)
saveState(controlTable)
elseif deviceTable.type == "4" then
deviceTable.type = "MFSU"
term.clear()
term.setCursorPos(1,9)
print(" What color are you using?")
sleep(1.5)
deviceTable.color = colorConvert(opt(colorOpt,0))
deviceTable.status = "None"
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,0))
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,0))
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,0))
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,0))
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
local deviceTable = {type="Firstrun"}
deviceTable.color = "completed"
deviceTable.status = "true"
table.insert(controlTable,deviceTable)
saveState(controlTable)
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Thank you. You will now be redirected.")
sleep(1.5)
end
function system()
local controlTable = loadState()
mainPage()
term.setCursorPos(1,6)
term.clearLine()
term.setCursorPos(1,4)
print("| System Status |")
print("+-----------------------------------------------+")
for dNum, dInfo in ipairs(controlTable) do
if dInfo.type == "Admin" then
textutils.slowWrite(dInfo.type)
textutils.slowWrite(": ")
sleep(.25)
textutils.slowWrite(dInfo.color)
textutils.slowWrite(", ")
sleep(.25)
textutils.slowPrint("*****")
sleep(.25)
elseif dInfo.type == "User" then
textutils.slowWrite(dInfo.type)
textutils.slowWrite(": ")
sleep(.25)
textutils.slowWrite(dInfo.color)
textutils.slowWrite(", ")
sleep(.25)
textutils.slowPrint("*****")
sleep(.25)
elseif dInfo.type == "Firstrun" then
textutils.slowWrite(dInfo.type)
textutils.slowWrite(" ")
sleep(.25)
textutils.slowWrite(dInfo.color)
textutils.slowWrite(": ")
sleep(.25)
textutils.slowPrint(dInfo.status)
else
textutils.slowWrite(dInfo.type)
textutils.slowWrite(": ")
sleep(.25)
textutils.slowWrite(toColor(dInfo.color))
textutils.slowWrite(", ")
sleep(.25)
textutils.slowPrint(dInfo.status)
sleep(.25)
end
end
while true do
term.setCursorPos(31,13)
write(".-----------------.")
term.setCursorPos(31,14)
write("| Press OK to |")
term.setCursorPos(31,15)
write("| continue |")
term.setCursorPos(31,16)
write("| |")
term.setCursorPos(31,17)
write("+------[OK]-------+")
event, p1 = os.pullEvent("key")
if p1 == 28 then
break
end
end
end
function toColor(c)
if c == "false" then return "None"
elseif c == "redstone" then return "Redstone"
elseif c == "1" then return "White"
elseif c == "2" then return "Orange"
elseif c == "4" then return "Magenta"
elseif c == "8" then return "Light Blue"
elseif c == "16" then return "Yellow"
elseif c == "32" then return "Lime"
elseif c == "64" then return "Pink"
elseif c == "128" then return "Gray"
elseif c == "256" then return "Light Gray"
elseif c == "512" then return "Cyan"
elseif c == "1024" then return "Purple"
elseif c == "2048" then return "Blue"
elseif c == "4096" then return "Brown"
elseif c == "8192" then return "Green"
elseif c == "16384" then return "Red"
elseif c == "32768" then return "Black"
else return "test"
end
end
function resume()
while true do
controlTable = loadState()
for eNum, dInfo in ipairs(controlTable) do
if dInfo.type ~= "Admin" and dInfo.type ~= "User" then
if dInfo.color == "redstone" then
if dInfo.status == "false" then
rs.setOutput("back",false)
elseif dInfo.status == "true" then
rs.setOutput("back",true)
end
elseif not dInfo.color == "redstone" then
if dInfo.status == "false" then
rs.setBundledOutput("back",colors.subtract(dInfo.color))
elseif dInfo.status == "true" then
rs.setBundledOutput("back",colors.combine(dInfo.color))
end
end
end
end break
end
end
--monitor actions
function monTitle()
repeat
mon.clear()
monTitle()
local controlTable = loadState()
for eNum,dInfo in ipairs(controlTable) do
if dInfo.type~="Admin" and dInfo.type~="User" and dInfo.type~="Firstrun" then
mon.setCursorPos(5,6)
mon.write("Production Status")
if dInfo.type=="Macerator" then
mon.setCursorPos(3,8)
mon.write("Macerator: ")
mon.write(mStatus(dInfo.status))
elseif dInfo.type=="Furnace" then
mon.setCursorPos(3,10)
mon.write("Furnace: ")
mon.write(mStatus(dInfo.status))
elseif dInfo.type=="Compressor" then
mon.setCursorPos(3,12)
mon.write("Compressor: ")
mon.write(mStatus(dInfo.status))
elseif dInfo.type=="Extractor" then
mon.setCursorPos(3,14)
mon.write("Extractor: ")
mon.write(mStatus(dInfo.status))
end
mon.setCursorPos(32,6)
mon.write("Power Status")
if dInfo.type=="MFSU" or dInfo.type == "Batbox" or dInfo.type == "MFE"then
mon.setCursorPos(27,8)
mon.write(dInfo.type..": ")
mon.write(dInfo.status)
end
for i=1,#pTypeX do
if dInfo.type==pTypeX[i] then
mon.setCursorPos(27,10)
mon.write(dInfo.type..": ")
mon.write(mStatus(dInfo.status))
end
end
if dInfo.type=="Reactor" and dInfo.color~="false" then
mon.setCursorPos(27,12)
mon.write("Reactor: ")
mon.write(status(dInfo.status))
mon.setCursorPos(27,14)
mon.write("Coolant: ")
mon.write(mStatus(dInfo.status))
end
end
end
sleep(1)
MCtime()
until pM==false
end
function mStatus(x)
local controlTable = loadState()
if x=="true" then state="On"
elseif x=="false" then state="Off"
end
return state
end
function MCscreen()
if pM then
local mX,mY = mon.getSize()
mon.clear()
mon.setCursorPos(1,1)
for i=1,mX do
mon.setCursorPos(i,1)
mon.write("-")
mon.setCursorPos(i,mY)
mon.write("-")
mon.setCursorPos(i,5)
mon.write("-")
mon.setCursorPos(i,7)
mon.write("-")
end
for i=1,mY do
mon.setCursorPos(1,i)
mon.write("|")
mon.setCursorPos(mX,i)
mon.write("|")
end
for i=6,mY-1 do
mon.setCursorPos(25,i)
mon.write("|")
mon.setCursorPos(50,i)
mon.write("|")
end
for i=2,mX do
mon.setCursorPos(i,16)
mon.write("-")
end
mon.setCursorPos(1,1)
mon.write(".")
mon.setCursorPos(mX,1)
mon.write(".")
mon.setCursorPos(1,5)
mon.write("+")
mon.setCursorPos(mX,5)
mon.write("+")
mon.setCursorPos(1,7)
mon.write("+")
mon.setCursorPos(mX,7)
mon.write("+")
mon.setCursorPos(1,mY)
mon.write("'")
mon.setCursorPos(mX,mY)
mon.write("'")
mon.setCursorPos(25,5)
mon.write("+")
mon.setCursorPos(50,5)
mon.write("+")
mon.setCursorPos(25,7)
mon.write("+")
mon.setCursorPos(50,7)
mon.write("+")
mon.setCursorPos(25,mY)
mon.write("+")
mon.setCursorPos(50,mY)
mon.write("+")
mon.setCursorPos(1,16)
mon.write("+")
mon.setCursorPos(mX,16)
mon.write("+")
mon.setCursorPos(25,16)
mon.write("+")
mon.setCursorPos(50,16)
mon.write("+")
local b = string.len("Master Control System Status")/2
local x = (mX/2)-b
mon.setCursorPos(x,3)
mon.write("Master Control System Status")
end
end
function MCtime()
while pM do
local mX,mY = mon.getSize()
local t = os.time()
time = textutils.formatTime(t,false)
mon.setCursorPos(mX-9,3)
mon.write(time)
sleep(0)
end
end
--main code
if not fs.exists("status") then
term.clear()
firstRun()
end
function MCS()
local user,pass = login()
while true do
newPage()
resume()
MCscreen()
controlTable = loadState()
for eNum, dInfo in ipairs(controlTable) do
if dInfo.type == "Firstrun" then
if dInfo.status == "false" then
firstRun()
elseif dInfo.status == nil then
firstRun()
end
end
end
local option = menuOpt()
if option == "1" then --production started
while true do
prodPage()
MCscreen()
local input = opt(pMenu,7)
if input == 1 then
controlTable = loadState()
for dNum, deviceTable in ipairs(controlTable) do
if deviceTable.type == "Macerator" then
if deviceTable.status == "false" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "true"
table.insert(controlTable,8,deviceTable)
table.remove(controlTable,9,deviceTable)
saveState(controlTable)
elseif deviceTable.status == "true" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "false"
table.insert(controlTable,8,deviceTable)
table.remove(controlTable,9,deviceTable)
saveState(controlTable)
end
end
end
elseif input == 2 then
controlTable = loadState()
for dNum, deviceTable in ipairs(controlTable) do
if deviceTable.type == "Furnace" then
if deviceTable.status == "false" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "true"
table.insert(controlTable,9,deviceTable)
table.remove(controlTable,10,deviceTable)
saveState(controlTable)
elseif deviceTable.status == "true" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "false"
table.insert(controlTable,9,deviceTable)
table.remove(controlTable,10,deviceTable)
saveState(controlTable)
end
end
end
elseif input == 3 then
controlTable = loadState()
for dNum, deviceTable in ipairs(controlTable) do
if deviceTable.type == "Compressor" then
if deviceTable.status == "false" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "true"
table.insert(controlTable,10,deviceTable)
table.remove(controlTable,11,deviceTable)
saveState(controlTable)
elseif deviceTable.status == "true" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "false"
table.insert(controlTable,10,deviceTable)
table.remove(controlTable,11,deviceTable)
saveState(controlTable)
end
end
end
elseif input == 4 then
controlTable = loadState()
for dNum, deviceTable in ipairs(controlTable) do
if deviceTable.type == "Extractor" then
if deviceTable.status == "false" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "true"
table.insert(controlTable,11,deviceTable)
table.remove(controlTable,12,deviceTable)
saveState(controlTable)
elseif deviceTable.status == "true" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "false"
table.insert(controlTable,11,deviceTable)
table.remove(controlTable,12,deviceTable)
saveState(controlTable)
end
end
end
elseif input == 5 then break
end
end
elseif option == "2" then --reactor control
if user == admin and pass == true then
while true do
nukePage()
MCscreen()
local input = opt(rMenu,7)
if input == 1 then
controlTable = loadState()
for dNum, deviceTable in ipairs(controlTable) do
if deviceTable.type == "Reactor" then
if deviceTable.status == "false" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "true"
table.insert(controlTable,5,deviceTable)
table.remove(controlTable,6,deviceTable)
saveState(controlTable)
end
elseif deviceTable.type == "Coolant" then
if deviceTable.status == "false" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "true"
table.insert(controlTable,6,deviceTable)
table.remove(controlTable,7,deviceTable)
saveState(controlTable)
end
end
end
elseif input == 2 then
controlTable = loadState()
for dNum, deviceTable in ipairs(controlTable) do
if deviceTable.type == "Reactor" then
if deviceTable.status == "true" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "false"
table.insert(controlTable,5,deviceTable)
table.remove(controlTable,6,deviceTable)
saveState(controlTable)
end
elseif deviceTable.type == "Coolant" then
if deviceTable.status == "true" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "false"
table.insert(controlTable,6,deviceTable)
table.remove(controlTable,7,deviceTable)
saveState(controlTable)
end
end
end
elseif input == 3 then break
end
end
else
term.clear()
term.setCursorPos(1,10)
print(" You must be Admin level to use the reactor ")
sleep(1)
end
elseif option == "3" then --lights
MCscreen()
controlTable = loadState()
for dNum, deviceTable in ipairs(controlTable) do
if deviceTable.type == "Lights" then
if deviceTable.status == "true" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.subtract(output, tonumber(deviceTable.color)))
deviceTable.status = "false"
table.insert(controlTable,3,deviceTable)
table.remove(controlTable,4,deviceTable)
saveState(controlTable)
elseif deviceTable.status == "false" then
local output = rs.getBundledOutput("back")
rs.setBundledOutput("back", colors.combine(output, tonumber(deviceTable.color)))
deviceTable.status = "true"
table.insert(controlTable,3,deviceTable)
table.remove(controlTable,4,deviceTable)
saveState(controlTable)
end break
end
end
elseif option == "4" then --maintenance
while true do
mainPage()
MCscreen()
local input = opt(mMenu,7)
if input == 1 then
system()
elseif input == 2 then
if user == admin and pass == true then
local controlTable = loadState()
for dNum, deviceTable in ipairs(controlTable) do
if deviceTable.type == "Firstrun" then
deviceTable.color = "completed"
deviceTable.status = "false"
table.insert(controlTable,12,deviceTable)
table.remove(controlTable,13,deviceTable)
saveState(controlTable)
end
break
end
else
term.clear()
term.setCursorPos(1,10)
print(" You must be Admin level to run Initialization ")
sleep(1.5)
end
elseif input == 3 then break
end
end
elseif option == "5" then --games
games()
MCscreen()
elseif option == "6" then os.shutdown()
end
end
end
--parallel
parallel.waitForAll(MCS,monTitle)
Edit: Strike that, it's not the loop, because I commented it out, but it's still giving me the error.
Edit 2: Wow, I'm an idiot. This was due to me calling the monTitle() within itself. Supposed to have been MCscreen()