Attempt to concatenate global 'q101' (a nil value)

匆匆过客 提交于 2019-12-24 02:30:13

问题


i like to load text form a external .lua file in to my game, here is a little test i setup to test the principal, i know if i give "q101" numbers like so "q101 = 123456" the code displays the numbers 123456 but i don't understand why it doesn't with letters.

Can some one please explain how i can do this is the right way, as this is clearly not the way of doing it

q101 = HELLO

Q1 = display.newText("".. q101, 160, 20, MYRIADPRO, 30)
Q1:setTextColor( 255, 255, 2552)
Q1.x = display.contentWidth/2  
Q1.y = display.contentHeight/2
screenGroup:insert(Q1)

回答1:


This line q101 = HELLO is setting the value of the q101 variable to the value of the HELLO variable. And as the global variable with that name has no value (as it has never been defined) you are assigning nil to your q101 variable.

Numbers cannot be variables and so do not work that way.

You want to assign the string "HELLO" to your variable: q101 = "HELLO".



来源:https://stackoverflow.com/questions/24493566/attempt-to-concatenate-global-q101-a-nil-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!