Difference between revisions of "User:DavidJCobb"
Jump to navigation
Jump to search
→Scratchpad: PlaceAtMe is safe
imported>DavidJCobb (→Scratchpad: dropped item handling sucks) |
imported>DavidJCobb (→Scratchpad: PlaceAtMe is safe) |
||
Line 20: | Line 20: | ||
**OnInit is neither reliable nor safe. It fires twice: once when the item is first added to the player's inventory, and again while the item is being dropped. In the second case, OnInit may (and usually will) fire before the item is actually safe to work with, i.e. ''while'' it's ''becoming'' a safe ObjectReference. In essence, the item will be an ObjectReference script wrapping a null entity; it doesn't equal None and you can cast it to ObjectReference and Form, but you can't call methods on it. | **OnInit is neither reliable nor safe. It fires twice: once when the item is first added to the player's inventory, and again while the item is being dropped. In the second case, OnInit may (and usually will) fire before the item is actually safe to work with, i.e. ''while'' it's ''becoming'' a safe ObjectReference. In essence, the item will be an ObjectReference script wrapping a null entity; it doesn't equal None and you can cast it to ObjectReference and Form, but you can't call methods on it. | ||
**OnLoad is safe but unreliable: when an item (whose base form has scripts) is dropped, Skyrim doesn't attach non-native scripts immediately, so your script may only be attached after the load event is fired. (OnContainerChanged is held until the script is attached; OnLoad is not.) | **OnLoad is safe but unreliable: when an item (whose base form has scripts) is dropped, Skyrim doesn't attach non-native scripts immediately, so your script may only be attached after the load event is fired. (OnContainerChanged is held until the script is attached; OnLoad is not.) | ||
***This delay doesn't seem to affect items spawned with PlaceAtMe. It seems to only affect items that the player has dropped. | |||
**OnItemRemoved can work, but due to the delay in attaching scripts, one must be careful. You won't be able to cast the akItemReference to the script that it ''should'' have until that script is attached. Thankfully, you can force Skyrim to attach the script immediately by performing certain (any?) concrete actions on the native ObjectReference, e.g. akItemReference.Disable() or even just akItemReference.MoveTo(akItemReference). | **OnItemRemoved can work, but due to the delay in attaching scripts, one must be careful. You won't be able to cast the akItemReference to the script that it ''should'' have until that script is attached. Thankfully, you can force Skyrim to attach the script immediately by performing certain (any?) concrete actions on the native ObjectReference, e.g. akItemReference.Disable() or even just akItemReference.MoveTo(akItemReference). | ||
***So given an item with MyItemScript attached to it, you'd try and cast akItemReference to a MyItemScript. If this fails, you'd do akItemReference.MoveTo(akItemReference) and then try casting again. One of these casts ''should'' succeed if the item is indeed a MyItemScript item; but then, this whole matter is insufficiently documented and I've only had this level of understanding for a day, as of this writing. | ***So given an item with MyItemScript attached to it, you'd try and cast akItemReference to a MyItemScript. If this fails, you'd do akItemReference.MoveTo(akItemReference) and then try casting again. One of these casts ''should'' succeed if the item is indeed a MyItemScript item; but then, this whole matter is insufficiently documented and I've only had this level of understanding for a day, as of this writing. |