First time using DB functions, so please forgive me if this is elementary.
My ultimate goal is to be able to pass variables and items persistently between characters on the same ‘account’ (via either GetPCPlayerName or GetPublicCDKey).
My thought was to pass an item, with the variables I need stored on it, between characters. It would be easy enough to modify a persistent storage chest system to accomplish this. But I’m not sure if items maintain local variables when passed through the database.
I added code to my Mod_OnEnter script to test that. Problem is, it never seems to retrieve a valid object. It creates the campaign token in my inventory, reports it created it, then reports it stored it. I exit and return with the same character, and get the same output (instead of telling me the token has been retrieved and reporting the value of the stored variable, as it should). So… it’s always returning OBJECT_INVALID.
Would like to understand what is wrong here - I’m sure it’s probably something simple I’m missing.
Am also open to suggestions for implementing persistent variable passing across multiple chars on the same player account. This is for an account-wide achievement system that would not need to be accessed often during play. I had hoped to be able to store all variables on an item and do a single DB transaction with the item instead of storing all the variables separately in the DB, but don’t have enough experience with the DB functionality (or it’s resource intensiveness) to know what’s best practice.
void main()
{
object oPC = GetEnteringObject();
// exit script if entering object is not a PC
if (!GetIsPC(oPC)) return;
// TESTING - persistent variables on items passed through DB
object oCampaignToken = RetrieveCampaignObject("dddcampaign", "campaigntoken", GetLocation(oPC), oPC);
if (oCampaignToken == OBJECT_INVALID)
{
DestroyCampaignDatabase("dddcampaign");
oCampaignToken = CreateItemOnObject("campaigntoken", oPC);
FloatingTextStringOnCreature("Campaign Token Created", oPC);
SetLocalInt(oCampaignToken, "testvalue", 5);
if (StoreCampaignObject("dddcampaign", "campaigntoken", oCampaignToken))
FloatingTextStringOnCreature("Campaign Token Stored", oPC);
}
else
{
int iTV = GetLocalInt(oCampaignToken, "testvalue");
FloatingTextStringOnCreature("Campaign Token Retrieved", oPC);
FloatingTextStringOnCreature(IntToString(iTV), oPC);
}