How to find tile to match object? (object "name" as an integer appended to it so no match)

How can one retrieve the object (rectangle) object from mte after a collection of the player to this object. 

If I look in the collision event for “local objectHit = event.other” I see there is a “name” field, however this has a “1” appended to it, so there’s no direct match.   That is if I had the name of this object in the objects layer in Tiled as being “pot”, the name in the “objectHit” is not “pot” but “pot1”.  

So what would be the safest way to retrieve the object from mte (so I can then get is custom properties) from within a collection event when the player collides with this object?

Do you have multiple objects named “pot” on the map? In the case of multiple objects with identical names MTE appends numbers to them so that they don’t conflict in the sprite table. 

Looking over the code, a small bug in addSprite (which drawObject calls) is appending 1’s to objects with unique names. You need to find this section of code in addSprite, at line 1375:

local spriteName = setup.name if not spriteName or spriteName == "" then spriteName = ""..sprite.x.."\_"..sprite.y.."\_"..layer end if sprites[spriteName] then local tempName = spriteName local counter = 1 while sprites[tempName] do tempName = ""..spriteName..counter counter = counter + 1 end spriteName = tempName end

And replace it with the following:

local spriteName = sprite.name or setup.name if not spriteName or spriteName == "" then spriteName = ""..sprite.x.."\_"..sprite.y.."\_"..layer end if sprites[spriteName] and sprites[spriteName] ~= sprite then local tempName = spriteName local counter = 1 while sprites[tempName] do tempName = ""..spriteName..counter counter = counter + 1 end spriteName = tempName end

That will prevent random 1’s from appearing at the end of your object names. As for retrieving the properties, the next update will include the Tiled object’s property table in the sprite it creates. You can make this change yourself by adding this line of code to mte.lua at line 6535:

sprites[spriteName].properties = object.properties

After making these changes you’ll be able to get the properties at event.other.properties.

fantastic stuff dyson - I’ve been asking quite a few questions so I’m kind of glad I managed to find one small bug  :slight_smile:

Do you have multiple objects named “pot” on the map? In the case of multiple objects with identical names MTE appends numbers to them so that they don’t conflict in the sprite table. 

Looking over the code, a small bug in addSprite (which drawObject calls) is appending 1’s to objects with unique names. You need to find this section of code in addSprite, at line 1375:

local spriteName = setup.name if not spriteName or spriteName == "" then spriteName = ""..sprite.x.."\_"..sprite.y.."\_"..layer end if sprites[spriteName] then local tempName = spriteName local counter = 1 while sprites[tempName] do tempName = ""..spriteName..counter counter = counter + 1 end spriteName = tempName end

And replace it with the following:

local spriteName = sprite.name or setup.name if not spriteName or spriteName == "" then spriteName = ""..sprite.x.."\_"..sprite.y.."\_"..layer end if sprites[spriteName] and sprites[spriteName] ~= sprite then local tempName = spriteName local counter = 1 while sprites[tempName] do tempName = ""..spriteName..counter counter = counter + 1 end spriteName = tempName end

That will prevent random 1’s from appearing at the end of your object names. As for retrieving the properties, the next update will include the Tiled object’s property table in the sprite it creates. You can make this change yourself by adding this line of code to mte.lua at line 6535:

sprites[spriteName].properties = object.properties

After making these changes you’ll be able to get the properties at event.other.properties.

fantastic stuff dyson - I’ve been asking quite a few questions so I’m kind of glad I managed to find one small bug  :slight_smile: