Container lying about item count?

Post » Tue Jun 11, 2013 6:13 am

Hi! I'm having this weird issue with items added to a container in the Creation Kit not reacting properly to GetItemCount(). I'm using SKSE's GetNumItems() and GetNthForm() functions to scan the contents of a container in another script's OnInit() section and it gives me all the correct values (namely, the items I put into it), but the item counts all evaluate to 0. In fact, the item counts remain 0 until I add or remove an item ingame. How is this possible? I know for a fact that there are 5 items in that chest.

To provide a bit of background: I'm building a system of weapon displays for my player home that directly reflect the contents of a chest (or several chests). I created activators that look like the different weapons (referred to as "displays") and the idea is to enable/disable them based on whether the chest contains the respective weapon. These are the scripts I'm using (they're pretty long):

Abstract base for display scripts:

Spoiler

Concrete display script for weapons (attached to the activators):

Spoiler

Script attached to the container:

Spoiler

As far as I can tell they work as expected if the observed containers are all empty at initialisation. They react appropriatly to items added to or removed from the chests at runtime. What I'd like them to do is reflect the contents of a container that I set up with a few low-value items, so I can preview the system without the player needing to touch anything first. But I cannot get it to work, since for some reason my scripts completely ignore any items added to the container in the CK prior to the moment the player adds or removes an item for the first time.

Is this common behaviour of containers? Is there some initialisation procedure I'm missing? I apologise if this is a well-known issue, but I couldn't find anything about it in the official Wiki. Also, general advice on my scripts would be welcome, I'm not entirely sure I'm doing this in the most efficient manner. Actually I'm amazed I got it to (partially) work at all :D

User avatar
Jinx Sykes
 
Posts: 3501
Joined: Sat Jan 20, 2007 11:12 pm

Return to V - Skyrim