Aller au contenu

Photo

SetCampaing weirdness


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

#1
Shadooow

Shadooow
  • Members
  • 4 470 messages

I needed to store items in store to database so I realized I will need some kind of structure to remove/add items on the fly and load them all after restart. Since I need to store an actual item and not resref, I cant use a list of resrefs at all, thus I realized I will need to use my list Ive did. But that one isnt persistent so I started scripting.

 

Its all working except one weird issue. The first item I store will not raise a "number_of_items" variable, this is sName+"_M", I tried to debug it and its even more weird because after setting the variable to 1, I can read it back and it returns 1. But when I store next item, this variable is 0 again! I dont get it. There is no other script messing with this variable, and while this failed for the first time, third, fourth and more items are working fine and the variable is increasing by 1 as expected, but not the first.

 

Here is code

 

const string LIST_ELEMENTS_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZáâäăćçéčëęíěîďóöôđúüý!#$%&()*+,-./:;<=>?@_~|{}[\]÷^`¦Ç'¶»¦¤ÁÂÄÇÉËÍÎÓÔÖ×ÚÜÝßĂĄĆČĎĘĚĹ弣ŃŇŐŔŘŚŞŠŢŮŰ";

 

string GetFirstUnusedChar(string sName)//pseudo-list private function
{
string sChar, pool = GetCampaignString("PERSISTENTLIST",sName+"_P");
 if(pool != "")
 {
 SetCampaignString("PERSISTENTLIST",sName+"_P",GetStringRight(pool,GetStringLength(pool)-2));
 return GetStringLeft(pool,2);
 }
int max = GetCampaignInt("PERSISTENTLIST",sName+"_M");//here it shows 0 for the second time and 1 for the third time
SetCampaignInt("PERSISTENTLIST",sName+"_M",max+1);
int test = GetCampaignInt("PERSISTENTLIST",sName+"_M");//here it shows 1 for the first time and 1 for second time
int y = max/150;
return GetSubString(LIST_ELEMENTS_ALPHABET,y,1)+GetSubString(LIST_ELEMENTS_ALPHABET,max-y*150,1);
}

string ListAddElement(string sName)
{
string sList = GetCampaignString("PERSISTENTLIST",sName);
string sElement = GetFirstUnusedChar(sName);
SetCampaignString("PERSISTENTLIST",sName,sList+sElement);
return sElement;
}

script for adding item into store looks like this:


 

string  sElement = ListAddElement("LIST_PERSSTORE");
StoreCampaignObject("PERSSTORE",sElement,oItem);

database after first pass:

 

PERSISTENTLIST

wakeupneo type_int 1

LIST_PERSSTORE type_string "00"

 

PERSSTORE

00 type_object *object_data_of_item1*

 

Note: expected LIST_PERSSTORE_M type_int 1 is missing!

 

database after second pass:

 

PERSISTENTLIST

wakeupneo type_int 1

LIST_PERSSTORE type_string "0000"

LIST_PERSSTORE_M type_int 1

 

PERSSTORE

00 type_object *object_data_of_item2* <= here its messed up now because it has same variable name

 

database after third pass:

 

PERSISTENTLIST

wakeupneo type_int 1

LIST_PERSSTORE type_string "000001"

LIST_PERSSTORE_M type_int 2

 

PERSSTORE

00 type_object *object_data_of_item2*

01 type_object *object_data_of_item3*

 

 

Note, the "wakeupneo" is a test variable Im setting in order to create database because after this bug Im always deleting them and starting from scratch, but this didnt help at all, wakeupneo is inserted into database and database is created but the bug with LIST_PERSSTORE_M continues.

 

Did anyone else encountered this? Any ideas what to do? Im normally working with nwnx, but I am just making prototype for now and need it working before I will rewrite it for nwnx.



#2
Shadooow

Shadooow
  • Members
  • 4 470 messages

solution found, yet mystery not expained

 

I tried setting SetCampaignInt twice, I tried use String instead of Int but to no avail

 

then I tried to store the integer under different name instead of sName+"_M" I choosed "M_"+sName and it worked.

 

Ie. instead of "LIST_PERSSTORE_M" "M_LIST_PERSSTORE" where the second variable was "LIST_PERSSTORE"

 

it looks there is something more than limit of 32 chars on varname, I think you cant use same variable name for different variable types, and possibly you cant store similar variable name like "LIST_PERSSTORE" and "LIST_PERSSTORE_M" without issues.

 

EDIT. setting "LIST_PERSSTORE_MAX" resulted in same issue


  • Squatting Monk aime ceci

#3
henesua

henesua
  • Members
  • 3 878 messages

I did not know about the similar variable names being a problem, but problems with using the same name for different types is a known issue (one of the things solved by NBDE).



#4
Squatting Monk

Squatting Monk
  • Members
  • 446 messages

From the Lexicon entry for SetCampaignString():

 

If an object is specified for oPlayer, it is possible to have more than one variable with the same name. However, it has not yet been rigourously tested, and it may be a good idea to use unique variable names anyway. 


Remember: sVarName has a limit of 32 characters, while SetLocal's do not have this limit, the database does, and so adding lots of variable strings together may result in problems!