NPC
Hammer and Hoe
08 Oct 2019, 06:31How can you make NPCs disappear after you shoot at them, for example?
mrangel
08 Oct 2019, 08:06Three ways to make an object disappear: You can make them invisible (bob.visible = false
), move them to somewhere the player can't go (RemoveObject (bob)
or bob.parent = null
), or actually destroy the object (destroy ("bob")
).
Destroying is more efficient, especially if you're making a game with large numbers of cloned objects. But if you destroy an object, any other scripts referring to it will cause an error, so you have to be more careful.
jmnevil54
08 Oct 2019, 12:49How it's often done.
if (this.hp <= 0) {
RemoveObject (this)
destroy ("this")
}
How I did it in "The Legend of the Secret of the Smelly, Stinky Fish."
obj.changedhitpoints => {
if (this.hitpoints < 1) {
msg ("The monster whited out!")
this.dead = true
player.exp = player.exp + 20
player.gold = player.gold + 20
love
game.lock = false
RemoveObject (this)
Lock2
}
}