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

Making A Selection Menu?

Started by ChaddJackson12, 07 September 2012 - 10:55 PM
ChaddJackson12 #1
Posted 08 September 2012 - 12:55 AM
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.
Writer #2
Posted 22 August 2014 - 05: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.
KingofGamesYami #3
Posted 22 August 2014 - 06:23 PM
[shameless self-promotion] I made a great menu function over here: http://www.computercraft.info/forums2/index.php?/topic/20087-ui-craftos-themed-menu/[/shameless self-promotion]
Sir_Mr_Bman #4
Posted 22 August 2014 - 06: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 on 22 August 2014 - 04:47 PM