Difference between revisions of "Walking Through Inventory Items"

no edit summary
imported>Haama
(Created)
 
imported>TheNiceOne
 
(19 intermediate revisions by 6 users not shown)
Line 1: Line 1:
There are 2 ways to walk the inventory:
__NOTOC__
#From the end to the beginning - Easier to use with RemoveItem, but slower
 
#From beginning to end - faster
'''{{ReqOBSE}}'''
 
There are two ways to walk an inventory:
#From the end to the beginning - Easier to use with RemoveItem
#From beginning to end


==From the End to the Beginning==
==From the End to the Beginning==
<pre>short InvPos
<pre>short invPos
ref pInvObj
ref pInvObj
ref pCont
ref pCont
...
...
set pCont to YourDesiredContainer
set pCont to YourDesiredContainer
set InvPos to pCont.GetNumItems
set invPos to pCont.GetNumItems
Label
While invPos > 0
if InvPos
   set invPos to (invPos - 1)
   set InvPos to (InvPos - 1)
   set pInvObj to (pCont.GetInventoryObject invPos)
   set pInvObj to (pCont.GetInventoryObject InvPos)
   ;Do whatever you want to do
   ;Do whatever you want to do
  ;You can run tests such as
Loop</pre>
    ;if (IsQuestItem pInvObj)
    ;if (pInvObj == Apple)
  Goto
endif</pre>


==From the Beginning to the End==
==From the Beginning to the End==
<pre>short InvPos
<pre>short invPos
short invCount
ref pInvObj
ref pInvObj
ref pCont
ref pCont
...
...
set pCont to YourDesiredContainer
set pCont to YourDesiredContainer
set InvPos to 0
set invPos to 0
Label
set invCount to pCont.GetNumItems
set pInvObj to (pCont.GetInventoryObject InvPos)
While invPos < invCount
if pInvObj
   set pInvObj to (pCont.GetInventoryObject invPos)
   set InvPos to (InvPos + 1)
   ;Do whatever you want to do
   ;Do whatever you want to do
   ;You can run tests such as
   set invPos to invPos + 1
    ;if (IsQuestItem pInvObj)
Loop</pre>
    ;if (pInvObj == Apple)
  Goto
endif</pre>


==Notes==
==Notes==
*[[GetInventoryObject]] returns the base object FormID. It can't be used when a reference should be used. The information returned about it (i.e., using [[GetSoulLevel]]) will be about the base object and not necessarily each object in the player's inventory. That is, if the player has 2 petty soul gems, one filled and the other empty and you use [[GetSoulLevel]] it will return the same for both (empty).
*[[GetInventoryObject]] returns the base object FormID. It can't be used when a reference should be used. The information returned about it (i.e., using [[GetSoulLevel]]) will be about the base object and not necessarily each object in the player's inventory. That is, if the player has 2 petty soul gems, one filled and the other empty and you use [[GetSoulLevel]] it will return the same for both (empty).
*Can be used for both [[Container|containers]] and [[:Category:Actors|actors]].
*Can be used for both [[Container|containers]] and [[:Category:Actors|actors]].
<ul>
<li>Some common things to do with the item</li>
*Run tests such as
if (IsQuestItem pInvObj)
if (pInvObj == Apple)
*Find out how many the player has
set InvObjCount to (pCont.GetItemCount pInvObj)
</ul>
==See Also==
*[[GetInventoryObject]]
*[[GetNumItems]]
*[[While]]


[[Category:Useful Code]]
[[Category:Useful Code]]
[[Category:Standardized Tutorial Snippets]]
[[Category:Standardized Snippets]]
Anonymous user