Posted 02 April 2013 - 09:57 PM
First off, I apologize if this counts as spamming and will delete it if told- it's just that I accidentally set the last post I made as 'finished,' only to find out it wasn't. So I have a program that should let me select an option using up and down arrow keys in combination with the enter key, after a bit of help. So far so good. Then I edited it to put [] around the option selected- and suddenly it broke. Can someone help me? I've been beating my head against this for most of a day.
Spoiler
--Screen/Drawing functions
-----------------------------
w,h = term.getSize()
hW = w/2
hH = h/2
function centerPrint(y,text)
term.setCursorPos(w/2 - #text/2, y)
term.write(text)
end
function drawAt(x,y,text)
term.setCursorPos(x,y)
write(text)
end
function cleanScreen()
term.clear()
term.setCursorPos(1,1)
end
input = 1
function drawArt()
c = colors.combine(colors.red,colors.black,colors.white,colors.green)
white = false
black = false
green = false
red = false
rs.setBundledOutput("back", c)
cleanScreen()
term.setTextColor(colors.lime)
term.setBackgroundColor(colors.black) --title and title background color
print[[
VAULT-TEC REACTOR MK 4 CONTROL STATION
AUTHORIZED PERSONEL ONLY!
]]
for i = 5,19 do
term.setBackgroundColor(colors.black) -- MAIN BACKGROUND SPAM COLOR
drawAt(1,i," ")
term.setBackgroundColor(colors.black)
end
if input == nil then
input = 1
end
term.setBackgroundColor(colors.black) -- menu section background
term.setTextColor(colors.red) -- menu section brackets
term.setCursorPos(9,(input + 5)
print("[")
term.setCursorPos(40,(input + 5))
print("]")
term.setBackgroundColor(colors.black)
options = {
" ",
" ACTIVATE REACTORS 1 - 3 ",
" DEACTIVATE REACTORS 1 - 3 ",
" ACTIVATE REACTORS 4 - 6 ",
" DEACTIVATE REACTORS 4 - 6 ",
" ACTIVATE BREEDER CORE 1 ",
" DEACTIVATE BREEDER CORE 1 ",
" ACTIVATE BREEDER CORE 2 ",
" DEACTIVATE BREEDER CORE 2 ",
" -EMERGENCY- CORE SHUTDOWN ",
" ",
}
for i = 1, #options do
term.setBackgroundColor(colors.black) -- options background color
term.setTextColor(colors.blue) -- options text color
drawAt(10,i + 4,options[i])
end
term.setTextColor(colors.red) -- option text color optional
drawAt(10,14," -EMERGENCY- CORE SHUTDOWN ")
end
function events()
evt, but = os.pullEvent()
if evt == "key" then
if but == 208 then --down arrow
input = input + 1
if input > 9 then
input = 9
end
elseif but == 200 then --up arrow
input = input - 1
if input < 1 then
input = 1
end
elseif but == 28 then --Enter
if input == 1 then
c = colors.subtract(c, colors.white)
rs.setBundledOutput("back",c)
white = not white
elseif input == 2 then
c = colors.combine(c, colors.white)
rs.setBundledOutput("back",c)
white = not white
elseif input == 3 then
c = colors.subtract(c, colors.black)
rs.setBundledOutput("back",c)
black = not black
elseif input == 4 then
c = colors.combine(c, colors.black)
rs.setBundledOutput("back",c)
black = not black
elseif input == 5 then
c = colors.subtract(c, colors.red)
rs.setBundledOutput("back",c)
red = not red
elseif input == 6 then
c = colors.combine(c, colors.red)
rs.setBundledOutput("back",c)
red = not red
elseif input == 7 then
c = colors.subtract(c, colors.green)
rs.setBundledOutput("back",c)
green = not green
elseif input == 8 then
c = colors.combine(c, colors.green)
rs.setBundledOutput("back", c)
green = not green
elseif input == 0 then
c = colors.combine(colors.green,colors.red,colors.white,colors.black)
green = false
red = false
black = false
white = false
rs.setBundledOutput("back", c)
end
end
end
end
function main()
while true do
cleanScreen()
drawArt()
events() --Handles the menu stuff
end
end
main()