Best practice: adding variables to display objects?

I’m working on a game. I create about 40 game sprites and need to keep track of action states and other information for each. Seems I have two options to work with all of this.

  1. Assign variables to each of the sprite objects created. Something like

local invader = sprite.newSprite( invader_spritesheet )
invader.is_hit = false
invader.row = row
invader.col = col
etc.

Or method 2) Create an array or table to hold a reference to the display object and hold properties describing the game state of that display object.

At the moment I’m using the second method using display object as the property for each table element. Which seems to work fine. [import]uid: 98652 topic_id: 18959 reply_id: 318959[/import]

This is more a matter of personal preference, but I add properties to the display objects, since they are effectively Lua tables. I don’t see a need to create another table to store data when I’ve already created one (the display object).

Thanks,
Darren [import]uid: 1294 topic_id: 18959 reply_id: 73064[/import]

Thanks for the reply. It is more convenient to use the display object to hold it’s own properties in many cases. I just worry about getting into bad habits.

[import]uid: 98652 topic_id: 18959 reply_id: 73071[/import]

As was said, it’s just personal preference :slight_smile: [import]uid: 84637 topic_id: 18959 reply_id: 73346[/import]