I am trying to setup a turtle so that it can replant a complex field with several stories. I borrowed this little program by Acuena that I tried to edit to make it fit my fields but I don't know how to make it plant the 7x5 field then go down to the next field until it's done.
Here is my progress (The prints are in french sorry :P/>)
Spoiler
-- * Planteur de champs 0.1
-- * Made by: AirChris117
-- * Utilisation : Slot 1 = Fuel ; Slot 2 à 16 = Seeds
--------------------------------------- Variables --------------------------------------- (WORKING)
curslot = 2
fuelused = 0
blocksplaced = -1
totalnrblocks = 0
fields = 6
length = 7
width = 5
--------------------------------------- Functions --------------------------------------- (WORKING)
function moveforward()
while not turtle.forward() do
checkfuel()
end
end
function moveback()
while not turtle.back() do
checkfuel()
end
end
function checkfuel()
if turtle.getFuelLevel() < 1 then
turtle.select(1)
if not turtle.refuel(1) then
print("Pas de fuel dans le slot 1, en attente de fuel")
while not turtle.refuel(1) do
end
print("Refuel avec succes, reprise de l'action")
end
fuelused = fuelused + 1
turtle.select(curslot)
end
end
function turnright()
turtle.turnRight()
moveforward()
turtle.turnRight()
end
function turnleft()
turtle.turnLeft()
moveforward()
turtle.turnLeft()
end
function checkblockcount()
if turtle.getItemCount(curslot) == 0 then
selnextslot()
end
end
function selnextslot()
curslot = curslot + 1
if curslot > 16 then
print("Plus de ressources, fin de l'action")
error()
end
turtle.select(curslot)
end
function place()
checkblockcount()
turtle.placeDown()
blocksplaced = blocksplaced + 1
end
function countblocks()
for i = 2,16 do
turtle.select(i)
totalnrblocks = totalnrblocks + turtle.getItemCount(i)
end
if not totalnrblocks == 0 then
totalnrblocks = totalnrblocks + 1
end
turtle.select(curslot)
end
function returntostart()
if orient == true then
turtle.turnRight()
for i = 1, width - 1 do
moveforward()
end
turtle.turnRight()
moveback()
elseif orient == false then
turtle.turnLeft()
for i = 1, width - 1 do
moveforward()
end
turtle.turnRight()
for i = 1, length do
turtle.back()
end
end
end
--------------------------------------- Code --------------------------------------- (NOT FINISHED - WORK IN PROGRESS) - Here is where I got stuck :(/>/>
if totalnrblocks < need then
print("Pas assez de ressources") -- Not enough fuel
print("Nombre total: "..need)
print("Nombre disponible: "..totalnrblocks)
error()
end
moveforward()
place()
for xx = 1,width - 1 do
for x = 1, length-1 do
moveforward()
place()
end
if orient == false then -- Should turn right
turnright()
place()
else -- Should turn left
turnleft()
place()
end
orient = not orient
end
for x = 1, length-1 do
moveforward()
place()
end
print("Orient: "..tostring(orient))
returntostart()
print("Fin du replantage")
print("Nombre de plantations: "..blocksplaced)
print("Consommation de fuel: "..fuelused)
Here is a screenshot of my fields :
https://imgur.com/a/dnlPf
Here is what I want it to do :
https://imgur.com/a/M5AYj