On a factory.create() call, where can I init custom variables?

if you spawn objects with a code line like this:

item=factory.create("#enemy_factory", p, go.set_scale(0.9), {level=self.baselvl})

and the prototype of enemy_factory has a script called enemy.script attached.
Where can I receive the custom level variable. Is it in a message (on message)? which message_id will be used? Is it available in the enemy.script?

if message_id == hash("init") then

Define the property in the script and it will be passed and accessible. Otherwise it won’t. What you’re probably missing is

go.property("level", 0)

in your enemy.script then you can access it via self.level in that script.

3 Likes