I didn't think ObjectRefs kept variables...

Post » Fri May 02, 2014 10:00 pm

Afternoon all. I was under the impression that ObjectReferences did not keep their script variables when added to a container. However the following test proved otherwise.


Script attached to an Axe placed in a cell in the CK:

Int MyIntegerEvent OnActivate(ObjectReference akActionRef)	BlockActivation()	if akActionRef == Game.GetPlayer()		if Game.GetPlayer().IsSneaking()			Debug.MessageBox("MyInteger = "+MyInteger)			Utility.Wait(1.0)			MyInteger += 1			Return		else			Game.GetPlayer().AddItem(self)			Return		endif	endifEndEvent

I tested by repeatadly activating the Axe whilst sneaking and the Integer increased as intended. After a few goes I'd add the Axe to my inventory, then remove it, and when acitvating again whilst sneaking the variable held true to the previous number. I tested also saving and loading and the variable stuck.

Is my understanding not right with this? I thought the ObjectReference needed to be held in a property somewhere in order to have it's variables persist... or is it working for me because this isn't an Axe with an FF form ID?
User avatar
naome duncan
 
Posts: 3459
Joined: Tue Feb 06, 2007 12:36 am

Return to V - Skyrim