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

Bios:339: [String "branch"]:141: '<Name>' Expected

Started by MmPMSFmM, 05 August 2013 - 07:08 AM
MmPMSFmM #1
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:
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
GamerNebulae #2
Posted 05 August 2013 - 09:13 AM
Putting this code on pastebin would be alot more helpfull, because we can't see any line numbers here. But I saw a mistake, you didn't concatinate a string right. You used a comma instead of a double point. Example:

name = "Brian"
print("Hello my name is "..name)
LBPHacker #3
Posted 05 August 2013 - 10:01 AM
Putting this code on pastebin would be alot more helpfull, because we can't see any line numbers here. But I saw a mistake, you didn't concatinate a string right. You used a comma instead of a double point. Example:

name = "Brian"
print("Hello my name is "..name)
Didn't see the code yet but if you're talking about a call for print, it accepts multiple arguments, and concats them for you.

After looking at the code (for the record, here's the pastebin link for it): The problem is that you use FOR a lot like this:
for 1, 6 do
Thing is, whatever you do, wheter you use it or not, the FOR requires a variable name - that's called the index. Using FOR properly looks like this
for ix = 1, 6 do

EDIT: To be precise, the problem is on line 130, according to pastebin.
EDIT#2: FTR Properly indented code
MmPMSFmM #4
Posted 05 August 2013 - 11:15 AM
Putting this code on pastebin would be alot more helpfull, because we can't see any line numbers here. But I saw a mistake, you didn't concatinate a string right. You used a comma instead of a double point. Example:

name = "Brian"
print("Hello my name is "..name)
Didn't see the code yet but if you're talking about a call for print, it accepts multiple arguments, and concats them for you.

After looking at the code (for the record, here's the pastebin link for it): The problem is that you use FOR a lot like this:
for 1, 6 do
Thing is, whatever you do, wheter you use it or not, the FOR requires a variable name - that's called the index. Using FOR properly looks like this
for ix = 1, 6 do

EDIT: To be precise, the problem is on line 130, according to pastebin.
EDIT#2: FTR Properly indented code
Thanks, this solved the problem…
TBH, I just KNEW it was a stupid mistake.