This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
EmTeaKay's profile picture

[Programming][Menu] Making a border

Started by EmTeaKay, 15 September 2012 - 06:23 PM
EmTeaKay #1
Posted 15 September 2012 - 08:23 PM
How do I make a menu border? So it would appear like this:

+———-+
| [1] |
| 2 |
| 3 |
+———-+

Also, here is my current code:

function clear()
term.clear()
term.setCursorPos(1,1)
end
function one()
sleep(.5)
clear()
print("Hello")
end
function two()
sleep(.5)
clear()
print("Hey")
end
function three()
sleep(.5)
clear()
print("Hi")
end
local menuOptions = {"1", "2", "3"}
local termX, termY = term.getSize()
local selected = 1
function centerText(text, termY)
term.setCursorPos(termX/2-#text/2,termY)
term.write(text)
return true
end
function start()
while true do
 term.clear()
 for i,v in ipairs(menuOptions) do
  if i == selected then
	   centerText("["..v.."]", i)
 else
    centerText(v,i)
 end
   end
   local id, key = os.pullEvent()
   if key == 208 and selected < #menuOptions then
    selected = selected + 1
   elseif key == 200 and selected > 1 then
    selected = selected - 1
   elseif key == 28 then
    return selected
   end
end
end
x = start()
print()
if selected == 1 then
 one()
end
if selected == 2 then
 two()
end
if selected == 3 then
 three()
end
Xhisor #2
Posted 15 September 2012 - 09:32 PM
How do I make a menu border? So it would appear like this:

+———-+
| [1] |
| 2 |
| 3 |
+———-+

Also, here is my current code:

function clear()
term.clear()
term.setCursorPos(1,1)
end
function one()
sleep(.5)
clear()
print("Hello")
end
function two()
sleep(.5)
clear()
print("Hey")
end
function three()
sleep(.5)
clear()
print("Hi")
end
local menuOptions = {"1", "2", "3"}
local termX, termY = term.getSize()
local selected = 1
function centerText(text, termY)
term.setCursorPos(termX/2-#text/2,termY)
term.write(text)
return true
end
function start()
while true do
term.clear()
for i,v in ipairs(menuOptions) do
  if i == selected then
	   centerText("["..v.."]", i)
else
	centerText(v,i)
end
   end
   local id, key = os.pullEvent()
   if key == 208 and selected < #menuOptions then
	selected = selected + 1
   elseif key == 200 and selected > 1 then
	selected = selected - 1
   elseif key == 28 then
	return selected
   end
end
end
x = start()
print()
if selected == 1 then
one()
end
if selected == 2 then
two()
end
if selected == 3 then
three()
end
http://www.computercraft.info/forums2/index.php?/topic/744-a-quick-guide-through-menu-making/page__fromsearch__1
Look through that thread, lots of good menu systems!
EmTeaKay #3
Posted 15 September 2012 - 11:39 PM
Okay, but that didn't help. Is there a way you could edit my code? And, if it's not too much trouble, could the person who helps me also change the options from vertical to horizontal?