and this is my code to remove the enemie when hit a bullet:
function on_message(self, message_id, message, sender)
if message_id == hash("collision_response") then
if message.group == hash("bullet") then
go.delete()
end
end
end
the questions:
the collection is destroyed? or just destroy enemie1.go?
Very important lesson: collections do not exist in the running game, so there’s no collection to destroy. A collection is simply a collection (duh!) of game objects, and when it is spawned using a collection factory or added directly in the editor inside another collection it will not exist as something that you can access in the running game. Only the game objects will exist at run-time. So, when you have an enemy.collection consisting of a number of game objects you need to delete all of them, even if they happen to be children of the game object that your script is attached to. Consider this setup:
If I in enemy.script do go.delete() then the body game object will be deleted but the turret game object will still exist. You need to do go.delete("turret") to delete that as well.
function init(self)
self.health = 2;
self.ids = {"cuerpo", "gun", "enemie1", "spawn_point"}
end
function on_message(self, message_id, message, sender)
if message_id == hash("hurt") then
hurt(self, message.damage)
end
end
function hurt(self, damage)
self.health = self.health - damage
if self.health <= 0 then
kill(self)
end
end
function kill(self)
go.delete_all(self.ids)
end
is correct? I need remove cuerpo, gun, enemie1 and spawn_point
collision object no need remove?
Collision objects are components, so they’ll disappear when the game object that contains them is deleted. (“enemie1” in this case.)
“cuerpo”, “gun”, and “spawn_point” are game objects (which just happen to be children of another game object), so they have to be purposefully deleted.