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

Help with Stair Mining Program

Started by swg18, 28 August 2013 - 08:04 PM
swg18 #1
Posted 28 August 2013 - 10:04 PM
This is the stair casing code I have so far it works to stair down but when it reaches a lava or water pool, it just goes right through it. I was wondering whether there was a way to at least seal off the stair from the pool as I could then remove the lava if there was not a way for it to do so. In addition, the part that places torches and chest was originally made for a strip mine and I tried to incorporate it but neither appears to work correctly. The torch section appears to be completely skipped. The chest section freezes the turtle after putting one item in the chest. I would appreciate any help I am new to ComputerCraft though I have done some basic programing before.


function dig()
turtle.dig()
turtle.digDown()
turtle.forward()
turtle.dig()
turtle.digDown()
turtle.forward()
turtle.digUp()
turtle.back()
end
local Level = 0
repeat
if turtle.down() then
Level = Level+1
end
dig()
turtle.back()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
dig()
turtle.turnRight()
turtle.dig()
turtle.dig()
turtle.forward()
  if Level == 10 then
   turtle.select(14)
	  print("Placing torch...")
	  turtle.place()
	  Level = 0
end

  if turtle.getItemCount(12) ~=0 then
  turtle.digDown()
  print("Placing Chest...")
  turtle.select(15)
  turtle.placeDown()
  turtle.select(1,12)
  turtle.dropDown
end

if turtle.getFueLLevel() <= 10 then
  turtle.select(16)
  turtle.refuel()
end
turtle.turnLeft()
until not turtle.down()
turtle.select(13)
turtle.placeDown()
Lyqyd #2
Posted 28 August 2013 - 10:07 PM
Split into new topic.
Shaun #3
Posted 29 August 2013 - 01:19 AM
Please indent and space out your code, it really helps with readability:
Spoiler
function dig()
  turtle.dig()
  turtle.digDown()
  turtle.forward()
  turtle.dig()
  turtle.digDown()
  turtle.forward()
  turtle.digUp()
  turtle.back()
end

local Level = 0

repeat
  if turtle.down() then
    Level = Level+1
  end

  dig()
  turtle.back()
  turtle.turnLeft()
  turtle.forward()
  turtle.turnRight()
  dig()
  turtle.turnRight()
  turtle.dig()
  turtle.dig()
  turtle.forward()

  if Level == 10 then
    turtle.select(14)
    print("Placing torch...")
    turtle.place()
    Level = 0
  end

  if turtle.getItemCount(12) ~=0 then
    turtle.digDown()
    print("Placing Chest...")
    turtle.select(15)
    turtle.placeDown()
    turtle.select(1,12)
    turtle.dropDown
  end

  if turtle.getFueLLevel() <= 10 then
    turtle.select(16)
    turtle.refuel()
  end

  turtle.turnLeft()
until not turtle.down()

turtle.select(13)
turtle.placeDown()

For the turtle going through liquids, you're going to want to give it a building block and have it place that on every wall along the way down.
That's going to involve a lot of turning left and right and placing blocks. If there's already a block, the place will just fail and it will move on.

Is the turtle saying it's placing torches? If it's printing out the torch line, make sure when it fires there is actually somewhere in front of the turtle for the torch to go.


turtle.dropDown
That should be
turtle.dropDown()


turtle.select(1,12)
turtle.select() only takes a single argument, the slot number to change to.
albrat #4
Posted 29 August 2013 - 04:45 AM

  if turtle.getItemCount(12) ~=0 then
    turtle.digDown()
    print("Placing Chest...")
    turtle.select(15)
    turtle.placeDown()
    for slots =1,12 do --// we want to select slots 1 to 12
      turtle.select(slots) --// select the slot our for loop is on
      turtle.dropDown() --// Drop the items down
    end
    turtle.select(1) --// select the first slot again now.
  end


That should work for selecting and dropping all items in slots 1 to 12 then reset the slot to start at 1 again.
swg18 #5
Posted 29 August 2013 - 07:18 PM
Is the turtle saying it's placing torches? If it's printing out the torch line, make sure when it fires there is actually somewhere in front of the turtle for the torch to go.
The turtle is not even saying it attempted to place the torch I believe it is a problem with how i set it to count levels but i'm not sure how to fix it.