Posted 05 January 2013 - 01:58 AM
Hey guys.
I've only started programming with these turtles recently and after a few attempts feel confident enough to share the fruits of my labor.
I started with something VERY simple. A program where the turtle just keeps trying to refuel until you terminate the program. I was using this with labeled computers so I could carry it over to lava and just keep dumping lava buckets in it until it's fuel reached 30k or so.
Lava Bucket Refueler
ctrl + t for a few seconds to terminate program. Breaking works too.
Just keep putting lava buckets in slot 1.
Pastebin: http://pastebin.com/qwC6Qt4i
After, I decided to write a program that would bridge across the gaps made by my turtles after excavating at y=16. Then I could start them excavating again. It has been designed to run until it hits the wall and measures that distance to use as how far it should run when making the bridge 3 wide. This program also checks if it needs more fuel and will select a different slot each time a stack runs out.
When finished, the turtle will run back to where it started.
v1.0 Bridge builder
Fuel goes in slot 1, blocks in any other slot. Will ask for blocks if/when empty.
Pastebin: http://pastebin.com/c8c9GQQX
That was a good learning curve, but I figured I could make it more efficient, as well as telling it to place torches as well. In version 2.0, it only runs down one row of blocks, placing it in the direction you want it to create the bridge. It will run forward until it reaches the end of the path, drop down one block and then place blocks either side and behind, occasionally placing torches when it might get dark enough for mobs to spawn.
v2.0 Bridge builder
Fuel in slot one, torches in slot two, blocks in any other slot.
Pastebin: http://pastebin.com/ULK49FXh
At the time of saving these programs to pastebin, I was sure they would work. There may still be some errors though, so I'd appreciate if you'd post them below. If you would like to use any of my code(selecting new stacks of blocks is a section I'm proud of :P/> ) then feel free. Just give credit.
Thanks for reading my journey :P/> They may not be the most impressive, but these programs were the first I made, so I'm quite proud of them.
Hope you all are having a fantastic day.
I've only started programming with these turtles recently and after a few attempts feel confident enough to share the fruits of my labor.
I started with something VERY simple. A program where the turtle just keeps trying to refuel until you terminate the program. I was using this with labeled computers so I could carry it over to lava and just keep dumping lava buckets in it until it's fuel reached 30k or so.
Lava Bucket Refueler
ctrl + t for a few seconds to terminate program. Breaking works too.
Just keep putting lava buckets in slot 1.
Pastebin: http://pastebin.com/qwC6Qt4i
Spoiler
while true do
if turtle.refuel() then
FuelNumber = turtle.getFuelLevel()
print (FuelNumber)
else
sleep(1)
end
end
After, I decided to write a program that would bridge across the gaps made by my turtles after excavating at y=16. Then I could start them excavating again. It has been designed to run until it hits the wall and measures that distance to use as how far it should run when making the bridge 3 wide. This program also checks if it needs more fuel and will select a different slot each time a stack runs out.
When finished, the turtle will run back to where it started.
v1.0 Bridge builder
Fuel goes in slot 1, blocks in any other slot. Will ask for blocks if/when empty.
Pastebin: http://pastebin.com/c8c9GQQX
Spoiler
-- 3 wide Bridge v1.0 by SparkVGX
--Var
continue = true
lane = 1
distance = 0
tLeft = false
blocksPlaced = 0
Fuel = 1
function bForward()
if turtle.detect() == true then
turtle.dig()
turtle.forward()
end
else
turtle.forward()
end
end
function checkFuel()
if turtle.getFuelLevel() <= 5 then
turtle.select(1) --fuel goes in this slot
turtle.refuel(1)
end
end
function selectBlock()
for sBlock=2,13 do
if turtle.getItemCount(sBlock)~=0 then
turtle.select(sBlock)
break
end
end
end
--Place down
function pDown()
selectBlock()
if turtle.detectDown() == false then
if turtle.placeDown() == false then
print("Need blocks")
sleep(5)
pDown()
end
blocksPlaced = blocksPlaced + 1
print(blocksPlaced)
end
end
function turn()
if tLeft then
turtle.turnLeft()
bForward()
turtle.turnLeft()
end
if tLeft == false then
turtle.turnRight()
bForward()
turtle.turnRight()
end
tLeft = not tLeft
end
function Lane()
if lane == 1 then
while turtle.detect() == false do
pDown()
checkFuel()
turtle.forward()
distance = distance + 1
lane = lane + 1
end
end
if lane ~= 1 then
for i=1,distance do
pDown()
checkFuel()
bForward()
pDown()
end
end
end
function goHome()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
for i=1,distance do
turtle.forward()
end
end
Lane()
turn()
Lane()
turn()
Lane()
goHome()
v2.0 Bridge builder
Fuel in slot one, torches in slot two, blocks in any other slot.
Pastebin: http://pastebin.com/ULK49FXh
Spoiler
-- 3 wide bridge v2.0 by SparkVGX
--Variables
distance = 0
blocksPlaced = 0
fuel = 1
torches = 2
spaceCounter = 7
-- If I need fuel, I will try use refuel
function checkFuel()
if turtle.getFuelLevel() <= 5 then
turtle.select(1) --fuel goes in this slot
turtle.refuel(1)
end
end
-- Place torch
function pTorch()
turtle.select(2)
turtle.up()
turtle.place()
turtle.down()
end
-- Select blocks to place
-- only slots 3-16 should have blocks
function selectBlock()
for slot=3,16 do
if turtle.getItemCount(slot)~=0 then
turtle.select(slot)
break
end
end
end
-- Select blocks and place them if possible, otherwise if out of blocks, wait.
function placeB()
selectBlock()
if turtle.detect() == false then
if turtle.place() == false then
print("Need blocks")
sleep(5)
placeB()
end
blocksPlaced = blocksPlaced + 1
end
end
-- pretty simple.. you turn around
function turnAround()
turtle.turnLeft()
turtle.turnLeft()
end
--initial start to get turtle in position
function runOnce()
checkFuel()
while turtle.detectDown() == true do
turtle.forward()
distance = distance + 1
end
turtle.down()
turtle.turnLeft()
placeB()
turnAround()
placeB()
turtle.turnRight()
end
-- takes the turtle back where it started
function goHome()
turtle.up()
turtle.up()
for i=1,distance do
turtle.forward()
end
turnAround()
turtle.down()
print("All done!")
print("I went " .. distance .. "meters and placed " .. blocksPlaced .. " blocks")
end
--The main code to run
function Start()
runOnce()
--checks fuel, places blocks behind and on the sides.
while turtle.back() do
checkFuel()
placeB()
turtle.turnLeft()
placeB()
turnAround()
placeB()
turtle.turnLeft()
spaceCounter = spaceCounter + 1
distance = distance + 1
-- every so often, places a torch and
-- resets the counter
if spaceCounter == 8 then
pTorch()
spaceCounter = 0
end
end
-- all done? return to start
goHome()
end
Start()
Thanks for reading my journey :P/> They may not be the most impressive, but these programs were the first I made, so I'm quite proud of them.
Hope you all are having a fantastic day.