Walking Through Inventory Items
Revision as of 04:14, 15 February 2011 by imported>TheNiceOne (→From the End to the Beginning)
Requires Oblivion Script Extender
Download
There are two ways to walk an inventory:
- From the end to the beginning - Easier to use with RemoveItem, but slower
- From beginning to end - faster
From the End to the Beginning
short invPos ref pInvObj ref pCont ... set pCont to YourDesiredContainer set invPos to pCont.GetNumItems While invPos > 0 set invPos to (invPos - 1) set pInvObj to (pCont.GetInventoryObject invPos) ;Do whatever you want to do Loop
From the Beginning to the End
short InvPos ref pInvObj ref pCont ... set pCont to YourDesiredContainer set InvPos to 0 Label set pInvObj to (pCont.GetInventoryObject InvPos) if pInvObj set InvPos to (InvPos + 1) ;Do whatever you want to do Goto endif
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).
- Can be used for both containers and actors.
- Some common things to do with the item
- Run tests such as
- Find out how many the player has
- 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.