newbie question...unexpected symbol near '..'

Hi, I want to ask a complete newbie question, I believe many of you know the answer, but I don’t…

I got error: unexpected symbol near '…'by the code below in line 3.

local tempY = 100 for i = 1, 3 do local cat..i= display.newText(\_G.index[i+\_G.index[1]+1],200, tempY,native.systemFontBold,40) tempY = tempY + 60 screenGroup:insert(cat..i) end

I tried below, they got error also:

tostring(“cat”…i)

cat…[i]

tostring(“cat”)…i

however, the code works fine, when it is just

local i =display.newText(_G.index[i+\_G.index[1]+1],200, tempY,native.systemFontBold,40)

but I don’t want the name just a number.

You cannot generate variable names on the fly as you try with “cat…i”. This is only used to combine two strings or string and number.

Just do:

local tempY = 100 for i = 1, 3 do local cat = display.newText(\_G.index[i+\_G.index[1]+1],200, tempY,native.systemFontBold,40) tempY = tempY + 60 screenGroup:insert(cat) end

The variable is local anyways and is only visible in the for block, so it doesn’t matter what kind of name it has.

it works, thanks a lot! :smiley:

You cannot generate variable names on the fly as you try with “cat…i”. This is only used to combine two strings or string and number.

Just do:

local tempY = 100 for i = 1, 3 do local cat = display.newText(\_G.index[i+\_G.index[1]+1],200, tempY,native.systemFontBold,40) tempY = tempY + 60 screenGroup:insert(cat) end

The variable is local anyways and is only visible in the for block, so it doesn’t matter what kind of name it has.

it works, thanks a lot! :smiley: