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

Tunnel/stairs program gravel removal help

Started by SilverEyes, 05 October 2012 - 11:30 AM
SilverEyes #1
Posted 05 October 2012 - 01:30 PM
Ok, I've made a couple of programs, one makes a 2x1 tunnel placing torches every 5 blocks and the other makes stairs downwards into the ground also placing torches. They seem to be having problems when encountering gravel though. With my tunnel one when it hits gravel it mines it but ends up making the tunnel too long then not returning back to where it started but instead in the middle of the tunnel. The stairs one when it hits gravel it mines it but makes a long shaft downwards infront of the gravel then also does not return home. I've tried changing some things around I'll put a comment on where I've tried to add some code for the gravel removal in both.

This is the tunnel code.
Spoiler

term.clear()
term.setCursorPos(1,1)
print("How far?")
local x
local y
x = read()
y = 0
print("Mining " ..x.. " metres")
turtle.select(1)
for i = 1, x do
   while not turtle.forward() do --Here is where I've tried to add the gravel remove part.
   turtle.dig()
   end
   turtle.dig()
   turtle.forward()
   turtle.digUp()
   y = y+1
	while y>5 do
	 turtle.placeUp()
	 y = y-6
	end
end
turtle.turnLeft()
turtle.turnLeft()
for i = 1, x do
  turtle.forward()
end
turtle.turnRight()
for i = 2, 16 do
  turtle.select(i)
  turtle.drop()
end
turtle.turnRight()
print("Tunnel complete")

This is the stairs code.
Spoiler

term.clear()
term.setCursorPos(1,1)
print("How far?")
local x
local y
x = read()
y = 0
turtle.select(1)
while not turtle.forward() do --Here is where I tried the gravel removal.
turtle.dig()
sleep(2)
end
for i = 1, x do
   turtle.dig()
   turtle.digDown()
   turtle.down()
   turtle.dig()
   turtle.forward()
   turtle.digUp()
   y = y+1
	while y>5 do
	 turtle.placeUp()
	 y = y-6
	end
end
turtle.turnLeft()
turtle.turnLeft()
for i = 1, x do
  turtle.forward()
  turtle.up()
end
turtle.turnRight()
for i = 2, 16 do
  turtle.select(i)
  turtle.drop()
end
turtle.turnRight()
print("Stairs completed")
PonyKuu #2
Posted 05 October 2012 - 01:58 PM
Write your own forward function and use it in each place, where you want turtle to move forward.

something like this:


local function smartForward ()
    while not turtle.forward () do
        if turtle.detect() then
            turtle.dig ()
        elseif turtle.attack () then
            print "Aggressive liveforms detected!"
        else
            print ("Impossible to move forward.")
            return false
        end
    end
    return true
end
KaoS #3
Posted 05 October 2012 - 02:01 PM

local function tunnel(length,torches)
  turtle.select(1)
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
   while turtle.detectUp() do turtle.digUp() end
   if torches and done%5==0 then turtle.placeUp() end
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
  end
  turtle.turnRight()
  for slot=2,16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end

term.clear()
term.setCursorPos(1,1)
print('How long should your tunnel be?')
write('length: ')
local len=read()
print('would you like to place torches? [yes | no]')
if string.lower(read())=='yes' then
  tunnel(len,true)
else
  tunnel(len)
end
SilverEyes #4
Posted 05 October 2012 - 03:10 PM

local function tunnel(length,torches)
  turtle.select(1)
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
   while turtle.detectUp() do turtle.digUp() end
   if torches and done%5==0 then turtle.placeUp() end
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
  end
  turtle.turnRight()
  for slot=2,16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end

term.clear()
term.setCursorPos(1,1)
print('How long should your tunnel be?')
write('length: ')
local len=read()
print('would you like to place torches? [yes | no]')
if string.lower(read())=='yes' then
  tunnel(len,true)
else
  tunnel(len)
end

Is this what I should do instead?
KaoS #5
Posted 05 October 2012 - 03:38 PM
give it a try and let me know what it does :(/>/>

this way it is a function (easier to use and debug) and you can specify if you want torches
SilverEyes #6
Posted 05 October 2012 - 03:59 PM
give it a try and let me know what it does :(/>/>

this way it is a function (easier to use and debug) and you can specify if you want torches
Seems to work greatly! Thanks!
Doyle3694 #7
Posted 05 October 2012 - 04:22 PM
maybe even add tArgs? Do you knwo how these work or do you want an explanation?
SilverEyes #8
Posted 05 October 2012 - 04:23 PM
maybe even add tArgs? Do you knwo how these work or do you want an explanation?
An explanation would be nice, please. :(/>/>
Doyle3694 #9
Posted 05 October 2012 - 04:34 PM
tArgs is pretty much the arguements you pass a program when calling it. I will use a example, "go forward 3". This will pass 2 arguements that will be stored in tArgs. tArgs is therefor a table(a table is just 1 variable that stores many variables pretty much). To check how many variables are stored in tArgs, you do #tArgs. the # sign asks for length. it will work on other tables too, so it's not tArgs specific. to get any variable from tArgs, you use tArgs[position]. in "go forward 3", "forward" will be the same as tArgs[1] and "3" will be the same as tArgs[2]. And that covers tArgs pretty much, ask if you have any questions.
SilverEyes #10
Posted 05 October 2012 - 04:37 PM
tArgs is pretty much the arguements you pass a program when calling it. I will use a example, "go forward 3". This will pass 2 arguements that will be stored in tArgs. tArgs is therefor a table(a table is just 1 variable that stores many variables pretty much). To check how many variables are stored in tArgs, you do #tArgs. the # sign asks for length. it will work on other tables too, so it's not tArgs specific. to get any variable from tArgs, you use tArgs[position]. in "go forward 3", "forward" will be the same as tArgs[1] and "3" will be the same as tArgs[2]. And that covers tArgs pretty much, ask if you have any questions.
I think I get it, but I'm not sure how I'd use it.
Doyle3694 #11
Posted 05 October 2012 - 04:41 PM
for knowing how many times it should do it's stuff and if it should place torches.
SilverEyes #12
Posted 05 October 2012 - 05:05 PM
for knowing how many times it should do it's stuff and if it should place torches.
ah ok
KaoS #13
Posted 05 October 2012 - 06:07 PM
well if you wanted to incorporate varying length between torches you just have to do the following:


local function tunnel(length,torches)
  turtle.select(1)
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
   while turtle.detectUp() do turtle.digUp() end
   if torches~='' and done%tonumber(torches)==0 then turtle.placeUp() end
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
  end
  turtle.turnRight()
  for slot=2,16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end
term.clear()
term.setCursorPos(1,1)
print('How long should your tunnel be?')
write('length: ')
local torches=read()
print('how often should torches be placed (blank for none)')
tunnel(len,torches)
SilverEyes #14
Posted 06 October 2012 - 09:56 AM
well if you wanted to incorporate varying length between torches you just have to do the following:


local function tunnel(length,torches)
  turtle.select(1)
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
   while turtle.detectUp() do turtle.digUp() end
   if torches~='' and done%tonumber(torches)==0 then turtle.placeUp() end
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
  end
  turtle.turnRight()
  for slot=2,16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end
term.clear()
term.setCursorPos(1,1)
print('How long should your tunnel be?')
write('length: ')
local torches=read()
print('how often should torches be placed (blank for none)')
tunnel(len,torches)
Oh thanks, I just jumped back on my computer after sleeping and I used the tunnel code from before in my legit world and found one problem, what it does when placing torches is it digs the block infront of it and places the torch on the block that was ontop of the one he dug then he digs that block that had the torch on it. So no torches are in the tunnel.
SilverEyes #15
Posted 07 October 2012 - 08:52 AM
Write your own forward function and use it in each place, where you want turtle to move forward.

something like this:


local function smartForward ()
	while not turtle.forward () do
		if turtle.detect() then
			turtle.dig ()
		elseif turtle.attack () then
			print "Aggressive liveforms detected!"
		else
			print ("Impossible to move forward.")
			return false
		end
	end
	return true
end
Hmm? How would I do that? Sorry, I'm pretty new to this. :D/>/>
Doyle3694 #16
Posted 07 October 2012 - 09:20 AM
how do you mean?
using your function?

YourFunctionName()
KaoS #17
Posted 07 October 2012 - 09:42 AM

local function tunnel(length,torches)
  turtle.select(1)
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
   while turtle.detectUp() do turtle.digUp() end
   if torches~='' and done%tonumber(torches)==0 then turtle.back() turtle.placeUp() turtle.forward() end
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
  end
  turtle.turnRight()
  for slot=2,16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end
term.clear()
term.setCursorPos(1,1)
print('How long should your tunnel be?')
write('length: ')
local torches=read()
print('how often should torches be placed (blank for none)')
tunnel(len,torches)

will move the torches one back so it cannot be placed on a block that will be mined
SilverEyes #18
Posted 07 October 2012 - 10:49 AM

local function tunnel(length,torches)
  turtle.select(1)
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
   while turtle.detectUp() do turtle.digUp() end
   if torches~='' and done%tonumber(torches)==0 then turtle.back() turtle.placeUp() turtle.forward() end
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end
  end
  turtle.turnRight()
  for slot=2,16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end
term.clear()
term.setCursorPos(1,1)
print('How long should your tunnel be?')
write('length: ')
local torches=read()
print('how often should torches be placed (blank for none)')
tunnel(len,torches)

will move the torches one back so it cannot be placed on a block that will be mined
Oh thanks! :D/>/>
KaoS #19
Posted 07 October 2012 - 11:33 AM
no problem, before using the program please read through it and familiarize yourself with how it works, then in future you can adapt the code. no point in asking for code and not learning

EDIT: I can add comments to the code to explain parts or you can ask questions if you cannot understand any of it
SilverEyes #20
Posted 07 October 2012 - 12:18 PM
no problem, before using the program please read through it and familiarize yourself with how it works, then in future you can adapt the code. no point in asking for code and not learning

EDIT: I can add comments to the code to explain parts or you can ask questions if you cannot understand any of it
Yeh, comments would be nice if you don't mind, I know some of it but I'm not 100% sure on some of it. :D/>/>
KaoS #21
Posted 07 October 2012 - 01:07 PM
many people are confused about the

while not turtle.forward() do
turtle.dig()
end
basically I am telling it to loop through the code between the 'do' and the 'end' as long as the turtle.forward() command returns false or nothing


local function tunnel(length,torches)
  turtle.select(1) --select slot 1 where the torches are
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end --keep calling the forward function and every time it fails dig, if it succeeds then end (for gravel)
   while turtle.detectUp() do turtle.digUp() end --as long as something is above the turtle dig it out, once nothing is there end (for gravel)
   if torches~='' and done%tonumber(torches)==0 then turtle.back() turtle.placeUp() turtle.forward() end --if torches is not a blank string (what the read command returns when they enter nothing) then check if the amount of the tunnel done is divisible by 5, if it is devisible then move back and place a torch and move forward again
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end --move back along the tunnel, digging out anything in the way (for gravel)
  end
  turtle.turnRight()
  for slot=2,16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end
term.clear()
term.setCursorPos(1,1)
print('How long should your tunnel be?')
write('length: ')
local len=read()
print('how often should torches be placed (blank for none)')
local torches=read()
tunnel(len,torches)

if there is still anything you do not understand feel free to ask
SilverEyes #22
Posted 08 October 2012 - 07:11 AM
many people are confused about the

while not turtle.forward() do
turtle.dig()
end
basically I am telling it to loop through the code between the 'do' and the 'end' as long as the turtle.forward() command returns false or nothing

Spoiler

local function tunnel(length,torches)
  turtle.select(1) --select slot 1 where the torches are
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end --keep calling the forward function and every time it fails dig, if it succeeds then end (for gravel)
   while turtle.detectUp() do turtle.digUp() end --as long as something is above the turtle dig it out, once nothing is there end (for gravel)
   if torches~='' and done%tonumber(torches)==0 then turtle.back() turtle.placeUp() turtle.forward() end --if torches is not a blank string (what the read command returns when they enter nothing) then check if the amount of the tunnel done is divisible by 5, if it is devisible then move back and place a torch and move forward again
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for done=1,tonumber(length) do
   while not turtle.forward() do turtle.dig() end --move back along the tunnel, digging out anything in the way (for gravel)
  end
  turtle.turnRight()
  for slot=2,16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end
term.clear()
term.setCursorPos(1,1)
print('How long should your tunnel be?')
write('length: ')
local len=read()
print('how often should torches be placed (blank for none)')
local torches=read()
tunnel(len,torches)

if there is still anything you do not understand feel free to ask
uh I don't get this part

  for done=1,tonumber(length) do
and what does this mean?

tunnel(len,torches)
KaoS #23
Posted 08 October 2012 - 07:34 AM
ah, the for loop. very useful

if I were to use the code

for i=1,5 do
  print(i)
end
it would print

1
2
3
4
5
basically it loops through the code between 'do' and 'end', it sets the variable 'i' (you can use any variable) to be the first number (1 in this case) and then keeps looping through the code, adding 1 to the variable each time until it gets to the second number.
this code can be used to effectively run a segment a specific number of times. there are also many other properties of the command but we will only go into that if necessary
SilverEyes #24
Posted 08 October 2012 - 08:28 AM
ah, the for loop. very useful

if I were to use the code

for i=1,5 do
  print(i)
end
it would print

1
2
3
4
5
basically it loops through the code between 'do' and 'end', it sets the variable 'i' (you can use any variable) to be the first number (1 in this case) and then keeps looping through the code, adding 1 to the variable each time until it gets to the second number.
this code can be used to effectively run a segment a specific number of times. there are also many other properties of the command but we will only go into that if necessary
Ahh ok, does the "tonumber(length)" mean that it starts at 1 and goes to whatever number was put in for length?
KaoS #25
Posted 08 October 2012 - 08:55 AM
exactly. perfect for executing the code a certain number of times
SilverEyes #26
Posted 08 October 2012 - 09:17 AM
exactly. perfect for executing the code a certain number of times
What about this?

torches~='' and done%tonumber(torches)==0
Does it mean if torches isn't = to blank then something?
KaoS #27
Posted 08 October 2012 - 09:28 AM
in an if statement you can have multiple things to check simultaneously. example:

if 1<2 and 2>0 then
  print('successfull')
end
would print successful
you can also use OR

if 1==2 or 1==1 then
would also work

what that code is doing is checking if the variable 'torches' is NOT a blank string (the read command returns a blank string if you enter nothing) and it also checks if the number value of torches is perfectly divisible by 5

the % operator is something I learned about fairly recently, it returns the remainder of a division so 3%2==1 because 3/2=1 and remainder 1
4%2==0 because there is no remainder, you can use bignumber%smallnumber==0 to check if they are mutiples
SilverEyes #28
Posted 08 October 2012 - 09:36 AM
in an if statement you can have multiple things to check simultaneously. example:

if 1<2 and 2>0 then
  print('successfull')
end
would print successful
you can also use OR

if 1==2 or 1==1 then
would also work

what that code is doing is checking if the variable 'torches' is NOT a blank string (the read command returns a blank string if you enter nothing) and it also checks if the number value of torches is perfectly divisible by 5

the % operator is something I learned about fairly recently, it returns the remainder of a division so 3%2==1 because 3/2=1 and remainder 1
4%2==0 because there is no remainder, you can use bignumber%smallnumber==0 to check if they are mutiples
So if torches isn't blank and done/spacing of torches has no remainder it puts down the torches?
KaoS #29
Posted 08 October 2012 - 09:45 AM
exactly, so you understand it now?
SilverEyes #30
Posted 08 October 2012 - 09:48 AM
exactly, so you understand it now?
Yeh, I think so. :D/>/> Thanks!
KaoS #31
Posted 08 October 2012 - 10:10 AM
no problem, try building your own version of the code without looking at the old one, once you can do that then you're all good. enjoy the mod
SilverEyes #32
Posted 08 October 2012 - 10:58 AM
no problem, try building your own version of the code without looking at the old one, once you can do that then you're all good. enjoy the mod
Ahaha I'll give it a shot. :D/>/> Thanks for the help
SilverEyes #33
Posted 08 October 2012 - 12:26 PM
no problem, try building your own version of the code without looking at the old one, once you can do that then you're all good. enjoy the mod
One more thing,

  turtle.turnRight()
  return true
What does the return true mean?
And is there any way we could add each other over something so we could respond quicker?
Do you have Steam or something?
SilverEyes #34
Posted 08 October 2012 - 12:40 PM
Ok I tried it myself I did look at yours a bit but here it is. I do have one error though not sure why?
It says "bios:206: [string "mytun"]:2: '(' expected

local function Tunneltest(length,torch)
turtle.select(1)
for i=1, tonumber(length) do
while not turtle.forward() do
turtle.dig()
while turtle.detectUp() do
turtle.digUp()
if torch~='' and i%(torches)==0 then
turtle.back()
turtle.placeUp()
turtle.forward()
end
turtle.turnLeft()
turtle.turnLeft()
for i = 1, tonumber(length) do
while not turtle.forward() do
turtle.dig()
end
turtle.turnRight()
for slot 2, 16 do
turtle.select(slot)
turtle.drop()
end
turtle.turnRight()
end
term.clear()
term.SetCurserPos(1,1)
print("How long do you want the tunnel?")
local length = read()
print("What block distance between torches? (Leave blank for none)")
local torch = read()
Tunneltest(length,torch)
KaoS #35
Posted 08 October 2012 - 12:43 PM
that error says it is on line 2, there are no issues on line 2 so don't know about that, I know you are not closing your while true loops and the for loop for dropping needs and '=' between slot and 2

EDIT: you also didn't close the second for loop…. try laddering your code to make it easier to see and use notepad++ syntax highlighting
SilverEyes #36
Posted 08 October 2012 - 12:47 PM
that error says it is on line 2, there are no issues on line 2 so don't know about that, I know you are not closing your while true loops and the for loop for dropping needs and '=' between slot and 2

EDIT: you also didn't close the second for loop…. try laddering your code to make it easier to see and use notepad++ syntax highlighting
Yeh I thought it meant there was an error on line 2 but I couldn't find it so yeh, I've fixed the ones you've pointed out I'll see how it runs now.
SilverEyes #37
Posted 08 October 2012 - 12:53 PM
that error says it is on line 2, there are no issues on line 2 so don't know about that, I know you are not closing your while true loops and the for loop for dropping needs and '=' between slot and 2

EDIT: you also didn't close the second for loop…. try laddering your code to make it easier to see and use notepad++ syntax highlighting
I'm using notpad++ but it doesn't highlight anything? What's laddering my code?
KaoS #38
Posted 08 October 2012 - 01:10 PM
go to languages->L->lua and it will use syntax highlighting, when I say ladder I mean this

for i=1,5 do
    print(i)
end
rather than this

for i=1,5 do
print(i)
end

so you can see when you need an 'end'
SilverEyes #39
Posted 08 October 2012 - 01:23 PM
go to languages->L->lua and it will use syntax highlighting, when I say ladder I mean this

for i=1,5 do
	print(i)
end
rather than this

for i=1,5 do
print(i)
end

so you can see when you need an 'end'
Ok I've done that turns out I forgot to close alot :D/>/> and I spelt cursor wrong. Testing it again now though ;)/>/>
SilverEyes #40
Posted 08 October 2012 - 01:25 PM
Ok, I've tested it after that. It works!!! :D/>/> It digs the gravel right and everything. ;)/>/> Well I've gotta go to bed here so I'll talk again tomorrow.
Lyqyd #41
Posted 08 October 2012 - 03:59 PM
go to languages->L->lua and it will use syntax highlighting, when I say ladder I mean this

for i=1,5 do
    print(i)
end
rather than this

for i=1,5 do
print(i)
end

so you can see when you need an 'end'

The correct term is indentation. One indents code so that it is easier to read and quickly see each block of code.
SilverEyes #42
Posted 09 October 2012 - 07:33 AM
go to languages->L->lua and it will use syntax highlighting, when I say ladder I mean this

for i=1,5 do
	print(i)
end
rather than this

for i=1,5 do
print(i)
end

so you can see when you need an 'end'

The correct term is indentation. One indents code so that it is easier to read and quickly see each block of code.
Ah
SilverEyes #43
Posted 09 October 2012 - 07:35 AM
exactly, so you understand it now?
Ok I'm here again. Here's my code that I did.

local function Tunneltest(length,torch)
  turtle.select(1)
  for i=1, tonumber(length) do
   while not turtle.forward() do turtle.dig() end
   while turtle.detectUp() do turtle.digUp() end
   if torch~='' and i%tonumber(torch)==0 then turtle.back() turtle.placeUp() turtle.forward() end
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for i=1, tonumber(length) do
   while not turtle.forward() do turtle.dig() end
  end
  turtle.turnRight()
  for slot=2, 16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end
term.clear()
term.setCursorPos(1,1)
print("How long do you want the tunnel?")
write("Length: ")
local length = read()
print("What block distance between torches? (Leave blank for none)")
local torch = read()
Tunneltest(length,torch)
KaoS #44
Posted 10 October 2012 - 07:36 AM
The correct term is indentation. One indents code so that it is easier to read and quickly see each block of code.

I stand corrected :P/>/> I have never formally learned to code so my terminology may be incorrect.


exactly, so you understand it now?
Ok I'm here again. Here's my code that I did.

local function Tunneltest(length,torch)
  turtle.select(1)
  for i=1, tonumber(length) do
   while not turtle.forward() do turtle.dig() end
   while turtle.detectUp() do turtle.digUp() end
   if torch~='' and i%tonumber(torch)==0 then turtle.back() turtle.placeUp() turtle.forward() end
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for i=1, tonumber(length) do
   while not turtle.forward() do turtle.dig() end
  end
  turtle.turnRight()
  for slot=2, 16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end
term.clear()
term.setCursorPos(1,1)
print("How long do you want the tunnel?")
write("Length: ")
local length = read()
print("What block distance between torches? (Leave blank for none)")
local torch = read()
Tunneltest(length,torch)

looks good, how does it run?
SilverEyes #45
Posted 10 October 2012 - 07:48 AM
The correct term is indentation. One indents code so that it is easier to read and quickly see each block of code.

I stand corrected ;)/>/> I have never formally learned to code so my terminology may be incorrect.


exactly, so you understand it now?
Ok I'm here again. Here's my code that I did.

local function Tunneltest(length,torch)
  turtle.select(1)
  for i=1, tonumber(length) do
   while not turtle.forward() do turtle.dig() end
   while turtle.detectUp() do turtle.digUp() end
   if torch~='' and i%tonumber(torch)==0 then turtle.back() turtle.placeUp() turtle.forward() end
  end
  turtle.turnLeft()
  turtle.turnLeft()
  for i=1, tonumber(length) do
   while not turtle.forward() do turtle.dig() end
  end
  turtle.turnRight()
  for slot=2, 16 do
   turtle.select(slot)
   turtle.drop()
  end
  turtle.turnRight()
  return true
end
term.clear()
term.setCursorPos(1,1)
print("How long do you want the tunnel?")
write("Length: ")
local length = read()
print("What block distance between torches? (Leave blank for none)")
local torch = read()
Tunneltest(length,torch)

looks good, how does it run?
It works great. :P/>/>
KaoS #46
Posted 10 October 2012 - 07:53 AM
excellent stuffz. time to move on to a more difficult project. try building other codes
SilverEyes #47
Posted 10 October 2012 - 08:13 AM
excellent stuffz. time to move on to a more difficult project. try building other codes
I saw on a video(Direwolf20's) a guy made a thing so that it shows on a monitor a person's latest tweet. Is that an easy thing to do? Because I'd like that. lol
KaoS #48
Posted 10 October 2012 - 08:42 AM
that uses the http API to access the internet, it is probably disabled on your PC by default and I have no experience in that area as I have no internet at home so I cannot use it. I'm sure someone else can help you though
SilverEyes #49
Posted 10 October 2012 - 08:46 AM
that uses the http API to access the internet, it is probably disabled on your PC by default and I have no experience in that area as I have no internet at home so I cannot use it. I'm sure someone else can help you though
Ahh ok. Is there anything I could add you on instead of talking in here? It'd be easier and there'd be faster responses. If you're ok with it. :P/>/>
KaoS #50
Posted 10 October 2012 - 08:58 AM
It's fine by me. got mxit?
SilverEyes #51
Posted 10 October 2012 - 09:06 AM
It's fine by me. got mxit?
I do now. :P/>/> My id thinger is SilverEyes1
SilverEyes #52
Posted 10 October 2012 - 09:28 AM
It's fine by me. got mxit?
How do I add you?
KaoS #53
Posted 10 October 2012 - 09:34 AM
I will PM you my id
SilverEyes #54
Posted 10 October 2012 - 09:37 AM
I will PM you my id
Ok :P/>/>
Hidinginthelight #55
Posted 08 November 2012 - 06:29 AM
Hello. I'm having issues with:
while turtle.detectUp() do turtle.digUp() end 

With a stack of gravel on top of the turtle, it will only break the first block. It detects again so quickly that the stack hasn't had time to drop enough that it gets detected.

I've gotten it to work with the follow but it wastes 2 movements, and am looking for a more elegant solution.

while not turtle.up() do
  turtle.digUp()
end
turtle.down()

Like I said it works, but wastes 2 movements for every time I need to dig up.

*Edit* ——–

Sortof fixed with:

while turtle.detectUp() do
  turtle.digUp()
  sleep(0.5)
end

Any better solutions?
Edited on 08 November 2012 - 05:54 AM
KaoS #56
Posted 08 November 2012 - 07:34 AM

while not turtle.up() do turtle.digUp() end
even if the gravel is still falling the turtle will not be able to move upwards so it will dig. then move down if you need to. what is the turtle trying to do? is it another tunnel prog?
Hidinginthelight #57
Posted 08 November 2012 - 07:49 AM

while not turtle.up() do turtle.digUp() end
even if the gravel is still falling the turtle will not be able to move upwards so it will dig. then move down if you need to. what is the turtle trying to do? is it another tunnel prog?

Yeah. I mentioned that in my post. That works, but wastes a lot of movements over the full course of a program.
Yes, it's another tunnel program.
Improving upon the first program I wrote. Basically the turtle strip mines for me, and I chase after it clearing out the walls.

In this version I'm trying to deal with problems I had in the first version. One was gravel from the top. Would sometimes cause issues with my torch placing (which in turn would throw off the count).. I think the sleep(0.5) in my edit works. been testing that so far and seems solid enough.