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

Turtle Invintory Management and Lava Problem

Started by Almerish, 14 January 2013 - 01:46 PM
Almerish #1
Posted 14 January 2013 - 02:46 PM
I am working on making a simple branch mining program (as shown below), however i seem to be having two problems. First is i am not sure how i am going to handle invintory. I want to make it so that when the turtle's slots get full it gose back to the start of the mine and drops off its invintory in a chest. I already put a code in to drop its invintory at the start of the program, but this is a temporary part of the coding. Second when my turtle hit lava it stoped its script completly. I know this for when i found it in the middle of a lava lake the script was off (it still had about 25,000 fuel if you were wondering). Any help would be apreciated (i do know i haven't put in the coding for gravle yet, but i do know how to do that coding so please don't put a post about it).

Spoiler

local function Torch()

turtle.turnLeft()
turtle.turnLeft()
turtle.up()
turtle.select(1)
turtle.place()
turtle.down()
turtle.turnLeft()
turtle.turnLeft()
end

turtle.turnLeft()
turtle.turnLeft()
turtle.select(2)
turtle.drop()
turtle.select(3)
turtle.drop()
turtle.select(4)
turtle.drop()
turtle.select(5)
turtle.drop()
turtle.select(6)
turtle.drop()
turtle.select(7)
turtle.drop()
turtle.select(8)
turtle.drop()
turtle.select(9)
turtle.drop()
turtle.select(10)
turtle.drop()
turtle.select(11)
turtle.drop()
turtle.select(12)
turtle.drop()
turtle.select(13)
turtle.drop()
turtle.select(14)
turtle.drop()
turtle.select(15)
turtle.drop()
turtle.select(16)
turtle.drop()
turtle.select(1)
turtle.turnLeft()
turtle.turnLeft()

Arg = (...)
if Arg ~= nil then
  Length = tonumber(Arg)
  Place = 8
  a = 1
  b = 1
  c = 1
  d = 0
  e = 1
  while a<= Length do
   if turtle.detect() then
	d = d+1
	turtle.dig()
	turtle.forward()
	if turtle.detectUp() then
	 turtle.digUp()
	end
   elseif not turtle.detect() then
	while b<= d do
	 turtle.back()
   b = b+1
   a = Arg
	end
  end
a = a+1
c = c+1
  while c>= Place do
   Torch()
   c = c-7
  end
end
while a>= Length do
  turtle.back()
  e = e+1
   while e>= a do
	a = a-a
   end
end
end
crazyguymgd #2
Posted 14 January 2013 - 02:57 PM
I usually run a check that says if slot 16 has something in it, go back to the start, unload, and then go back to the position it left off. (actually I say if it's full, drop an enderchest, unload, then pick the enderchest back up).
To go back to the home position, you'll have to keep track of it's position every time it moves in variables like currentX and currentZ and currentY. Then when you need to reload, you go from the currentX to the chestX, then the currentZ to the chestZ, then y… and then back to where you were by doing the reverse.

With the lava problem, I'm not sure why this would be happening to you. I've never had a problem with my turtles in lava. My guess is there is some other factor causing it to stop. Possibly because you only move and dig forward if you detect something.
Almerish #3
Posted 14 January 2013 - 03:32 PM
I know how to do the programing for the returning to starting pos and return to the last spot dug. What i don't know is how to make it check to see if slot 16 has something in it. I put in the scripte that it only digs when it detects a block so that it will stop when it finds a cave.
theoriginalbit #4
Posted 14 January 2013 - 03:37 PM

if turtle.getItemCount( 16 ) > 0 then
  print( "There is something in the slot" )
else
  print( "There isn't" )
end
crazyguymgd #5
Posted 14 January 2013 - 04:00 PM

if turtle.getItemCount( 16 ) > 0 then
  print( "There is something in the slot" )
else
  print( "There isn't" )
end
theoriginalbit #6
Posted 14 January 2013 - 04:05 PM
HAHAHAHAHA you just had to get that like in somehow! :P/>
crazyguymgd #7
Posted 14 January 2013 - 04:07 PM
Lol could not resist the urge!