Advertisement
Inksaver

Demo of menu.lua library

Apr 7th, 2020
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. --[[
  2.     This is a demonstration of the use ofthe menu library at:
  3.     https://pastebin.com/BhjbYsw4
  4.    
  5. ]]
  6. function main()
  7.     local menu = require("menu")
  8.     local prompt = "Choose your option:"
  9.     --[[ table of options. The first choice will be cut down to size,
  10.          the 11th exceeds permissible views on a turtle so will not
  11.          appear, but will appear on a computer, which can show 16 options
  12.       ]]
  13.     local options = {"First choice which has been made into a very long string",
  14.                     "Second choice", "Third choice", "Fourth choice",
  15.                     "Fifth choice", "Sixth choice","Seventh choice", "Eighth choice",
  16.                     "Ninth choice", "Tenth choice","This choice won't show on a turtle"}
  17.     -- show the menu to get user input
  18.     local choice = menu.new(prompt, options)
  19.     if choice == nil then
  20.         print ("You chose to cancel the menu")
  21.     else
  22.         print("You chose option no "..choice..": "..options[choice])
  23.     end
  24.     sleep(3)   
  25.     prompt = "which direction do you want to go?"
  26.     options = {"North", "East", "South", "West"}
  27.     choice = menu.new(prompt, options)
  28.     if choice == nil then
  29.         print ("You chose to stay where you are")
  30.     else
  31.         print("Great! We are heading "..options[choice])
  32.     end
  33.    
  34. end
  35.  
  36. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement