Jump to content




Making A Selection Menu?

lua utility help

3 replies to this topic

#1 ChaddJackson12

  • Members
  • 264 posts

Posted 07 September 2012 - 11:55 PM

I would like to know how I can make a selection menu...

I already know how to make stuff that deals with inputs that have to do with words, such as: Type an option: shutdown, play, ect...

I would like to have a selection menu, like this for an example:

[ ]Shutdown Computer
[ ]Play CD

Where, an 'o' would be in the selected thing. Like this for an example:

[o]Shutdown Computer
[ ]Play CD

I do not know the code to do this, please help me with it as much as you can! Thanks.

#2 Writer

  • Members
  • 34 posts

Posted 22 August 2014 - 04:10 PM

If you try to write the 'o', it will be a lot more complicated than click in the [ ] and write there an 'o', simply because you could type many other things.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 22 August 2014 - 05:23 PM

[shameless self-promotion] I made a great menu function over here: http://www.computerc...os-themed-menu/[/shameless self-promotion]



#4 Sir_Mr_Bman

  • Members
  • 62 posts

Posted 22 August 2014 - 05:44 PM

Here's some code I dug up from my old projects:
local function centerPrint(text)
  msgLen = string.len(text)
  screenWidth,_ = term.getSize()
  xCoords = tonumber(math.ceil((screenWidth / 2) - (msgLen / 2)))
  _,termY = term.getCursorPos()
  term.setCursorPos(xCoords, termY)
  print(text)
  return xCoords
end
local place = 1
while true do
  term.setTextColor(colors.green)
  term.setBackgroundColor(colors.gray)
  term.clear()
  term.setCursorPos(1, 1)
  print("Security Options")
  print("")
  term.setTextColor(colors.yellow)
  if place == 1 then
	centerPrint("> Open Door <")
	centerPrint("Edit Redstone")
	centerPrint("Administration")
	centerPrint("Developer Tools")
  elseif place == 2 then
	centerPrint("Open Door")
	centerPrint("> Edit Redstone <")
	centerPrint("Administration")
	centerPrint("Developer Tools")
  elseif place == 3 then
	centerPrint("Open Door")
	centerPrint("Edit Redstone")
	centerPrint("> Administration <")
	centerPrint("Developer Tools")
  elseif place == 4 then
	centerPrint("Open Door")
	centerPrint("Edit Redstone")
	centerPrint("Administration")
	centerPrint("> Developer Tools <")
  end
  _, key = os.pullEvent("key")
  if key == keys.up and place > 1 then
	place = place - 1
  elseif key == keys.down and place < 4 then
	place = place + 1
  elseif key == keys.enter then
	break
  end
end
  if place == 1 then
	-- Do something
  elseif place == 2 then
	-- Something else
  elseif place == 3 then
	-- Something else
  elseif place == 4 then
	-- Something else
  end

I just ripped it from a file, so some of the code may seem a little odd, and or incorrect spacing. Like I said, I took it out of an old project. I was too lazy to remove the centerPrint functions as well, so why not.

Edit: I noticed I didn't change the selection character to "o".... I think you should be able to figure it out on your own.... any troubles, just message me.

Edited by Sir_Mr_Bman, 22 August 2014 - 05:47 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users