KublaKhan1797 asked a question about variable scope on the official boards, and ScarfaceDM gave a nice summary:
A standard variable defined outside (and above) any function or void main will be global within that script, a standard variable defined within a function or void main will not be global within that script, it will be usable within the function or void main that it was defined in.
A local variable is stored on an object and is retrievable from any script as long as it exists, they are not persistent unless stored on items in a PCs inventory and then the PCs character exported.
A global variable is not persistent in any way, it is simply 'global', it is not stored on any object thus making it retrievable via its sVarName and not from an object.
A campaign variable is stored in the database folder in your NWN2 directory and also not on any object, and is persistent and retrievable from any script as long as it exists.
The thread is here:
http://nwn2forums.bioware.com/forums/viewtopic.html?topic=539873&forum=1...
These get get saved to the Bioware Database, which is included in NWN2. They can be accessed via the SetCampaign* and GetCampaign* functions. This is a physical write to the hard drive, and can bog down servers if there are a lot of requests happening at once.
It is worth noting that variable names cannot be longer than 32 characters, or the setting of the variable will fail.
A good system for managing campaign variables is Knat's NBDE.
Globals get saved to a globals.xml file that gets placed in your save game directory when you save the game. You can set and get global variables with the SetGlobal* and GetGlobal* functions.
These variables exist at a level similar to the campaign folder, meaning they exist in the context of a saved game and can cross from one module to another. They are not physically written to the xml file until a save happens, however.
A good way to check that your variables are getting saved correctly is to save the game an open the file.
One important thing to note is that global variable names can have spaces, but they cannot be more than 32 characters long.