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 :
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) :
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)