Difference between revisions of "Walking Through Inventory Items"
Walking Through Inventory Items (edit)
Revision as of 04:29, 15 February 2011
, 04:29, 15 February 2011no edit summary
imported>Haama m (words) |
imported>TheNiceOne |
||
(11 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
'''{{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 | #From the end to the beginning - Easier to use with RemoveItem | ||
#From beginning to end | #From beginning to end | ||
==From the End to the Beginning== | ==From the End to the Beginning== | ||
<pre>short | <pre>short invPos | ||
ref pInvObj | ref pInvObj | ||
ref pCont | ref pCont | ||
... | ... | ||
set pCont to YourDesiredContainer | set pCont to YourDesiredContainer | ||
set | set invPos to pCont.GetNumItems | ||
While invPos > 0 | |||
set invPos to (invPos - 1) | |||
set | set pInvObj to (pCont.GetInventoryObject invPos) | ||
set pInvObj to (pCont.GetInventoryObject | |||
;Do whatever you want to do | ;Do whatever you want to do | ||
Loop</pre> | |||
==From the Beginning to the End== | ==From the Beginning to the End== | ||
<pre>short | <pre>short invPos | ||
short invCount | |||
ref pInvObj | ref pInvObj | ||
ref pCont | ref pCont | ||
... | ... | ||
set pCont to YourDesiredContainer | set pCont to YourDesiredContainer | ||
set | set invPos to 0 | ||
set invCount to pCont.GetNumItems | |||
set | While invPos < invCount | ||
set pInvObj to (pCont.GetInventoryObject invPos) | |||
set | |||
;Do whatever you want to do | ;Do whatever you want to do | ||
set invPos to invPos + 1 | |||
Loop</pre> | |||
==Notes== | ==Notes== | ||
Line 44: | 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) | ||
</ul> | </ul> | ||
==See Also== | ==See Also== | ||
*[[GetInventoryObject]] | *[[GetInventoryObject]] | ||
*[[GetNumItems]] | *[[GetNumItems]] | ||
*[[While]] | |||
[[Category:Useful Code]] | [[Category:Useful Code]] | ||
[[Category:Standardized Snippets]] | [[Category:Standardized Snippets]] |