Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Menu(...) -- Put the menu text in. User chooses one. The function returns the selection he choose.
- --You now need to type in the number the menu starts, and the number it ends. Made by libraryaddict
- local MenuStuff = {...}
- local first = MenuStuff[1]
- local second = MenuStuff[2]
- table.remove(MenuStuff, 1)
- table.remove(MenuStuff, 1)
- local Scrolled = 1
- local DownDown = 0
- local Mouse = first
- local function rewrite()
- local i = 0
- for n=first, second do
- i = i+1
- if MenuStuff[i+DownDown] then
- term.setCursorPos(4, n)
- term.write(string.rep(" ", string.len(MenuStuff[i+DownDown])))
- end
- end
- end
- local function Draw()
- local i = 0
- for n=first,second do
- i = i+1
- term.setCursorPos(4, n)
- term.write(MenuStuff[i+DownDown])
- end
- term.setCursorPos(1, Mouse)
- term.write(">>")
- end
- Draw()
- while true do
- event,param1 = os.pullEvent()
- if event == "key" then
- term.setCursorPos(1, Mouse)
- term.write(" ")
- rewrite()
- if param1 == 200 then -- Up
- if Scrolled > 1 then
- if Mouse == first and MenuStuff[Scrolled-1] then
- DownDown = DownDown-1
- else
- Mouse = Mouse-1
- end
- Scrolled = Scrolled-1
- end
- elseif param1 == 208 then -- Down
- if Scrolled < #MenuStuff then
- if Mouse == second then
- DownDown = DownDown+1
- else
- Mouse = Mouse+1
- end
- Scrolled = Scrolled+1
- end
- elseif param1 == 28 then -- Enter
- rewrite()
- return MenuStuff[Scrolled]
- -- break
- end
- Draw()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment