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

"Pausing" a Loop

Started by lynchy94, 26 December 2012 - 11:37 AM
lynchy94 #1
Posted 26 December 2012 - 12:37 PM
I'm writing my first functioning quarry program. I got the turtle to travel to any coordinates i specify and it can dig a x by x hole of any size. Now i'm trying to make the turtle return to drop items or refuel if it needs to. I was trying to find out if there was a way to "pause" the loop then make the turtle refuel and stuff before making it return to the same spot and resume. Making the turtle resume where it left off would be much simpler then.

sorry about the sloppy code, I'm pretty new at this.

I found something about using this while loop on the internet but i can't get it to work. The turtle doesn't stop if its inventory is full or it's fuel gets too low.


function quarryDig()
  while true do
	while turtle.getFuelLevel() < 70000 or turtle.getItemCount(16) ~= 0 do

	  returnItems()

	end


	for inty = 1, size do
	  for intx = 1, size - 1 do
	  forward()
	  end
		row = row + 1
		rowTurn = rowTurn + 1
	   if row < tonumber(size) then
		 if rowTurn >= 2 then rowTurn = 0 end
		 if rowTurn == 0 then
		   right()
		   forward()
		   right()
		 end
		 if rowTurn == 1 then
		   left()
		   forward()
		   left()
		 end
	   else
		 if rowTurn == 0 then
		   left()
		   row = 0
		   rowTurn = 0
		 else
		   right()
		   right()
		   row = 0
		   rowTurn = 0
		  end
	   end
	end
end
remiX #2
Posted 26 December 2012 - 12:44 PM
I don't quite understand what you're trying to do.

Are you wanting the to pause the loop and while it's paused, the turtle must go refuel and when it's done refueling, it must continue?
lynchy94 #3
Posted 26 December 2012 - 01:39 PM
Yes that's what im attempting to do.

I want the turtle to do this code while its fuel is above 70000 and slot 16 has no items in it


for inty = 1, size do
		  for intx = 1, size - 1 do
		  forward()
		  end
				row = row + 1
				rowTurn = rowTurn + 1
		   if row < tonumber(size) then
				 if rowTurn >= 2 then rowTurn = 0 end
				 if rowTurn == 0 then
				   right()
				   forward()
				   right()
				 end
				 if rowTurn == 1 then
				   left()
				   forward()
				   left()
				 end
		   else
				 if rowTurn == 0 then
				   left()
				   row = 0
				   rowTurn = 0
				 else
				   right()
				   right()
				   row = 0
				   rowTurn = 0
				  end
		   end
		end
end




and i want it to call the function returnItems() (Returns to home, dumps items, refuels, and returns to the place where it ran out of space or fuel) if the fuel level falls below 70000 or slot 16 has any items in it. When it gets back i want it to continue from the point when it didnt meet one of those two requirements.
ChunLing #4
Posted 26 December 2012 - 02:25 PM
Put the function into your loop, inside an if turtle.getFuel() < 70000 or turtle.getItemCount(16) > 0 then goHomeAndComeBack() end
lynchy94 #5
Posted 26 December 2012 - 07:42 PM
I don't know why that didn't occur to me..so much wasted time haha but thanks for the help i've got it working now.