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

(Lua) Redpower Frame Quarry

Started by boesshawn, 01 September 2012 - 10:34 PM
boesshawn #1
Posted 02 September 2012 - 12:34 AM
I have a functional frame quarry and this program seems to work, I was hoping some of the experts here could tell what I could do to make the code a bit cleaner and suggest where to start to improve the program. I want to eventually be able to select how deep the miner goes and to have an abort function that will recall the miner to the surface.

Spoiler

depth = 30
recover = depth * 2

function MoveNorth()
 print("MoveNorth")
 rs.setBundledOutput("bottom", 8)
 sleep(1)
 rs.setBundledOutput("bottom", 8)
 sleep(1)
 rs.setBundledOutput("bottom", 0)
end


function MoveSouth()
 print("MoveSouth")
 rs.setBundledOutput("bottom", 4)
 sleep(1)
  rs.setBundledOutput("bottom", 4)
 sleep(1)
 rs.setBundledOutput("bottom", 0)
end

function MoveEast()
 print("MoveEast")
 rs.setBundledOutput("bottom", 2)
 sleep(1)
 rs.setBundledOutput("bottom", 2)
 sleep(1)
 rs.setBundledOutput("bottom", 0)
end
 
function MoveWest()
 print ("MoveWest")
 rs.setBundledOutput("bottom", 1)
 sleep(1)
 rs.setBundledOutput("bottom", 1)
 sleep(1)
 rs.setBundledOutput("bottom", 0)
end
 
function MoveUp()
 print ("MoveUp")
 rs.setBundledOutput("bottom", 32)
 sleep(1)
 rs.setBundledOutput("bottom", 0)
 sleep(1)
 rs.setBundledOutput("bottom", 32)
 sleep(1)
 rs.setBundledOutput("bottom", 0)
end

function MoveDown()
 print ("MoveDown")
 rs.setBundledOutput("bottom", 16)
 sleep(1)
 rs.setBundledOutput("bottom", 16)
 sleep(1)
 rs.setBundledOutput("bottom", 0)
end
 
function BBreaker()
 print ("BBreaker")
 rs.setBundledOutput("bottom", 64)
 sleep(1)
 rs.setBundledOutput("bottom", 0)
end

function Recover()
 print ("Bringing Miner to Surface")
  for i = 1 , recover do
   MoveUp()
   end
 end
 
for i = 1, depth do
 BBreaker()
 MoveEast()
 BBreaker()
 MoveDown()
 BBreaker()
 MoveWest()
 BBreaker()
 MoveDown()
 end
 
Recover()


Thanks Boes
Lettuce #2
Posted 02 September 2012 - 02:43 AM
That's pretty clean code. I'm not great with redstone, so I can't improve you there. Variables can be set by the user with this:

depth = tonumber(read())
and as for an abort function, that's a bit less convenient, it will have to stop after every row and ask to continue:

function abort()
   print "Shall I go on? q to quit."
   stop = io.read()
	  if stop == "q" then
	  Recover()
	  end
end
but you have to babysit it.
boesshawn #3
Posted 02 September 2012 - 02:43 PM
Thanks for the suggestions on, I know have another idea for it so i'm going to have to expand the program quite a bit to make the quarry use gps as well so i can just set it and forget it, i really don't like the idea of having to babysit it, i wonder if it would be possible to have the abort time out and just go back to mining if i don't hit the abort, i'll do some research into that idea. Thanks again
BigSHinyToys #4
Posted 02 September 2012 - 03:21 PM
using the parallel API you could have the program waiting for a abort key to be pressed while running the other code on the background. or it could respond to a rednet message example.

local function move()
    while true do
	    turtle.forward()
	    turtle.turnLeft()
    end
end
local function abort()
    while true do
    local sEvent,arg1,arg2,arg3 = os.pullEvent()
	    if sEvent == "key" and arg1 == 28 then
		    break -- breaks out of the loop causing the thread it was in to end making paralell end the program
	    end
    end
end
term.clear()
term.setCursorPos(1,1)
print("Press ENTER to stop turtle")
parallel.waitForAny(move,abort)
print("Program Aborted By User")
Lettuce #5
Posted 02 September 2012 - 04:08 PM
So you can have two sections running at once? Wow. That would've made my life so much easier.