Advertisement
PaymentOption

gui

Jul 29th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. -- Since this is a basic indepenant
  2. -- menu, the use of access specifiers
  3. -- are not necessary.
  4. -- Access specifiers in LUA: "local"
  5.  
  6. nSelect = 1 -- Holds the current selection
  7. nWidth, nHeight = term.getSize() -- Size of the screen
  8.  
  9. -- You can set up menues within tables
  10. -- however I don't, because I am lazy :P
  11. -- Tables for menues are beneficial (spelling lol)
  12. -- They make your code efficient by allowing for
  13. -- use of the '#' operator.
  14.  
  15. function cPrint(height, string)
  16. local xPos = nWidth/2 - string.len(string)/2
  17. -- The abve line holds the position to print
  18. -- In the exact center of the screen.
  19.  
  20. term.setCursorPos(xPos, height)
  21. term.write(string)
  22. end
  23.  
  24. function clear() term.clear(); term.setCursorPos(1, 1) end
  25. -- Clears the screen.
  26.  
  27. function printMenu()
  28. -- This is where tables for menues are good
  29. -- You can call menues in a simple and small
  30. -- loop. Instead I just right long 'if' 'else'
  31. -- statements.
  32.  
  33. if nSelect == 1 then cPrint(6, "[ Option 1 ]")
  34. else cPrint(6, " Option 1 ") end
  35.  
  36. -- The above checks if we selected this option
  37. -- If we did then print in the center of the screen
  38. -- The option with brackets. If we didn't
  39. -- then print the option in the same spot without
  40. -- brackets. We put spaces in the non bracketed
  41. -- options because it prevents the brackets
  42. -- from not being cleared when we print the options.
  43.  
  44. if nSelect == 2 then cPrint(7, "[ Option 2 ]")
  45. else cPrint(7, " Option 2 ") end
  46.  
  47. if nSelect == 3 then cPrint(8, "[ Exit ]")
  48. else cPrint(8, " Exit ") end
  49. -- Always make sure your strings to print
  50. -- are aligned. It helps :D
  51. end
  52.  
  53. -- Here is where we loop all of the stuff together
  54. -- literally.
  55.  
  56.  
  57. -- When creating infinite loops as the one below
  58. -- it is common practice to have a variable as
  59. -- the condition instead of 'true, but I don't care
  60. -- right now :P.
  61. while true do
  62. clear() -- Clear the screen to be updated.
  63. printMenu() -- Update the screen
  64.  
  65. event, key = os.pullEvent()
  66.  
  67. if event == "key" then
  68. if key == 200 and nSelect > 1 then nSelect = nSelect-1
  69. elseif key == 208 and nSelect < 3 then nSelect = nSelect+1
  70. elseif key == 28 and nSelect == 3 then clear(); print(os.version()); break
  71. end
  72. end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement