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 
 
Loop Brain Fart

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support
View previous topic :: View next topic  
Author Message
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Sun Sep 16, 2007 2:27    Post subject: Loop Brain Fart Reply with quote

Hey Guys,

I used to do this with NWNX2, but I cannot seem to remember how since it has been so long.

I am executing some code like this:
Code:

   string     sSQL;
   location lRowStoneLocation;
   object    oRowStone;
   int       nDataFetch;
   
   sSQL  = "SELECT RowStoneLocation FROM nym_farming";
   SQLExecDirect(sSQL);
   nDataFetch = SQLFetch();
   while(nDataFetch == SQL_SUCCESS) {
      lRowStoneLocation = SQLStringToLocation(SQLGetData(1));
      oRowStone = GetNearestObjectToLocation(OBJECT_TYPE_PLACEABLE, lRowStoneLocation);
      RestorePersistentFarmingData(oRowStone);
      GrowPlants(oRowStone);
      WriteTimestampedLogEntry("Initializing: " + GetTag(oRowStone));
      nDataFetch = SQLFetch();
   }


For some reason, it isn't looping through the record set. The while loop stops after one record when there are several. Can anyone point out my error(s)? I am racking my brain and cannot get it working.
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
Dusty_Monk



Joined: 14 Aug 2007
Posts: 3

PostPosted: Sun Sep 16, 2007 9:27    Post subject: Reply with quote

If RestorePersistentFarmingData() or GrowPlants() access the database it could break the loop.
Back to top
View user's profile Send private message
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Sun Sep 16, 2007 15:31    Post subject: Reply with quote

Dusty_Monk wrote:
If RestorePersistentFarmingData() or GrowPlants() access the database it could break the loop.


RestorePersistentFarmingData() does access the database. So, what is the best practice to get around that?
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
Dusty_Monk



Joined: 14 Aug 2007
Posts: 3

PostPosted: Sun Sep 16, 2007 22:33    Post subject: Reply with quote

Either using DelayCommand, an Action Queue or both.

Code:

void DoStuff(object oRowStone){
   RestorePersistentFarmingData(oRowStone);
   GrowPlants(oRowStone);
   WriteTimestampedLogEntry("Initializing: " + GetTag(oRowStone)); }

...

 while(nDataFetch == SQL_SUCCESS) {
      lRowStoneLocation = SQLStringToLocation(SQLGetData(1));
      oRowStone = GetNearestObjectToLocation(OBJECT_TYPE_PLACEABLE, lRowStoneLocation);
      AssignCommand(GetModule(), ActionDoCommand(DoStuff(oRowStone)));
      nDataFetch = SQLFetch();
   }
Back to top
View user's profile Send private message
Urlord



Joined: 17 Nov 2006
Posts: 122

PostPosted: Mon Sep 17, 2007 3:52    Post subject: Reply with quote

Thanks a bunch. I will try this.
_________________
Jim (aka, Urlord)
Visit the Persistent World of Nymri
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support 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