Advertisement
kurruk

gui

Sep 21st, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. local options={
  2. "option1",
  3. "option2",
  4. "option3"
  5. }
  6. local n=CUI(options)
  7. print(n)
  8.  
  9. function CUI(options) --declare function
  10. n=1 --declare selected option
  11. while true do --start a loop for the 'go to step#2' part
  12. term.clear() term.setCursorPos(1,2) --clear the sceen and position the cursor
  13. for i=1, #m, 1 do --traverse the table of options
  14. if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end --print them
  15. end
  16. a, b= os.pullEvent("key") --wait for keypress
  17. if b==200 and n>1 then n=n-1 end --arrow up pressed, one option up
  18. if b==208 and n<=l then n=n+1 end --arrow down pressed, one option down
  19. if b==28 then break end --enter pressed, break the loop
  20. end
  21. term.clear() term.setCursorPos(1,1) --clear screen
  22. return n --return the value
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement