Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input_slot = 1 -- location in inventory that the turtle uses to grab an item to place
- additional_input_slot = 5 -- location in inventory of the second input to be used when the first is empty
- checking_slot = 15 -- locaiton in inventory that the turtle sucks an item to check if it is complete
- target_slot = 16 -- location in inventory that the turtle compares an item against to see if it is complete
- output_slot = 2 -- location in inventory that the final output is placed
- error_slot = 3 -- location in inventory that the final output is placed if output_slot is full of something else
- function IsDone()
- local done = false
- if turtle.getItemCount(target_slot) > 0 then -- only compares to target_slot if something in target_slot
- turtle.select(checking_slot)
- turtle.suck()
- if turtle.compareTo(target_slot) then -- compare the new item to the target item
- -- items match, we're done
- turtle.transferTo(output_slot) -- move to final location
- done = true
- else
- -- not done, put it back in and continue
- turtle.drop()
- end
- else
- turtle.select(output_slot)
- turtle.suck()
- done = true
- end
- return done
- end
- -- main program
- local current_input_slot = input_slot
- turtle.select(current_input_slot)
- if turtle.getItemCount(current_input_slot) > 0 then
- turtle.drop(1)
- while true do
- local lamp = rs.getAnalogInput("front")
- if lamp == 15 then -- only check when done is triggered
- if IsDone() then
- turtle.select(current_input_slot)
- if turtle.getItemCount() == 0 then -- if input_slot is empty, break the loop and end program.
- current_input_slot = additional_input_slot
- turtle.select(current_input_slot)
- if turtle.getItemCount() == 0 then
- break
- end
- end
- -- if slot isn't empty, insert the next one
- turtle.drop(1)
- end
- end
- os.pullEvent("redstone")
- end
- end
- write("Input slot is empty.\n")
Advertisement
Add Comment
Please, Sign In to add comment