Advertisement
kurruk

Untitled

Feb 24th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.40 KB | None | 0 0
  1. p = peripheral.wrap("back")
  2. rednet.open("right")
  3. p.setTextScale(1.5)
  4. p.setBackgroundColor(colors.black)
  5. p.setTextColor(colors.white)
  6. button={}
  7. amount = 0
  8.  
  9. function split(str, delim, maxNb)
  10.  
  11.   if string.find(str, delim) == nil then
  12.     return { str }
  13.   end
  14.  
  15.   if maxNb == nil or maxNb < 1 then
  16.     maxNb = 0
  17.   end
  18.  
  19.   local result = {}
  20.   local pat = "(.-)" ..delim.. "()"
  21.   local nb = 0
  22.   local lastPos
  23.  
  24.   for part, pos in string.gmatch(str, pat) do
  25.     nb = nb + 1
  26.     result[nb] = part
  27.     if nb == maxNb then
  28.       break
  29.     end
  30.   end
  31.  
  32.   return result
  33.  
  34. end
  35.    
  36. function setTable(name, func, xmin, xmax, ymin, ymax)
  37.    button[name] = {}
  38.    button[name]["func"] = func
  39.    button[name]["active"] = false
  40.    button[name]["xmin"] = xmin
  41.    button[name]["ymin"] = ymin
  42.    button[name]["xmax"] = xmax
  43.    button[name]["ymax"] = ymax
  44. end
  45.  
  46. function hit()
  47.   print("hit()")
  48.   amount = 0
  49.   p.setBackgroundColor(colors.blue)
  50.   p.clear()
  51.   button={}
  52.   setTable("1", save, 4, 10, 3, 7)
  53.   setTable("2", save, 12, 18, 3, 7)
  54.   setTable("3", save, 20, 26, 3, 7)
  55.   setTable("4", save, 4, 10, 9, 13)
  56.   setTable("5", save, 12, 18, 9, 13)
  57.   setTable("6", save, 20, 26, 9, 13)
  58.   setTable("7", save, 4, 10, 15, 19)
  59.   setTable("8", save, 12, 18, 15, 19)
  60.   setTable("9", save, 20, 26, 15, 19)
  61.   setTable("0", save, 28, 34, 9, 13)
  62.   setTable("Get Items", send, 28, 42, 15, 19)
  63.   setTable("Stack", stack, 28, 42, 3, 7)
  64.   setTable("reset", reset, 43, 48, 22, 22)
  65.   screenNum() --line 214
  66.   herp_der_derp() --line 76
  67.   event, side, x, y = os.pullEvent("monitor_touch")
  68.   checkxy2(x,y) --line 176
  69. end
  70.  
  71. function reset() --a reset button for the seletion screen
  72.     print("reset")
  73.     hit()
  74. end
  75.  
  76. function herp_der_derp()
  77.     print("herp_der_derp()")
  78.     amount = tonumber(amount)
  79.     amount = tostring(amount)
  80.     p.setBackgroundColor(colors.lime)
  81.     p.setTextColor(colors.blue)
  82.     size = math.floor((42 - 36 - string.len(amount)) /2) + 1
  83.     place = math.floor(41 - string.len(amount) - 36) /2
  84.     p.setCursorPos(36,9)
  85.     for i=1, 7 do
  86.         p.write(" ")
  87.     end
  88.     p.setCursorPos(36,10)
  89.     for i=1, 7 do
  90.         p.write(" ")
  91.     end
  92.     p.setCursorPos(36,11)
  93.     for i=1, size do
  94.         p.write(" ")
  95.     end
  96.     p.write(amount)
  97.     p.write(" ")
  98.     for i=1, place do
  99.         p.write(" ")
  100.     end
  101.     p.setCursorPos(36,12)
  102.     for i=1, 7 do
  103.         p.write(" ")
  104.     end
  105.     p.setCursorPos(36,13)
  106.     for i=1, 7 do
  107.         p.write(" ")
  108.     end
  109.     p.setBackgroundColor(colors.black)
  110.     p.setTextColor(colors.white)
  111. end
  112.  
  113. function stack() -- button for selectiong to add a stack
  114.     print("stack()")
  115.     amountStack = 0
  116.     amount = tonumber(amount)
  117.     amountStack = hey
  118.     amountStack = 63
  119.     amount = amount + amountStack + 1
  120.     amount = tostring(amount)
  121.     herp_der_derp()
  122.     event, side, x, y = os.pullEvent("monitor_touch")
  123.     checkxy2(x,y)
  124. end
  125.  
  126. function save() -- a function to save the amount that has been entered
  127.     print("save()")
  128.    hey = tonumber(hey)
  129.    amount = amount..hey
  130.    amount = tostring(amount)
  131.    herp_der_derp()
  132.    event, side, x, y = os.pullEvent("monitor_touch")
  133.    checkxy2(x,y)
  134. end
  135.  
  136. function send() -- the requesting function
  137.     print("send()")
  138.     send = 0
  139.     input = 0
  140.     amount = tonumber(amount)
  141.     if amount >= 64 then
  142.         send = amount / 64
  143.         send = math.floor(send)
  144.         for i = 1, send do
  145.             rednet.broadcast(thing..":64")
  146.         end
  147.         send = send * 64
  148.         input = amount - send
  149.         input = tostring(input)
  150.         if input == not 0 then
  151.             rednet.broadcast(thing..":"..input)
  152.         end
  153.         print (thing..":"..amount)
  154.     else
  155.         amount = tostring(amount)
  156.         rednet.broadcast(thing..":"..amount)
  157.         print (thing..":"..amount)
  158.     end
  159. end
  160.  
  161. function checkxy1(x, y)
  162.     print("checkxy1()")
  163.    for name, data in pairs(button) do
  164.       if y >=data["ymin"] and  y <= data["ymax"] then
  165.          if x >=data["xmin"] and x <= data["xmax"] then
  166.             mess = {}
  167.             mess = split(name, ":") --line 9 just splits it on the : and returns the first half
  168.             thing = tostring(mess[1])
  169.             print (thing)
  170.             data["func"]() --line 46
  171.          end
  172.       end
  173.    end
  174. end
  175.  
  176. function checkxy2(x, y)
  177.     print("checkxy2()")
  178.    for name, data in pairs(button) do
  179.       if y >=data["ymin"] and  y <= data["ymax"] then
  180.          if x >=data["xmin"] and x <= data["xmax"] then
  181.             hey = name
  182.             print(data["func"])
  183.             data["func"]()
  184.          end
  185.       end
  186.    end
  187. end
  188.  
  189. function fillNum(text, color, bData)
  190.   p.setBackgroundColor(colors.lime)
  191.   p.setTextColor(colors.blue)
  192.   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  193.   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  194.   for j = bData["ymin"], bData["ymax"] do
  195.     p.setCursorPos(bData["xmin"], j)
  196.     if j == yspot then
  197.       for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  198.         if k == xspot then
  199.           p.write(text)
  200.         else
  201.           p.write(" ")
  202.         end
  203.       end
  204.     else
  205.       for i = bData["xmin"], bData["xmax"] do
  206.          p.write(" ")
  207.       end
  208.     end
  209.   end
  210.   p.setBackgroundColor(colors.black)
  211.   p.setTextColor(colors.white)
  212. end
  213.  
  214. function screenNum()
  215.   local currColor
  216.   for name,data in pairs(button) do
  217.     currColor = colors.lime
  218.     fillNum(name, currColor, data) --line 189
  219.   end
  220. end
  221.  
  222. function fill(text, color, bData)
  223.     p.setCursorPos(bData["xmin"], bData["ymin"])
  224.     p.write(text)
  225. end
  226.  
  227. function screen()
  228.    for name,data in pairs(button) do
  229.       fill(name, currColor, data) --line 222
  230.    end
  231. end
  232.  
  233. run = 1
  234.  
  235. function1 = function()
  236.   button={}
  237.   message = "cobble: 1000"
  238.   line = 2
  239.   item = 95
  240.   p.clear()
  241.   for i=1, 1 do
  242.  
  243.     rednet.send(item, "update")
  244.  
  245.     --id, message = rednet.receive(0.05)
  246.  
  247.     if message == nil then
  248.        
  249.     elseif line <=20 then
  250.       length = string.len(message) + 3
  251.       setTable(message, hit, 3, length, line, line) --line 36
  252.       screen() --line 227
  253.     elseif line > 15 and line <= 30 then
  254.       l = line - 14
  255.       length = string.len(message) + 3
  256.       setTable(message, hit, 16, length, l, l) --line 36
  257.       screen() --line 227
  258.     else
  259.       l = line - 29
  260.       length = string.len(message) + 3
  261.       setTable(message, hit, 29, length, l, l) --line 36
  262.       screen() --line 227
  263.     end
  264.     line = line + 1
  265.     item = item + 1
  266.   end
  267.   local timerID=os.startTimer(10)
  268.   while true do
  269.     event, side, x, y = os.pullEvent()
  270.     if event == "monitor_touch" then
  271.       checkxy1(x,y) --line 161
  272.       break
  273.     elseif event=="timer" and side==timerID then
  274.         break
  275.     end
  276.   end
  277. end
  278.  
  279. while true do
  280.   function1() -- line 235
  281. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement