Difference between revisions of "Walking Through Inventory Items"

248 bytes removed ,  04:29, 15 February 2011
no edit summary
imported>KyleWollaston
imported>TheNiceOne
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__


<font color="red" size="3">Requires <b>[http://cs.elderscrolls.com/constwiki/index.php/Category:Oblivion_Script_Extender OBSE]</b></font>
'''{{ReqOBSE}}'''


There are two ways to walk an inventory:
There are two ways to walk an inventory:
#From the end to the beginning - Easier to use with RemoveItem, but slower
#From the end to the beginning - Easier to use with RemoveItem
#From beginning to end - faster
#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 47: Line 45:
*Find out how many the player has
*Find out how many the player has
  set InvObjCount to (pCont.GetItemCount pInvObj)
  set InvObjCount to (pCont.GetItemCount pInvObj)
<li>If you are using more than 1 Label/Goto in your script you may need to use an ID for them. See [[Label]] or [[GoTo]] for more information.</li>
</ul>
</ul>


==See Also==
==See Also==
*[[GetInventoryObject]]
*[[GetInventoryObject]]
*[[Label]]
*[[GetNumItems]]
*[[GetNumItems]]
*[[While]]


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