Posted 30 December 2012 - 02:56 PM
This will be my first program with lua. I think that computercraft and turtles are a great way of learning a programming language.
It would be great if Pro could read over my code and give me some suggestions.
What i am trying to make is a turtle that digs a 2 by 1 shaft for the distance given and detects for gravel.
Code is in the spoiler:
EDIT 1: Thanks mikey53591 for the gravel detect code.
EDIT 2: Water/lava detection doesn't work, water and lava count as blocks (face-palm)
EDIT 3: Added a torch placer, once every 7 blocks
It would be great if Pro could read over my code and give me some suggestions.
What i am trying to make is a turtle that digs a 2 by 1 shaft for the distance given and detects for gravel.
Code is in the spoiler:
Spoiler
local function refuel()
-- refuel: checks the fuel level, if it is not unlimited or if there is fuel/power left it does nothing, otherwise it selects slot one and refuels from it
local fuelLevel = turtle.getFuelLevel()
if fuelLevel ~= "unlimited" or fuelLevel > 0 then
turtle.select(1)
turtle.refuel(1)
end
end
local function twoByOne()
--the actually digging for the turtle
while turtle.detect()==true do
turtle.dig()
if turtle.detect()~=true then
turtle.forward()
sleep(0.5)
end
while turtle.detectUp()==true do
turtle.digUp()
if turtle.detectUp()~=true then
end
end
--##CREDIT TO mikey53591 ON THE CC FORUMS## This tells the turtle to keep digging until there are no blocks detected then ends the cycle--
-- asks the user for the distance to dig
print "How far forward? "
y = io.read()
y = tonumber(y)
i = 1
for i = 1, y, 1 do
-- torch placer
if i%7 == 0 then
turtle.select(2)
turtle.placeUp()
end
-- main loop that runs the functions until the distance required is meet
refuel()
sleep(0.25)
twoByOne()
sleep(0.25)
end
EDIT 1: Thanks mikey53591 for the gravel detect code.
EDIT 2: Water/lava detection doesn't work, water and lava count as blocks (face-palm)
EDIT 3: Added a torch placer, once every 7 blocks