NPC

How can you make NPCs disappear after you shoot at them, for example?


Three 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.


How 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
 }
}

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums