The situation is as follows: I want all creatures to be removed after a player loses. In theory I can write a function that records the id of all spawned creatures, but maybe there is a simpler way to do it ? I have in mind an internal function in the defold itself that keeps track of all spawned go.
Note: Restarting the level is not an option due to code peculiarities.
collectionfactory.create returns a table of urls, one for each game object in the collection. I usually have a root game object containing all other game objects of the collections. So maybe the spawner can do something like this:
-- in init
self.spawned_urls = {}
self.count = 0
-- when spawning
self.count = self.count + 1
self.spawned_urls[self.count] = collectionfactory.create(...)["/root"]
-- when deleting
for i = 1, self.count do
go.delete(self.spawned_urls[i], true) -- true to recursively delete all children
end
I hope what I am suggesting is right. I am not an expert in Lua, maybe there are better ways or, even, I am missing something.