Posted 22 December 2012 - 08:44 AM
I'm new to the whole programming thing. I've never really done much programming other than a bit of visual basic so I know a bit about loops etc but I've never made a program as complex as this one although people that know how to code will see this code as simple.
(back story skip paragraph for what the code does)
So anyway I was showing my brother the computer craft mod and how i made a turtle create stairs and then he said to make one to make a tunnel. So i decided to give it a go and I know that there's a tunnel program built in but that seems to only work under ground unless i'm doing something wrong.
(what the code is supposed to do)
The program that i'm trying to write builds a tunnel above ground. So far I've managed to get it to ask you how long you want it and then it builds a tunnel which is one block width and 2 height (door size). theres nothing wrong with this code but now what i want to to do it to remove any blocks in it's way. So say it comes to a hill then it digs the block up and replaces it with what ever is in the inventory. But it needs to do this for what ever is in front of it or above it and also loop that code with in the loop for the actual tunnel
so how do i code it. The code is below i know i can use more loops etc to tidy it up but i'm not sure how to do that either unless i work at it but for now i want to do what i said in the above paragraph.
Heres the code: (i tried attempting to write the code my self but it only does it once per loop)
local times = 0
term.write("how many block long?")
length = read()
for i = 1, length do
if turtle.detect() then
turtle.dig()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
turtle.turnRight()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.place()
turtle.down()
turtle.placeUp()
turtle.place()
turtle.down()
turtle.place()
turtle.down()
turtle.place()
turtle.turnRight()
turtle.forward()
end
end
(back story skip paragraph for what the code does)
So anyway I was showing my brother the computer craft mod and how i made a turtle create stairs and then he said to make one to make a tunnel. So i decided to give it a go and I know that there's a tunnel program built in but that seems to only work under ground unless i'm doing something wrong.
(what the code is supposed to do)
The program that i'm trying to write builds a tunnel above ground. So far I've managed to get it to ask you how long you want it and then it builds a tunnel which is one block width and 2 height (door size). theres nothing wrong with this code but now what i want to to do it to remove any blocks in it's way. So say it comes to a hill then it digs the block up and replaces it with what ever is in the inventory. But it needs to do this for what ever is in front of it or above it and also loop that code with in the loop for the actual tunnel
so how do i code it. The code is below i know i can use more loops etc to tidy it up but i'm not sure how to do that either unless i work at it but for now i want to do what i said in the above paragraph.
Heres the code: (i tried attempting to write the code my self but it only does it once per loop)
local times = 0
term.write("how many block long?")
length = read()
for i = 1, length do
if turtle.detect() then
turtle.dig()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
turtle.turnRight()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.place()
turtle.down()
turtle.placeUp()
turtle.place()
turtle.down()
turtle.place()
turtle.down()
turtle.place()
turtle.turnRight()
turtle.forward()
end
end