Is it possible to include a properties subtable when using addSprite?

I guess my current task is to create a new sprite that has properties values so that when i collide with it, i can read/take the “egg.properties.health”.  right now, if i collide with an object that does not have egg.properties I crash out and get "attempt to index field ‘properties’ (a nil value).  

If there is not a way to specify a properties table (like what i pull from Tiled properties) while initially adding the sprite, then is there a different way to do this?  a super simple example would be great.  

this is what i had with examples and samples:

local poopegg = function()

                    local eggSheet = graphics.newImageSheet(“egg@2x.png”, {width = 60, height = 60, numFrames = 1})

                    local sequenceData = {

                        {name = “idle”, sheet = eggSheet, frames = {1}, time = 1600, loopCount = 0},        

                    }

                    egg = display.newSprite(eggSheet, sequenceData)

                    local setup = {

                        kind = “sprite”,

                        layer =  3,  --adds the player sprite to this layer

                        locX = 5, --sets the position of the player at tile x location on map

                        locY = 12,  --sets the position of the player at tile y location on map

                        levelWidth = 60,  --the actual width of the player sprite

                        levelHeight = 60, --the actual height of the player sprite

                        offsetX = 0, 

                        offsetY = 0,

                        properties = {

                                                health = 999,

                                                bleh = 30

                                    }

                    }

                    mte.addSprite(egg, setup)

I also looked at setObjectProperties(), but would love to have another example if this is the correct approach for setting egg.properties.bleh

Thank you in advance!

Hello Adam,

The correct way to do this at the moment would be as follows:

local poopegg = function() local eggSheet = graphics.newImageSheet("egg@2x.png", {width = 60, height = 60, numFrames = 1}) local sequenceData = { {name = "idle", sheet = eggSheet, frames = {1}, time = 1600, loopCount = 0}, } egg = display.newSprite(eggSheet, sequenceData) local setup = { kind = "sprite", layer = 3, --adds the player sprite to this layer locX = 5, --sets the position of the player at tile x location on map locY = 12, --sets the position of the player at tile y location on map levelWidth = 60, --the actual width of the player sprite levelHeight = 60, --the actual height of the player sprite offsetX = 0, offsetY = 0, } mte.addSprite(egg, setup) egg.properties = { health = 999, bleh = 30 }

The Corona SDK makes the process of adding data to a display object nice and simple. Every display object- sprites, imageRects, etc- is a table to which you can add any information you like, so long as you don’t overwrite anything important. The setup table of addSprite configures the information MTE needs to position and scale the sprite on the map.

Awesome!  Exactly what i needed.  Thank you!

Hello Adam,

The correct way to do this at the moment would be as follows:

local poopegg = function() local eggSheet = graphics.newImageSheet("egg@2x.png", {width = 60, height = 60, numFrames = 1}) local sequenceData = { {name = "idle", sheet = eggSheet, frames = {1}, time = 1600, loopCount = 0}, } egg = display.newSprite(eggSheet, sequenceData) local setup = { kind = "sprite", layer = 3, --adds the player sprite to this layer locX = 5, --sets the position of the player at tile x location on map locY = 12, --sets the position of the player at tile y location on map levelWidth = 60, --the actual width of the player sprite levelHeight = 60, --the actual height of the player sprite offsetX = 0, offsetY = 0, } mte.addSprite(egg, setup) egg.properties = { health = 999, bleh = 30 }

The Corona SDK makes the process of adding data to a display object nice and simple. Every display object- sprites, imageRects, etc- is a table to which you can add any information you like, so long as you don’t overwrite anything important. The setup table of addSprite configures the information MTE needs to position and scale the sprite on the map.

Awesome!  Exactly what i needed.  Thank you!