Lua 'end' expected (to close 'if' at line 11) near 'until'

一个我正在使用的函数在运行时给出了 'end' expected (to close 'if' at line 11) near 'until' 错误,但我已经检查了整个程序,没有缺少 'end' 的情况。同时,我没有使用 return 或其他类似的命令(就我所知)

function sell_item(item, soldfor)
  items_found = 0
  for i, v in pairs(inv) do
      if v == item then
          items_found = items_found + 1
      end
  end
  if items_found ~= 0 then
      items_destroyed = 0
      until items_destroyed == 1 do
          for i, v in pairs(inv) do
              if v == item then
                  pop_inv(item)
                  items_destroyed = 1
                  io.write(item .. " sold for " .. soldfor .. " coins")
                  count = 0
                  while count ~= soldfor do
                      table.insert(money, "coin")
                      count = count + 1
                  end
                  count = 0
              end
          end
          items_destroyed = 0
      end
  elseif items_found == 0 then
      io.write("您没有这个物品")
  end
end
点赞
用户5699329
用户5699329

问题在于 untilrepeat - until 循环的后半段,而你已经写出了没有先前的 repeat 语句。替换 untilwhile,这样它就应该可以正常运行,因为你想要一个测试在循环开始时的循环,这是一个 while 循环。until 循环的测试在循环结束时进行。

2016-04-09 06:08:24