Manual factory Components self.spawned_coins?

In Factory component manual There is:

-- spawner.script
self.spawned_coins = {}

and

-- coin.script
-- Delete all spawned coins.
for _, coin_id in ipairs(self.spawned_coins) do
    go.delete(coin_id)
end

That is the manual shows self.spawned_coins defined in one script and used in another. This does not work for me. I tried doing this in the Side scroller tutorial.
I put it in the init of factory.script and printed in init of star.script and got null.

I am doing to learn and not for anything specific.
Please can someone explain.

Edit: In the side scroller tutorial, I was trying to see if I could get the stars to stop when p.x ==200 (say) and go back the other way; just for fun! Then I discovered that all stars use the same instance (parameter values) of the script. So I need to find a way to identify individual stars…

Ah, no, that’s not right. It should say spawner.script for both snippets of code. I’ve pushed a fix to that manual. The self that you get in all lifecycle functions is unique to each script instance. If you need to share some data between scripts you can instead but the data in a Lua module.

Thank you , my confusion is reduced:-)

1 Like