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

Mining Program=almost working but not yet.

Started by RoyalKingZB, 17 October 2014 - 11:55 PM
RoyalKingZB #1
Posted 18 October 2014 - 01:55 AM
So my mining program is working great. Its supposed to make a tunnel and place a torch every 8 blocks, place blocks under it as it goes and not have a problem with gravel. After its done all that, its suppose to go to a chest at its starting point then move on to the next tunnel with a two block gap between each tunnel. It does all this perfectly except the moving on the the next tunnel part. Everytime it moves to the next tunnel, it adds a block when transitioning. So it untimately ends up not going to the chest on the 3rd tunnel and up. It adds a block so when it comes back, it passes the chest and how far it passes the chest depends on what number tunnel its on. Any help? Heres the pastebin:
http://pastebin.com/uPLFfz3x
valithor #2
Posted 18 October 2014 - 02:30 AM
Before I try to help I am going to help make some of the function a little easier to read.

edited code

term.clear()
term.setCursorPos(1,1)
local z = 0

local function smartForward()
  while not turtle.forward() do
	turtle.dig()
	turtle.attack()
  end
  turtle.digUp()
  z = z+1
end

local function smartForwardNo()
  turtle.placeDown()
  while not turtle.forward() do
	turtle.dig()
	turtle.attack()
  end
end
  
local function smartTorch()
  while not turtle.placeUp() do
	if turtle.detectUp() then
		  turtle.digUp()
	end
  end
end

local function torch()
  if z % 8 == 0 then
	turtle.digUp()
	turtle.turnLeft()
	turtle.up()
	turtle.place()
	turtle.down()
	turtle.placeDown()
	turtle.select(16)
	smartTorch()
	turtle.turnRight()
	turtle.select(1)
  end
end

print("How Far?")
x = read()
y = tonumber(x)
tunnel = 0
while true do
  for all = 1, y do

	smartForward()
  
	torch()

  end

   turtle.turnLeft()
   turtle.turnLeft()
  for i = 1, y do
	smartForwardNo()
  end

  tunnel   = tunnel+1
  tempvar = tunnel*3
  turtle.turnRight()

  for i = 1, tempvar do
	smartForwardNo()
  end


  for j = 2, 15 do
	turtle.select(j)
	turtle.drop()
  end

  turtle.turnRight()
  turtle.turnRight()

  for i i=1, tempvar do
	 smartForwardNo()
  end

  smartForwardNo()
  smartForwardNo()
  smartForwardNo()
  turtle.turnLeft()
  z = 0
end

I have not actually tested this, but I believe that it should now work. If you have any questions about this please ask. I tried to keep as much of the original code as possible, so it would be easier to follow and understand. Most of the functions that I changed I just removed steps which were un-needed, or made the function difficult to understand or read.
Edited on 18 October 2014 - 01:10 AM
RoyalKingZB #3
Posted 18 October 2014 - 03:07 AM
Ok. Can you put that into a pastebin?
valithor #4
Posted 18 October 2014 - 03:11 AM
Ok. Can you put that into a pastebin?

http://pastebin.com/4de24MPM

This uses a single chest. I do not know if the other program used one or multiple.
RoyalKingZB #5
Posted 18 October 2014 - 03:12 AM
Im truly amazed how amazing you guys are at coding and helping me out ;)/>
valithor #6
Posted 18 October 2014 - 03:15 AM
Ehh found a error was writing this in edit on the forums and it kept auto correcting my for loops. Give me a second and I am going to bug test it.

Edit: Fixed code http://pastebin.com/Sfpf16jF
Btw The only reason I fixed the code for you is because I have been watching the other threads regarding this program. By me doing it you do not actually learn why it works. Please read through it instead of just downloading it and using it.
Edited on 18 October 2014 - 01:23 AM
RoyalKingZB #7
Posted 18 October 2014 - 03:32 AM
Uhhhh it gave me a few errors I think…
valithor #8
Posted 18 October 2014 - 03:35 AM
Uhhhh it gave me a few errors I think…

Did you try the new one, after i gave you that code i tested it and fixed the errors i found.
valithor #9
Posted 18 October 2014 - 03:49 AM
Sorry… Am tired right now. Tested it on a server where pastebin uploads are disabled so I manually fixed the errors, but I missed one in the other pastebin. Here is a working pastebin code http://pastebin.com/1QuP2DNw
Edited on 18 October 2014 - 01:52 AM
RoyalKingZB #10
Posted 18 October 2014 - 04:14 AM
It doesnt do a lot of the things I programmed the first one to do O.o I just wanted you to help me modify it. Not rewrite the entire program…
valithor #11
Posted 18 October 2014 - 03:23 PM
[quote name='RoyalKingZB' timestamp='1413602091'
post='196420']It doesnt do a lot of the things I programmed the first one to do O.o I just wanted you to help me modify it. Not rewrite the entire program…


I really didnt rewrite the entire program. I shortened a few of the functions and removed stuff that I thought was pointless. Now that i have actually run the original the only thing I see I missed was making it place a block where the tunnel was.

Only thing I really added was the thing at the end to make it go back to the chest.
Edited on 18 October 2014 - 01:24 PM