Newbie tile insert questions

Hi there!

Probably a simple thing but I just have not been able to find a reference how to do it…
If I have a loaded map with several tilesets in it is there a way to get a tile or a set of tiles based on a tile property? I wanted to get a tile based on a given property then insert into a layer on the map.
I think I have the second part as soon as I figure out how to get the gid once I get the tile…

[import]uid: 165606 topic_id: 28849 reply_id: 328849[/import]

Hmm. Not really sure what happens with multiple tile sets; probably it all gets merged together. But there are a couple of options.

[code]-- Fetch the tile layer
local ground = map:getTileLayer(“whatever you named the layer in Tiled”)

– Next, fetch a list of every tile with the property.
– You can do this without getting the layer but then it will search and pull from ALL layers
local list = ground:getTilesWithProperty(“property name”)[/code]

That would get you a list of tiles that have a specific property. I think map:findValuesByTilePropertyName(name) might also help; it says in the doc that it returns tiles but maybe it returns a list? In the worst case you can just fetch the list from the above example code and then use a for loop to fetch the value of the property on each tile.
[import]uid: 41884 topic_id: 28849 reply_id: 116373[/import]

Thank you for the thoughts on this. Time heals all wounds and helps developers learn!

I came up with a way (not sure if it is optimal though) which seems to work.

[code]
— Gets a GID based on a matching key and value
@param gid The gid to use.
@return The tileset at the gid location.
function Map:getGIDFromKV(key, value)

local tileSets = self.tileSets

if( #tileSets > 0)then
for i=1, #tileSets, 1 do

for tentry=0, tileSets[i].tileCount,1 do

local props=tileSets[i]:getPropertiesForTile(tileSets[i].firstgid+tentry)
if #props > 0 then
for ic =1,#props,1 do
–print (props[ic]:getName()…","…props[ic]:getValue())
if props[ic]:getName()==key and props[ic]:getValue()==value then

return tileSets[i].firstgid+tentry
end

end
end
end
end

else
return nil
end
end
[/code] [import]uid: 165606 topic_id: 28849 reply_id: 116674[/import]