Guest User

[Help] aspects: 15: attempt to index ? (a nil value)

a guest
Oct 6th, 2014
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.74 KB | None | 0 0
  1. startup -
  2.  
  3. shell.run("aspects")
  4.  
  5.  
  6.  
  7.  
  8.  
  9. aspects -
  10.  
  11. --rednet.open("left")
  12. os.loadAPI("button")
  13. --local turtleID = 40
  14. local essentia = {}
  15. local jars = peripheral.getNames()
  16. local m = peripheral.wrap("monitor_0")
  17. local monCoord = {}
  18. local currEssentia
  19. local fillAmt = 0
  20. local rowsActive = true
  21. local pipe = peripheral.wrap("LogisticsPipes:Request_0")
  22. local beans = {}
  23.  
  24. function findBeans()
  25.    data = pipe.getAvailableItems()
  26.    for i,j in pairs(data) do
  27.       data2 = pipe.getNBTTagCompound(j[1])
  28.       beans[data2["value"]["Aspects"]["value"][1]["value"]["key"]["value"]] = i
  29.    end
  30. --   print(beans["instrumentum"][1])
  31. end
  32.  
  33. function sortEss(t)
  34.    local keys = {}
  35.    for k in pairs(t) do keys[#keys+1] = k end
  36.    table.sort(keys)
  37.    
  38.    local i = 0
  39.    return function()
  40.       i = i+1
  41.       if keys[i] then
  42.          return keys[i], t[keys[i]]
  43.       end
  44.    end
  45. end
  46.  
  47. function scanEssentia()
  48.   for i,j in ipairs(jars) do
  49.      if peripheral.getType(j) == "tt_aspectContainer" then
  50.        asp = peripheral.call(j, "getAspects")
  51.        print(asp)
  52.        countasp = peripheral.call(j, "getAspectCount", asp)
  53.        if countasp > 0 then
  54.          essentia[asp] = math.floor(countasp)
  55.        end
  56. --       print(countasp)
  57. --     print(asp..":"..countasp)
  58. --     print(peripheral.getType(j))
  59.      end
  60.   end
  61. end
  62.  
  63. function printEssentia()
  64.   m.setTextColor(colors.white)
  65.   local x = 1
  66.   local y = 1
  67.   monCoord[x] = {}
  68. --  for a = 1,17 do
  69.   for i,j in sortEss(essentia) do
  70.      if j<=20 then m.setTextColor(colors.red) end
  71.      if j<40 and j>20 then m.setTextColor(colors.yellow) end
  72.      if j>=40 then m.setTextColor(colors.green) end
  73.      
  74.      m.setCursorPos(x,y)
  75.      m.write(i)
  76.      m.setCursorPos(x+14,y)
  77.      m.write(tostring(j))
  78. --     print(j)
  79.      monCoord[x][y] = i
  80.      if y < 17 then
  81.         y = y+1
  82.      else
  83.         y = 1
  84.         x = x+17
  85.         monCoord[x] = {}  
  86.      end
  87.   end
  88. -- end
  89.  m.setTextColor(colors.white)
  90. end
  91.  
  92. function getClick()
  93.    local event,side,x,y = os.pullEvent()
  94.    if event=="monitor_touch" then
  95.      if button.checkxy(x,y) then
  96.         print("button")
  97.      else
  98.         if rowsActive then
  99.           fillAmt = 0
  100.           print(x..":"..x-(x%17)+1)
  101.           print(monCoord[x-(x%17)+1][y])
  102.           currEssentia = monCoord[x-(x%17)+1][y]
  103.           if currEssentia ~= nil then
  104.           if essentia[currEssentia] < 64 then
  105.              fillTable2()
  106.           else
  107.              m.clear()
  108.              button.label(1,10, currEssentia.." is already full.  Please choose another.")
  109.              sleep(3)
  110.              refresh()
  111.           end
  112.           end
  113.         end
  114.      end
  115.    end
  116. end
  117.  
  118. function refresh()
  119.    button.flash("Refresh")
  120.    m.clear()
  121.    scanEssentia()
  122.    printEssentia()
  123.    print("Refreshed")
  124.    button.screen()
  125. end
  126.  
  127. function fillTable()
  128.    rowsActive = true
  129.    button.clearTable()
  130.    button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
  131.    button.screen()
  132. end
  133.  
  134. function addEss(num)
  135.    fillAmt = fillAmt + num
  136.    if fillAmt < 0 then fillAmt = 0 end
  137.    if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end
  138.    m.clear()
  139.    fillTable2()
  140. end
  141.  
  142. function fillEss2()
  143.    pipe.makeRequest(data[beans[currEssentia]][1], fillAmt)
  144.    m.clear()
  145.    fillTable()
  146.    refresh()
  147. end
  148.  
  149. function fillEss()
  150.    --No longer used, see fillEss2()
  151.    local essData = {}
  152.    essData[1] = currEssentia
  153.    essData[2] = fillAmt
  154.    local sendData = ""
  155.    sendData = textutils.serialize(essData)
  156.    rednet.send(turtleID, sendData)
  157.    m.clear()
  158.    button.label(7, 10, "Waiting for aspects to finish cooking....")
  159.    button.label(7, 12, "Don't forget to refresh the screen after")
  160.    button.label(7, 13, "the golem is done moving the essentia.")
  161.    rednet.receive()
  162.    m.clear()
  163.    fillTable()
  164.    refresh()
  165. end
  166.  
  167. function cancel()
  168.    m.clear()
  169.    fillTable()
  170.    refresh()
  171. end  
  172.  
  173. function fillTable2()
  174.    rowsActive = false
  175.    button.clearTable()
  176.    m.clear()
  177.    button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia])
  178.    button.setTable("+1", addEss, 1, 8, 18, 6,6)
  179.    button.setTable("+5", addEss, 5, 20, 30, 6, 6)
  180.    button.setTable("+10", addEss, 10, 32, 42, 6, 6)
  181.    button.setTable("-1", addEss, -1, 8, 18, 8, 8)
  182.    button.setTable("-5", addEss, -5, 20, 30, 8, 8)
  183.    button.setTable("-10", addEss, -10, 32, 42, 8 ,8)
  184.    button.setTable("Refill Jar", addEss, 64-essentia[currEssentia], 8, 42, 10, 10)
  185.    button.setTable("Execute Fill Request", fillEss2, "", 8, 42, 16, 18)
  186.    button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
  187.    button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.")
  188.    button.screen()
  189. end
  190.  
  191. fillTable()
  192. refresh()
  193. findBeans()
  194. while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment