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

Digging turtle. level an area

Started by Tbbas, 28 December 2012 - 09:40 PM
Tbbas #1
Posted 28 December 2012 - 10:40 PM
So hi!
First of all, I am really new to lua,and tried to read the tutorials but did,'t really get them, so i thought that you could help me.
So I want to create a program for a digging turtle which makes it level an area.
Any help would be appreciated
Thank you!
AngelMalus #2
Posted 29 December 2012 - 01:34 AM
Making it level an area.

Is the area above ground? Undergrownd? If the turtle finds blocks, you want them to break them only 1 level up or 2 levels up or infinite levels up?
The program is relative simple, just have a turtle swipe an area walking back and forward, checking both sides so you can clear a 3 area wide on every swipe.

So start your turtle code as this:

Define area (give the turtle some input on how far and how deep and how high you want it to check up)

lets say

cleanArea 8 12 4 – so it would go 8 blocks to left and right and 12 blocks deep, or it can also mean loops.

then have the turtle move forward, and check both sides, break if detects anything.

(to clean up) make the turtle move up and check if there is something to detect up there, if there is something move up and repeat 4 times. if not, return down and continue until 12
then move to RIGHT then LEFT defined on the program it self, do that 8 times.

Make sure turtle keeps checking fuel levels before each move.
theoriginalbit #3
Posted 29 December 2012 - 02:08 AM
- snip -

Also to add to this, have it place down blocks if it doesn't find any blocks below it.
AngelMalus #4
Posted 29 December 2012 - 03:47 AM
- snip -

Also to add to this, have it place down blocks if it doesn't find any blocks below it.

True, give the turtle some sand or gravel and it will fill any hole or normal blocks it will cover any hole that finds on the way.
theoriginalbit #5
Posted 29 December 2012 - 03:52 AM
- snip -

Also to add to this, have it place down blocks if it doesn't find any blocks below it.

True, give the turtle some sand or gravel and it will fill any hole or normal blocks it will cover any hole that finds on the way.

Make sure that you wait before checking again with gravel and sand before moving on as their fall can fool the turtle into thinking there is a block there, so sleep for, 0.8? seconds. or is it 0.4, cant remember.
AngelMalus #6
Posted 29 December 2012 - 04:05 AM
- snip -

Also to add to this, have it place down blocks if it doesn't find any blocks below it.

True, give the turtle some sand or gravel and it will fill any hole or normal blocks it will cover any hole that finds on the way.

Make sure that you wait before checking again with gravel and sand before moving on as their fall can fool the turtle into thinking there is a block there, so sleep for, 0.8? seconds. or is it 0.4, cant remember.


Exactly 0.4, just confirmed it. (Tekkit 3.1.3 SinglePlayer)
0.8 is for the MotorFrames :P/>
Tbbas #7
Posted 29 December 2012 - 06:06 AM
Thank you! But as I said, I am really new to this sort of thing, so could someone give me an example of the code?
remiX #8
Posted 29 December 2012 - 09:41 AM
Here's what you could use, it's a simple code and sand/gravel proof. It only goes up if there is a block above it, so if you have a gap between two blocks, it will not go up more.

Spoiler

args = {...}
length = tonumber(args[1])
width = tonumber(args[2])
needFuel = true
if not width or not length or #args ~= 2 then
    print("Usage: "  .. fs.getName(shell.getRunningProgram()) .. " <length> <width>")
    print("<length> is the amount of times it will go forward from the starting point")
    print("<width> is the amount of times it will go to the right of the starting point")
    return
end

while needFuel do
    if turtle.getFuelLevel() < 300 then
        print("I need fuel!\nWhich slot must I use?")
        nSlot = tonumber(read())
        turtle.select(nSlot)
        if turtle.refuel() then
            print("Fueled! I now have " .. turtle.getFuelLevel .. " fuel.")
        else
            print("No fuel in that slot.")
        end
    else
        needFuel = false
    end
end

for i = 1, length do
    for k = 1, width do
        while turtle.detect() do
            turtle.dig()
            sleep(0.4)
        end
        turtle.forward()
        x = 0
        while turtle.detectUp() do
            turtle.digUp()
            turtle.up()
            x = x + 1
        end
        for l = 1, x do
            turtle.down()
        end
    end
    for k = 1, width do
        turtle.back()
    end
    if i ~= length then
        turtle.turnRight()
        turtle.forward()
        turtle.turnLeft()
    end
end

-- Return to start
turtle.turnLeft()
for i = 1, length do
    turtle.forward()
end
turtle.turnRight()
AngelMalus #9
Posted 29 December 2012 - 12:12 PM
Not fuel friendly but it works.
ChunLing #10
Posted 29 December 2012 - 04:39 PM
The thing with the sand/gravel is optional, by the way. If you really only need a level area, airspaces below it are probably not a big deal. And a large drop will use your sand/gravel pretty quick.
remiX #11
Posted 29 December 2012 - 10:37 PM
Not fuel friendly but it works.

Yeah, well I added that in the last minute :P/> I set mine to unlimited fuel for testing, anyway.
Tbbas #12
Posted 30 December 2012 - 01:21 PM
Thanks everyone!