Advertisement
Guest User

receive

a guest
Jun 11th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. --Turtle-side Shop App
  2. local w,h=term.getSize()
  3.  
  4. function receiveAll()
  5.   id,sumChar,prot=rednet.receive("shop")
  6.   id,cartItemsSerial,prot=rednet.receive("shop")
  7. end
  8.  
  9. function processPackage()
  10.   sum=tonumber(sumChar)
  11.   cartItems=textutils.unserialize(cartItemsSerial)
  12. end
  13.  
  14. function writeSum()
  15.   term.setCursorPos(26,1)
  16.   term.setTextColor(colors.red)
  17.   term.write("    ")
  18.   term.setCursorPos(26,1)
  19.   term.write(sum)
  20. end
  21.  
  22. function rednetGetInfo()
  23.   rednet.open("left")
  24.   receiveAll()
  25.   processPackage()
  26.   rednet.close("left")
  27. end
  28.  
  29. function checkPayment()
  30.   turtle.select(4)
  31.   turtle.suck()
  32.   turtle.select(1)
  33.   if turtle.compareTo(4)==true then
  34.     turtle.drop()
  35.   end
  36.   turtle.select(4)
  37.   turtle.drop()
  38.   turtle.select(1)
  39. end
  40.  
  41. function buttonCheck()
  42.   while true do
  43.     local event,button,x,y=os.pullEvent("mouse_click")
  44.     if ((x>=(w-8) and x<=(w)) and y==1) then
  45.       checkPayment()
  46.       break
  47.     end
  48.     if ((x>=(w-8) and x<=(w)) and y==3) then
  49.       break
  50.     end
  51.   end
  52. end
  53.  
  54. function terminalSetup()
  55.   term.clear()
  56.   term.setTextColor(colors.lightBlue)
  57.   term.setCursorPos(1,1)
  58.   term.write("Your Total Amount Due is:          ")
  59.   term.setCursorPos(w-8,1)
  60.   term.setTextColor(colors.white)
  61.   term.setBackgroundColor(colors.lime)
  62.   term.write(" SUBMIT ")
  63.   term.setCursorPos(w-8,3)
  64.   term.setBackgroundColor(colors.red)
  65.   term.write(" CANCEL ")
  66.   term.setBackgroundColor(colors.black)
  67.   term.setCursorPos(1,3)
  68.   term.setTextColor(colors.white)
  69.   term.write("Place payment in the top-left ")
  70.   term.setCursorPos(1,4)
  71.   term.write("slot of the turtle. Then click")
  72.   term.setCursorPos(1,5)
  73.   term.write("either SUBMIT or CANCEL to tell")
  74.   term.setCursorPos(1,6)
  75.   term.write("the turtle to proceed to it's  ")
  76.   term.setCursorPos(1,7)
  77.   term.write("item gathering and payment pro-")
  78.   term.setCursorPos(1,8)
  79.   term.write("cessing. Please be patient.")
  80.   term.setTextColor(colors.blue)
  81.   term.setBackgroundColor(colors.gray)
  82.   for i=1,w do
  83.     term.setCursorPos(i,2)
  84.     term.write("-")
  85.   end
  86.   term.setBackgroundColor(colors.black)
  87.   term.setCursorPos(1,9)
  88. end
  89.  
  90. terminalSetup()
  91. while true do
  92.   rednetGetInfo()
  93.   writeSum()
  94.   buttonCheck()
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement