corona - Error when trying to add a point to my score counter. Lua -


i have error have run when trying create score counter lua game. here code have.

score = 0  local playerscore = display.newtext("score" ..score, 0, 10, "americantypewriter-bold",          16); playerscore:settextcolor(0, 0, 0);   playerscore.text = "score: " .. score  function ball:touch( event ) if event.phase == "began" playerscore.text = playerscore.text + 1  ball:applyforce(0, -10) return true end end  

here line gives me error.

playerscore.text = playerscore.text + 1  

the error gives me.

attempt perform arithmetic on field 'text' (a string value) 

you attempting add 1 string "score: 1" (where 1 may number), instead should increment score variable , update text.

this should job.

score = score + 1 playerscore.text = "score: " .. score 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -