Advertisement
aidenmagrath

Amount

Aug 4th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. function split(pString, pPattern) --("A_Small_Dog", "_")
  2.   local Table = {}
  3.   local fpat = "(.-)" .. pPattern
  4.   local last_end = 1
  5.   local s, e, cap = pString:find(fpat, 1)
  6.   while s do
  7.     if s ~= 1 or cap ~= "" then
  8.       table.insert(Table, cap)
  9.     end
  10.     last_end = e + 1
  11.     s, e, cap = pString:find(fpat, last_end)
  12.   end
  13.   if last_end <= #pString then
  14.     cap = pString:sub(last_end)
  15.     table.insert(Table, cap)
  16.   end
  17.   return Table
  18. end
  19.  
  20. function r(uuid)
  21.   id, message = rednet.receive()
  22.   m = split(message, " ")
  23.   if m[1] == "inv" then
  24.     if m[2] == "replyAmount" then
  25.       if tonumber(m[3]) == tonumber(uuid) then
  26.         return m[4]
  27.       end
  28.     end
  29.   end
  30.   return nil
  31. end
  32.  
  33. args = {...}
  34. msg = table.concat(args, " ")
  35. rednet.open("back")
  36. term.setTextColor(colors.gray)
  37. print("Sent: \"Checking amount of " ..msg .."\"")
  38. term.setTextColor(colors.white)
  39. rednet.broadcast("inv getAmount " ..msg)
  40. amount = nil
  41. while amount == nil do
  42.   amount = r(msg)
  43. end
  44. print("Amount: " ..amount)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement