Advertisement
ullbergm

Crucible Turtle

May 19th, 2013
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. state = {
  2.   lastMessage = nil,
  3.   target = 4   -- change this to your monitor computer's id
  4. }
  5.  
  6. util = {
  7.   send = function(msg, force)
  8.     if msg ~= nil and state.lastMessage ~= msg or force then
  9.       print("Sending message: "..msg)
  10.       rednet.send(state.target, msg)
  11.       state.lastMessage = msg
  12.     end
  13.   end,
  14.   sendSerialized = function(msg, force)
  15.     if msg ~= nil then
  16.       util.send(textutils.serialize(msg), force)
  17.     end
  18.   end,
  19.   hasItems = function()
  20.     for i = 1, 16 do
  21.       if turtle.getItemCount(i) > 0 then
  22.         return true
  23.       end
  24.     end
  25.    
  26.     return false
  27.   end,
  28.   dropItems = function()
  29.     for i = 1, 16 do
  30.       if turtle.getItemCount(i) > 0 then
  31.         turtle.select(i)
  32.         turtle.dropDown()
  33.         sleep(.5)
  34.       end
  35.     end
  36.     turtle.select(1)
  37.   end
  38. }
  39.  
  40. local scanner = peripheral.wrap("right")
  41. rednet.open("right")
  42.  
  43. while true do
  44. --  print("Checking aspects")
  45.   local aspects = scanner.getAspectsDown()  
  46.  
  47.   if next(aspects) == nil then
  48.     util.send("none")
  49.   else
  50.     util.sendSerialized(aspects)
  51.   end
  52.  
  53.   if util.hasItems() then
  54.     print("Dropping items in to crucible.")
  55.     util.dropItems()
  56.   end
  57.  
  58.   sleep(1)
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement