Jump to content




Tunnel/stairs program gravel removal help


  • You cannot reply to this topic
56 replies to this topic

#1 SilverEyes

  • New Members
  • 30 posts

Posted 05 October 2012 - 12: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

This is the stairs code.
Spoiler


#2 PonyKuu

  • Members
  • 215 posts

Posted 05 October 2012 - 12: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


#3 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 05 October 2012 - 01: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


#4 SilverEyes

  • New Members
  • 30 posts

Posted 05 October 2012 - 02:10 PM

View PostKaoS, on 05 October 2012 - 01:01 PM, said:

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?

#5 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 05 October 2012 - 02: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

#6 SilverEyes

  • New Members
  • 30 posts

Posted 05 October 2012 - 02:59 PM

View PostKaoS, on 05 October 2012 - 02:38 PM, said:

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!

#7 Doyle3694

  • Members
  • 815 posts

Posted 05 October 2012 - 03:22 PM

maybe even add tArgs? Do you knwo how these work or do you want an explanation?

#8 SilverEyes

  • New Members
  • 30 posts

Posted 05 October 2012 - 03:23 PM

View PostDoyle3694, on 05 October 2012 - 03:22 PM, said:

maybe even add tArgs? Do you knwo how these work or do you want an explanation?
An explanation would be nice, please. :(/>

#9 Doyle3694

  • Members
  • 815 posts

Posted 05 October 2012 - 03: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.

#10 SilverEyes

  • New Members
  • 30 posts

Posted 05 October 2012 - 03:37 PM

View PostDoyle3694, on 05 October 2012 - 03:34 PM, said:

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.

#11 Doyle3694

  • Members
  • 815 posts

Posted 05 October 2012 - 03:41 PM

for knowing how many times it should do it's stuff and if it should place torches.

#12 SilverEyes

  • New Members
  • 30 posts

Posted 05 October 2012 - 04:05 PM

View PostDoyle3694, on 05 October 2012 - 03:41 PM, said:

for knowing how many times it should do it's stuff and if it should place torches.
ah ok

#13 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 05 October 2012 - 05: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)


#14 SilverEyes

  • New Members
  • 30 posts

Posted 06 October 2012 - 08:56 AM

View PostKaoS, on 05 October 2012 - 05:07 PM, said:

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.

#15 SilverEyes

  • New Members
  • 30 posts

Posted 07 October 2012 - 07:52 AM

View PostPonyKuu, on 05 October 2012 - 12:58 PM, said:

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/>

#16 Doyle3694

  • Members
  • 815 posts

Posted 07 October 2012 - 08:20 AM

how do you mean?
using your function?

YourFunctionName()

#17 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 07 October 2012 - 08: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

#18 SilverEyes

  • New Members
  • 30 posts

Posted 07 October 2012 - 09:49 AM

View PostKaoS, on 07 October 2012 - 08:42 AM, said:

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/>

#19 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 07 October 2012 - 10: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

#20 SilverEyes

  • New Members
  • 30 posts

Posted 07 October 2012 - 11:18 AM

View PostKaoS, on 07 October 2012 - 10:33 AM, said:

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/>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users