Does it matter where do I store my variables? (Single Player Only module)

Background info: I am a very, very, very basic, primitive, inept scripter. Most of the time I’ve no idea what I’m doing and I copy existing scripts.

So, things are often achieved by checking variables, right? And I store basically all of the quest-related variables I need on the PC: the variables set to mark that the PC has said something, met someone, killed someone, the variables used to keep track of romances, the whole caboodle.

But lately I’ve begun to wonder, whether or not that’s a good practice? It’s simple, and lets me not worry about that side of things, but is it a good idea? I know I can store variables on many other things - NPCs, items, areas… the module itself, too.

How much does it matter?

I store all quest related vars on the PC–or the PCs whole party in case the PC has a friend who’d like to play along as well. I don’t know if that’s the best practice, but it works for me.

You can use:
SetLocalIntOnAll(object, string, int)

The function lives in the following library:
#include “X0_I0_PARTYWIDE”

1 Like

The only real determining factor, if it is a single player mod, is what the variables are for. If you are tracking how many uses a particular placeable has suffered, store it on the placeable. If it based on a certain action for the PC, store it on the PC. If you have an NPC that needs to do certain repeated actions a specific number of times, store it on the NPC or the module.
The real trick is just remembering where that particular variable is stored so you can check it correctly. Often when I started learning scripting, this was where the script would be in error.

1 Like

The only real problem occurs if you rely on variables set on an object that might die or be destroyed.

Best practice is to store variables on the object they refer to, which in SP can equally be the PC or the module for most plot purposes, but might be the area for the current weather, and NPC for whether you’ve spoken to them or not, etc.

A pragmatic consideration is the length of the variable list in Debug mode. The more you put on the PC, the longer the list you have to wade through. On the other hand, if vital plot variables are defined on objects that might not be in the PC’s current area, they’re harder to debug.


Thank you everyone for informative and coherent replies.

Learning is happening!

After a few scripts and variables I found it best to have an excel spreadsheet. A simple list of variables and their stored location. After a while I also had a column for how I was using the variable too.

A little anal but really useful for big mods.