Advertisement
aidenmagrath

Amount Display

Aug 5th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. items = {{"Stone", 1}, {"Dirt", 3}, {"Cobble", 4}}
  2.  
  3. function split(pString, pPattern) --("A_Small_Dog", "_")
  4.   local Table = {}
  5.   local fpat = "(.-)" .. pPattern
  6.   local last_end = 1
  7.   local s, e, cap = pString:find(fpat, 1)
  8.   while s do
  9.     if s ~= 1 or cap ~= "" then
  10.       table.insert(Table, cap)
  11.     end
  12.     last_end = e + 1
  13.     s, e, cap = pString:find(fpat, last_end)
  14.   end
  15.   if last_end <= #pString then
  16.     cap = pString:sub(last_end)
  17.     table.insert(Table, cap)
  18.   end
  19.   return Table
  20. end
  21.  
  22. function getReply(uuid)
  23.   id, message = rednet.receive()
  24.   m = split(message, " ")
  25.   if m[1] == "inv" then
  26.     if m[2] == "replyAmount" then
  27.       if tonumber(m[3]) == tonumber(uuid) then
  28.         return m[4]
  29.       end
  30.     end
  31.   end
  32.   return nil
  33. end
  34.  
  35. mon = peripheral.wrap("left")
  36. mon.clear()
  37.  
  38. rednet.open("back")
  39.  
  40. while true do
  41.   for i=1, #items do
  42.     rednet.broadcast("inv getAmount " ..items[i][2])
  43.     amount = nil
  44.     while amount == nil do
  45.       amount = getReply(items[i][2])
  46.     end
  47.  
  48.     mon.setCursorPos(1, i)
  49.     mon.write(items[i][1] ..": " ..amount)
  50.   end
  51.   sleep(30)
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement