Jump to content




Help turning a program into a menu?

lua

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

#1 Tassyr

  • Members
  • 80 posts

Posted 01 April 2013 - 11:21 PM

So here's the situation; I have a reactor control program that I've been tinkering with and I really like. but I'd like to make it an actual 'menu' with scroll up/down options instead of just 'input the number to get the effect.' Here's what I have so far: (And yes, this is a 'fallout' based world. XD)
Spoiler
http://pastebin.com/YKYnazTS

So, how do I make this a menu where you scroll up and down over the options, instead of having to type something in manually? the examples I find online don't seem to be much help.

#2 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 01 April 2013 - 11:54 PM

Why dont you make it simple?
Just make them press the button:
local _, char = os.pullEvent("char")
if char == "1" then
  -- code
elseif char == "2" then
  -- code
end

Really to modify your code, you have to remove the input = io.read() and replace with code above. Only you must change char into input, otherwise it will mess up you if-statements.

#3 Tassyr

  • Members
  • 80 posts

Posted 02 April 2013 - 12:05 AM

Well, that's one way- but I've seen menus where you could scroll up and down along the program, and it looked AWESOME- it's just that I can't figure out how to make one of those interfaces. I'll hold this in reserve, though! And experiment with i

#4 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 02 April 2013 - 12:08 AM

You want to run that menu on an advanced computer, right? (Cuz if so, I throw together a "menu API" or something like that - probably gonna make a tutorial about menus... Hmm...)

#5 JokerRH

  • Members
  • 147 posts

Posted 02 April 2013 - 01:42 AM

View PostJokerRH, on 01 April 2013 - 12:09 PM, said:

...

And to the Menue thingy:
local options = {
  {"Option1", func1},
  {"Option2", func2},
  {"OptionX", func3}
}
local selected = 1

function draw()
  --Set the position for the first option. Change the second number if you want a headline or so...
  term.setCursorPos(1, 1)

  --Iterate over any option and print then on the screen
  for ind, param in ipairs(options) do
	--Clear line
	term.clearLine()

	--Print with or without marker
	if selected == ind then
	  print(">"..param[1])
	else
	  print(" "..param[1])
	end
  end
end

function run()
  while true do
	--Pull the event
	local _, key = os.pullEvent("key")

	if key == keys.up and selected > 1 then
	  --Decrement selected.
	  selected = selected - 1
	elseif key == keys.down and selected < #options then
	  --Increment selected.
	  selected = selected + 1
	elseif key == keys.enter then
	  --Run the function saved in the second slot of the currently selected option.
	  options[selected][2]()
	  break
	end

	--Redraw the screen
	draw()
  end
end

draw()
run()

That's what I posted in the

Press any key to continue & Scroll-Enter

thread

#6 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 02 April 2013 - 01:49 AM

Here's a little code for you..
I edited yours a little and added menu functions so you have to press up and down arrow to use it..
And enter to select an options ofcourse..
Here you go!
Spoiler

Hope it helped! :)

#7 Tassyr

  • Members
  • 80 posts

Posted 02 April 2013 - 07:38 AM

JokerRH - yeah, I saw that on your post, but for some reason it just didn't sink in. x.x I can't say why.
Hellkid-MUCH closer to what I was after! I have a few tweaks to make- I was hoping for one of those 'bracketed' selection menus, but you've given me enough of a template to figure out,

I broke something. x.x Could someone please take a look at this http://pastebin.com/fdzPg810 and tell me why for some reason the program won't change the redstone outputs now?


Spoiler


#8 Tassyr

  • Members
  • 80 posts

Posted 02 April 2013 - 11:39 AM

Sorry to bump, but I still can't figure out why it won't actually perform the functions it should. I can't see any error in the code, but then I'm new to lua and menus especially...





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users