displayGroup and table is there a possible to do it easier ?

hello,

My way works but imagine with 20 value ! is there a way to do it easier ? i try with a boucle but i can’t not…

Thanks if you have a better solution.

   local text={}    text.TicTac=display.newText(optionsTicTac)     text.Timer=display.newText(optionsTimer)     text.Level=display.newText(optionsLevel)     text.EnemyAdded=display.newText(optionsEnemyAdded)         local textV1=text.TicTac     local textV2=text.Timer     local textV3=text.Level     local textV4=text.EnemyAdded         myGrouptext:insert(textV1)     myGrouptext:insert(textV2)     myGrouptext:insert(textV3)     myGrouptext:insert(textV4)

Specify the parent field when setting up your ‘options’, or assign it before using the options to create the text field.

optionsTicTac.parent = myGrouptext optionsTimer.parent = myGrouptext optionsLevel.parent = myGrouptext optionsEnemyAdded.parent = myGrouptext local text = {} text.TicTac = display.newText( optionsTicTac ) text.Timer = display.newText( optionsTimer ) text.Level = display.newText( optionsLevel ) text.EnemyAdded = display.newText( optionsEnemyAdded )

By the way, I think you’re translating your questions with a tool, because I’ve seen you post the word 

_ boucle  _

a few time and have no idea what that is.  We aren’t talking about yarn here, so my guess, is the word is getting mistranslated by a tool.

@Ed,

Boucle is French for ‘loop’.

Anil

Ahh!  Thanks Anil.  That makes total sense.  

Cool.

@bexphones,

I’m sure there is a way to make this even shorter with a loop, but because you are using a new option table for each object, that may be kind of hard to do.  At least it is hard to do without seeing your code.

However, consider this as one of MANY ways to shorten this process (assumes common settings between options):

-- Warning: May contain typos -- local parentGroup = display.newGroup() local textObjects = {} local baseOptions = { parent = parentGroup, width = 100, font = native.systemFont, fontSize = 12, } local indexNames = { "tictac", "timer", "level", "enemyadded" } local defaults = { "X", "0:00", "1", "0" } local xyPos = { {10, 10}, {100, 10}, {10, 50}, {100, 50} } for i = 1, #fieldNames do -- Set new values for 'options' table baseOptions.text = defaults[i] baseOptions.x = xyPos[i][1] baseOptions.y = xyPos[i][2] -- Create the object local tmp = display.newText( baseOptions ) -- Store it in a table textObjects[indexNames[i]] = tmp end 

Now, later you could do this:

textObjects.level.text = "2" -- or textObjects["level"].text = "2"

hi Roaminggamer,

You succeeded with the sheep !!! :)…You have understand me even if i used a tool for translating.

Thanks for your explanation.

Have a nice day. 

Specify the parent field when setting up your ‘options’, or assign it before using the options to create the text field.

optionsTicTac.parent = myGrouptext optionsTimer.parent = myGrouptext optionsLevel.parent = myGrouptext optionsEnemyAdded.parent = myGrouptext local text = {} text.TicTac = display.newText( optionsTicTac ) text.Timer = display.newText( optionsTimer ) text.Level = display.newText( optionsLevel ) text.EnemyAdded = display.newText( optionsEnemyAdded )

By the way, I think you’re translating your questions with a tool, because I’ve seen you post the word 

_ boucle  _

a few time and have no idea what that is.  We aren’t talking about yarn here, so my guess, is the word is getting mistranslated by a tool.

@Ed,

Boucle is French for ‘loop’.

Anil

Ahh!  Thanks Anil.  That makes total sense.  

Cool.

@bexphones,

I’m sure there is a way to make this even shorter with a loop, but because you are using a new option table for each object, that may be kind of hard to do.  At least it is hard to do without seeing your code.

However, consider this as one of MANY ways to shorten this process (assumes common settings between options):

-- Warning: May contain typos -- local parentGroup = display.newGroup() local textObjects = {} local baseOptions = { parent = parentGroup, width = 100, font = native.systemFont, fontSize = 12, } local indexNames = { "tictac", "timer", "level", "enemyadded" } local defaults = { "X", "0:00", "1", "0" } local xyPos = { {10, 10}, {100, 10}, {10, 50}, {100, 50} } for i = 1, #fieldNames do -- Set new values for 'options' table baseOptions.text = defaults[i] baseOptions.x = xyPos[i][1] baseOptions.y = xyPos[i][2] -- Create the object local tmp = display.newText( baseOptions ) -- Store it in a table textObjects[indexNames[i]] = tmp end 

Now, later you could do this:

textObjects.level.text = "2" -- or textObjects["level"].text = "2"

hi Roaminggamer,

You succeeded with the sheep !!! :)…You have understand me even if i used a tool for translating.

Thanks for your explanation.

Have a nice day.