Posted 13 July 2015 - 06:06 AM
I wrote a small program to try to get my turtle to dig a square out, using variables (though i've since removed the variable from the body of the code, cause i couldn't get it to work) for a 19x11 square. The program is supposed to loop dig() 19 times, then activate turnAboutR or L based on the variable x being even or odd, using x as the width as well. However, while it's activating the dig() function, it's not completing it before moving on. I've marked it's first 17 movements after activating the program. I haven't checked to see if it's endless or if it'll stop on it's own;
- dig forward
- dig up
- dig forward
- dig up
- turn right
- turn right
- move forward
- turn right
- move forward
- turn right
- dig forward
- dig up
- move forward
- dig up
- dig forward
- move forward
- dig up
- local args = { … } vari = tonumber(args[1])
- x = 11 currentSlot = turtle.getSelectedSlot() local function refuel(currentSlot) if turtle.getFuelLevel() < 13 then turtle.select(16) turtle.refuel(1) turtle.select(currentSlot) print( "refueled" ) return currentSlot end end function turnAboutL() turtle.forward() turtle.turnLeft() turtle.forward() turtle.turnLeft() return true end function turnAboutR() turtle.forward() turtle.turnRight() turtle.forward() turtle.turnRight() return true end function dig(vari) refuel() for a=1,vari,1 do turtle.dig() turtle.digUp() turtle.forward() turtle.digUp() return true end end while x > 0 do dig() sleep(1) print("dig function ended") if dig() then if (x % 2 == 0) then turnAboutL() print("Left turn complete") else turnAboutR() print("Right turn complete") end end if turnAboutR() or turnAboutL() then x = x - 1 end end
Edited on 13 July 2015 - 05:26 AM