Aller au contenu

Photo

issue with while loop


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
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 .


#2
DM_Vecna

DM_Vecna
  • Members
  • 280 messages

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


#3
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
For the life of me I cannot seem to post code in this forum :(

#4
henesua

henesua
  • Members
  • 3 883 messages
 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/

#5
Failed.Bard

Failed.Bard
  • Members
  • 774 messages
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 .


#6
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
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 :D