GM: instance destroy

From GMpedia.org Wiki

Jump to: navigation, search
The correct title of this article is instance_destroy(). It appears incorrectly here because of technical restrictions.
The correct title of this article is instance_destroy(). It appears incorrectly here because of technical restrictions.


Arguments

none

Limitations

none

Note: Please remove limitations and port them in the "Remarks" section at the end of the article.

This command destroys the instance that the command is in.

[edit] Example

You usually use this command in an enemy instance when you want it destroyed, perhaps when a bullet has hit it. The object isn't removed from the game program itself but the instance is destroyed. You can use the object again at any time (see instance_create) but will produce a different instance id. instance_destroy() only destroys the instance it's in, you cannot use instance_destroy(<instance name>) to destroy one particular instance from another, in order to destroy one instance from another you have to use the with command:

with(obj_enemy01)
{
 instance_destroy();
}

But be warned, ALL instances of the specified object will be destroyed, so if you had multiple instance of say, obj_enemy01, and you use the with command like the example above, all instances of obj_enemy01 will disappear because you're specifying an object name, of which there could be multiple copies running around. This could be useful though in, say, a puzzle game, where destroying a gem would destroy all of the same type.

This article was originally found at the Game Maker Knowledge Base, contributed by nickydude.
See the talk page for details
Personal tools