Collectionfactory.create : Ask for argument "8"?

Hello,
So, I started to try those “collection” stuff. By replacing the normal factory by a collection factory.
I created a collection, and replaced the factory.creation function in the script by :

idf = collectionfactory.create("#factory_etoile", pos, nil, { id = self.id }, 1)

And I have this weird error message :

bad argument #8 to 'create' (hash expected, got string)

There is no argument 8…

True, in this case the Lua error becomes a bit confusing. I think it refers to this:

id = self.id

Is self.id a string perhaps? Try making it a hash instead id = hash(self.id)

No change.
self.id is a number.
As the script create a great number of instances (stars), each has its own number, created basicaly like that :

	for i = 1, Nombre_Etoiles do
		self.id = i
                ...
		idf = collectionfactory.create("#factory_etoile", pos, nil, { id = hash(self.id) }, 1)
		lua_ecrire_systeme(self.id, "id_instance", idf)

where lua_ecrire_systeme is a function in a lua that write in a table everything about the star system (position, color, number of planets… and of course its game ID, a number going to 1 to some “max number” (Nombre_Etoile) of stars in the game").

The weird thing is that the exact same function used before to spawn instances with the normal “object” factory…

For some reason, when I delete the last argument (“1”), the error message say “bad argument #7
And apparently, it’s really id = self.id the problem (that worked with factory.create) :

idf = collectionfactory.create("#factory_etoile", pos, nil, {  }, 1)

No error message.

Ah, hold on, I didn’t look closely enough at your code. If you wish to pass properties to the created game objects in the collection you also need to specify which game object should have which property:

Let’s say that your star.collection has a game object “/go” with a script property “id” then the code should look like this:

local props = {
    [hash("/go")] = { id = hash(self.id) }
}
collectionfactory.create("#factory_etoile", pos, nil, props, 1)
2 Likes

I will look at that. Thank you.

Works flawlessly. Thanks for your help.