Jump to content

Properly deleting an object reference


Spinner385

Recommended Posts

Hi, I'm setting up a MiscObject called "TestForm" with a script on it called "TestScript". The script only has a property on it called "index". Then i'm placing 2 copies of the MiscObject at a marker and filling "index" of each. Finally I want to delete these placed object references.

 

Here's the script:

 

 

ObjectReference Property Marker Auto
MiscObject Property TestForm Auto
ObjectReference Property Test1 Auto
ObjectReference Property Test2 Auto

Event OnPlayerLoadGame()
Test1 = Marker.PlaceAtMe(TestForm)
Test2 = Marker.PlaceAtMe(TestForm)
(Test1 as TestScript).Index = 1
(Test2 as TestScript).Index = 2
objectreference tempref1 = Test1
objectreference tempref2 = Test2
Test1 = None
Test2 = None
tempref1.Disable()
tempref2.Disable()
tempref1.Delete()
tempref2.Delete()
Debug.MessageBox((tempref1 as TestScript).Index + " + " + (tempref2 as TestScript).Index)
EndEvent

 

 

The message box still displays "1 + 2" as if they weren't deleted. From reading the wiki it appears I've meet the conditions to delete them.

 

I need to make sure I am deleting these object references before I can begin to start what I'm doing. Can anyone please help me assure that I am deleting them properly?

 

P.S. - I created the object in a custom cell (where the marker is) so it couldn't be referenced else where. Also the script on the object has no code just the "index" property.

Link to comment
Share on other sites

It looks like you've got an issue with persistence, coupled with the fact that Delete() is not an immediate action, but rather it flags the reference to be deleted when it's no longer in use -- but the persistence of your script's variables are keeping them around!

 

I'm no expert on such things when it comes to Papyrus, however I think your solution would be to assign the value None to them after you call the Delete() method on each.

 

To test that they're being deleted, you can go to your test cell and activate your event (well, a different event than this one, I guess, i.e. one you can activate at will) and watch your test markers get created (use something big and visible for TestForm, e.g. a boulder). Remove the calls to Disable(). You will then either see the objects get deleted right in front of you, or else they'll stick around until you leave (unload) the cell, and be gone when you return.

Edited by kromey
Link to comment
Share on other sites

Thnx =]

 

I was basing it on the delete wiki page. It was saying it was only filled properties that stopped the delete. But I'm pretty sure your right and that regular variable is stopping it.

 

I'm going to put some kind of event (one that doesn't register) on the TestScript along with the Index property on it. Then I'll trip the event and see what items respond. After clearing the variable of course.

 

Thanks again for the help =]

Edited by Spinner385
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...