Lua&#39; end&#39;预期(关闭&#39;功能&#39;在&#39; <eof>&#39; </eof>附近

时间:2014-04-19 08:44:51

标签: lua

我找不到丢失的结尾,iI经过双重检查,三重检查语法,让我发疯。我已经在线和本地测试了编译,所以我的具体问题是为什么会抛出错误?

这是错误:

  

第71行:'结束'预期(在第25行关闭'功能')附近'&lt; eof&gt;'

以下是代码:

    tArgs = { ... }
--Argument validation
if #tArgs < 2 then
  printUsage()
  return
end

--globals
local MAX_INV_SLOT = 16
local depth = tonumber(tArgs[1])
local bredth = tonumber(tArgs[2])

--Usage output
local function printUsage()
  print("Usage: <branch depth> <num branches>")
end

--wrap turtle.forward()
local function fwd()
 while turtle.forward() == false do
  turtle.dig()
 end
end
-- check / get fuels
local function checkFuel()
  while turtle.getFuelLevel() == 0 do
   for k=0, 16, 1 do
     if turtle.refuel(i) then
       return
     end
   end  
  return
end
--mine 1 wide 3 tall segment
local function step()
 fwd()
 turtle.digUp()
 turtle.digDown()
end

local function control()
  for i=0, bredth,1 do
    for j=0, depth,1 do
      checkFuel()
      step()
    end
    -- Turn Corner
    if (i % 2) == 0 then
      step()
      turtle.turnRight()
      step()
      step()
      step()
      turtle.turnRight()
    else
      -- Left U turn
      step()
      turtle.turnLeft()
      step()
      step()
      step()
      turtle.turnLeft()
    end
  end
  print("Should be done!")
end



control()

1 个答案:

答案 0 :(得分:8)

end机构中缺少checkFuel();它会关闭while块。

-- check / get fuels
local function checkFuel()
  while turtle.getFuelLevel() == 0 do
   for k=0, 16, 1 do
     if turtle.refuel(i) then
       return
     end
   end
  return
  end
end