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

11,007

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".

Share:
11,007
kevin ver
Author by

kevin ver

Updated on June 04, 2022

Comments

  • kevin ver
    kevin ver almost 2 years

    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)
    
  • kevin ver
    kevin ver almost 10 years
    i have one more little question, i'f updated the original question
  • Etan Reisner
    Etan Reisner almost 10 years
    q1 is a string "q201". You then use that in your display call. So you display that string. You want that used as a variable. You need to look it up in the globals table _G[q1] or use a local table instead of _G and do the same sort of lookup.