2016-04-09 8 views
1

我使用的函數在運行時給我提供了'end' expected (to close 'if' at line 11) near 'until'錯誤,但我檢查了並且我沒有忽略'end'整個程序。另外,我沒有使用回報或其他一些命令一樣,(我所知道的)Lua'end'預計(如果'在第11行'關閉')直到'

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("You do not have this item") 
    end 
end 
+0

你的'if'缺少'then'。 – daurnimator

+0

@daurnimator忘了更新, – IcecreamSwirlys

回答

2

的問題是,untilrepeat - until環下半年,你寫它沒有前面的重複陳述。將until替換爲while,它應該運行良好,因爲看起來您希望在循環的開始處有一個循環,這是一個while循環。一個until循環最後有測試。

+0

清理了這個問題,一直在追求3個小時,謝謝! – IcecreamSwirlys

相關問題