Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("gui")
- os.loadAPI("shop")
- mon = peripheral.find("monitor")
- mon.clear()
- rednet.open("top")
- --initialization of counting vars
- amount=16
- cost=0
- --variables to sync with buttons
- selection=nil
- --runs buttons program
- function getClick()
- event,side,x,y = os.pullEvent("monitor_touch")
- gui.checkxy(x,y)
- end
- --items in the shop
- shop.newItem("Bread", 8, 93, 95, 88)
- shop.newItem("F.Fries", 16, 93, 99, 88)
- --------------buttons-------------------
- function fillTable()
- gui.setTable("Bread",bread,7,15,3,5)
- gui.setTable("F.Fries",fries,17,25,3,5)
- gui.setTable("Checkout",checkout,31,39,10,12)
- gui.setTable("+",add,2,4,2,4)
- gui.setTable("-",subtract,2,4,8,10)
- gui.screen()
- end
- function bread()
- gui.flash("Bread")
- selection="Bread"
- end
- function fries()
- gui.flash("F.Fries")
- selection="F.Fries"
- end
- function checkout()
- if selection~=nil then
- gui.flash("Checkout")
- writeProcessing()
- result,stock=shop.vend(selection, amount)
- writeResult()
- sleep(1)
- end
- end
- function add()
- gui.flash("+")
- amount=amount+16
- if amount>64 then
- amount=64
- end
- end
- function subtract()
- gui.flash("-")
- amount=amount-16
- if amount<16 then
- amount=16
- end
- end
- ----------------------------------------
- function writeAmount()
- mon.setCursorPos(3,6)
- mon.write(amount)
- curX,curY=mon.getCursorPos()
- mon.setCursorPos(curX-2,6)
- mon.write(" ")
- end
- function writeSelection(selection)
- monW,monH=mon.getSize()
- mon.setCursorPos(9,1)
- mon.write("Current Selection: "..selection.." ")
- end
- function updateCost()
- cost=shop.calcCost(selection, amount)
- end
- function writeCost(cost)
- monW,monH=mon.getSize()
- mon.setCursorPos(9,monH)
- mon.write("Cost: "..math.ceil(cost).." Gold Ingots")
- end
- function writeProcessing()
- mon.setCursorPos(9,1)
- mon.write(" ")
- mon.setCursorPos(9,1)
- mon.write("Processing payment...")
- end
- function writeResult()
- if result then
- mon.setCursorPos(9,1)
- mon.write(" ")
- mon.setCursorPos(9,1)
- mon.write("Payment received!")
- elseif not stock then
- mon.setCursorPos(9,1)
- mon.write(" ")
- mon.setCursorPos(9,1)
- mon.write("Out of stock!")
- else
- mon.setCursorPos(9,1)
- mon.write(" ")
- mon.setCursorPos(9,1)
- mon.write("Invalid payment!")
- end
- end
- fillTable()
- while true do
- writeAmount()
- getClick()
- if selection~=nil then
- updateCost()
- writeCost(cost)
- writeSelection(selection)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement