Variable concatenation

Hi guys, im having some problems trying to concatenate some stuff and it’ll help me a lot reducing my current code.

Lets say i have this:

local image1 = display.newImage("image1.png") local image2 = display.newImage("image2.png") local image3 = display.newImage("image3.png") local equip = 1 image1.isVisible = false image2.isVisible = false image3.isVisible = false

and then somewhere else in the code i want to check “equip” value and show that image.

if equip == 1 then "image"..equip.isVisible = true "image"..equip.x = 200 "image"..equip.y = 300 end

I know this isn’t working, and i’ve tried other methods but all of them give me errors. I know this might be a little bit basic by this time but i don’t know how to resolve this.

I’ve tried 

local conc = "image"..equip if equip == 1 then conc.isVisible = true end

but it gives me an error because conc is a string, isnt there a way to transform that string into data? i just want to use the variable reference

Thanks in advance.

You could do something like this:

[lua]

local images = {}

for a = 1, 3, 1 do

    local i = display.newImage(“image”…a…".png")

    i.isVisible = false

    images[a] = i

end

images[equip].isVisible = true

images[equip].x = 200

images[equip].y  = 300

[/lua]

Oh right, totally forgot i could add display objects inside a table. Thanks a lot

You could do something like this:

[lua]

local images = {}

for a = 1, 3, 1 do

    local i = display.newImage(“image”…a…".png")

    i.isVisible = false

    images[a] = i

end

images[equip].isVisible = true

images[equip].x = 200

images[equip].y  = 300

[/lua]

Oh right, totally forgot i could add display objects inside a table. Thanks a lot