Lua期望出现'end'(用于关闭与行号'<'eof>'接近的'function')。

我找不到缺失的“end”,我已经仔细检查过语法,但却疯了。我已经在线和本地测试了编译,所以我在此特定问题的问题是为什么会抛出错误?

以下是错误:

line 71:'end' expected(在第25行关闭'function'附近的)< eof >'

以下是代码:

    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()
点赞
用户3435489
用户3435489

checkFuel() 函数体中缺少一个 end ,它应该结束 while 循环块。

-- 检查/获取燃料
local function checkFuel()
  while turtle.getFuelLevel() == 0 do
   for k=0, 16, 1 do
     if turtle.refuel(i) then
       return
     end
   end
  end
  return
end
2014-04-19 08:49:24