I’ve got a factory that spawns enemy ships and the ships contain a factory to spawn bombs.
I need to pass a message from the bomb object back to the parent enemy ship object.
Is there a way to get the url of the parent ship from within the bomb script?
Something like this maybe:
function spawn_bomb(self)
local bomb = factory.create("#bomb")
msg.post(bomb, “set_ship”)
end
And then listen for that message in on_message and save the sender to a variable.
You could also have a property on the bomb:
go.property(“parent”, msg.url())
And set that property when you call factory.create
Great, thanks Johan - that seems to work!
I would go for this solution as well. Nice and clean.
This should definitely be in the list of pro tips or in the documentation. It’s a very useful feature when you spawn objects to have a two way communication.
Good idea! I will add a section about this in the factory manual.
@sicher could you kindly add the solution with go.property to the Factory documentation since I don’t fully grasp it in the example in this thread and probably there are others like me.