Difference between revisions of "Walking Through Inventory Items"

no edit summary
imported>Haama
m (Walking an Inventory moved to Walking through Items in an Inventory: Easier to understand name)
imported>TheNiceOne
 
(16 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
  Goto
Loop</pre>
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
   Goto
   set invPos to invPos + 1
endif</pre>
Loop</pre>


==Notes==
==Notes==
Line 44: Line 46:
  set InvObjCount to (pCont.GetItemCount pInvObj)
  set InvObjCount to (pCont.GetItemCount pInvObj)
</ul>
</ul>
==See Also==
*[[GetInventoryObject]]
*[[GetNumItems]]
*[[While]]


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