logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Perisistent Storage data corruption problem

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
xtrick8



Joined: 31 Jul 2006
Posts: 8
Location: Melbourne, Australia

PostPosted: Mon Jul 31, 2006 1:08    Post subject: Perisistent Storage data corruption problem Reply with quote

Ok I wrote some code for some persistent storage on containers in the Persistent Player housing in my mod and it all works well. I just need to add these two scripts to onopen and onclose. Everything works great, except that every now and then an item gets substituted for something else. I suspect that it is related to some sort of string concatenation in NWNx or in the APS system. Can someone please tell me how I can make this more bullet proof please !


//::///////////////////////////////////////////////
//:: Name "HN_DRAWER_OPEN"
//:://////////////////////////////////////////////
/*
Persistent Storage Cabinet.

Place this file in the Cabinet's OnOpen event.
*/
//:://////////////////////////////////////////////
//:: Created By: Xtrick8
//:: Created On: 27 Jul 2006
//:://////////////////////////////////////////////

#include "aps_include"

void main()
{
int iItem;
int bContinue = TRUE;
object oCreated;
object oSelf = OBJECT_SELF;
string sCase = GetStringRight(GetTag(OBJECT_SELF), 3);
object oChest1 = GetObjectByTag("PCDrawer"+sCase);

// First destroy all the contents of the container
if (GetHasInventory(oSelf) == TRUE) {
object oItem = GetFirstItemInInventory(oSelf);
// destroy everything in the inventory first
while (oItem != OBJECT_INVALID)
{
DestroyObject(oItem);
oItem = GetNextItemInInventory(oSelf);
}
}

while (bContinue)
{
oCreated = GetPersistentObject(oChest1, "Item_" + IntToString(iItem), oChest1);
if (!GetIsObjectValid(oCreated))
bContinue = FALSE;
else
iItem++;
}


SendMessageToPC(GetFirstPC(), "Retrieved " + IntToString(iItem) + " objects from database.");
}


//::///////////////////////////////////////////////
//:: Name "HN_DRAWER_CLOSE"
//:://////////////////////////////////////////////
/*
Persistent Storage Cabinet.

Place this file in the Cabinet's OnClose event.
*/
//:://////////////////////////////////////////////
//:: Created By: Xtrick8
//:: Created On: 27 Jul 2006
//:://////////////////////////////////////////////

#include "aps_include"

void main()
{
int iItem;
object oSelf = OBJECT_SELF;
string sCase = GetStringRight(GetTag(OBJECT_SELF), 3);
object oChest = GetObjectByTag("PCDrawer"+sCase);
object oItem = GetFirstItemInInventory(oChest);

// Delete all entries for this object in the DB
SQLExecDirect("Delete from pwobjdata where tag = '"+"PCDrawer"+sCase+"'");


while (GetIsObjectValid(oItem))
{
SetPersistentObject(oChest, "Item_" + IntToString(iItem), oItem);
oItem = GetNextItemInInventory(oChest);
iItem++;
}

SendMessageToPC(GetFirstPC(), "Stored " + IntToString(iItem) + " objects in database.");
}
_________________
- xtrick8 (Lead Writer for Noreshia)
http://www.noreshia.com/
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group