Difference between revisions of "OnContainerChanged - ObjectReference"
Jump to navigation
Jump to search
imported>Cipscis (→Notes: Briefly summarised the issues discovered by Chesko back in February, and added a link to source for more detail) |
imported>Mofakin |
||
Line 40: | Line 40: | ||
*Reminder: If you call RemoveItem() on an object and don't give it a destination container it is destroyed... such destroyed objects won't run an OnContainerChanged event. | *Reminder: If you call RemoveItem() on an object and don't give it a destination container it is destroyed... such destroyed objects won't run an OnContainerChanged event. | ||
*This event should only be relied upon for single objects. Moving stacked objects or objects from a stack will not always cause the event to fire. See [http://forums.bethsoft.com/topic/1349382-event-in-script-attached-to-misc-item-only-firing-once/ this thread] on the official Creation Kit forum for more information. | *This event should only be relied upon for single objects. Moving stacked objects or objects from a stack will not always cause the event to fire. See [http://forums.bethsoft.com/topic/1349382-event-in-script-attached-to-misc-item-only-firing-once/ this thread] on the official Creation Kit forum for more information. | ||
*The "stacked" problem is caused because OnContainerChanged listens to ObjectReferences instead of Forms. All stacked items in your Inventory are Forms, no ObjectReferences. | |||
== See Also == | == See Also == | ||
*[[ObjectReference Script]] | *[[ObjectReference Script]] |
Revision as of 03:55, 4 January 2014
Member of: ObjectReference Script
Event called when the object reference enters/leaves/moves between containers.
Syntax
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
Parameters
- akNewContainer: The container this object is entering. If this is None, the object was dropped.
- akOldContainer: The container this object just left. If this is None, the object was picked up.
Examples
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
if akOldContainer && !akNewContainer
Debug.Trace("We have been dropped!")
elseif akNewContainer && !akOldContainer
Debug.Trace("We have been picked up!")
else
Debug.Trace("We have switched containers!")
endIf
endEvent
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
if akNewContainer == Game.GetPlayer()
Debug.Trace("I just got put in the player's inventory!")
endIf
endEvent
Notes
- Once an object has been added to a container it is no longer valid to call functions on it. Functions on self will fail to run with an error.
- Reminder: If you call RemoveItem() on an object and don't give it a destination container it is destroyed... such destroyed objects won't run an OnContainerChanged event.
- This event should only be relied upon for single objects. Moving stacked objects or objects from a stack will not always cause the event to fire. See this thread on the official Creation Kit forum for more information.
- The "stacked" problem is caused because OnContainerChanged listens to ObjectReferences instead of Forms. All stacked items in your Inventory are Forms, no ObjectReferences.