Store character collections and later delete

URLs cannot be used as table keys. See this thread.

Assuming the fish game object has a script, you could store the key as a script property and check against that. Something like:

local fish = collectionfactory.create(...)
table.insert(self.spawned_fish, fish[hash("/main")])
msg.post(fish[hash("/main")], hash("setup_key", {key = #self.spawned_fish})

The fish script needs to have the property defined:

go.property("key", 0)

(It also needs to handle the message sent earlier, I’ll skip that)

Then to get the right fish you iterate over the table of all fish to get the right one:

local fish_key
  for key, val in ipairs(self.spawned_fish) do
    if go.get(msg.url(nil, val, "name_of_the_script"), "key") == key then
        fish_key = key
        break
    end
end

This is probably not the cleanest solution, but the first one to come to my mind.