Guest User

Bug in line 28?

a guest
Feb 8th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. local mon = peripheral.wrap("right")
  2. mon.setTextScale(1)
  3. mon.setTextColor(colors.white)
  4. local button={}
  5. mon.setBackgroundColor(colors.black)
  6.  
  7. function setTable(name, func, xmon, xmax, ymin, ymax)
  8.   button[name] = {}
  9.   button[name]["func"] = func
  10.   button[name]["active"] = false
  11.   button[name]["xmin"] = xmin
  12.   button[name]["ymin"] = ymin
  13.   button[name]["xmax"] = xmax
  14.   button[name]["ymax"] = ymax
  15. end
  16.  
  17. function funcName()
  18.   print("You Clicked buttonText")
  19. end
  20.  
  21. function fillTable()
  22.   setTable("buttonText", funcName, 5, 25, 4, 8)
  23. end
  24.  
  25. function fill(text, color, bData)
  26.   mon.setBackgroundColor(color)
  27.   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  28.   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  29.   for j = bData["ymin"], bData["ymax"] do
  30.     mon.setCursorPos(bData["xmin"], j)
  31.     if j == yspot then
  32.       for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  33.         if k == xspot then
  34.           mon.write(text)
  35.         else
  36.           mon.write("")
  37.         end
  38.       end
  39.     else
  40.       for i = bData["xmin"], bData["xmax"] do
  41.         mon.write("")
  42.       end
  43.     end
  44.   end
  45.   mon.setBackgroundColor(colors.black)
  46. end
  47.  
  48. function screen()
  49.   local currColor
  50.   for name,data in pairs(button) do
  51.     local on = data["active"]
  52.     if on == true then currColor = colors.lime else currColor = colors.red end
  53.     fill(name, currColor, data)
  54.   end
  55. end
  56.  
  57. function checkxy(x, y)
  58.   for name, data in pairs(button) do
  59.     if y>=data["ymin"] and y <= data["ymax"] then
  60.       if x>=data["xmin"] and x<= data["xmax"] then
  61.         data["func"]()
  62.         data["active"] = not data["active"]
  63.         --print(name)
  64.       end
  65.     end
  66.   end
  67. end
  68.  
  69. function heading(text)
  70.   w, h = mon.getSize()
  71.   mon.setCursorPos((w-string.len(text))/2+1, 1)
  72.   mon.write(text)
  73. end
  74.  
  75. fillTable()
  76. while true do
  77.   mon.clear()
  78.   heading("Mob Control")
  79.   screen()
  80.   local e,side,x,y = os.pullEvent("monitor_touch")
  81.   --print(x..":"..y)
  82.   checkxy(x,y)
  83.   sleep(.1)
  84. end
Advertisement
Add Comment
Please, Sign In to add comment