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

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 Corona Runtime Error “attempt to concatenate field ‘?’ (a nil value)” and it is from line 662 and 678.

this is my code from line 662-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()

Is anyone able to help? Appreciate for all helps :smiley:

you guys can view https://stackoverflow.com/questions/48089980/corona-runtime-error-attempt-to-concatenate-field-a-nil-value for more details

It’s likely this line:

print("EBAS:"..ebasRating\_Arr[i])

since that’s the concatenation you’re doing.  ebasRating_Arr[] may have nil’s in it. I would suggest not doing a concatenate in the print, but instead, do:

print("EBAS:", ebasRating\_Arr[i], i)

That way you can see which values are nil and then you can figure out from there why they are nil.

Rob

Yes i am able to see all the value but i just could not go to the next screen. i cant find the nil value. Can you advice what i should do?

If you have nils then your maths will fail too.  Change

tempScore = tempScore + ebasRating\_Arr[i]

to

tempScore = tempScore + (ebasRating\_Arr[i] or 0)

i now i get a slight different error. instead of attempt to concatenate field ‘?’ i get something like " attempt to concatenate field ‘EBAS_ID’ (a nil value) on lua:713"

the ? have change to EBAS_ID and here are the code

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  

My question is: Is there something wrong with my code? or is it another type of error? can you help me to solve the problem?

Please, you must use code formatting when posting code here. It’s the blue <> button in the row with Bold,  Italic, etc. Click that button and paste your code into the window that pops up or type in

[code]

paste your code in then

[/code]

No one is going to look at that jumbled up code and make any sense of it.

Rob

Sorry about that.

i now i get a slight different error. instead of attempt to concatenate field ‘?’ i get something like " attempt to concatenate field ‘EBAS_ID’ (a nil value) on lua:713"

the ? have change to EBAS_ID and here are the code

 

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 

My question is: Is there something wrong with my code? or is it another type of error? can you help me to solve the problem?

[['WHERE id=']].. \_G.EBAS\_ID..[[';]]

Is EBAS_ID a global variable?  Does it exist and have a value in it?  If it’s nil, you can’t concatenate it.

Rob

Yes EBAS_ID is a global variable and its value is row id the code look like this

 \_G.EBAS\_ID = row.id

Is there any problem with this?

if row doesn’t have a member named .id or of row.id is nil, then _G.EBAS_ID will be nil.

ohhh I see! so is there a method I can auto-populate the table once there is a new entry? or I cant go towards this approach?

Where is row.id coming from? You haven’t shown us the code where you’re populating (or expecting that value to be populated) from.

Rob

Hi Rob,

I have solved the problem. Thanks for your help. Really appreciate it :DD

It’s likely this line:

print("EBAS:"..ebasRating\_Arr[i])

since that’s the concatenation you’re doing.  ebasRating_Arr[] may have nil’s in it. I would suggest not doing a concatenate in the print, but instead, do:

print("EBAS:", ebasRating\_Arr[i], i)

That way you can see which values are nil and then you can figure out from there why they are nil.

Rob

Yes i am able to see all the value but i just could not go to the next screen. i cant find the nil value. Can you advice what i should do?

If you have nils then your maths will fail too.  Change

tempScore&nbsp;=&nbsp;tempScore&nbsp;+&nbsp;ebasRating\_Arr[i]

to

tempScore&nbsp;=&nbsp;tempScore&nbsp;+&nbsp;(ebasRating\_Arr[i] or 0)

i now i get a slight different error. instead of attempt to concatenate field ‘?’ i get something like " attempt to concatenate field ‘EBAS_ID’ (a nil value) on lua:713"

the ? have change to EBAS_ID and here are the code

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  

My question is: Is there something wrong with my code? or is it another type of error? can you help me to solve the problem?

Please, you must use code formatting when posting code here. It’s the blue <> button in the row with Bold,  Italic, etc. Click that button and paste your code into the window that pops up or type in

[code]

paste your code in then

[/code]

No one is going to look at that jumbled up code and make any sense of it.

Rob

Sorry about that.

i now i get a slight different error. instead of attempt to concatenate field ‘?’ i get something like " attempt to concatenate field ‘EBAS_ID’ (a nil value) on lua:713"

the ? have change to EBAS_ID and here are the code

 

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 

My question is: Is there something wrong with my code? or is it another type of error? can you help me to solve the problem?

[['WHERE id=']].. \_G.EBAS\_ID..[[';]]

Is EBAS_ID a global variable?  Does it exist and have a value in it?  If it’s nil, you can’t concatenate it.

Rob