Jump to content




Filling in a squared area.


  • You cannot reply to this topic
2 replies to this topic

#1 fanzypantzy

  • Members
  • 14 posts

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


#2 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 13 January 2013 - 12:44 AM

you sould use for loops:
for l1=1,size do
turtle.dosomething()
end


#3 W00dyR

  • Members
  • 135 posts

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users