Page 1 of 1

Persistent Variables

Posted: Wed Aug 13, 2008 1:39 pm
by Teric neDhalir
Following on from various discussions about alignment/reputation and dynamic statics I'm interested to try some scripts including persistent variables. Two questions; To use the functions detailed on the Wiki do you need an include in your script; and are you encouraging such things or would you rather the database was left alone?
Cheers,
Teric

Posted: Wed Aug 13, 2008 9:09 pm
by indio
This is to be used in a conversation in Actions Taken (hit refresh so you can set the variable name and value).

Code: Select all

#include "ginc_param_const"
#include "ginc_var_ops"
#include "acr_db_persist_i"

void main(string sVariable, string sChange, string sTarget)
{
    object oPC = GetPCSpeaker();
	if (GetIsObjectValid(oPC) == FALSE) 
		PrintString("ga_local_int: " + sTarget + " is invalid");

	int nOldValue = ACR_GetPersistentInt(oPC, sVariable);
	int nNewValue = CalcNewIntValue(nOldValue, sChange);

	ACR_SetPersistentInt(oPC, sVariable, nNewValue, 0);
	
    //PrintString(sTarget + "'s variable " + sVariable + " is now set to " + IntToString(nNewValue) );
}
And this is the Text Appears When version:

Code: Select all

#include "ginc_var_ops"
#include "acr_db_persist_i"

int StartingConditional(string sVariable, string sCheck)

{
	object oPC = GetPCSpeaker();	
	int nValue = ACR_GetPersistentInt(oPC, sVariable);
    int iRet = CompareInts(nValue, sCheck);

    //PrintString ("gc_global_int: nValue = " + IntToString(nValue) + ",  sCheck = " + sCheck + " -- return val: " + IntToString(iRet));
    return (iRet);
}
But AL will have the definitive method of doing it. This is just the way I do it.