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

Filling in a squared area.

Started by fanzypantzy, 12 January 2013 - 11:28 PM
fanzypantzy #1
Posted 13 January 2013 - 12:28 AM
Hi I'm pretty new to this turtle programming but I got a little program I wanted to finish. Its basicly just gonna be for filling in large areas.

The code I got until now Is ok but it dont have a repeat of the turning, only way I have been able to fix it is to copy paste the turning over and over again. Pluss it only takes stuff out of the 1 spot which means I need to move stuff manually into spot 1. So I need help to put stuff into slot 1 or select other spots with stuff inn, and how to automate the turning on a repeat so it every other turn, turns in the oposite direction. Or else it will go in sircles.

Anyways here is the code:


function place()
if turtle.detectDown() == false then
  turtle.placeDown()
end
if turtle.detectDown() then
  turtle.forward()
end
end

function turnright()
if turtle.detectDown() == false then
  turtle.placeDown()
end
turtle.turnRight()
turtle.forward()
turtle.turnRight()
end

function turnleft()
if turtle.detectDown() == false then
  turtle.placeDown()
end
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end

--start
if turtle.detect() == false then
repeat
  place()
until turtle.detect()
  turnright()
end

if turtle.detect() == false then
repeat
place()
until turtle.detect()
turnleft()
end
PixelToast #2
Posted 13 January 2013 - 12:44 AM
you sould use for loops:
for l1=1,size do
turtle.dosomething()
end
W00dyR #3
Posted 13 January 2013 - 02:08 AM
For the moving items, you could make a little function that checks the block ammount and select a different slot if its empty, I am not sure if this is the easiest way to do this, but you will have to call it every time you tell it to place a block


function checkBlocks()
  slot = 1
  while turtle.getItemCount(slot) <= 1 do
	slot = slot + 1
	turtle.select(slot)
  end
end

You can also incorporate this in the place() function