Single variable with many children

How a single variable can have many children.I don’t know the correct word.

                                                  What is wrong with the below code?

local timer\_array={} local function timerr(timez,image,posn) local timex; table.insert( timer\_array,timex) timex.image=display.newImageRect(image.."png",w/10,w/10) timex.textt=display.newText(timez, xc+(xc/3), yc/8, "jokerman",w/19 ) if posn==1 then timex.image.x,timex.image.y=xc,yc timex.textt.x,timex.textt.y=xc+30,yc elseif posn==2 then timex.image.x,timex.image.y=xc+60,yc timex.textt.x,timex.textt.y=xc+90,yc end timex.time=timez timex.timer=timer.performWithDelay( 1000, function() if timex.timez~=1 then timex.timez=timex.timez-1 timex.textt.text=timex.timez else print("timer stopped") display.remove( timex.image ) display.remove( timex.textt ) timer.cancel( timex.timer ) end end, timex.time) end timerr(20,"life",2)

What is the possible way the-above-said-thing can be done?

Not sure I understand your question, and your code is pretty unusual as well.

Seems like a complicated way to loop through the creation of display objects.

That being said, a single variable cant hold multiple instances “children” unless its a table, in which case it should work fine.

But, if you use a local variable in a creation loop, each instance will have its own identity (variable), even if the same variable name is used. This is lua scope, and if you intend to have any control of these later by reference, you’re gonna run into issues. Better to store them in a table, or at least give them a separate user defined tag (property).

But, if you use a local variable in a creation loop, each instance will have its own identity (variable), even if the same variable name is used.

That solved my problem!..Thanks

your code is pretty unusual as well.

I am learning…!

Glad it worked out  :slight_smile:

Not sure I understand your question, and your code is pretty unusual as well.

Seems like a complicated way to loop through the creation of display objects.

That being said, a single variable cant hold multiple instances “children” unless its a table, in which case it should work fine.

But, if you use a local variable in a creation loop, each instance will have its own identity (variable), even if the same variable name is used. This is lua scope, and if you intend to have any control of these later by reference, you’re gonna run into issues. Better to store them in a table, or at least give them a separate user defined tag (property).

But, if you use a local variable in a creation loop, each instance will have its own identity (variable), even if the same variable name is used.

That solved my problem!..Thanks

your code is pretty unusual as well.

I am learning…!

Glad it worked out  :slight_smile: