尝试连接全局'q101'(nil值) [英] Attempt to concatenate global 'q101' (a nil value)

查看:73
本文介绍了尝试连接全局'q101'(nil值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢将文本从外部.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 = HELLOq101变量的值设置为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆