Tes3Mod:SetDelete

The UESPWiki – Your source for The Elder Scrolls since 1995

Jump to: navigation, search

SetDelete

                SetDelete, Flag

       Where:   Flag = 1 to delete object, 0 to clear

        Type:   Misc, Tribunal

     Returns:   none

     Example:   SetDelete, 1

     Scripts:   trapProjScript
                explosion_pushout

The SetDelete function can be used in combination with Disable to remove an object more completely. SetDelete 1 marks a reference for deletion while SetDelete, 0 clears that flag.

If the reference was placed in-game (e.g., by the player dropping an item, or by a PlaceAtPC script command), then it will be deleted immediately. But if the reference was placed by an esm or esp file, then it will be marked as deleted, and will not display nor have its scripts run. If you delete from the console you will notice this as in the title of the console: for an ingame reference, the title will revert back to "Console", while for an esp/esm reference the title will continue to match the reference id, and you will be able to setdelete 0, if you wish.

[edit] Tips

There are a couple of things that should be done to make this work, as I had some problems with using it crashing the game otherwise. If you use this on an object, give it a bit of time of inactivity before you delete it, and Disable it ahead of time. So you could put something like this in your script near the top, as an example:

if ( deleteobj = 1 ) ;Local variable, set when you want to delete
    if ( deletetimer == 0 )
        Disable
    endif

    if ( deletetimer < 10 )
        set deletetimer to ( deletetimer + 1 )
    endif

    if ( deletetimer == 10 )
        "my_object_01"->SetDelete, 1
    endif

    Return

endif

That way, with the return, it stops the rest of the script if it's up near the top of it (below where you setup the variables though), and disables it, and gives it a bit of time before it's deleted. It may not need 10 frames, but that's not long, and it worked in my scripts. It can be quite a useful function in scripting things, as it allows for a script to use PlaceAtPC or PlaceItem scripts or such to create items within the world, at different locations, or different situations, where you may want to delete such items after.

Other useful tips for successfully using SetDelete are:

  1. Always call setDelete from a local script.
  2. Give at least 2 seconds if you've used Cast or ExplodeSpell, otherwise it is perfectly OK to Disable one frame then SetDelete the next.
  3. Never SetDelete if the object is in an inventory.
  4. Always Disable first.

See Also: DontSaveObject

Sponsored Links
Personal tools