尝试连接全局'q101'(nil值) [英] Attempt to concatenate global 'q101' (a nil value)
问题描述
我喜欢将文本从外部.lua文件加载到我的游戏中,这是我设置的一个小测试,用于测试主体,我知道是否可以给"q101" 这样的数字"q101 = 123456" 该代码显示数字 123456 ,但我不明白为什么它不带字母.
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)
推荐答案
此行q101 = HELLO
将q101
变量的值设置为HELLO
变量的值.并且由于具有该名称的全局变量没有值(因为从未定义过),因此您要将nil
分配给q101
变量.
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.
您要将字符串"HELLO"
分配给变量:q101 = "HELLO"
.
You want to assign the string "HELLO"
to your variable: q101 = "HELLO"
.
这篇关于尝试连接全局'q101'(nil值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!