Aller au contenu

Photo

Persistent global variables


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
Grani

Grani
  • Members
  • 558 messages

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?



#2
Shadooow

Shadooow
  • Members
  • 4 471 messages

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



#3
henesua

henesua
  • Members
  • 3 882 messages

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


  • Squatting Monk aime ceci

#4
_Guile

_Guile
  • Members
  • 685 messages

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!



#5
EzRemake

EzRemake
  • Members
  • 118 messages

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);
    }


  • kalbaern aime ceci