Author Topic: Persistent global variables  (Read 374 times)

Legacy_Grani

  • Hero Member
  • *****
  • Posts: 1040
  • Karma: +0/-0
Persistent global variables
« on: October 11, 2014, 11:29:41 am »


               

I've only started learning about database scripting and have been wondering how to set and retrieve global variables stored this way.


As far as I've read about it, SetCampaignInt and GetCampaignInt (or string or whatever) can only be used to persistently store and retrieve variables stored on PCs.


 


So how can global variables be stored persistently?



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Persistent global variables
« Reply #1 on: October 11, 2014, 02:45:19 pm »


               

i dont really think that storing on PC work as well, so the workaround is unique varname and store on OBJECT_INVALID



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Persistent global variables
« Reply #2 on: October 11, 2014, 02:48:53 pm »


               

Your use of terminology is a little confusing so I am not clear what you need to achieve.


 


But the functions you mention provide persistence of data beyond the scope of the module allowing the module to be shutdown and another loaded or even the same module to be loaded again - no save game required.


 


Most importantly you should use the lexicon when you have specific questions about a function. Example: SetCampaignInt


 


-edit-


And even more importantly, if these are the kinds of functions you want to use, I suggest using Knat's wrapper for them:


NBDE



               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Persistent global variables
« Reply #3 on: October 20, 2014, 12:00:04 pm »


               


I've only started learning about database scripting and have been wondering how to set and retrieve global variables stored this way.


As far as I've read about it, SetCampaignInt and GetCampaignInt (or string or whatever) can only be used to persistently store and retrieve variables stored on PCs.


 


So how can global variables be stored persistently?




 


The Function SetCapaignInt/Float/String etc & GetCampaign....  both store everything persistently into a database, NOT on the PC...


 


If you store anything on the PC, if it's in single player game, then it will NOT stick to them if they start a new game, but I'm pretty sure that variables stick when loading a saved game.  Online (Server or LAN Game), the variables always stick to (Stay with) the PC unless you are hosting a local vault, then the variables will NOT stick on the PC, because each time they load a character it will not have any variables on it...


 


I use to place variables on an item in the PC's inventory, the only problem with this is, you have to loop through the inventory of the PC to get the item, and that can run into server issues if the PC's inventory becomes bloated.  (Which is often the case)


 


The NWN Database is slow & clonky, it doesn't store pesistent locations efficiently (as sometimes it will indeed be wrong), and that's an issue....


 


I haven't tried what the above poster recommended, but nwnx2 + aps seems to work just fine for most servers...


 


Personally, I'm ready to begin my own database, but alas I don't know how to code outside of the game, unfortunately, otherwise I'd put everything in an XML document, which can Store/Retrieve 10,000 entries in a fraction of a second!


               
               

               
            

Legacy_EzRemake

  • Full Member
  • ***
  • Posts: 220
  • Karma: +0/-0
Persistent global variables
« Reply #4 on: October 27, 2014, 04:11:23 am »


               

Create an undroppable item on the PC, this will be your 'data base item' that will store variables.


 


When you want a PC to have a variable forever, you apply the variable to the database item, not the pc itself.


 


**EDIT: Just realized you were referring to globals, not locals. My bad. I'll leave the example anyways, as maybe a similar method would work? I've never used globals to be honest so I can't help you. It probably would have been suggested by now if it would have.


 


Example


 


 


object oPC = GetEnteringObject();

object oStorage = GetItemPossessedBy(oPC, "StorageItemTag");


 


int iIntro = GetLocalInt(oStorage, "Intro");


 


if(iIntro == 0){


    SetLocalInt(oStorage, "Intro", 1);

    }