电晕运行时错误“试图连接字段'?" (零值)" [英] Corona Runtime Error "attempt to concatenate field '?' (a nil value)"
问题描述
我的移动应用程序移交项目中有这8个问题调查.起初,电晕没有提示我任何错误消息,并且该应用程序运行正常,但是当我向其添加2个问题时,我开始收到此消息错误
我不确定为什么错误是"nil值",但是我的代码看起来像这样.(行662到678)
i have this 8 question survey in my mobile application handover project. At first the corona did not prompt me any error message and the app works just fine but when i add 2 more question to it i start getting this message error
i am not sure why the error is "a nil value" but my code look something like this.(line 662 to 678)
function checkEBASComplete()
local tempScore = 0
for i = 1, 10 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
checkEBASComplete()
我在第110行有类似的内容.我只添加了2个"-1" behide
and i have something like this at line 110. i just add 2 more "-1" behide
local ebasRating_Arr = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
有人可以帮助我吗?感谢所有帮助:D
Is anyone able to help me with this? Appreciate for all helps :D
新问题--------------------------------------------- ---------
NEW QUESTION------------------------------------------------------
这是我的第705-711行中的代码
this is my code from line 705 - 711
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
推荐答案
当您的ebasRating_Arr
对于checkEBASComplete
函数内部的for循环而言太短时,将发生错误.您的原始表只有8个条目,但是您的for循环检查表的10个条目.这意味着您尝试访问9.条目的时刻就会发生错误,因为该错误不存在.
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.
我建议将固定的for循环从1 to 10
更改为相对的for循环1 to the end of the array
.这将与#array
(或Lua中的表)运算符一起使用.您的代码如下所示:
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
这篇关于电晕运行时错误“试图连接字段'?" (零值)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!