Jump to content

When is self not self?


lofgren

Recommended Posts

I am being driven mad.

 

The keyword "self" in papyrus, in most cases, seems to refer to the object that the script is attached to. This is what every reference I have found says that "self" SHOULD refer to. For example, when used this way in a quest script ("self.setstage(20)") it seems to work just fine.

 

But now I have created a script and added it to a piece of armor, and "self" seems to refer to the SCRIPT, not the armor.

 

Does anyone know of a resource that can explain when "self" refers to the script, and when it refers to the object the script is attached to?

 

And can anybody offer a suggestion for how to create a script that can be added to multiple pieces of armor and then perform functions on the specific piece that has been activated? I know I can create a property and then go through and manually insert the armor's id into that property through the property dialogue, but that seems silly. Surely there must be a way for the script to refer to the item it is attached to?

 

Any assistance would be appreciated.

Link to comment
Share on other sites

No, this is about "self" returning something different than expected.

 

Here are more details:

 

I added a script to a piece of armor. It extends ObjectReference. What I want to do is immediately unequip the armor if the player equips it. I discovered this problem when I added the line:

 

akActor.UnEquipItem(self, false, true)

 

That did not work so I tried:

 

akActor.UnEquipItem(self.GetBaseObject(), false, true)

akActor.UnEquipItem(self.GetBaseObject() as Armor, false, true)

armor me = self.GetBaseObject() as Armor

akActor.UnEquipItem(me, false, true)

 

armor me = self as Armor

akActor.UnEquipItem(me, false, true)

And probably another half dozen variations on that theme. Finally I just did thus:

 

debug.Notification(self as string)

 

The notification that popped up was the name of the script, not the item!

 

If anybody can figure out how to do this, I would be very thankful. Alternatively, if anybody has figured out if attempting to equip/unequip an item flagged with abPreventRemoval/abPreventEquip send any kind of event that Papyrus can register, that would even better.

Link to comment
Share on other sites

AAAAnd I'm an idiot.

 

I still haven't solved my problem, but I did discover that the notification was getting truncated. self as string actually returns [scriptname (object 1 in container 14)]. I still need a way to capture the item that the script is attached to, though.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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