Author Topic: issue with while loop  (Read 324 times)

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
issue with while loop
« on: July 16, 2011, 04:21:37 am »


               void PrimeLootitems()

int nChestNum=1;        
string sItemResref;        
string sItemTag;        
string sItemName;        
string sItemValue;        
object oInv;        
string sChestTag = "ss_t_chest_"+IntToString(nChestNum);        
object oChest = GetObjectByTag(sChestTag);        

        while (oChest != OBJECT_INVALID)      
        {
        oInv = GetFirstItemInInventory(oChest);                
                while (GetIsObjectValid(oInv) == TRUE)              
                {              
                 sItemResref = GetResRef(oInv);              
                 sItemTag = GetTag(oInv);                
                 sItemName = GetName(oInv, FALSE);                
                 sItemValue = IntToString(GetGoldPieceValue(oInv));
                oInv = GetNextItemInInventory(oChest);                
                 }                
                 if (oInv == OBJECT_INVALID)
                 nChestNum++;
            oChest =GetObjectByTag("ss_t_chest_"+IntToString(nChestNum));        
            }
}
               
               

               


                     Modifié par DM_Vecna, 16 juillet 2011 - 03:29 .
                     
                  


            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
issue with while loop
« Reply #1 on: July 16, 2011, 04:24:44 am »


               
               
               

               


                     Modifié par DM_Vecna, 16 juillet 2011 - 03:25 .
                     
                  


            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
issue with while loop
« Reply #2 on: July 16, 2011, 04:25:24 am »


               For the life of me I cannot seem to post code in this forum '<img'>
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
issue with while loop
« Reply #3 on: July 16, 2011, 04:43:12 am »


                You should use the BBCode setting to post code, and keep somewhat decent formatting. But you can also use a site like paste bin
http://pastebin.com/
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
issue with while loop
« Reply #4 on: July 16, 2011, 05:30:39 am »


               What are you doing with the strings after you get them? It looks like you just cycle through the inventories of every chest without ever actually doing anything with the information.
Is it going to be used to populate a database?

Also, what exactly is the issue you're having? TMI error would seem likely if you have quite a few chests and/or items.


  Edit:  I did a quick test, 8 barrels tagged appropriately, 2 items in each barrell, and it cycled through all of them properly.  I assigned the routine to a PC to test and added a debug line to make sure.
  The only change I made, aside from cosmetic ones, was to remove the check before  nChestNum ++; .
It was unneeded, since it would only get to there once oInv was invalid to begin with.


void PrimeLootitems()
{
 int nChestNum = 1;
 string sItemResref, sItemTag, sItemName, sItemValue;
 object oInv;
 string sChestTag = "ss_t_chest_" + IntToString (nChestNum);
 object oChest = GetObjectByTag (sChestTag);
 while (GetIsObjectValid (oChest))
    {
     oInv = GetFirstItemInInventory(oChest);
     while (GetIsObjectValid (oInv))
        {
         sItemResref = GetResRef(oInv);
         sItemTag = GetTag(oInv);
         sItemName = GetName(oInv, FALSE);
         sItemValue = IntToString(GetGoldPieceValue(oInv));
         // Debug Line
         SpeakString (sItemResref + ":" + sItemTag + ":" + sItemName + ":" + sItemValue);
         oInv = GetNextItemInInventory(oChest);
        }
     nChestNum ++;
     oChest = GetObjectByTag("ss_t_chest_" + IntToString(nChestNum));
    }
}
               
               

               


                     Modifié par Failed.Bard, 16 juillet 2011 - 05:00 .
                     
                  


            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
issue with while loop
« Reply #5 on: July 19, 2011, 04:08:10 am »


               Thanks for your help here failed.bard I got the issue fixed. Firstly I wanted the container that the items were stored in and I was able to move that into the loop. Secondly I was writing to a NWNX database and didnt realize I used an apostrophe in the name of the items tracked but had not encoded the special characters. It would have taken me a lot longer to spot those issues without your help plus I cleaned up my script a bit. Thanks again '<img'>