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

A quick guide through menu making

Started by Liraal, 18 March 2012 - 11:22 AM
Liraal #1
Posted 18 March 2012 - 12:22 PM
Okay, so you have come here to look for a quick way to set up a menu? Good. Before we start, please note that I will first show an algorithm, then the code and finally an explanation. Now we can begin.

1. Yes/No Menu

First and easiest type of menu is a yes/no menu. We need it to act like:

1. Print "Yes No" with one option highlighted, like ">Yes< No"
2. Wait for key pressed.
3. If pressed enter return yes (true) or no (false) and end program
4. If pressed arrow left/right highlight the correct option and go to Step 1.


okay, here is the code:
Spoiler

function yN()
local n=1
while true do
local x, y=term.getCursorPos()
term.clearLine()
if n==1 then write(">YES<   NO") else write (" YES   >NO<") end
term.setCursorPos(x, y)
a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent() end
if b==203 and n==2 then n=1 end
if b==205 and n==1 then n=2 end
if b==28 then print("") break end
end
if n==1 then return true end
if n==2 then return false end
return false
end

what it does is:

Spoiler

function yN()									--declare a function (note that I am not actually runningit anywhere)
local n=1										  --declares the starting selected option (a 'yes')
while true do									 -- a loop, necessary for going from step4 to step 1
term.clearLine()								--clears one line for writing
if n==1 then write("[YES]   NO") else write (" YES   [NO]") end --writes options with one highlighted
a, b=os.pullEvent("key")				   --waits for a key press
if b==203 and n==2 then n=1 end	--if pressed arrow left and selected option is 'no' then select 'yes'
if b==205 and n==1 then n=2 end	--if pressed arrow right and selected option is 'yes' then select 'no'
if b==28 then print("") break end	  --if pressed enter then break the loop and execute the code outside it
end												   --close the loop code
if n==1 then return true end			 --if chosen 'yes' then return true
if n==2 then return false end			--if chosen 'no', return false
end												   --close the function

2. Customizable Menu


Okay, it's now time for the more advanced stuff. Say, you don't want all your menus to only have yes/no options, right? Now I will show you how to make a better version.

1. Get the list of options, preferably a table.
2. Print those options.
3. Select the first one.
4. If pressed arrow up go one option up and go to step#2.
5. If pressed arrow down do the reverse and go to step#2.
6. If pressed enter end and return selected option.


Code:


function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
And explanation:

function CUI(m) --declare function
n=1 --declare selected option
while true do --start a loop for the 'go to step#2' part
term.clear() term.setCursorPos(1,2) --clear the sceen and position the cursor
for i=1, #m, 1 do --traverse the table of options
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end --print them
end
a, b= os.pullEvent("key") --wait for keypress
if b==200 and n>1 then n=n-1 end --arrow up pressed, one option up
if b==208 and n<=l then n=n+1 end --arrow down pressed, one option down
if b==28 then break end --enter pressed, break the loop
end
term.clear() term.setCursorPos(1,1) --clear screen
return n --return the value
end

Please note that the above function requires to be called with a table, like this:

local options={
"option1",
"option2",
"option3"
}
local n=CUI(options)
print(n)

and returns the number of the option chosen.

Do you want me to make some other types of menus as well? If so, post them below.
jtdavis99 #2
Posted 18 March 2012 - 11:41 PM
How did you know what codes were equivalent to the keys?
Espen #3
Posted 19 March 2012 - 12:00 AM
How did you know what codes were equivalent to the keys?
http://www.minecraftwiki.net/wiki/Key_Codes
Liraal #4
Posted 19 March 2012 - 01:12 PM
Posted another version of menu. Hope this will be enough.

And for key codes I actually used trial and error, but espen solution is much more elegant :D/>/>
Wesnc #5
Posted 19 March 2012 - 04:14 PM
I was messing around with your code a bit here, and its only showing option #2, I'll post snippets of the code.




for i=1, l, 1 do
if i==selection then print("["..options[i].."]" .. " " .. options[i]) else print(options[i] .. " ["..options[i].."]") end
end


local optionsTable = {
"OPEN",
"CLOSE"
}

Those are pretty much the only edits, besides keys. Issue is it only shows option 2 ex:
CLOSE [CLOSE]
What have I did wrong here?


EDIT: I fixed it, I think. kinda defeats the purpose of the whole thing though, just a quick fix, not a proper one.

if i==selection then print("["..options[1].."]" .. " " .. options[2]) else print(options[1] .. " ["..options[2].."]") end

It was throwing the selection numbers off too, so I fixed that for now
 return selection-1 
EDIT: a stupid mistake, a mis-arrangement of print, fixed.

Help still needed, if this is NOT the correct way of doing it(obviously)

I'm also looking into having multiple selections, by that I mean something like this:
Door1 - OPEN CLOSE
Door2 - OPEN CLOSE
Door3 - OPEN CLOSE
and even making use of nested tables for a selection menu such as that.
Not sure how I would get into the nested table and the table itself. Was thinking for the table to look like this:

optionsTable = {
["Door1"] = {
"OPEN"
"CLOSE"
},
["Door2"] = {
"OPEN"
"CLOSE"
}
}

Mainly, I need to get the string within ["Door1"] and the nested table, unsure how to do this in LUA.

and I know there are easier ways to do this, this is just the way I would prefer. less code clutter
Ian-Moone #6
Posted 21 March 2012 - 12:26 PM
really helpful thanks :(/>/>
this will speed up development of my programs so much
ps.ill give you a mention in the credits when and where i use it
fuj1n #7
Posted 25 March 2012 - 04:42 AM
How did you know what codes were equivalent to the keys?
What I Do Is Simply Create A Computer Program Where It Does The Following:
Spoiler

term.clear()
term.setCursorPos(1,1)
print("Key Testing Utility 1.0")
while true do
act, key = os.pullEvent("key")
print("Your Keycode Is: " ..key)
end
Simple And Easy
Alex_ #8
Posted 25 March 2012 - 08:41 PM
Thank You :(/>/>
Aerik #9
Posted 06 April 2012 - 07:43 PM
Loved it, thanks a lot!

Is it possible to create a menu where it asks you to enter several variables, for things such as, say, a set of coodinates, or the depth, width and heigth of a room to dig/build?
Wolvan #10
Posted 06 April 2012 - 08:27 PM
Loved it, thanks a lot!

Is it possible to create a menu where it asks you to enter several variables, for things such as, say, a set of coodinates, or the depth, width and heigth of a room to dig/build?
Sure that's possible! Just use read() :)/>/>
Aerik #11
Posted 06 April 2012 - 08:40 PM
Lol, yeah, I'd just figured that out myself :)/>/>
Thanks anyway!
Liraal #12
Posted 06 April 2012 - 08:57 PM
I may do a menu for this later on as well.
libraryaddict #13
Posted 14 May 2012 - 11:50 AM
Created a menu API featuring unlimited menu selections here : http://www.computercraft.info/forums2/index.php?/topic/1719-menu-scrollable/

Its scrollable :
However it deletes everything else on the screen atm >.>
giangigzu #14
Posted 13 July 2012 - 03:48 AM
Hello, i was hoping you could help me with a little menu that i've been trying to learn how to do. its suppossed to have three options: Pump-Tank, Tank-Gen., Gen-MFE.
when one of them is selected then it should open a sub-menu that actualy asks me if i want to turn the feature on. i only need this base and i will later add the bundled cable outputs myself. Please send me a message with the finished code, if i figure it out first ill tell u. THANK YOU!
Graypup #15
Posted 29 July 2012 - 07:05 PM
My only use for a menu is an installer, but this is well explained enough for me to bother with a menu at all.
Brodur #16
Posted 29 July 2012 - 07:32 PM
How do you add an action to the options? I tried

local options={
"Launch VaulTec",
"Continue to CraftOS 1.3"
}
local n=CUI(options)
print(n)
if n=1 then
sleep(0.1)
shell.run "vault"
else
shell.run "shell"
end

and this doesn't work, so how do I add an action to the option? Please help!
Cranium #17
Posted 02 August 2012 - 04:52 PM
Another REALLY simple menu is just this:

function newMenu()
term.setCursorPos(1,1)
print("Please make your selection now")
term.setCursorPos(1,9)
write("Selection: ")
end
function selection()
print("1. Selection1")
print("2. Selection2")
--you can add more selections if you want
term.setCursorPos(11,9) -- Resets the cursor back to the end of the selection line. Can be changed to any cursor position.
end
-- Now, the actual code
term.clear()
newMenu()
selection()
local input = read() --can add (*) if using passwords
if input == "1" then --can also be anything else to designate the selection
-- Do stuff here
elseif input == "2" then
--Do other stuff here
else
  print("INVALID SELECTION. PLEASE TRY AGAIN")
  sleep(1)
  os.reboot() --only necessary if using this as a startup code.
end
Nothing fancy, but easily modified to add as manyy selections as you can fit onto a screen.
BigSHinyToys #18
Posted 02 August 2012 - 05:16 PM
well seeing as I have released programs with this menu Open Source I am throwing down. You may recognize it from some of my progs (probably not)
Spoiler

local function menu(...) -- ver 0.1
    local sel = 1
    local list = {...}
    local offX,offY = term.getCursorPos()
    local curX,curY = term.getCursorPos()
    while true do
	    if sel > #list then sel = 1 end
	    if sel < 1 then sel = #list end
	    for i = 1,#list do
		    term.setCursorPos(offX,offY+i-1)
		    if sel == i then
			    print("["..list[i].."]") -- very customisible example print(">"..list[i])
		    else
			    print(" "..list[i].." ") -- very customisible
		    end
	    end
	    while true do
		    local e,e1,e2,e3,e4,e5 = os.pullEvent()
		    if e == "key" then
			    if e1 == 200 then -- up key
				    sel = sel-1
				    break
			    end
			    if e1 == 208 then -- down key
				    sel = sel+1
				    break
			    end
			    if e1 == 28 then
				    term.setCursorPos(curX,curY)
				    return list[sel],sel
			    end
		    end
	    end
    end
end
-- Example Usage
print("Please select Option")
local selection = menu("Redstone","Hardware","WiFi","Event Monitor","Turtle Driver","Infomation/Help","Exit")
if selection == "Redstone" then
    RedstoneControl()
elseif selection == "Hardware" then
    Hardware()
elseif selection == "WiFi" then
    wifi()
elseif selection == "Event Monitor" then
    EventMonitor()
elseif selection == "Turtle Driver" then
    TurtleDriver()
elseif selection == "Infomation/Help" then
    help()
elseif selection == "Exit" then
    bRunning = false
end
This menu will display on the screen from where ever the cursor is last at.
Xhisor #19
Posted 06 August 2012 - 05:04 PM
well seeing as I have released programs with this menu Open Source I am throwing down. You may recognize it from some of my progs (probably not)
Spoiler

local function menu(...) -- ver 0.1
	local sel = 1
	local list = {...}
	local offX,offY = term.getCursorPos()
	local curX,curY = term.getCursorPos()
	while true do
		if sel > #list then sel = 1 end
		if sel < 1 then sel = #list end
		for i = 1,#list do
			term.setCursorPos(offX,offY+i-1)
			if sel == i then
				print("["..list[i].."]") -- very customisible example print(">"..list[i])
			else
				print(" "..list[i].." ") -- very customisible
			end
		end
		while true do
			local e,e1,e2,e3,e4,e5 = os.pullEvent()
			if e == "key" then
				if e1 == 200 then -- up key
					sel = sel-1
					break
				end
				if e1 == 208 then -- down key
					sel = sel+1
					break
				end
				if e1 == 28 then
					term.setCursorPos(curX,curY)
					return list[sel],sel
				end
			end
		end
	end
end
-- Example Usage
print("Please select Option")
local selection = menu("Redstone","Hardware","WiFi","Event Monitor","Turtle Driver","Infomation/Help","Exit")
if selection == "Redstone" then
	RedstoneControl()
elseif selection == "Hardware" then
	Hardware()
elseif selection == "WiFi" then
	wifi()
elseif selection == "Event Monitor" then
	EventMonitor()
elseif selection == "Turtle Driver" then
	TurtleDriver()
elseif selection == "Infomation/Help" then
	help()
elseif selection == "Exit" then
	bRunning = false
end
This menu will display on the screen from where ever the cursor is last at.
Oh i've been looking for a good way to make a nice menu, can i use (and modify) your menu in my turtle program? You will get credited of course!
BigSHinyToys #20
Posted 06 August 2012 - 05:58 PM
– snip –
Oh i've been looking for a good way to make a nice menu, can i use (and modify) your menu in my turtle program? You will get credited of course!
You can use,modify,set fire too,detonate or anything else you can think of to that program. While i would appreciate crediting a simple note in the code will suffice but is not required.

I take it a compliment that out of all the above menu systems you chose mine so Thank you.
odd_kid #21
Posted 06 August 2012 - 11:49 PM
Not sure if this is too improtant;

but this COULD be wrong, im not sure at all. Just posting this. If its not wrong, please tell me. I didnt know you could combine these…


term.clear() term.setCursorPos(1,1)
Cranium #22
Posted 08 August 2012 - 01:51 AM
This is great! I'm gonna try it now…
KaoS #23
Posted 16 August 2012 - 09:19 AM
here is a link to a basic menu generator I made a few days ago, turns out it didn't help the guy asking for help but you are welcome to use and adapt it

http://www.computercraft.info/forums2/index.php?/topic/3253-help-advanced-menu/

please read to the end of the thread though so you can get the correct version
ben657 #24
Posted 04 September 2012 - 07:11 AM
Nice useful code, but a quick suggestion, it's generally good practice to name your variables something meaningful. Just because you know what they are, doesn't mean other people do!

But still, very useful code!
KaoS #25
Posted 05 September 2012 - 07:05 AM
yeah, I've made a much better one since then though: runs better and can run in any area of the screen with customizable delimiters etc

http://pastebin.com/X9cC2MS3
Creator13 #26
Posted 15 September 2012 - 06:04 PM
I feel quite stupid asking this, but where do I put this part of the code

local options={
"option1",
"option2",
"option3"
}
local n=CUI(options)
print(n)
into this?

function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
Because, when I put it just above it all, it gives an "attempt to call nil"-error at line

local n=CUI(options)
Cricket #27
Posted 15 September 2012 - 08:47 PM
I feel quite stupid asking this, but where do I put this part of the code

local options={
"option1",
"option2",
"option3"
}
local n=CUI(options)
print(n)
into this?

function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
Because, when I put it just above it all, it gives an "attempt to call nil"-error at line

local n=CUI(options)
Put it below the function
EmTeaKay #28
Posted 15 September 2012 - 11:07 PM
How do I make a border for my menu? I tried asking in Ask a Pro forum section, and they said to come here.
Also, my options looke like this:
1
2
3
When I want them to look like this:
1 2 3
Any help?
Here's the 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
Creator13 #29
Posted 16 September 2012 - 09:19 AM
@EmTeaKay thanks, it works now.
I'm also trying to figure out how i get the options in one line. I didn't found any solutions yet…
EmTeaKay #30
Posted 16 September 2012 - 12:51 PM
Well, if you find a way to do it, would you please PM me how?
KaoS #31
Posted 18 September 2012 - 08:20 AM
I took a look at your code and made it put all the choices on the same line, it is still set to use the up and down arrow keys to navigate, that should be easy to change

http://pastebin.com/XCN2RHPf
Mr. Fang #32
Posted 21 September 2012 - 01:02 AM
Thank You this really helped a large amount! I'm rdy to make my Home CPU Now!
Bansheebandit #33
Posted 24 October 2012 - 01:34 AM
Im trying to make a menu that highlights different options in my Nuclear Powerplants OS. Ive currently been using the simple menu that requests the user to type an option but think its time for an upgrade. Could you help me?
KaoS #34
Posted 24 October 2012 - 05:08 AM
sure, try making an option based menu like above, once you have that it is easy to upgrade. if you have problems let us know
88theturbo #35
Posted 28 March 2013 - 09:09 AM
Hmm. When I try to run it it says bios:337: [string "menu"] :17: 'then' expected
When I check it. there is a then… Can someone help?
KaoS #36
Posted 28 March 2013 - 09:25 AM
which code?
88theturbo #37
Posted 28 March 2013 - 10:15 AM
I used Cranium's Code, But I fixed it already. :)/> I didnt use the right amount of = signs in a part of the code. :D/>
KaoS #38
Posted 28 March 2013 - 10:19 AM
cool stuff, good luck to you sir
TheOddByte #39
Posted 01 April 2013 - 12:27 AM
You can also open up the lua prompt and do this

 while true do
     print(os.pullEvent())
 end
That's much quicker I think..
DerDuden #40
Posted 06 April 2013 - 12:18 PM
Thanks man really good work =)
Chrisvn #41
Posted 06 June 2013 - 01:53 PM
Okay, so you have come here to look for a quick way to set up a menu? Good. Before we start, please note that I will first show an algorithm, then the code and finally an explanation. Now we can begin.

1. Yes/No Menu

First and easiest type of menu is a yes/no menu. We need it to act like:

1. Print "Yes No" with one option highlighted, like ">Yes< No"
2. Wait for key pressed.
3. If pressed enter return yes (true) or no (false) and end program
4. If pressed arrow left/right highlight the correct option and go to Step 1.


okay, here is the code:
Spoiler

function yN()
local n=1
while true do
local x, y=term.getCursorPos()
term.clearLine()
if n==1 then write(">YES<   NO") else write (" YES   >NO<") end
term.setCursorPos(x, y)
a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent() end
if b==203 and n==2 then n=1 end
if b==205 and n==1 then n=2 end
if b==28 then print("") break end
end
if n==1 then return true end
if n==2 then return false end
return false
end

what it does is:

Spoiler

function yN()									--declare a function (note that I am not actually runningit anywhere)
local n=1										  --declares the starting selected option (a 'yes')
while true do									 -- a loop, necessary for going from step4 to step 1
term.clearLine()								--clears one line for writing
if n==1 then write("[YES]   NO") else write (" YES   [NO]") end --writes options with one highlighted
a, b=os.pullEvent("key")				   --waits for a key press
if b==203 and n==2 then n=1 end	--if pressed arrow left and selected option is 'no' then select 'yes'
if b==205 and n==1 then n=2 end	--if pressed arrow right and selected option is 'yes' then select 'no'
if b==28 then print("") break end	  --if pressed enter then break the loop and execute the code outside it
end												   --close the loop code
if n==1 then return true end			 --if chosen 'yes' then return true
if n==2 then return false end			--if chosen 'no', return false
end												   --close the function

2. Customizable Menu


Okay, it's now time for the more advanced stuff. Say, you don't want all your menus to only have yes/no options, right? Now I will show you how to make a better version.

1. Get the list of options, preferably a table.
2. Print those options.
3. Select the first one.
4. If pressed arrow up go one option up and go to step#2.
5. If pressed arrow down do the reverse and go to step#2.
6. If pressed enter end and return selected option.


Code:


function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
And explanation:

function CUI(m) --declare function
n=1 --declare selected option
while true do --start a loop for the 'go to step#2' part
term.clear() term.setCursorPos(1,2) --clear the sceen and position the cursor
for i=1, #m, 1 do --traverse the table of options
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end --print them
end
a, b= os.pullEvent("key") --wait for keypress
if b==200 and n>1 then n=n-1 end --arrow up pressed, one option up
if b==208 and n<=l then n=n+1 end --arrow down pressed, one option down
if b==28 then break end --enter pressed, break the loop
end
term.clear() term.setCursorPos(1,1) --clear screen
return n --return the value
end

Please note that the above function requires to be called with a table, like this:

local options={
"option1",
"option2",
"option3"
}
local n=CUI(options)
print(n)

and returns the number of the option chosen.

Do you want me to make some other types of menus as well? If so, post them below.
I'm able to print 3 options but the last one can't be selected, any idea on why?
KaoS #42
Posted 06 June 2013 - 02:19 PM
when asking for help with a problem in your code always provide your code
Chrisvn #43
Posted 07 June 2013 - 04:01 PM
when asking for help with a problem in your code always provide your code
I sent that in a rush and pressed complete because I had to drive my girlfriend home, sorry.
Anyway I managed to fix that problem I used this
if b==208 and n<=1 then n=n+1 end
instead of this
if b==208 and n<=l then n=n+1 end
If you can't see it well I used 1 (number one) instead of l (L), quite confusing for peope like me with dyslexia.
Then I stumbled on another problem which is that I tried to pull a menu from a menu option however after several attempts I decided to try and use the first code but with more options than yes and no, this is what I came up with (it works fyi).
Please note everything is declared in Dutch so I putted English commentary.
selectie = 1 –declare that selection is 1 at the start

function hoofdMenu() –declare the options
if selectie == 1 then print("> Meer opties <") else print(" Meer opties ") end –if the selection is 1 then meer opties will be highlighted else it won't
if selectie == 2 then print("> Print test <") else print(" Print test") end
if selectie == 3 then print("> Afsluiten <") else print(" Afsluiten")end
end

function tekenhoofdMenu() –drawing the menu and using the arrow keys to change our variable
term.clear()
term.setCursorPos(1,1)
while true do
hoofdMenu()

local id, key = os.pullEvent("key")
if key == 200 and selectie > 1 then –You should recognise it from the original code
selectie = selectie - 1
elseif key == 208 and selectie < 3 then –However here I predefined the final possible value rather than giving it as a variabel
selectie = selectie + 1
end

if key == 28 then –here is where the real magic happens
if selectie == 3 then –inputted shutdown so I can shutdown the OS and remove the floppy where I saved this as startup
os.shutdown()
elseif select == 1 then tekenmeerMenu() –this will draw another menu when meer opties was highlighted and enter pressed
elseif select == 2 then print("Test") –prints test
end
break
end
end
end

function meerMenu() –declaring of the extra options
if selectie == 1 then print("> Optie 1 <") else print(" Optie 1") end
if selectie == 2 then print("> Optie 2 <") else print(" Optie 2") end
end

function tekenmeerMenu() –drawing the second menu
term.clear()
term.setCursorPos(1,1)
while true do
meerMenu()

local id, key = os.pullEvent("key")
if key == 200 and selectie > 1 then
selectie = selectie - 1
elseif key == 208 and selectie < 2 then
selectie = selectie + 1
end

if key == 28 then
if select == 1 then print(" Optie 1 is gekozen")
elseif select == 2 then print("Optie 2 is gekozen")
end
break
end
end
end

Note that this is saved on a server I have no access to so I typed it over(I always type a double in Notepad to find errors more easily), not sure if it is 100% correct but it should work, for anyone that sees it please feel free to use it as I based myself on the original code of this thread.
Might try to test it out with
function drawMenu(Menu)
Where menu is your function (like hoofdmenu()) so you only need 1 draw function, but I doubt it works as I am not sure if you can pas down other functions into a function.

Hope this helps anyone.