Jump to content




[Programming][Menu] Making a border


  • You cannot reply to this topic
2 replies to this topic

#1 EmTeaKay

  • Members
  • 115 posts

Posted 15 September 2012 - 07: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


#2 Xhisor

  • New Members
  • 37 posts
  • LocationSweden

Posted 15 September 2012 - 08:32 PM

View PostEmTeaKay, on 15 September 2012 - 07:23 PM, said:

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.computerc...__fromsearch__1
Look through that thread, lots of good menu systems!


#3 EmTeaKay

  • Members
  • 115 posts

Posted 15 September 2012 - 10: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?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users