Advertisement
Guest User

startup

a guest
May 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. os.loadAPI("gui")
  2. os.loadAPI("shop")
  3. mon = peripheral.find("monitor")
  4. mon.clear()
  5.  
  6. rednet.open("top")
  7.  
  8. --initialization of counting vars
  9. amount=16
  10. cost=0
  11.  
  12. --variables to sync with buttons
  13. selection=nil
  14.  
  15. --runs buttons program
  16. function getClick()
  17.     event,side,x,y = os.pullEvent("monitor_touch")
  18.     gui.checkxy(x,y)
  19. end
  20.  
  21. --items in the shop
  22. shop.newItem("Bread", 8, 93, 95, 88)
  23. shop.newItem("F.Fries", 16, 93, 99, 88)
  24.  
  25. --------------buttons-------------------
  26. function fillTable()
  27.     gui.setTable("Bread",bread,7,15,3,5)
  28.     gui.setTable("F.Fries",fries,17,25,3,5)
  29.     gui.setTable("Checkout",checkout,31,39,10,12)
  30.     gui.setTable("+",add,2,4,2,4)
  31.     gui.setTable("-",subtract,2,4,8,10)
  32.     gui.screen()
  33. end
  34.  
  35.  
  36. function bread()
  37.     gui.flash("Bread")
  38.     selection="Bread"
  39. end
  40.  
  41. function fries()
  42.     gui.flash("F.Fries")
  43.     selection="F.Fries"
  44. end
  45.  
  46. function checkout()
  47.     if selection~=nil then
  48.         gui.flash("Checkout")
  49.         writeProcessing()
  50.         result,stock=shop.vend(selection, amount)
  51.         writeResult()
  52.         sleep(1)
  53.     end
  54. end
  55.  
  56. function add()
  57.     gui.flash("+")
  58.     amount=amount+16
  59.     if amount>64 then
  60.         amount=64
  61.     end
  62. end
  63. function subtract()
  64.     gui.flash("-")
  65.     amount=amount-16
  66.     if amount<16 then
  67.         amount=16
  68.     end
  69. end
  70. ----------------------------------------
  71.  
  72. function writeAmount()
  73.     mon.setCursorPos(3,6)
  74.     mon.write(amount)
  75.     curX,curY=mon.getCursorPos()
  76.     mon.setCursorPos(curX-2,6)
  77.     mon.write("  ")
  78. end
  79.  
  80. function writeSelection(selection)
  81.     monW,monH=mon.getSize()
  82.     mon.setCursorPos(9,1)
  83.     mon.write("Current Selection: "..selection.."         ")
  84. end
  85.  
  86. function updateCost()
  87.     cost=shop.calcCost(selection, amount)
  88. end
  89.  
  90. function writeCost(cost)
  91.     monW,monH=mon.getSize()
  92.     mon.setCursorPos(9,monH)
  93.     mon.write("Cost: "..math.ceil(cost).." Gold Ingots")
  94. end
  95.  
  96. function writeProcessing()
  97.     mon.setCursorPos(9,1)
  98.     mon.write("                                ")
  99.     mon.setCursorPos(9,1)
  100.     mon.write("Processing payment...")
  101. end
  102.  
  103. function writeResult()
  104.     if result then
  105.         mon.setCursorPos(9,1)
  106.         mon.write("                                ")
  107.         mon.setCursorPos(9,1)
  108.         mon.write("Payment received!")
  109.     elseif not stock then
  110.         mon.setCursorPos(9,1)
  111.         mon.write("                                ")
  112.         mon.setCursorPos(9,1)
  113.         mon.write("Out of stock!")
  114.     else
  115.         mon.setCursorPos(9,1)
  116.         mon.write("                                ")
  117.         mon.setCursorPos(9,1)
  118.         mon.write("Invalid payment!")
  119.     end
  120. end
  121.  
  122. fillTable()
  123.  
  124. while true do
  125.     writeAmount()
  126.     getClick()
  127.     if selection~=nil then
  128.         updateCost()
  129.         writeCost(cost)
  130.         writeSelection(selection)
  131.     end
  132. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement