【问题标题】:lua corona runtime error: attempt to perform arithmetic on field '?' (a nil value)lua corona 运行时错误:尝试对字段“?”执行算术运算(零值)
【发布时间】:2018-01-18 16:50:56
【问题描述】:

我正在尝试使用电晕显示表单摘要。起初它可以工作,但是当我添加 2 个新问题时,我得到一个错误

所以有我的场景 15 的代码

--line689   checkEBASComplete()

--line691   function  checkAMTComplete()
            local tempScore = 0
            for i = 1, 11 do
--line694   tempScore = tempScore + amtRating_Arr[i]
            if (amtRating_Arr[i] == -1) then
                amtScore = 0
                amtScore_text.text = "Test Incomplete"
            else
                amtScore = tempScore
                amtScore_text.text = tostring(amtScore)
                end

                end

                tempScore = 0
                end
--line707   checkAMTComplete()

    function saveResults()

        local q = [[UPDATE EBAS_DEP SET rating1=']]..ebasRating_Arr[1] .. [[',rating2=']] .. ebasRating_Arr[2] .. [[',rating3=']] .. ebasRating_Arr[3] .. [[',rating4=']] .. ebasRating_Arr[4] .. [[',rating5=']] .. ebasRating_Arr[5] .. [[',rating6=']] .. ebasRating_Arr[6] .. [[',rating7=']] .. ebasRating_Arr[7] .. [[',rating8=']] .. ebasRating_Arr[8] .. [[',rating9=']] .. ebasRating_Arr[9] .. [[',rating10=']] .. ebasRating_Arr[10] .. [[',rating11=']] .. amtRating_Arr[1] .. [[',rating12=']] .. amtRating_Arr[2] .. [[',rating13=']] .. amtRating_Arr[3] .. [[',rating14=']] .. amtRating_Arr[4] .. [[',rating15=']] .. amtRating_Arr[5] .. [[',rating16=']] .. amtRating_Arr[6] .. [[',rating17=']] .. amtRating_Arr[7] .. [[',rating18=']] .. amtRating_Arr[8] .. [[',rating19=']] .. amtRating_Arr[9] .. [[',rating20=']] .. amtRating_Arr[10] .. [[',rating21=']] .. amtRating_Arr[11] .. [[',ebas_score=']] .. ebasScore ..[[',amt_score=']] .. amtScore ..  [['WHERE id=']].. _G.EBAS_ID..[[';]]
        db:exec( q )
        print(db:errcode(), db:errmsg())

    end

有人能给点建议吗?谢谢

【问题讨论】:

  • amtRating_Arr[i] 的某个值是nil
  • @EgorSkriptunoff 你有什么方法可以检查缺失的内容吗?非常感谢您的帮助这是我第一次使用 lua
  • 检查填充该数组的部分代码。
  • 如果您想将空元素视为零,请尝试tempScore = tempScore + (amtRating_Arr[i] or 0)
  • @EgorSkriptunoff 是的,我之前已经将它设置为 tempScore = 0

标签: lua coronasdk


【解决方案1】:

所以这是我自己问题的解决方案,希望它可以帮助像我这样的新电晕用户

        function  checkEBASComplete()
        local tempScore = 0
        for i = 1, #ebasRating_Arr do
            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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 2014-02-17
    • 2020-08-22
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多