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

Gravel is messing up my mineshaft! (lava too)

Started by The_Awe35, 06 January 2013 - 05:13 PM
The_Awe35 #1
Posted 06 January 2013 - 06:13 PM
I've been using my turtle to make a mineshaft and put up a torch, and then id come in after it and get all the ore. it has been working well, until I hit gravel. then the shit hits the fan. Ive been trying for days and I cant figure out a way to get completely around it. I have made it so it dosent just completely mess up, but it will always ruin the distance I want it to go. here is the part of the code that the gravel is messing with.

–[[fill slot 2 with stone. slot 3 with gravel]]–

function block()
for a=1,8 do
turtle.select(2)
turtle.placeDown()
turtle.dig()
turtle.up()
turtle.dig()
turtle.down()
turtle.select(3)
if turtle.compare() then
turtle.dig()
turtle.dig()
turtle.dig()
turtle.dig()
turtle.dig()
turtle.dig()
turtle.dig()
else
turtle.forward()
end
end
end

I know it is not the most elegant of things, but it was all I could do to make it work. I have also found a it has a problem with lava, I don't know what the problem with it is exactly , but it messes it up. I have it going 8 because I later put some torches up and any farther and mobs appear. I think the problem with it is that after it compares, it starts all over again, instead of then moving forward. Im still a computercraft n00b, so i cant figure out any way around this. And thats hopefully where you come in! so, do you know how to fix it?
zajrik #2
Posted 06 January 2013 - 07:03 PM
I keep gravel in slot 3 and run this function before pretty much anything movement related:

function gravelCheck()
    turtle.select( 3 )
    if turtle.compare() then
        for i=1, 20 do
            turtle.dig()
            sleep( 0.1 )
        end
    else
        return
    end
end
LikeableBump #3
Posted 06 January 2013 - 07:46 PM
Or you can do this


  if not turtle.forward() then
   repeat
    turtle.dig()
    sleep(0.2)
   until turtle.forward()
  end

That way it makes sure it digs until it moves, and the tunnels will be a consistent length. Also if you do this you don't need gravel in your inventory.
zajrik #4
Posted 06 January 2013 - 07:52 PM
I'm fairly new to Lua myself, so most of my methods I've figured out to circumvent problems are highly inefficient. I may have to try this. I also have code for attacking things that are in the way and I could just combine it with this. I'll have to change a lot because i use a few different compares for torch placement as well. Even after all of my inefficient methods, though, my tunnels are all of consistent length with floor gaps filled and torches placed with a configurable distance between them.

Edit: Not necessarily new to Lua, been using it for years with WoW, but I am fairly new to ComputerCraft. I'd say I have maybe a month, almost 2 months of experience with it now. I've never looked at anyone else's code other than once, and I was using it to figure out using the monitor peripheral. Everything else has just been learning the CC APIs.
LikeableBump #5
Posted 06 January 2013 - 08:01 PM
Me too :)/> I stole most of that piece of code from someone elses mining program; probably should have mentioned that. I am by no means a pro, just finally found a problem I could help with.
theoriginalbit #6
Posted 06 January 2013 - 09:23 PM
most efficient way I have discovered (and its based from CC's excavate program) :



while not turtle.forward() do
  if turtle.detect() then
	if not turtle.dig() then
	  return false
	end
  else
	sleep( 0.5 ) -- wait for sand / gravel to fall
  end
end

distanceMoved = distanceMoved + 1

EDIT: Also a side note, please use code tags when posting short code, and pastebin when pasting long code. code tags are (code) code goes here (/code) with [ ] instead of ( )
Edited on 06 January 2013 - 08:25 PM
The_Awe35 #7
Posted 07 January 2013 - 03:16 AM
Awesome! thanks you alot!