So, I recently asked (a couple months ago) help for a quarry program that excavated a certain (restricted) area. So, to take advantage of the new frames block in redpower, I am completely rewriting the code to allow for the quarry to dig a completely user specified area. The problem? It is not easy (for me). So I just finished writing what I'm hoping will be the first of very few drafts of this program. What I want to know is:
- Will the code actually work?
- Is there any I can improve it/make it smaller?
Don't worry about the GUI or how the user selects the area, I already know how to do that. Also, I'm not worried really about the timing between the frame engines moving, I can tweak that once I build the machine. I just want to know if the logic will work. Any construction criticism is appreciated. Thanks even if this seems like too much!
function bundledOn(side, color)
c = colors.combine(c, colors[color])
rs.setBundledOutput(side, c)
end
function bundledOff(side, color)
c = colors.subtract(c, colors[color])
rs.setBundledOutput(side, c)
end
function bundledPulse(side, color, interval)
c = colors.combine(c, colors[color])
rs.setBundledOutput(side, c)
sleep(interval)
c = colors.subtract(c, colors[color])
rs.setBundledOutput(side, c)
end
function printCentered(height, value)
local xpos = w/2 - string.len(value)/2
term.setCursorPos(xpos, height)
term.write(value)
end
function clearA()
term.clear()
term.setCursorPos(1,1)
end
w, h=term.getSize()
function configCheck()
if fs.exists("quarry/config") then
config=fs.open("quarry/config", "r")
tmpSide=config.readLine()
config.close()
if tmpSide ~= "top" and tmpSide ~= "bottom" and tmpSide ~= "left" and tmpSide ~= "right" and tmpSide ~= "front" and tmpSide ~= "back" then
shell.run("pages/config")
end
else
shell.run("pages/config")
end
return tmpSide
end
side=configCheck()
up="white"
down="orange"
west="magenta"
east="lightBlue"
north="yellow"
south="lime"
dig="black"
bundledPulse(side, up, 2)
print(side)
y=65 -- Up/Down
x=14 -- East/West
z=14 -- North/South
zReverse=false
xreverse=false
function breakBlocks()
bundledPulse(side, dig, 0.2)
end
function xMovE()
rX=x%7
if xReverse==false then
if rX==0 then
for cX=1, x/7 do
breakBlocks()
for eM=1, 7 do
bundledPulse(side, east, 0.8)
sleep(0.2)
eM=eM+1
end
zMovE()
cX=cX+1
end
else
for cX=1, x/7 do
breakBlocks()
for eM=1, 7 do
bundledPulse(side, east, 0.8)
sleep(0.2)
eM=eM+1
end
cX=cX+1
end
for cX=1, rX do
breakBlocks()
bundledPulse(side, east, 0.8)
cX=cX+1
zMovE()
end
end
elseif xReverse==true then
if rX==0 then
for cX=1, x/7 do
breakBlocks()
for wM=1, 7 do
bundledPulse(side, west, 0.8)
sleep(0.2)
wM=wM+1
end
zMovE()
cX=cX+1
end
else
for cX=1, x/7 do
breakBlocks()
for wM=1, 7 do
bundledPulse(side, west, 0.8)
sleep(0.2)
wM=wM+1
end
cX=cX+1
end
for cX=1, rX do
breakBlocks()
bundledPulse(side, west, 0.8)
cX=cX+1
zMovE()
end
end
else error("An unknown error has occurred")
end
if xReverse==false then
xReverse=true
else
xReverse=false
end
end
function zMovE()
rZ=z%7
if zReverse==false then
if rZ==0 then
for cZ=1, z/7 do
breakBlocks()
for nM=1, 7 do
bundledPulse(side, north, 0.8)
sleep(0.2)
nM=nM+1
end
cZ=cZ+1
end
else
for cZ=1, z/7 do
breakBlocks()
for nM=1, 7 do
bundledPulse(side, north, 0.8)
sleep(0.2)
nM=nM+1
end
cZ=cZ+1
end
for cZ=1, rZ do
breakBlocks()
bundledPulse(side, north, 0.8)
cZ=cZ+1
end
end
elseif zReverse==true then
if rZ==0 then
for cZ=1, z/7 do
breakBlocks()
for nM=1, 7 do
bundledPulse(side, south, 0.8)
sleep(0.2)
nM=nM+1
end
cZ=cZ+1
end
else
for cZ=1, z/7 do
breakBlocks()
for nM=1, 7 do
bundledPulse(side, south, 0.8)
sleep(0.2)
nM=nM+1
end
cZ=cZ+1
end
for cZ=1, rZ do
breakBlocks()
bundledPulse(side, south, 0.8)
cZ=cZ+1
end
end
else error("An unknown error has occurred")
end
if zReverse==false then
zReverse=true
else
zReverse=false
end
end
function excavateLayer()
zMovE()
breakBlocks()
bundledPulse(side, down, 0.8)
end
function excavate()
for i=1, y do
excavateLayer()
i=i+1
end
end
excavate()