Paste: Mass Fab Helper Turtle

Author: bwochinski
Mode: lua
Date: Sat, 3 Aug 2013 03:57:57
Plain Text |
--[[
This script causes a turtle to supply a mass fab with scrapboxes while
also pulling any generated UU matter out.
(by bwochinski)

Set scrapSlots to the number of slots which are holding scrapboxes.
Any remaining slots should be left empty to accept UU matter.
]]--

scrapSlots = 12

curSlot = nil
emptySlot = scrapSlots + 1
curEmpty = nil

-- Run forever
while true do

	curSlot = nil

	-- Loop through the slots up to "scrapSlots" checking if there is scrap in that slot
	for i=1,scrapSlots do
		-- If there is scrap, use that slot and move on
		if turtle.getItemCount(i) > 0 then
			curSlot = i
			break
		end
	end

	if curSlot == nil then
		-- If no scrap was found, print an error message
		print("No more scrapboxes remaining! Refill the first " .. scrapSlots .." slots!")
	else
		-- Try to drop the scrap from curSlot into the mass fab
		turtle.select(curSlot)
		turtle.drop(turtle.getItemCount(curSlot))
	end

	curEmpty = nil
	
	-- loop through the empty slots after the scrapSlots looking for empty space
	for k=emptySlot,16 do
		if turtle.getItemSpace(k) > 0 then
			curEmpty = k
			break
		end
	end

	if curEmpty == nil then
		-- If the slots used to store UU matter fill up, print an error and sleep longer
		print("No space left for UU matter! Empty the last " .. emptySlot .. " slots!")
		sleep(30)
	else
		-- Suck in UU matter to fill the available space in the curEmpty slot
		turtle.suck()
	end

	sleep(5)
end

New Annotation

Summary:
Author:
Mode:
Body: