Jump to content

Help writing a Turtle program for placing blocks.


Cabius

Recommended Posts

Ok I am trying to make a turtle place a single layer of blocks across a 24X40 block area. Could some one help me write the program? I tried to do something like

turtle.place()

turtle.moveBack()

turtle.place()

But it doesn't work and I cant make it do a 24X40 area. Any help would be appreciated. Thankyou. It wouldn't be bad to have it remove the next block behind it to so I don't have to clear the layer of blocks before putting the turtle down. Maybe at the start of the program it would dig down one block then dig behind it then place one in front then dig behind again then place and so fourth. I suppose it would have to not pick up the blocks it is digging so its inventory doesn't get full.

Link to comment
Share on other sites

This has a decent amount of error checking (blocked path, no fuel, out of blocks). If turtle's don't need fuel on your server the script should still work OK in CC 1.41. If your server is still 3.1.2, you might need to remove the function about refueling. There is no turtle.digBehind() so while yes, it is possible, it would require your turtle to do a complete rotation to check/dig the block behind then return to the starting direction. The other option is to go forwards and dig the area before starting to place blocks, but this would take up twice as much fuel. If you want to add this, it's up to you.

--the turtle places blocks for 'height' blocks, then turns around and repeats until it has placed 'width' rows

local width = 40

local height = 24

 

function back()

  if not turtle.back() then

    print("Something's in the way!")

    return false

  end

  return true

end

 

function refuel(needed)

  while turtle.getFuelLevel() < needed do

    selected = 0

    while(turtle.refuel(1) == false) do

      selected = selected + 1

      if selected == 17 then

        print("Out of fuel!")

        return false

      end

      turtle.select(selected)

    end

  end

  return true

end

 

function place()

  selected = 0

  while(turtle.place() == false) do

    selected = selected + 1

    if selected == 17 then

      print("Out of blocks or block already placed!")

      return false

    end

    turtle.select(selected)

  end

  return true

end

 

for w = 1, width do

  if not refuel(height + 2) then

    return

  end

  for h = 2, height do

    if not (place() and back()) then

      return

    end

  end

  if not place() then

    return

  end

  if w % 2 == 0 then

    turtle.turnRight()

  else

    turtle.turnLeft()

  end

  if not back() then

    return

  end

  if w % 2 == 0 then

    turtle.turnRight()

  else

    turtle.turnLeft()

  end

  if not (back() and back()) then

    return

  end

end

 

print("Job finished successfully")

Edit: Alternately, you could modify this script to make the turtle go forwards and dig/place blocks *under* it..but now that I've posted it I'm not going to do it unless necessary

Link to comment
Share on other sites

  • 2 weeks later...

Okay, so there is no command for a turtle to rotate blocks. Is there any other way to automatically rotate a frame motor? That's really what I want to do, because annoyingly, when it gets placed it points the conveyor downwards, the least useful way.

So THAT'S what you wanted. You should have been more specific, because that's easy. Use a screwdriver/sonic screwdriver. Right clicking will turn the direction it moves stuff, shift-right clicking it will change the side it moves from. While a turtle and deployers can do a normal right click if given a screwdriver, only you will be able to do the shift-right click.

Link to comment
Share on other sites

Cabius copy and paste that code go into your tekkit folder and look for the computercraft folder and go into programs and create a new text document and paste the code and save the document

C:\Users\PCUSERNAME\AppData\Roaming\.techniclauncher\tekkit\mods\ComputerCraft\lua\rom\programs\turtle

Alternatively, actually paste the file directory? Much better.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...