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

Turtle Wall building program

Started by Patrick1005de-CC, 21 October 2014 - 07:23 PM
Patrick1005de-CC #1
Posted 21 October 2014 - 09:23 PM
Hi Guys,

I have script a code for my turtles, to build in my house walls…
But how can i do it, when slot 1 with Item 64 = 0 then select the slot 2 with item 64 and when slot 2 = 0 then select slot 3 ?!

Hier is the Code:

print("---------Mauern bauen----------")
print("Baumaterial in Slot 1,2,3 legen")
print("Kohle in Slot 16 legen")
print("--------------------------------")
a = 0
write("Wie breit soll die Mauer sein: ")
Breit = io.read()
write("Wie hoch soll die Mauer werden: ")
Hoch = io.read()
c = a+Breit
d = a+Hoch
d1 = a+Hoch
while c > 0 do
while d > 0 do
  turtle.select(16)
  turtle.refuel()
  turtle.select(1)
   if turtle.detect() then
   turtle.dig()
  end
  turtle.place()
  turtle.up()
  d = (d - 1)
end
d = (d + d1)
while not turtle.detectDown() do
turtle.down()
end
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
c = (c - 1)
end

Thank you !
Bomb Bloke #2
Posted 22 October 2014 - 02:10 AM
Put this at the top:

local function placeBlock()
  for i = 1, 15 do
    if turtle.getItemCount(i) > 0 then
      turtle.select(i)
      turtle.place()
      return
    end
  end
end

Then later in your script, instead of using turtle.place(), use placeBlock(). :)/>