Corona Runtime Error “attempt to concatenate field '?' (a nil value)”

↘锁芯ラ 提交于 2019-12-06 08:18:00

The error occurs when your ebasRating_Arr is too short for the for-loop inside the checkEBASComplete-function. Your original table has only 8 entries but your for-loop checks 10 entries of the table. That means the moment you attempt to access the 9. entry the error occurs because it doesn´t exist.

I would recommend changing the fixed for-loop from 1 to 10 to a relative for-loop 1 to the end of the array. This would work with the #array (or table in Lua) operator. Your code would look like this:

function checkEBASComplete()
    local tempScore = 0
    for i = 1, #ebasRating_Arr do       -- Changed to relative for-loop
        print("EBAS:"..ebasRating_Arr[i])
        tempScore = tempScore + ebasRating_Arr[i]
        if (ebasRating_Arr[i] == -1) then
            ebasScore = 0
            ebasScore_text.text = "Test Incomplete"
        else
            ebasScore = tempScore
            ebasScore_text.text = tostring(ebasScore)
        end
    end
    tempScore = 0
end
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!