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

[Turtle] End to close if at line..

Started by xizors, 21 April 2013 - 07:09 AM
xizors #1
Posted 21 April 2013 - 09:09 AM
Hi! :D/>

Im currently trying to improve my obsidian mining turtle.

By executing this command I want it to keep mining whatever is in front of it in a line, until it cant detect anything, and then find another line next to it.

But I am getting an error: 'end' expected (to close 'if' at line 22)


    function diggy()
        while turtle.detect() do
                turtle.dig()
                turtle.forward()
        end
end

        while not turtle.detect() do
        turtle.turnRight()
        if turtle.detect() then
        turtle.dig()
        turtle.forward()
        turtle.turnRight()
        if turtle.detect() then diggy()
        if not turtle.detect() then
        turtle.turnLeft()
        end

        else
        turtle.turnLeft()
        if turtle.detect() then
        turtle.dig()
        turtle.forward()
        turtle.turnLeft()
        if turtle.detect() then diggy()
        if not turtle.detect() then
        turtle.turnRight()
end

Hope you can help :)/>

Edit: Its still not finished, just in case you wondered.
Kingdaro #2
Posted 21 April 2013 - 09:20 AM
Proper code tabbing can help you easily find where you're missing ends:

function diggy()
    while turtle.detect() do
        turtle.dig()
        turtle.forward()
    end
end

while not turtle.detect() do
    turtle.turnRight()
    if turtle.detect() then
        turtle.dig()
        turtle.forward()
        turtle.turnRight()
        if turtle.detect() then diggy()
            if not turtle.detect() then
                turtle.turnLeft()
            end
        else
            turtle.turnLeft()
            if turtle.detect() then
                turtle.dig()
                turtle.forward()
                turtle.turnLeft()
                if turtle.detect() then
                    diggy()
                    if not turtle.detect() then
                        turtle.turnRight()
                    end
                end -- 'missing this end here'
            end -- 'and here'
        end -- 'and here'
    end -- 'and here'
end -- 'and here'
remiX #3
Posted 21 April 2013 - 09:20 AM
If you indent your code, you get this:

function diggy()
    while turtle.detect() do
        turtle.dig()
        turtle.forward()
    end
end

while not turtle.detect() do
    turtle.turnRight()
    if turtle.detect() then
        turtle.dig()
        turtle.forward()
        turtle.turnRight()
        if turtle.detect() then diggy()
            if not turtle.detect() then
                turtle.turnLeft()
            end
        else
            turtle.turnLeft()
            if turtle.detect() then
                turtle.dig()
                turtle.forward()
                turtle.turnLeft()
                if turtle.detect() then
                    diggy()
                    if not turtle.detect() then
                        turtle.turnRight()
end

Yeah.. quite a few missing ends :)/>/>

edit: Lol damn you kingdaro!
xizors #4
Posted 21 April 2013 - 09:34 AM
Never knew you had to end for every tab you had.. But thanks! I'm learning something new everyday, lol :P/>