This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
joaopada's profile picture

[Lua][Noob] Help With Code: A Simple Getflint Program.

Started by joaopada, 25 July 2013 - 04:06 PM
joaopada #1
Posted 25 July 2013 - 06:06 PM
Hi! For practice, I am writing a GetFlint program. I know, there are plenty of them around, this is just made to test skills and to learn a bit more. Here's my current code:


while true do
  if turtle.detect() == true then
   turtle.dig()
   turtle.place()
  elseif
   turtle.place() == false then
   turtle.dropUp()
   turtle.select(2)
   turtle.dropUp()
   turtle.select(3)
   turtle.dropUp()
   turtle.select(4)
   turtle.dropUp()
   turtle.select(1)
   print "No gravel detected, shutting down..."
   sleep(3)
   os.reboot()
end
end

The issue with this is: If I place gravel in the second slot of the turtle, it'll place the gravel in the chest that's on top of it, where only flint was supposed to go. How would I go about fixing this?

This part:


turtle.dropUp()
   turtle.select(2)
   turtle.place()
   turtle.dropUp()
   turtle.select(3)
   turtle.dropUp()
   turtle.select(4)
   turtle.dropUp()
   turtle.select(1)

Any way to make it shorter and do that to all the slots easily and in a cleaner way?

I know there are more issues, but I'll edit them later on, gotta go to sleep now.

Thanks in advance for your help!
Lord_Spelunky #2
Posted 25 July 2013 - 06:27 PM
Why don't you dedicate more slots to gravel? And when you want it to dump use
slot = 4
for i = 4, 8 do
turtle.select(slot)
turtle.dropUp()
slot = slot + 1
end

It's a lot neater
LNETeam #3
Posted 25 July 2013 - 09:59 PM
Well by dropping up, you are adding whatever is in your current slot, may i suggest using something like:



turtle.select(1)
while turtle.detect() do
	turtle.place()
	turtle.dig()
	for i=1,3 do
		if turtle.getItemCount(i) == 0 then
			break
		else
			turtle.select(i)
		end
	end
end
while not turtle.detect() do
	for i=4,8 do --This can be adjusted for however many slots you have reserved for gravel and flint. Here I have 1 slot set for gravel. Thus only 4-8 can have flint.
		if turtle.getItemCount(i)>0 then
			turtle.placeUp()
		end
	end
end