Can you please add a note to every single line of code?
just to help me learn.
As I said in my one post I 'sort of' know how it works… but I'll tell you what I can I guess :)/>/>
local function menu(...)
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].."]") --[[ The characters between the quotation marks are the characters used to show which option is active ]]--
else
print(" "..list[i].." ")
end
end
while true do
local e,e1,e2,e3,e4,e5 = os.pullEvent() --[[ Pulls the event for when a key is pressed ]]--
if e == "key" then
if e1 == 200 then --[[ This detects when the up arrow is pressed, it will then move one up. If you click it when you have the first option active, it will return to the bottom ]]--
sel = sel-1
break
end
if e1 == 208 then --[[ This detects when the down arrow is pressed, it will then move one down. If you click it when you have the last option active, it will return to the top ]]--
sel = sel+1
break
end
if e1 == 28 then --[[ This is when the enter key is pressed. It returns which ever option in the selection is active ]]--
term.setCursorPos(curX,curY)
return list[sel],sel
end
end
end
end
end
function Option1() --[[ Option1, Option2, Option3 are the functions for each option in the menu. You don't have to do this, I just do it because it looks cleaner. ]]--
print("You have selected option 1!")
sleep(3)
end
function Option2()
print("You have selected option 2!")
sleep(3)
end
function Option3()
print("You have selected option 3!")
sleep(3)
end
while true do
local selection = menu( --[[ This is what is displayed on the screen. Separate each with a comma ]]--
"Option 1",
"Option 2",
"Option 3")
if selection == "Option 1" then --[[ If the selected option is this one after clicking enter it would call Option1 function. and so on... ]]--
Option1()
elseif selection == "Option 2" then
Option2()
elseif selection == "Option 3" then
Option3()
end
end
That is actually all I know. If I studied it more I would understand it better but I do not worry because it works fine and I dont need to know how it works. You could ask other people how it works, im sure there are others that understand this code better.