View previous topic :: View next topic |
Author |
Message |
Urlord
Joined: 17 Nov 2006 Posts: 122
|
Posted: Sun Sep 16, 2007 2:27 Post subject: Loop Brain Fart |
|
|
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 |
|
|
Dusty_Monk
Joined: 14 Aug 2007 Posts: 3
|
Posted: Sun Sep 16, 2007 9:27 Post subject: |
|
|
If RestorePersistentFarmingData() or GrowPlants() access the database it could break the loop. |
|
Back to top |
|
|
Urlord
Joined: 17 Nov 2006 Posts: 122
|
Posted: Sun Sep 16, 2007 15:31 Post subject: |
|
|
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 |
|
|
Dusty_Monk
Joined: 14 Aug 2007 Posts: 3
|
Posted: Sun Sep 16, 2007 22:33 Post subject: |
|
|
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 |
|
|
Urlord
Joined: 17 Nov 2006 Posts: 122
|
|
Back to top |
|
|
|