[Resolved] Accessing Sprite Details entered into Table.

Can someone explain if the following is possible, and indeed if I’m actually going about this the correct way…

I’ve create a table, of which I’ve inserted a collection of Sprites like so:

 for i=1,#levOneLayout do  
 tileMap[i]=display.newSprite (imageSheet, { name=levOneLayout[i].name, start=levOneLayout[i].tileVal, count=2, time=500 })  
 tileMap[i].x=levOneLayout[i].x  
 tileMap[i].y=levOneLayout[i].y  
 tileMap[i].touch = onObjectTouch  
 tileMap[i]:addEventListener( "touch", tileMap[i] )  
 end  

What I’m now trying to do is iterate through all the sprites in the “tileMap” table, and get the details, I currently have this:

 for i=1,#tileMap do  
 text = display.newText( tileMap[i].x, 0, 0, nil, 16 )  
 text:setTextColor( 255, 255, 255 )  
 text.x = i\*16  
 text.y = 32  
 end  

Now that indeed does print out the X position of the Sprite, but if I wanted the name I’d have thought changing the line to read:

text = display.newText( tileMap[i].name, 0, 0, nil, 16 )  

But this doesn’t work at all.

Am I doing this totally and utterly wrong, or is there something ‘simple’ that I’m omitting? [import]uid: 41429 topic_id: 30370 reply_id: 330370[/import]

** Please Ignore **

Just seen my mistake. Apologies. [import]uid: 41429 topic_id: 30370 reply_id: 121659[/import]

Could you share your solution, please? [import]uid: 147322 topic_id: 30370 reply_id: 121733[/import]

Sure, silly omission which I suddenly realised 20mins after posting…

 for i=1,#levOneLayout do  
 tileMap[i]=display.newSprite (imageSheet, { name=levOneLayout[i].name, start=levOneLayout[i].tileVal, count=2, time=500 })  
 tileMap[i].x=levOneLayout[i].x  
 tileMap[i].y=levOneLayout[i].y  
  
 tileMap[i]=levOneLayout[i].name  
 tileMap[i]=levOneLayout[i].tileVal  
 tileMap[i].touch = onObjectTouch  

I was, of course, not passing any values to .name and .tileVal (or whatever keys i want to set in the table, the beauty of Lua)

Now I know that’s the solution, I’ve managed to pass in a whole host of attributes, per sprite, which I can easily access in the table.

Apologies for not posting solution, I should have done sooner. [import]uid: 41429 topic_id: 30370 reply_id: 121735[/import]

No worries! Thanks for posting. [import]uid: 147322 topic_id: 30370 reply_id: 121738[/import]

** Please Ignore **

Just seen my mistake. Apologies. [import]uid: 41429 topic_id: 30370 reply_id: 121659[/import]

Could you share your solution, please? [import]uid: 147322 topic_id: 30370 reply_id: 121733[/import]

Sure, silly omission which I suddenly realised 20mins after posting…

 for i=1,#levOneLayout do  
 tileMap[i]=display.newSprite (imageSheet, { name=levOneLayout[i].name, start=levOneLayout[i].tileVal, count=2, time=500 })  
 tileMap[i].x=levOneLayout[i].x  
 tileMap[i].y=levOneLayout[i].y  
  
 tileMap[i]=levOneLayout[i].name  
 tileMap[i]=levOneLayout[i].tileVal  
 tileMap[i].touch = onObjectTouch  

I was, of course, not passing any values to .name and .tileVal (or whatever keys i want to set in the table, the beauty of Lua)

Now I know that’s the solution, I’ve managed to pass in a whole host of attributes, per sprite, which I can easily access in the table.

Apologies for not posting solution, I should have done sooner. [import]uid: 41429 topic_id: 30370 reply_id: 121735[/import]

No worries! Thanks for posting. [import]uid: 147322 topic_id: 30370 reply_id: 121738[/import]