In this case I need to access the variable on the NPCs death or during conversation with him/her. I have never used a dialog script, but I don't think it will work since the variable is currently stored on the
object's script in the NPCs inventory.
Anyway, I've taken QQuix's suggestion and just made it into an array.
I am curious about something else: Which of the following is a better scripting practice:
- Adding scripted tokens to every NPC, but only having the script use OnAdd and MenuMode blocks (AFAIK these scripts will only process when the NPC is in the same cell or surrounding cells as the player)
- Having a single quest script with a large array of NPCs constantly iterating
Agree that the first option is better, since you are running menumode only. Not sure if it were gamemode, considering that lots of NPC scripts still run when they are in mid or low level processing.
But, again, you may have other options.
For example, if you don't need to keep track of past encounters with the NPCs, you might just rebuild the array when the player changes cells (http://cs.elderscrolls.com/constwiki/index.php/GetCellChanged).
Otherwise, you may have a master array with all NPCs you have encountered and a small array with the nearby NPCs.
In both cases, the 'active' NPCs array will be very small (a dozen entries, maybe) to iterate frequently and this 'arquitecture' may change the tide toward option 2.