Posted 05 August 2013 - 09:08 AM
I was tinkering around with my branch mine code to execute another kind of branch mine, however it really hates both of my "for" loops.
The error code when I execute this code with the for loops is in the title.
I really hoped someone could explain the meaning of the <name> expected error. And how to fix it in this case.
This is the code:
The error code when I execute this code with the for loops is in the title.
I really hoped someone could explain the meaning of the <name> expected error. And how to fix it in this case.
This is the code:
Spoiler
--According to Benjamin Buford "Bubba" Blue I should make notes.
-- aLenght is the Actual length of the branch mine. length is the desired length of the branch mine in blocks. The height is the desired height of the branch mine in 2 meter high floors. progress indicates the stage of the mining process; 1 is branch; 2 is trunk; 3 is level change.
local arg1,arg2 = ...
local length = tonumber(arg1)
local zLength = length
local height = tonumber(arg2)
local aLength = 0
local aHeight = 1
local progress = 0
--Checks if the arguments are valid.
if length == nil or height == nil then
print[[ Please only use numbers.
Usage: oBranch <length> <height>]]
return false
elseif length < 3 or height < 2 then
print[[ Please only use positive numbers.
This message might also have occurred because the entered numbers were too low.
Usage: oBranch <height> <height>]]
return false
end
--Changes valid length to match the second floors' (2nd, 4th, 6th, etc.) branches.
local function lengthChange()
if length % 4 == 3 then
zLength = length
print( "The branch mine will be the desired ", length, "." )
elseif length % 4 == 2 then
zLength = length - 3
print( "I'm sorry, we have had to change the length from ", length, " to ", zLength, ". I'm sorry for the inconvenience." )
elseif length % 4 == 1 then
zLength = length - 2
print( "I'm sorry, we have had to change the length from ", length, " to ", zLength, ". I'm sorry for the inconvenience." )
else
zLength = length - 1
print( "I'm sorry, we have had to change the length from ", length, " to ", zLength, ". I'm sorry for the inconvenience." )
end
end
lengthChange()
--[[Source for function refuel(): tunnel, a standard CC mining turtle program. All credit goes to the original author.
It refuels :o/>]]
local function refuel()
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" or fuelLevel > 0 then
return
end
local function tryRefuel()
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
turtle.select(1)
return true
end
end
end
turtle.select(1)
return false
end
if not tryRefuel() then
print( "Add more fuel to continue." )
while not tryRefuel() do
sleep(1)
end
print( "Resuming Tunnel." )
end
end
--Digs forward.
local function frontDig()
while turtle.detect() do
turtle.dig()
sleep(0.25)
end
end
--Digs up.
local function upDig()
while turtle.detectUp() do
turtle.digUp()
sleep(0.25)
end
end
--Digs down.
local function downDig()
while turtle.detectDown() do
turtle.digDown()
sleep(0.25)
end
end
--Goes forward.
local function frontGo()
refuel()
frontDig()
while turtle.attackUp() do
turtle.attackUp()
sleep(0.25)
end
turtle.forward()
end
--Goes up.
local function upGo()
refuel()
upDig()
while turtle.attackUp() do
turtle.attackUp()
sleep(0.25)
end
turtle.up()
end
--Goes down.
local function downGo()
refuel()
downDig()
while turtle.attackDown() do
turtle.attackDown()
sleep(0.25)
end
turtle.down()
end
--Turns 'round.
local function roundTurn()
for 1,6 do
turtle.turnLeft()
end
end
--Makes branchMine()
local function branchMine()
--Makes branches.
local function branch()
local function stick()
for 1,6 do
frontGo()
upDig()
end
end
turtle.turnLeft()
stick()
roundTurn()
stick()
stick()
roundTurn()
stick()
turtle.turnRight()
end
--Makes the main trunk
local function trunk()
frontGo()
turtle.turnLeft()
frontDig()
upGo()
frontDig()
roundTurn()
frontDig()
downGo()
frontDig()
turtle.turnRight()
if aLength ~= zLength then
frontGo()
end
end
--Elevates to the next floor
local function level()
upGo()
upGo()
roundTurn()
end
--Decides the order of mining.
if progress == 1 then
branch()
aLength = aLength + 1
progress = progress + 1
elseif progress == 2 or progress == 3 or progress == 4 then
trunk()
aLength = aLength + 1
progress = progress + 1
elseif progress == 0 then
level()
aHeight = height + 1
progress = 1
end
--Makes the circle round
if progress == 5 then
progress = 1
end
if aLength % 25 then
print( "The branch mine is now ", aLength, " blocks long." )
end
if aLength == zLength then
print( "Finished floor number ", aHeight, "." )
if aHeight == 1 then
print( "The branch mine is now the appointed/desired ", aLength, " blocks long." )
end
if aHeight ~= height then
progress = 0
aLength = 0
end
end
end
print( "Mining ", zLength, " blocks long branch mine." )
--Makes branch mine until desired length is achieved.
while aLength < zLength do
branchMine()
end