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

[Turtle] Modification of Guude's Area Flatten

Started by Gods_Goo, 25 December 2012 - 05:31 AM
Gods_Goo #1
Posted 25 December 2012 - 06:31 AM
I have been trying to modify Guude's Area Flatten Script by adding a new function called empty(), which in concept should empty the turtles inventory into an ender chest in slot 1.

I can't find anything wrong with it, but it won't place the chest or carry out the function. This is probably due to me being a complete novice at coding

This is a copy of my edited code and link


-- Area Flatten v1.0 by Guude
-- Vars
local tArgs = { ... }
local togo = tonumber(tArgs[1])
local width = tonumber(tArgs[2])
togo = togo or 1
width = width or togo
-- Functions
function tfuel(amount)
if turtle.getFuelLevel() < 5 then
  turtle.select(16)
  turtle.refuel(amount)
  turtle.select(1)
end
end
function upuntil()
local upc = 0
for u = 1, 5 do
  repeat
   tfuel(1)
   turtle.digUp()
   if turtle.up() then
    upc = upc + 1
   end
   sleep(0.25)
  until turtle.detectUp() == false
end
for dc = 1, upc do
  tfuel(1)
  turtle.down()
end
end
function turnaround()
  turtle.turnRight()
  turtle.turnRight()
end
function itemcount()
  turtle.getItemCount(9)
end
function empty()
  if itemcount() = 1 then
   turtle.dig()
   turtle.select(1)
   turtle.place()
	 for i = 2, 9 do
	  turtle.select(i)
	  turtle.drop()
   end
end
  sleep(5)
  turtle.dig()
end
-- Main Script
for i = 1, width do
for j = 1, togo do
  tfuel(1)
  if turtle.detect() then
   repeat
    turtle.dig()
    sleep(0.5)
   until turtle.detect() == false
   turtle.forward()
   upuntil()
  else
   turtle.forward()
   upuntil()
  end
end
turnaround()
empty()
for j = 1, togo do
  tfuel(1)
  turtle.forward()
end
turtle.turnLeft()
if turtle.detect() then
  repeat
   turtle.dig()
   sleep(0.5)
  until turtle.detect() == false
end
turtle.forward()
turtle.turnLeft()
end
end

Any help would be appreciated :D/> Thanks
remiX #2
Posted 25 December 2012 - 07:10 AM
if itemcount() = 1 then 

If statements require two =='s because you're comparing two variables:

if itemcount() == 1 then

Also you need to return the item count of a slot:


function itemcount()
  return turtle.getItemCount(9)
end