Delete Unit

From LuaSTG Wiki
Jump to navigation Jump to search

A delete unit node marks an object to be deleted at the end of a frame.


Deletion of Objects[edit | edit source]

After an object is created in LuaSTG, it can be removed from the game from either deletion or a kill (see Kill Unit). A delete unit node does this job of deleting the object.

When the delete unit node is executed, the object will not be removed from the game instantly. Instead, it will be flagged to be deleted by the engine at the end of the current frame, which is done by setting the .status attribute of the object to delete. After all tasks, frame functions and other things finished execution in a particular frame, all objects that are flagged are deleted one by one.

However, on del method will be called as soon as the node executes, despite the object will still exist until the end of the frame.

As a result, we may continue access and modify the attributes of an object after the delete unit node is executed, but before the end of the frame.


Parameters[edit | edit source]

This is list of parameters of delete unit node.

Parameters Function
Target (LuaSTG object) The object to be deleted
Trigger Event (Boolean) Whether or not to trigger the deletion event of the object

If Trigger Event parameter is set to true, the unit will execute its on del method before its deletion. For a bullet, this is displaying the deletion effect by default (this potentially can cause obscure bugs, see the Deletion section of Define Bullet for example).


Equivalent Code[edit | edit source]

Upon running the script, the delete unit node will be translated to something like "_del(unit, true)", where unit is the object to be deleted. A similar alternative to write this in code is to use Del(unit).