Lua 'end' 预期(在 'function' 附近的行关闭 '<eof>'

标签 lua

我找不到遗漏的地方在哪里,我已经仔细检查了语法并再次检查了三遍,这让我很生气。我已经在线和本地测试了编译,所以我的具体问题是为什么会抛出错误?

这是错误:

line 71: 'end' expected (to close 'function' at line 25) near '< 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()

最佳答案

缺少一个endcheckFuel() body ;它关闭了 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

关于Lua 'end' 预期(在 'function' 附近的行关闭 '<eof>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23167890/

相关文章:

regex - 匹配 Lua 模式中的可选数字

基于前几个字节的 TCP 负载平衡和重新路由

lua - 尝试通过 "pgsql"DSN 连接到 PostgreSQL 数据库在 FreeSWITCH 1.8 上返回 "ERR [unable to open database file]"

lua - 如何在Lua中匹配一个句子

debugging - 访问深度嵌套表没有错误?

vim - 在 Vim 中打开 Lua .love 文件

xml - 使用lua存储游戏数据效率高吗?

sql - 如何在Lua中将SQL日期转换为字符串?

c - 使用lua的lightuserdata注册定时器回调

lua - 如何使用 Lua 从 zip 文件中提取文件?