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 
 
Getting Multiple Rows one at a time
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support
View previous topic :: View next topic  
Author Message
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Fri Jun 22, 2007 20:35    Post subject: Getting Multiple Rows one at a time Reply with quote

Ok here is my code:

Code:


    sSQL = "SELECT WaypointTag,MobResRef,MobTag,IsBoss,SpawnOnlyAtNight,DespawnAtDayBreak,SpawnOnlyDuringDay,DespawnAtTwilight,SpawnChance FROM Spawn_Data WHERE AreaTag='" + GetTag(oArea) + "'";
    SQLExecDirect(sSQL);

    while(SQLFetch() == SQL_SUCCESS)
    {     
      
         
   
      SpeakString("Current Spawn Info: ", TALKVOLUME_SHOUT);
        sWaypointTag = SQLGetData(1);   //this is the first datafield returned by the query
      SpeakString("WaypointTag: "+sWaypointTag, TALKVOLUME_SHOUT);
      sMobResRef = SQLGetData(2);
      SpeakString("MobResRef: "+sMobResRef, TALKVOLUME_SHOUT);
      sMobTag = SQLGetData(3);
      SpeakString("MobTag: "+sMobTag, TALKVOLUME_SHOUT);
      
      iIsBoss = StringToInt(SQLGetData(4));
      iSpawnOnlyAtNight = StringToInt(SQLGetData(5));
      iDespawnAtDayBreak = StringToInt(SQLGetData(6));
      iSpawnOnlyDuringDay = StringToInt(SQLGetData(7));
      iDespawnAtTwilight = StringToInt(SQLGetData(8));
      iSpawnChance = StringToInt(SQLGetData(9));
      
      //see if the mob exists, if so bail
      if(GetObjectByTag(sMobTag) != OBJECT_INVALID)
      {
         SpeakString("Mob Exists!", TALKVOLUME_SHOUT);
      }
      else
      {
      
         //everything checks, spawn that bitch!
         SpeakString("everything checks, spawn that bitch!!", TALKVOLUME_SHOUT);

         CreateObject(OBJECT_TYPE_CREATURE,sMobResRef,GetLocation(GetWaypointByTag(sWaypointTag)),TRUE, sMobTag);
      }
    }


Ok now, what this is supose to do (and does in my mysql gui client) is get all the mob spawn info from the database for the area. However, it only gets the first row. Then the second time the function is called, the second row is fetched, and so on. But if say the mob is not there, it creates that creature and then stops till the code is called again... so ummm... how do i make it so i can do all my spawning at once instead of in say 7 callings of this code...

this is using 1.08 2 btw
Back to top
View user's profile Send private message
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Sat Jun 23, 2007 2:48    Post subject: Reply with quote

fixed, just removed the == SQL_SUCCESS and it now loops till it has no more rows to look at Smile
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Sat Jun 23, 2007 10:26    Post subject: Reply with quote

utimagus wrote:
fixed, just removed the == SQL_SUCCESS and it now loops till it has no more rows to look at Smile


Yes, but now the question is /why/ Wink Only thing I can think of is that the function is not returning SQL_SUCCESS on a successful result, unless I'm missing something obvious.
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Sat Jun 23, 2007 18:30    Post subject: Reply with quote

i guess it isn't, i dun know... but in order for it to keep looping, something that equals 1 must be returned... just wierd i tells ya...
Back to top
View user's profile Send private message
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Mon Jun 25, 2007 15:26    Post subject: Reply with quote

ok it just stopped working and is doing what it did before... anyone have a clue why?
Back to top
View user's profile Send private message
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Mon Jun 25, 2007 15:47    Post subject: Reply with quote

Code:
    //get the information of all the mobs to spawn in the area
    sSQL = "SELECT WaypointTag,MobResRef,MobTag,IsBoss,SpawnOnlyAtNight,DespawnAtDayBreak,SpawnOnlyDuringDay,DespawnAtTwilight,SpawnChance FROM Spawn_Data WHERE AreaTag='" + GetTag(oArea) + "'";
    SQLExecDirect(sSQL);

   //cycle throguh the entries till we are out of them
    while(iCount < 8)
    {     
      SQLFetch();
      
        sWaypointTag = SQLGetData(1);   //this is the first datafield returned by the query
      sMobResRef = SQLGetData(2);
      
      sMobTag = SQLGetData(3);
      
      
      iIsBoss = StringToInt(SQLGetData(4));
      iSpawnOnlyAtNight = StringToInt(SQLGetData(5));
      iDespawnAtDayBreak = StringToInt(SQLGetData(6));
      iSpawnOnlyDuringDay = StringToInt(SQLGetData(7));
      iDespawnAtTwilight = StringToInt(SQLGetData(8));
      iSpawnChance = StringToInt(SQLGetData(9));
      
      //see if the mob exists, if so bail
      if(GetObjectByTag(sMobTag) != OBJECT_INVALID)
      {
         
      }else
   
      //if the chance of spawn is not enough, bail
      if(Random(100) > iSpawnChance)
      {
         
      }else
         
      //if it is daytime, and the mob is supose to spawn at night, bail
      if(GetTimeHour() > iDayBreak && GetTimeHour() < iTwilight && iSpawnOnlyAtNight)
      {
         
      }else
         
      //if it is nighttime, and the mob is supose to spawn during the day, bail
      if(GetTimeHour() < iDayBreak && GetTimeHour() > iTwilight && iSpawnOnlyDuringDay)
      {
         
      }else
         
      //if the Boss_Spawn Timer is greater than 1 and the mob is a boss, bail
      if(GetTimer("Boss_Spawn") > 1 && iIsBoss)
      {
         
         
      }else
      {
      
         //everything checks, spawn that bitch!
         CreateObject(OBJECT_TYPE_CREATURE,sMobResRef,GetLocation(GetWaypointByTag(sWaypointTag)),TRUE, sMobTag);
      }
      iCount++;
    }
   SpeakString("Exited loop! Fetch = " + IntToString(iMore), TALKVOLUME_SHOUT);
   SpeakString("Loop Amount = " + IntToString(iCount), TALKVOLUME_SHOUT);


ok i tried this code too, and only one spawns, but says it went through 8 times... i know the if else' are not to blame as the data for each are identical save for the tags which are set accordingly... i am just really flabbergasted at this... oh and it said that at an 8 count that SQLFetch returned a 1...

gonna try having a loop inside a loop to see if that helps...
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Mon Jun 25, 2007 16:25    Post subject: Reply with quote

If the issue is occurring with the hard-coded statement, there is definitely an issue in the code or data that is preventing it from working, since it is extremely unlikely that they nwscript "while" statement is going to abruptly stop working. When debugging, it's always better to break something down into a more simple structure rather than making it more complex in a hit or miss approach.

Try first adding some PrintStrings into each if/else so you can be 100% sure of what the script is doing. It also won't hurt to log out the actual data returned from the query itself.
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Tue Jun 26, 2007 0:05    Post subject: Reply with quote

Please add the contents of the relevant portion of xp_mysql.txt or xp_sqlite.txt (depending on whatever DB you are using) with loglevel = 2 as well.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Tue Jun 26, 2007 2:35    Post subject: Reply with quote

* Executing: SELECT SpawnFlag FROM Territory_Data WHERE AreaTag='Valdedomus'
* Returning: 1 (column 0)
* Executing: SELECT WaypointTag,MobResRef,MobTag,IsBoss,SpawnOnlyAtNight,DespawnAtDayBreak,SpawnOnlyDuringDay,DespawnAtTwilight,SpawnChance FROM Spawn_Data WHERE AreaTag='Valdedomus'
* Returning: spawn_valdedomus_wilddog1 (column 0)
* Returning: krs_badger01 (column 1)
* Returning: valdedomus_wilddog1 (column 2)
* Returning: 0 (column 3)
* Returning: 0 (column 4)
* Returning: 0 (column 5)
* Returning: 0 (column 6)
* Returning: 0 (column 7)
* Returning: 100 (column Cool

there is the log of the query
Back to top
View user's profile Send private message
Grinning Fool



Joined: 12 Feb 2005
Posts: 264

PostPosted: Tue Jun 26, 2007 3:10    Post subject: Reply with quote

The data itself looks good; next thing to check is the code. Add those Print/SpeakStrings especially in the part where you do the createobject.
SpeakString("Resref: " + sMobResRef);
SpeakString("SPAWN POINT: " + GetName(GetWaypointByTag(sWaypointTag));
object creature = CreateObject(OBJECT_TYPE_CREATURE,sMobResRef,GetLocation(GetWaypointByTag(sWaypointTag)),TRUE, sMobTag);
SpeakString("Creature: " + GetName(creature);


The thing is, without some additional debugging statements, you don't know which parts of your code are actually executing. Adding the above will make let you know that you /are/ reachiing the CreateObject command, and it will display key info (such as if the waypoint name is valid).

Edit: is that the entire log? ie, first row only?
_________________
Khalidine, a NWN2 persistent world

Looking for volunteers.
Back to top
View user's profile Send private message
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Tue Jun 26, 2007 3:20    Post subject: Reply with quote

it only runs that once i've seen... sooo either the loop isn't looping anymore (had debug messages before and it worked till i took them out) or i pooched my loop...which as it is a while, it wouldn't fetch the first row returned if it wasn't entering the loop as 1 mob is spawned at a time... so on the first call of that function a mob is spawned, then on the second call the second is spawned, and so on.
Back to top
View user's profile Send private message
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Tue Jun 26, 2007 5:15    Post subject: Reply with quote

if you want the entire log i can post it...but it is VERY long... but the fetch befre that was to see if it was time to spawn, and after was a timer update.
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Tue Jun 26, 2007 10:49    Post subject: Reply with quote

The way I understand it so far, is that your SELECT statement returns multiple rows when ran manually, but only one row when run through NWNX. Do you have a chance to try your code with NWNX 1.07 ?
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Tue Jun 26, 2007 15:00    Post subject: Reply with quote

yeah i can try 1.07. will post my results and the log.
Back to top
View user's profile Send private message
utimagus



Joined: 22 Jun 2007
Posts: 20

PostPosted: Tue Jun 26, 2007 15:28    Post subject: Reply with quote

* Executing: SELECT SpawnFlag FROM Territory_Data WHERE AreaTag='Valdedomus'
* Returning: 1 (column 0)
* Executing: SELECT WaypointTag,MobResRef,MobTag,IsBoss,SpawnOnlyAtNight,DespawnAtDayBreak,SpawnOnlyDuringDay,DespawnAtTwilight,SpawnChance FROM Spawn_Data WHERE AreaTag='Valdedomus'
* Returning: spawn_valdedomus_wilddog1 (column 0)
* Returning: krs_badger01 (column 1)
* Returning: valdedomus_wilddog1 (column 2)
* Returning: 0 (column 3)
* Returning: 0 (column 4)
* Returning: 0 (column 5)
* Returning: 0 (column 6)
* Returning: 0 (column 7)
* Returning: 100 (column Cool
* Executing: SELECT LastKnownTime FROM Timers WHERE TimerName='Boss_Spawn'
* Returning: 156 (column 0)
* Executing: UPDATE Territory_Data SET SpawnFlag=0 WHERE AreaTag='Valdedomus'

same thing happens and here is the log.

And yes pap, you are correct in what you understand Smile

Also, I am running NWN2 1.06 Final if that means anything...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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